drivers/elog: Rename ramstage_elog_add_boot_count() to elog_add_boot_count()
[coreboot.git] / util / cbfstool / cbfs_sections.c
blob088534adc9732283e59e4752ae59bbb04f2ecb65
1 /*
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"
17 #include "common.h"
19 #include <assert.h>
20 #include <stdlib.h>
21 #include <string.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;
31 } cbfs_sections;
33 static bool seen_primary_section = false;
35 static void descriptor_list_prepend(struct descriptor_list *list,
36 struct descriptor_node *new_head)
38 assert(list);
39 assert(new_head);
41 new_head->next = list->head;
42 list->head = new_head;
43 if (!list->tail)
44 list->tail = new_head;
47 static void descriptor_list_append(struct descriptor_list *list,
48 struct descriptor_node *new_tail)
50 assert(list);
51 assert(new_tail);
53 if (list->tail)
54 list->tail->next = new_tail;
55 list->tail = new_tail;
56 if (!list->head)
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)
66 return false;
68 list_node = (struct descriptor_node *)malloc(sizeof(*list_node));
69 if (!list_node) {
70 ERROR("Cannot allocate CBFS flag node!\n");
71 return false;
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;
79 } else {
80 descriptor_list_append(&cbfs_sections, list_node);
83 return true;
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)
93 assert(it);
94 if (!*it)
95 return false;
97 *it = (*it)->next;
98 return true;
101 const struct flashmap_descriptor *cbfs_sections_iterator_deref(
102 cbfs_section_iterator_t it)
104 assert(it);
105 return it->val;
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;
116 cur; cur = next) {
117 next = cur->next;
118 free(cur);
120 cbfs_sections.head = NULL;
121 cbfs_sections.tail = NULL;