google/eve: Configure I2C3 pins as GPIO inputs
[coreboot.git] / util / cbfstool / cbfs_sections.c
blobf87b2c8b5a923426e1ed9cf655e6237f1817e8b3
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"
18 #include <assert.h>
19 #include <stdlib.h>
20 #include <string.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;
30 } cbfs_sections;
32 static bool seen_primary_section = false;
34 static void descriptor_list_prepend(struct descriptor_list *list,
35 struct descriptor_node *new_head)
37 assert(list);
38 assert(new_head);
40 new_head->next = list->head;
41 list->head = new_head;
42 if (!list->tail)
43 list->tail = new_head;
46 static void descriptor_list_append(struct descriptor_list *list,
47 struct descriptor_node *new_tail)
49 assert(list);
50 assert(new_tail);
52 if (list->tail)
53 list->tail->next = new_tail;
54 list->tail = new_tail;
55 if (!list->head)
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;
72 } else {
73 descriptor_list_append(&cbfs_sections, list_node);
76 return true;
79 return false;
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)
89 assert(it);
90 if (!*it)
91 return false;
93 *it = (*it)->next;
94 return true;
97 const struct flashmap_descriptor *cbfs_sections_iterator_deref(
98 cbfs_section_iterator_t it)
100 assert(it);
101 return it->val;
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;
112 cur; cur = next) {
113 next = cur->next;
114 free(cur);
116 cbfs_sections.head = NULL;
117 cbfs_sections.tail = NULL;