blob: 3760ed4220802ca4940c916197e5e1157adff197 [file] [log] [blame]
Richard Hughes47ae4f82019-10-02 13:55:04 +01001/*
2 * Copyright (C) 2019 Richard Hughes <richard@hughsie.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1+
5 */
6
7#include "config.h"
8
9#include "fu-common.h"
10#include "fu-srec-firmware.h"
11#include "fu-ihex-firmware.h"
12
13int
14main (int argc, char **argv)
15{
16 g_autofree gchar *str = NULL;
17 g_autoptr(FuFirmware) firmware = NULL;
18 g_autoptr(GBytes) blob = NULL;
19 g_autoptr(GError) error = NULL;
20 gsize sz = 0;
21 const guint8 *buf;
22
23 /* no args */
24 if (argc != 2) {
25 g_printerr ("firmware filename required\n");
26 return 2;
27 }
28
29 /* load firmware */
30 blob = fu_common_get_contents_bytes (argv[1], &error);
31 if (blob == NULL) {
32 g_printerr ("failed to load file: %s\n", error->message);
33 return 1;
34 }
35 buf = g_bytes_get_data (blob, &sz);
36 if (sz < 2) {
37 g_printerr ("firmware invalid\n");
38 return 2;
39 }
40 if (buf[0] == 'S' && buf[1] == '0') {
41 firmware = fu_srec_firmware_new ();
42 } else if (buf[0] == ':') {
43 firmware = fu_ihex_firmware_new ();
44 } else {
45 g_printerr ("firmware invalid type, expected .srec or .hex\n");
46 return 2;
47 }
48 if (!fu_firmware_parse (firmware, blob, FWUPD_INSTALL_FLAG_FORCE, &error))
49 return FALSE;
50 str = fu_firmware_to_string (firmware);
51 g_print ("%s", str);
52 return 0;
53}