Commit Graph

30 Commits

Author SHA1 Message Date
Richard Hughes
0c51630991 Check firmware magic in a more standard way
Some parsers are ignoring the magic when using _FLAG_IGNORE_CHECKSUM
(which is wrong; fuzzers have no problem with enforcing a static prefix)
and other either disregard the offset or check the magic in an unsafe
way. Also, use FWUPD_ERROR_INVALID_FILE consistently for magic failure.

Add a vfunc, and move all the clever code into one place.
2022-07-14 14:48:15 +01:00
Richard Hughes
0491b07a93 Make the FuFirmware->parse() vfunc more helpful
This removes the 100% unused addr_end parameter and explicitly makes
the addr_start into the start offset in more cases.
2022-06-27 15:40:11 -05:00
Richard Hughes
425fedcca1 trivial: Remove fu_byte_array_set_size_full() 2022-06-14 14:36:52 -05:00
Richard Hughes
ed1b13da28 Split out the memory helpers to a new source file 2022-06-14 14:36:52 -05:00
Richard Hughes
4b1313b406 Split out the GByte helpers to a new source file 2022-06-14 14:36:52 -05:00
Richard Hughes
c6581fb7a6 Split out the GByteArray helpers to a new source file 2022-06-14 14:36:52 -05:00
Richard Hughes
f885ab6d2a Allow patching firmware files at known offsets
This allows us to replace the 'dfu-tool replace' with a much more
controlled 'fwupdtool firmware-patch' command that patches at a set of
specific offsets.

Drop in the new functionality into the existing firmware ->write()
vfuncs so that the image headers, footers and/or checksums are correct.
2022-01-05 09:51:45 +00:00
Richard Hughes
52fd89f9ab Add fu_memmem_safe() with fallback code for win32 2021-12-15 12:57:49 +00:00
Mario Limonciello
55de39c077 trivial: reformat the whole tree to match new format 2021-08-24 11:18:40 -05:00
Richard Hughes
a02c1073f2 trivial: Fix up some of the developer docs
And add some missing content as requried.
2021-06-11 09:39:03 +01:00
Mario Limonciello
1e17457b16 Allow building the documentation with gi-docgen and gtk-doc
Until gi-docgen is declared stable support either of them.
This effectively means that hand builds and CI builds will use
gi-docgen, but distro builds use gtk-doc-tools.
2021-06-09 22:21:53 +01:00
Richard Hughes
f4d3a365f1 fmap: Use standard FuFirmware properties 2021-03-15 12:07:30 +00:00
Richard Hughes
52441f28a4 Allow objects to deserialize to XML
This makes a lot more sense; we can parse a firmware and export the same XML
we would use in a .builder.xml file. This allows us to two two things:

 * Check we can round trip from XML -> binary -> XML

 * Using a .builder.xml file we can check ->write() is endian safe
2021-03-15 12:07:30 +00:00
Richard Hughes
408b056984 trivial: Use fu_byte_array_append_bytes() in more places 2021-03-15 09:46:02 +00:00
Richard Hughes
1981c63d58 Remove FuFirmwareImage and just use FuFirmware instead
This allows us to 'nest' firmware formats, and removes a ton of duplication.

The aim here is to deprecate FuFirmwareImage -- it's almost always acting
as a 'child' FuFirmware instance, and even copies most of the vfuncs to allow
custom types. If I'm struggling to work out what should be a FuFirmware and
what should be a FuFirmwareImage then a plugin author has no hope.

For simple payloads we were adding bytes into an image and then the image into
a firmware. This gets really messy when most plugins are treating the FuFirmware
*as* the binary firmware file.

The GBytes saved in the FuFirmware would be considered the payload with the
aim of not using FuFirmwareImage in the single-image case.
2021-03-09 21:14:12 +00:00
Richard Hughes
293ccbf106 fmap: Fix self test failure on PPC64 2021-02-12 10:47:34 +00:00
Richard Hughes
c3ecec575b fmap: Use memmem to find the FMAP signature
Trust glibc to optimize for the binary search, removing a oss-fuzz detected
crash with our bad pointer maths.
2021-02-11 20:27:20 +00:00
Richard Hughes
a14de30153 trivial: Require <string.h> for strlen() and memcpy() 2020-12-14 16:49:03 +00:00
Richard Hughes
72df114793 fmap: Do not assume FuFmapArea.name is NUL terminated 2020-12-11 14:33:50 +00:00
Richard Hughes
fdea9336a6 fmap: Make mixed-endian safe 2020-12-11 14:33:50 +00:00
Richard Hughes
8b99d4f2ec fmap: Use fu_memcpy_safe() to prevent buffer over-read 2020-12-11 14:33:50 +00:00
Richard Hughes
531b8b417f fmap: Fix a critical warning when the FmapArea has zero size 2020-12-10 20:43:54 +00:00
Richard Hughes
976b6afe63 trivial: Allow turning off the FMAP binary search when fuzzing
This speeds up the fuzzing task from 22ms to 33us.
2020-12-09 18:08:08 +00:00
Richard Hughes
84617b6699 fmap: Allow writing and reading the image base 2020-12-09 18:02:07 +00:00
Richard Hughes
5771756f85 fmap: Allow creating test firmware from builder.xml 2020-12-09 18:02:07 +00:00
Richard Hughes
a9060f671c fmap: Correctly check minimum firmware size 2020-12-09 18:02:07 +00:00
Richard Hughes
05e3377d11 trivial: Add fu_common_bytes_new_offset()
This is a safer version of g_bytes_new_from_bytes() which returns a GError
if the offsets are invalid rather than emitting a critical warning.

This prevents a critical warning and potential crash when parsing invalid
bcm57xx firmware.
2020-12-08 20:54:25 +00:00
Richard Hughes
fa595a7334 libfwupdplugin: Do not overwrite GError when parsing invalid fmap 2020-12-08 20:32:21 +00:00
Benson Leung
23ca19acf8 fmap-firmware: Parse flashmap format into images
Implements a search for the fmap, and follow the map to break the firmware
into the constituent images.

Tested using a servo_micro firmware:
$ fwupdtool firmware-parse servo_micro_v2.4.17-df61092c3.bin
<select fmap option>
FuFmapFirmware:
  FuFirmwareImage:
  ID:                    EC_RO
  Index:                 0x1
  Data:                  0xf000
  FuFirmwareImage:
  ID:                    FR_MAIN
  Index:                 0x2
  Data:                  0xf000
  FuFirmwareImage:
  ID:                    RO_FRID
  Index:                 0x3
  Address:               0xc4
  Data:                  0x20
  FuFirmwareImage:
  ID:                    FMAP
  Index:                 0x4
  Address:               0x9a40
  Version:               1.0
  Data:                  0x15e
  FuFirmwareImage:
  ID:                    WP_RO
  Index:                 0x5
  Data:                  0x10000
  FuFirmwareImage:
  ID:                    EC_RW
  Index:                 0x6
  Address:               0x10000
  Data:                  0x10000
  FuFirmwareImage:
  ID:                    RW_FWID
  Index:                 0x7
  Address:               0x100c4
  Data:                  0x20
2020-06-20 07:24:32 +01:00
Benson Leung
acba98bd50 fmap-firmware: Add initial skeleton for fmap
fmap is a Google flash layout format that is used in several of Google's
firmware projects, including Chrome OS Embedded Controller and the Chrome OS
coreboot firmwares. Introduce it as a firmware format in libfwupdplugin.
2020-06-20 07:24:32 +01:00