1 /* fmap_from_fmd.c, tool to distill flashmap descriptors into raw FMAP sections */
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; version 2 of the License.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
13 #include "fmap_from_fmd.h"
20 static bool fmap_append_fmd_node(struct fmap
**flashmap
,
21 const struct flashmap_descriptor
*section
,
22 unsigned absolute_watermark
) {
24 if (strlen(section
->name
) >= FMAP_STRLEN
) {
25 ERROR("Section name ('%s') exceeds %d character FMAP format limit\n",
26 section
->name
, FMAP_STRLEN
- 1);
30 absolute_watermark
+= section
->offset
;
32 if (section
->flags
.f
.preserve
)
33 flags
|= FMAP_AREA_PRESERVE
;
35 if (fmap_append_area(flashmap
, absolute_watermark
, section
->size
,
36 (uint8_t *)section
->name
, flags
) < 0) {
37 ERROR("Failed to insert section '%s' into FMAP\n",
42 fmd_foreach_child(subsection
, section
) {
43 if (!fmap_append_fmd_node(flashmap
, subsection
,
51 struct fmap
*fmap_from_fmd(const struct flashmap_descriptor
*desc
)
54 assert(desc
->size_known
);
56 if (strlen(desc
->name
) >= FMAP_STRLEN
) {
57 ERROR("Image name ('%s') exceeds %d character FMAP header limit\n",
58 desc
->name
, FMAP_STRLEN
- 1);
62 struct fmap
*fmap
= fmap_create(desc
->offset_known
? desc
->offset
: 0,
63 desc
->size
, (uint8_t *)desc
->name
);
65 ERROR("Failed to allocate FMAP header\n");
69 fmd_foreach_child(real_section
, desc
) {
70 if (!fmap_append_fmd_node(&fmap
, real_section
, 0)) {