coreboot-kgpe-d16/util/cbfstool
Hung-Te Lin 49a4450563 cbfstool: Support new FMD flag "PRESERVE"
When updating firmware, it is very often that we may want to preserve
few sections, for example vital product data (VPD) including serial
number, calibration data and cache. A firmware updater has to hard-code
the section names that need to be preserved and is hard to maintain.

A better approach is to specify that in FMAP area flags (the `area_flag`
field) using FMAP_AREA_PRESERVE. With this patchset, a FMD parser flag
"PRESERVE" is introduced and will be converted to FMAP_AREA_PRESERVE
when generating FMAP data (by fmap_from_fmd.c).

For example, The FMD statement:

  RO_VPD(PRESERVE)@0x0 16k

will generate an FMAP firmware section that:

  area_name = "RO_VPD"
  area_offset = 0
  area_size = 16384
  area_flags = FMAP_AREA_PRESERVE

BUG=chromium:936768
TEST=make; boots on x86 "google/eve" and arm "google/kukui" devices
     Manually added 'PRESERVE' to some FMD files, and verify (by running
     fmap.py) the output coreboot.rom has FMAP_AREA_PRESERVE set

Change-Id: I51e7d31029b98868a1cab0d26bf04a14db01b1c0
Signed-off-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/31707
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
2019-03-05 20:51:39 +00:00
..
console Remove extra newlines from the end of all coreboot files. 2016-07-31 18:19:33 +02:00
flashmap fmap: Add FMAP_AREA_PRESERVE 2019-03-04 13:25:01 +00:00
lz4 util/cbfstool: Fix typos 2018-08-28 14:20:15 +00:00
lzma util/cbfstool: Fix typos 2018-08-28 14:20:15 +00:00
EXAMPLE
Makefile treewide: use /usr/bin/env where appropriate 2018-11-17 07:32:03 +00:00
Makefile.inc Move compiler.h to commonlib 2018-10-08 16:57:27 +00:00
ProcessorBind.h Remove extra newlines from the end of all coreboot files. 2016-07-31 18:19:33 +02:00
README.fmaptool cbfstool: Change FMD annotation to flags 2019-03-05 19:31:43 +00:00
cbfs-mkpayload.c util/cbfstool: fix build with clang 2018-07-20 16:06:29 +00:00
cbfs-mkstage.c util/cbfstool/cbfs-mkstage: Support x86_64 2018-12-19 06:06:49 +00:00
cbfs-payload-linux.c util/cbfstool: Fix to build with latest llvm 2017-01-04 21:37:39 +01:00
cbfs.h Move compiler.h to commonlib 2018-10-08 16:57:27 +00:00
cbfs_image.c util/cbfstool: Fix GCC error due to a shadowed declaration 2018-11-23 05:08:30 +00:00
cbfs_image.h cbfstool: add unprocessed flag for file exporting 2018-11-16 09:47:35 +00:00
cbfs_sections.c cbfstool: Change FMD annotation to flags 2019-03-05 19:31:43 +00:00
cbfs_sections.h
cbfscomptool.c cbfstool: fix implicit declaration of strcasecmp 2018-07-27 10:48:17 +00:00
cbfstool.c util/cbfstool/cbfstool.c: Fix typo 2018-12-24 08:13:48 +00:00
coff.h
common.c util/cbfstool: Fix typos 2018-08-28 14:20:15 +00:00
common.h util/cbfstool: Fix typos 2018-08-28 14:20:15 +00:00
compress.c
default-x86.fmd Makefile.inc: Create a default SMMSTORE region 2019-02-06 18:15:59 +00:00
default.fmd drivers/mrc_cache: Always generate an FMAP region 2018-01-20 16:11:44 +00:00
description.md util: Add description.md to each util 2018-07-26 13:26:50 +00:00
elf.h util/cbfstool: Support AMD64 rmodules 2018-12-19 06:05:52 +00:00
elfheaders.c util/cbfstool: Support AMD64 rmodules 2018-12-19 06:05:52 +00:00
elfparsing.h util/cbfstool: Fix typos 2018-08-28 14:20:15 +00:00
fdt.h util/cbfstool: Support FIT payloads 2018-06-15 09:13:24 +00:00
fit.c Move compiler.h to commonlib 2018-10-08 16:57:27 +00:00
fit.h cbfstool: Update FIT entries in the second bootblock 2018-06-26 05:59:52 +00:00
flashmap_tests.c
fmap_from_fmd.c cbfstool: Support new FMD flag "PRESERVE" 2019-03-05 20:51:39 +00:00
fmap_from_fmd.h
fmaptool.c fmaptool: Make base offsets absolute in fmap_config.h 2016-06-21 17:14:27 +02:00
fmd.c util/cbfstool: avoid memleaks and off-by-ones 2017-03-20 20:05:09 +01:00
fmd.h cbfstool: Support new FMD flag "PRESERVE" 2019-03-05 20:51:39 +00:00
fmd_parser.c_shipped cbfstool: Support new FMD flag "PRESERVE" 2019-03-05 20:51:39 +00:00
fmd_parser.h_shipped cbfstool: Support new FMD flag "PRESERVE" 2019-03-05 20:51:39 +00:00
fmd_parser.y cbfstool: Support new FMD flag "PRESERVE" 2019-03-05 20:51:39 +00:00
fmd_scanner.c_shipped cbfstool: Support new FMD flag "PRESERVE" 2019-03-05 20:51:39 +00:00
fmd_scanner.h_shipped cbfstool: Support new FMD flag "PRESERVE" 2019-03-05 20:51:39 +00:00
fmd_scanner.l cbfstool: Support new FMD flag "PRESERVE" 2019-03-05 20:51:39 +00:00
fv.h
ifwitool.c Move compiler.h to commonlib 2018-10-08 16:57:27 +00:00
linux.h util/cbfstool: Fix typos 2018-08-28 14:20:15 +00:00
linux_trampoline.S linux_trampoline: use trampoline RAM for the GDT 2018-07-18 21:32:26 +00:00
linux_trampoline.c linux_trampoline: use trampoline RAM for the GDT 2018-07-18 21:32:26 +00:00
linux_trampoline.h
option.h
partitioned_file.c util/cbfstool: Check for NULL before dereference 2017-12-20 16:35:13 +00:00
partitioned_file.h
rmodtool.c
rmodule.c rmodule: Add support for R_X86_64_PLT32 2019-03-05 19:36:52 +00:00
rmodule.h util/cbfstool/rmodule.{c,h}: Fix typo and correct header 2018-11-22 14:58:38 +00:00
swab.h
xdr.c

