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"
22 struct descriptor_node
{
23 const struct flashmap_descriptor
*val
;
24 struct descriptor_node
*next
;
27 static struct descriptor_list
{
28 struct descriptor_node
*head
;
29 struct descriptor_node
*tail
;
32 static bool seen_primary_section
= false;
34 static void descriptor_list_prepend(struct descriptor_list
*list
,
35 struct descriptor_node
*new_head
)
40 new_head
->next
= list
->head
;
41 list
->head
= new_head
;
43 list
->tail
= new_head
;
46 static void descriptor_list_append(struct descriptor_list
*list
,
47 struct descriptor_node
*new_tail
)
53 list
->tail
->next
= new_tail
;
54 list
->tail
= new_tail
;
56 list
->head
= new_tail
;
59 /* Implementation of cbfs module's callback; invoked during fmd file parsing */
60 bool fmd_process_annotation_impl(const struct flashmap_descriptor
*node
,
61 const char *annotation
)
63 if (strcmp(annotation
, SECTION_ANNOTATION_CBFS
) == 0 &&
64 node
->list_len
== 0) {
65 struct descriptor_node
*list_node
= malloc(sizeof(*list_node
));
66 list_node
->val
= node
;
67 list_node
->next
= NULL
;
69 if (strcmp(node
->name
, SECTION_NAME_PRIMARY_CBFS
) == 0) {
70 descriptor_list_prepend(&cbfs_sections
, list_node
);
71 seen_primary_section
= true;
73 descriptor_list_append(&cbfs_sections
, list_node
);
82 cbfs_section_iterator_t
cbfs_sections_iterator(void)
84 return cbfs_sections
.head
;
87 bool cbfs_sections_iterator_advance(cbfs_section_iterator_t
*it
)
97 const struct flashmap_descriptor
*cbfs_sections_iterator_deref(
98 cbfs_section_iterator_t it
)
104 bool cbfs_sections_primary_cbfs_accounted_for(void)
106 return seen_primary_section
;
109 void cbfs_sections_cleanup(void)
111 for (struct descriptor_node
*cur
= cbfs_sections
.head
, *next
= NULL
;
116 cbfs_sections
.head
= NULL
;
117 cbfs_sections
.tail
= NULL
;