1 /* fmap_from_fmd.c, tool to distill flashmap descriptors into raw FMAP sections */
2 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include "fmap_from_fmd.h"
11 static bool fmap_append_fmd_node(struct fmap
**flashmap
,
12 const struct flashmap_descriptor
*section
,
13 unsigned absolute_watermark
) {
15 if (strlen(section
->name
) >= FMAP_STRLEN
) {
16 ERROR("Section name ('%s') exceeds %d character FMAP format limit\n",
17 section
->name
, FMAP_STRLEN
- 1);
21 absolute_watermark
+= section
->offset
;
23 if (section
->flags
.f
.preserve
)
24 flags
|= FMAP_AREA_PRESERVE
;
26 if (fmap_append_area(flashmap
, absolute_watermark
, section
->size
,
27 (uint8_t *)section
->name
, flags
) < 0) {
28 ERROR("Failed to insert section '%s' into FMAP\n",
33 fmd_foreach_child(subsection
, section
) {
34 if (!fmap_append_fmd_node(flashmap
, subsection
,
42 struct fmap
*fmap_from_fmd(const struct flashmap_descriptor
*desc
)
45 assert(desc
->size_known
);
47 if (strlen(desc
->name
) >= FMAP_STRLEN
) {
48 ERROR("Image name ('%s') exceeds %d character FMAP header limit\n",
49 desc
->name
, FMAP_STRLEN
- 1);
53 struct fmap
*fmap
= fmap_create(desc
->offset_known
? desc
->offset
: 0,
54 desc
->size
, (uint8_t *)desc
->name
);
56 ERROR("Failed to allocate FMAP header\n");
60 fmd_foreach_child(real_section
, desc
) {
61 if (!fmap_append_fmd_node(&fmap
, real_section
, 0)) {