README.fmaptool

Flashmap descriptors in coreboot
================================
Flashmap (https://code.google.com/p/flashmap) is a binary format for representing the layout of
flash chips. Since coreboot is starting to use a "partition" of this format to describe the flash
chip layout---both at runtime and when flashing a new image onto a chip---, the project needed a
reasonably expressive plaintext format for representing such sections in the source tree. Our
solution is the fmd ("flashmap descriptor") language, and the files in this directory contain a
scanner, parser, semantic analyser, and flashmap converter. Here's an informal language description:

# <line comment>
<image name>[@<memory-mapped address>] <image size> {
	<section name>[(flags)][@<offset from start of image>] [<section size>] [{
		<subsection name>[@<offset from start of parent section>] [<subsection size>] [{
			# Sections can be nested as deeply as desired
			<subsubsection name>[(flags)][@...] [...] [{...}]
		}]
		[<subsection name>[(flags)][@...] [...] [{...}]]
		# There can be many subsections at each level of nesting: they will be inserted
		# sequentially, and although gaps are allowed, any provided offsets are always
		# relative to the closest parent node's and must be strictly increasing with neither
		# overlapping nor degenerate-size sections.
	}]
}

Note that the above example contains a few symbols that are actually metasyntax, and therefore have
neither meaning nor place in a real file. The <.*> s indicate placeholders for parameters:
 - The names are strings, which are provided as single-word---no whitespace---groups of
   syntactically unimportant symbols (i.e. everything except @, {, and }): they are not surrounded
   by quotes or any other form of delimiter.
 - The other fields are nonnegative integers, which may be given as decimal or hexadecimal; in
   either case, a K, M, or G may be appended---without intermediate whitespace---as a multiplier.
 - Comments consist of anything one manages to enter, provided it doesn't start a new line.
The [.*] s indicate that a portion of the file could be omitted altogether:
 - Just because something is noted as optional doesn't mean it is in every case: the answer might
   actually depend on which other information is---or isn't---provided.
 - The "flag" specifies the attribute or type for given section. The most
   important supported flag is "CBFS", which indicates the section will contain a CBFS structure.
 - In particular, it is only legal to place a (CBFS) flag on a leaf section; that is, choosing
   to add child sections excludes the possibility of putting a CBFS in their parent. Such
   flags are only used to decide where CBFS empty file headers should be created, and do not
   result in the storage of any additional metadata in the resulting FMAP section.
Additionally, it's important to note these properties of the overall file and its values:
 - Other than within would-be strings and numbers, whitespace is ignored. It goes without saying
   that such power comes with responsibility, which is why this sentence is here.
 - Although the .*section names must be globally unique, one of them may---but is not required to---
   match the image name.
 - It is a syntax error to supply a number---besides 0---that begins with the character 0, as there
   is no intention of adding octals to the mix.
 - The image's memory address should be present on---and only on---layouts for memory-mapped chips.
 - Although it may be evident from above, all .*section offsets are relative only to the immediate
   parent. There is no way to include an absolute offset (i.e. from the beginning of flash), which
   means that it is "safe" to reorder the .*section s within a particular level of nesting, as long
   as the change doesn't cause their positions and sizes to necessitate overlap or zero sizes.
 - A .*section with omitted offset is assumed to start at as low a position as possible---with no
   consideration of alignment---and one with omitted size is assumed to fill the remaining space
   until the next sibling or before the end of its parent.
 - It's fine to omit any .*section 's offset, size, or both, provided its position and size are
   still unambiguous in the context of its *sibling* sections and its parent's *size*. In
   particular, knowledge of one .*section 's children or the .*section s' common parent's siblings
   will not be used for this purpose.
 - Although .*section s are not required to have children, the flash chip as a whole must have at
   least one.
 - Though the braces after .*section s may be omitted for those that have no children, if they are
   present, they must contain at least one child.

PL people and sympathizers may wish to examine the formal abstract syntax and context-free grammar,
which are located in fmd_scanner.l and fmd_scanner.y, respectively. Those interested in the
algorithm used to infer omitted values will feel at home in fmd.c, particularly near the definition
of validate_and_complete_info().