mb/dell: Add Latitude E5520 (Sandy Bridge)
[coreboot.git] / util / cbfstool / cbfs_sections.c
bloba8560dc560fc3e928091b92b76c77e5691c89c2d
1 /* track which sections of the image will contain CBFSes */
2 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include "cbfs_sections.h"
5 #include "common.h"
7 #include <assert.h>
8 #include <stdlib.h>
9 #include <string.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;
19 } cbfs_sections;
21 static bool seen_primary_section = false;
23 static void descriptor_list_prepend(struct descriptor_list *list,
24 struct descriptor_node *new_head)
26 assert(list);
27 assert(new_head);
29 new_head->next = list->head;
30 list->head = new_head;
31 if (!list->tail)
32 list->tail = new_head;
35 static void descriptor_list_append(struct descriptor_list *list,
36 struct descriptor_node *new_tail)
38 assert(list);
39 assert(new_tail);
41 if (list->tail)
42 list->tail->next = new_tail;
43 list->tail = new_tail;
44 if (!list->head)
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)
54 return false;
56 list_node = (struct descriptor_node *)malloc(sizeof(*list_node));
57 if (!list_node) {
58 ERROR("Cannot allocate CBFS flag node!\n");
59 return false;
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;
67 } else {
68 descriptor_list_append(&cbfs_sections, list_node);
71 return true;
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)
81 assert(it);
82 if (!*it)
83 return false;
85 *it = (*it)->next;
86 return true;
89 const struct flashmap_descriptor *cbfs_sections_iterator_deref(
90 cbfs_section_iterator_t it)
92 assert(it);
93 return it->val;
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;
104 cur; cur = next) {
105 next = cur->next;
106 free(cur);
108 cbfs_sections.head = NULL;
109 cbfs_sections.tail = NULL;