1 /* track which sections of the image will contain CBFSes */
2 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include "cbfs_sections.h"
11 struct descriptor_node
{
12 const struct flashmap_descriptor
*val
;
13 struct descriptor_node
*next
;
16 static struct descriptor_list
{
17 struct descriptor_node
*head
;
18 struct descriptor_node
*tail
;
21 static bool seen_primary_section
= false;
23 static void descriptor_list_prepend(struct descriptor_list
*list
,
24 struct descriptor_node
*new_head
)
29 new_head
->next
= list
->head
;
30 list
->head
= new_head
;
32 list
->tail
= new_head
;
35 static void descriptor_list_append(struct descriptor_list
*list
,
36 struct descriptor_node
*new_tail
)
42 list
->tail
->next
= new_tail
;
43 list
->tail
= new_tail
;
45 list
->head
= new_tail
;
48 /* Implementation of cbfs module's callback; invoked during fmd file parsing */
49 bool fmd_process_flag_cbfs(const struct flashmap_descriptor
*node
)
51 struct descriptor_node
*list_node
;
53 if (node
->list_len
!= 0)
56 list_node
= (struct descriptor_node
*)malloc(sizeof(*list_node
));
58 ERROR("Cannot allocate CBFS flag node!\n");
61 list_node
->val
= node
;
62 list_node
->next
= NULL
;
64 if (strcmp(node
->name
, SECTION_NAME_PRIMARY_CBFS
) == 0) {
65 descriptor_list_prepend(&cbfs_sections
, list_node
);
66 seen_primary_section
= true;
68 descriptor_list_append(&cbfs_sections
, list_node
);
74 cbfs_section_iterator_t
cbfs_sections_iterator(void)
76 return cbfs_sections
.head
;
79 bool cbfs_sections_iterator_advance(cbfs_section_iterator_t
*it
)
89 const struct flashmap_descriptor
*cbfs_sections_iterator_deref(
90 cbfs_section_iterator_t it
)
96 bool cbfs_sections_primary_cbfs_accounted_for(void)
98 return seen_primary_section
;
101 void cbfs_sections_cleanup(void)
103 for (struct descriptor_node
*cur
= cbfs_sections
.head
, *next
= NULL
;
108 cbfs_sections
.head
= NULL
;
109 cbfs_sections
.tail
= NULL
;