2 * fmap_sections.c, track which sections of the image will contain CBFSes
4 * Copyright (C) 2015 Google, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include "cbfs_sections.h"
23 struct descriptor_node
{
24 const struct flashmap_descriptor
*val
;
25 struct descriptor_node
*next
;
28 static struct descriptor_list
{
29 struct descriptor_node
*head
;
30 struct descriptor_node
*tail
;
33 static bool seen_primary_section
= false;
35 static void descriptor_list_prepend(struct descriptor_list
*list
,
36 struct descriptor_node
*new_head
)
41 new_head
->next
= list
->head
;
42 list
->head
= new_head
;
44 list
->tail
= new_head
;
47 static void descriptor_list_append(struct descriptor_list
*list
,
48 struct descriptor_node
*new_tail
)
54 list
->tail
->next
= new_tail
;
55 list
->tail
= new_tail
;
57 list
->head
= new_tail
;
60 /* Implementation of cbfs module's callback; invoked during fmd file parsing */
61 bool fmd_process_flag_cbfs(const struct flashmap_descriptor
*node
)
63 struct descriptor_node
*list_node
;
65 if (node
->list_len
!= 0)
68 list_node
= (struct descriptor_node
*)malloc(sizeof(*list_node
));
70 ERROR("Cannot allocate CBFS flag node!\n");
73 list_node
->val
= node
;
74 list_node
->next
= NULL
;
76 if (strcmp(node
->name
, SECTION_NAME_PRIMARY_CBFS
) == 0) {
77 descriptor_list_prepend(&cbfs_sections
, list_node
);
78 seen_primary_section
= true;
80 descriptor_list_append(&cbfs_sections
, list_node
);
86 cbfs_section_iterator_t
cbfs_sections_iterator(void)
88 return cbfs_sections
.head
;
91 bool cbfs_sections_iterator_advance(cbfs_section_iterator_t
*it
)
101 const struct flashmap_descriptor
*cbfs_sections_iterator_deref(
102 cbfs_section_iterator_t it
)
108 bool cbfs_sections_primary_cbfs_accounted_for(void)
110 return seen_primary_section
;
113 void cbfs_sections_cleanup(void)
115 for (struct descriptor_node
*cur
= cbfs_sections
.head
, *next
= NULL
;
120 cbfs_sections
.head
= NULL
;
121 cbfs_sections
.tail
= NULL
;