xref: /aosp_15_r20/external/vboot_reference/host/lib/include/fmap.h (revision 8617a60d3594060b7ecbd21bc622a7c14f3cf2bc)
1 /* Copyright 2011 The ChromiumOS Authors
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  */
5 
6 #ifndef VBOOT_REFERENCE_FMAP_H_
7 #define VBOOT_REFERENCE_FMAP_H_
8 
9 #include <inttypes.h>
10 #include <stddef.h>
11 
12 /* FMAP structs. See http://code.google.com/p/flashmap/wiki/FmapSpec */
13 #define FMAP_NAMELEN 32
14 #define FMAP_SIGNATURE "__FMAP__"
15 #define FMAP_SIGNATURE_SIZE 8
16 #define FMAP_SEARCH_STRIDE 4
17 #define FMAP_VER_MAJOR 1
18 typedef struct _FmapHeader {
19 	/* Avoid endian issues in signature... */
20 	char        fmap_signature[FMAP_SIGNATURE_SIZE];
21 	uint8_t     fmap_ver_major;
22 	uint8_t     fmap_ver_minor;
23 	uint64_t    fmap_base;
24 	uint32_t    fmap_size;
25 	char        fmap_name[FMAP_NAMELEN];
26 	uint16_t    fmap_nareas;
27 } __attribute__((packed)) FmapHeader;
28 
29 enum fmap_flags {
30 	FMAP_AREA_STATIC	= 1 << 0,
31 	FMAP_AREA_COMPRESSED	= 1 << 1,
32 	FMAP_AREA_RO		= 1 << 2,
33 	/* Should be preserved on update or rollback. */
34 	FMAP_AREA_PRESERVE	= 1 << 3,
35 };
36 
37 typedef struct _FmapAreaHeader {
38 	uint32_t area_offset;
39 	uint32_t area_size;
40 	char     area_name[FMAP_NAMELEN];
41 	uint16_t area_flags;
42 } __attribute__((packed)) FmapAreaHeader;
43 
44 
45 /* Find and point to the FMAP header within the buffer */
46 FmapHeader *fmap_find(uint8_t *ptr, size_t size);
47 
48 /* Search for an area by name, return pointer to its beginning */
49 uint8_t *fmap_find_by_name(uint8_t *ptr, size_t size,
50 			   /* optional, will call fmap_find() if NULL */
51 			   FmapHeader *fmap,
52 			   /* The area name to search for */
53 			   const char *name,
54 			   /* optional, return pointer to entry if not NULL */
55 			   FmapAreaHeader **ah);
56 
57 #endif  /* VBOOT_REFERENCE_FMAP_H_ */
58