Debian Codegraph @

util/cbfstool/fit.c

raw symbols SCIP
1 /* Firmware Interface Table support */
2 /* SPDX-License-Identifier: GPL-2.0-only */
3
4 #include <inttypes.h>
5 #include <stdint.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9
10 #include "fit.h"
11
12 /* FIXME: This code assumes it is being executed on a little endian machine. */
13
14 #define FIT_POINTER_LOCATION 0xffffffc0
15 #define FIT_TABLE_LOWEST_ADDRESS ((uint32_t)(-(16 << 20)))
16 #define FIT_ENTRY_CHECKSUM_VALID 0x80
17 #define FIT_HEADER_VERSION 0x0100
18 #define FIT_HEADER_ADDRESS "_FIT_ "
19 #define FIT_MICROCODE_VERSION 0x0100
20 #define FIT_PLATFORM_BOOT_POLICY_VERSION 0x0100
21 #define FIT_TXT_VERSION 0x0100
22
23 #define FIT_SIZE_ALIGNMENT 16
24
25 struct fit_entry {
26 /**
27 * Address is the base address of the firmware component
28 * must be aligned on 16 byte boundary
29 */
30 uint64_t address;
31 /**
32 * Size is the span of the component in multiple of 16 bytes
33 * Bits [24:31] are reserved and must be set to 0
34 */
35 uint32_t size_reserved;
36 /**
37 * Component's version number in binary coded decimal (BCD) format.
38 * For the FIT header entry, the value in this field will indicate the
39 * revision number of the FIT data structure. The upper byte of the
40 * revision field indicates the major revision and the lower byte
41 * indicates the minor revision.
42 */
43 uint16_t version;
44 /**
45 * FIT types 0x00 to 0x7F
46 * Bit 7 (C_V) indicates whether component has valid checksum.
47 */
48 uint8_t type_checksum_valid;
49 /**
50 * Component's checksum. The modulo sum of all the bytes in the
51 * component and the value in this field (Chksum) must add up to zero.
52 * This field is only valid if the C_V flag is non-zero.
53 */
54 uint8_t checksum;
55 } __packed;
56
57 struct fit_table {
58 struct fit_entry header;
59 struct fit_entry entries[];
60 } __packed;
61
62 struct microcode_header {
63 uint32_t version;
64 uint32_t revision;
65 uint32_t date;
66 uint32_t processor_signature;
67 uint32_t checksum;
68 uint32_t loader_revision;
69 uint32_t processor_flags;
70 uint32_t data_size;
71 uint32_t total_size;
72 uint8_t reserved[12];
73 } __packed;
74
75 struct microcode_entry {
76 int offset;
77 int size;
78 };
79
80 static inline void *rom_buffer_pointer(struct buffer *buffer, int offset)
81 {
82 return &buffer->data[offset];
83 }
84
85 static inline size_t fit_entry_size_bytes(const struct fit_entry *entry)
86 {
87 return (entry->size_reserved & 0xffffff) << 4;
88 }
89
90 static inline void fit_entry_update_size(struct fit_entry *entry,
91 const int size_bytes)
92 {
93 /* Size is multiples of 16 bytes. */
94 entry->size_reserved = (size_bytes >> 4) & 0xffffff;
95 }
96
97 static inline void fit_entry_add_size(struct fit_entry *entry,
98 const int size_bytes)
99 {
100 int size = fit_entry_size_bytes(entry);
101 size += size_bytes;
102 fit_entry_update_size(entry, size);
103 }
104
105 static inline int fit_entry_type(struct fit_entry *entry)
106 {
107 return entry->type_checksum_valid & ~FIT_ENTRY_CHECKSUM_VALID;
108 }
109
110 /*
111 * Get an offset from a host pointer. This function assumes the ROM is located
112 * in the host address space at [4G - romsize -> 4G). It also assume all
113 * pointers have values within this address range.
114 */
115 static inline int ptr_to_offset(fit_offset_converter_t helper,
116 const struct buffer *region, uint32_t host_ptr)
117 {
118 return helper(region, -host_ptr);
119 }
120
121 /*
122 * Get a pointer from an offset. This function assumes the ROM is located
123 * in the host address space at [4G - romsize -> 4G). It also assume all
124 * pointers have values within this address range.
125 */
126 static inline uint32_t offset_to_ptr(fit_offset_converter_t helper,
127 const struct buffer *region, int offset)
128 {
129 return -helper(region, offset);
130 }
131
132 /*
133 * Return the number of FIT entries.
134 */
135 static inline size_t fit_table_entries(const struct fit_table *fit)
136 {
137 if (!fit)
138 return 0;
139
140 return (fit_entry_size_bytes(&fit->header) / FIT_SIZE_ALIGNMENT) - 1;
141 }
142
143 /*
144 * Return the number of unused entries.
145 */
146 static inline size_t fit_free_space(struct fit_table *fit,
147 const size_t max_entries)
148 {
149 if (!fit)
150 return 0;
151
152 return max_entries - fit_table_entries(fit);
153 }
154
155 /*
156 * Sort entries by type and fill gaps (entries with type unused).
157 * To be called after adding or deleting entries.
158 *
159 * This one is critical, as mentioned in Chapter 1.2.1 "FIT Ordering Rules"
160 * "Firmware Interface Table BIOS Specification".
161 *
162 * We need to use a stable sorting algorithm, as the order of
163 * FIT_TYPE_BIOS_STARTUP matter for measurements.
164 */
165 static void sort_fit_table(struct fit_table *fit)
166 {
167 struct fit_entry tmp;
168 int i, j, num_entries, swapped;
169
170 num_entries = fit_table_entries(fit);
171
172 /* Bubble sort entries */
173 for (j = 0; j < num_entries - 1; j++) {
174 swapped = 0;
175 for (i = 0; i < num_entries - j - 1; i++) {
176 if (fit->entries[i].type_checksum_valid <=
177 fit->entries[i + 1].type_checksum_valid)
178 continue;
179 /* SWAP entries */
180 memcpy(&tmp, &fit->entries[i], sizeof(tmp));
181 memcpy(&fit->entries[i], &fit->entries[i + 1],
182 sizeof(fit->entries[i]));
183 memcpy(&fit->entries[i + 1], &tmp,
184 sizeof(fit->entries[i + 1]));
185 swapped = 1;
186 }
187 if (!swapped)
188 break;
189 }
190 }
191
192 static int fit_table_verified(struct fit_table *table)
193 {
194 if (!table)
195 return 0;
196
197 /* Check that the address field has the proper signature. */
198 if (strncmp((const char *)&table->header.address, FIT_HEADER_ADDRESS,
199 sizeof(table->header.address)))
200 return 0;
201
202 if (table->header.version != FIT_HEADER_VERSION)
203 return 0;
204
205 if (fit_entry_type(&table->header) != FIT_TYPE_HEADER)
206 return 0;
207
208 /* Assume that the FIT table contains at least the header */
209 if (fit_entry_size_bytes(&table->header) < sizeof(struct fit_entry))
210 return 0;
211
212 return 1;
213 }
214
215 /*
216 * Update the FIT checksum.
217 * To be called after modifiying the table.
218 */
219 static void update_fit_checksum(struct fit_table *fit)
220 {
221 int size_bytes;
222 uint8_t *buffer;
223 uint8_t result;
224 int i;
225
226 if (!fit)
227 return;
228
229 fit->header.checksum = 0;
230 size_bytes = fit_entry_size_bytes(&fit->header);
231 result = 0;
232 buffer = (void *)fit;
233 for (i = 0; i < size_bytes; i++)
234 result += buffer[i];
235 fit->header.checksum = -result;
236 }
237
238 /*
239 * Return a pointer to the next free entry.
240 * Caller must take care if enough space is available.
241 */
242 static struct fit_entry *get_next_free_entry(struct fit_table *fit)
243 {
244 return &fit->entries[fit_table_entries(fit)];
245 }
246
247 static void fit_location_from_cbfs_header(uint32_t *current_offset,
248 uint32_t *file_length, void *ptr)
249 {
250 struct buffer buf;
251 struct cbfs_file header;
252 memset(&buf, 0, sizeof(buf));
253
254 buf.data = ptr;
255 buf.size = sizeof(header);
256
257 bgets(&buf, header.magic, sizeof(header.magic));
258 header.len = xdr_be.get32(&buf);
259 header.type = xdr_be.get32(&buf);
260 header.attributes_offset = xdr_be.get32(&buf);
261 header.offset = xdr_be.get32(&buf);
262
263 *current_offset = header.offset;
264 *file_length = header.len;
265 }
266
267 static int
268 parse_microcode_blob(struct cbfs_image *image,
269 const char *blob_name,
270 size_t *mcus_found,
271 struct microcode_entry *mcus,
272 const size_t max_fit_entries)
273 {
274 size_t num_mcus;
275 uint32_t current_offset;
276 uint32_t file_length;
277 struct cbfs_file *mcode_file;
278
279 mcode_file = cbfs_get_entry(image, blob_name);
280 if (!mcode_file) {
281 ERROR("Couldn't find microcode blob.\n");
282 return 1;
283 }
284
285 fit_location_from_cbfs_header(&current_offset, &file_length,
286 mcode_file);
287 current_offset += cbfs_get_entry_addr(image, mcode_file);
288
289 num_mcus = 0;
290 while (file_length > sizeof(struct microcode_header)) {
291 const struct microcode_header *mcu_header;
292
293 mcu_header = rom_buffer_pointer(&image->buffer, current_offset);
294 if (!mcu_header) {
295 ERROR("Couldn't parse microcode header.\n");
296 return 1;
297 }
298
299 /* Newer microcode updates include a size field, whereas older
300 * containers set it at 0 and are exactly 2048 bytes long */
301 uint32_t total_size = mcu_header->total_size ?: 2048;
302
303 /* Quickly sanity check a prospective microcode update. */
304 if (total_size < sizeof(*mcu_header) ||
305 total_size > file_length)
306 break;
307
308 if (num_mcus == max_fit_entries) {
309 ERROR("Maximum of FIT entries reached.\n");
310 return 1;
311 }
312
313 /* FIXME: Should the checksum be validated? */
314 mcus[num_mcus].offset = current_offset;
315 mcus[num_mcus].size = total_size;
316
317 /* Proceed to next payload. */
318 current_offset += mcus[num_mcus].size;
319 file_length -= mcus[num_mcus].size;
320 num_mcus++;
321 if (file_length < sizeof(struct microcode_header))
322 break;
323 }
324
325 /* Update how many microcode updates we found. */
326 *mcus_found = num_mcus;
327
328 return 0;
329 }
330
331 /* There can be zero or more FIT_TYPE_MICROCODE entries */
332 static void update_fit_ucode_entry(struct fit_table *fit,
333 struct fit_entry *entry,
334 const uint64_t mcu_addr)
335 {
336 entry->address = mcu_addr;
337 /*
338 * While loading MCU, its size is not referred from FIT and
339 * rather from the MCU header, hence we can assign zero here.
340 */
341 entry->size_reserved = 0;
342 entry->type_checksum_valid = FIT_TYPE_MICROCODE;
343 entry->version = FIT_MICROCODE_VERSION;
344 entry->checksum = 0;
345 fit_entry_add_size(&fit->header, sizeof(struct fit_entry));
346 }
347
348 /*
349 * There can be zero or one FIT_TYPE_BIOS_ACM entry per table.
350 * In case there's a FIT_TYPE_BIOS_ACM entry, at least one
351 * FIT_TYPE_BIOS_STARTUP entry must exist.
352 *
353 * The caller has to provide valid arguments as those aren't verfied.
354 */
355 static void update_fit_bios_acm_entry(struct fit_table *fit,
356 struct fit_entry *entry,
357 const uint64_t acm_addr)
358 {
359 entry->address = acm_addr;
360 /*
361 * The Address field points to a BIOS ACM. The Address field points to
362 * the first byte of the AC module header. When BIOS ACM is loaded in
363 * Authenticated Code RAM, one MTRR base/limit pair is used to map it.
364 */
365 entry->size_reserved = 0;
366 entry->type_checksum_valid = FIT_TYPE_BIOS_ACM;
367 entry->version = FIT_TXT_VERSION;
368 entry->checksum = 0;
369 fit_entry_add_size(&fit->header, sizeof(struct fit_entry));
370 }
371
372 static void update_fit_pbp_entry(struct fit_table *fit,
373 struct fit_entry *entry,
374 const uint64_t pbp_addr)
375 {
376 entry->address = pbp_addr;
377 entry->size_reserved = 0;
378 entry->type_checksum_valid = FIT_TYPE_PLATFORM_BOOT_POLICY;
379 entry->version = FIT_PLATFORM_BOOT_POLICY_VERSION;
380 entry->checksum = 0;
381 fit_entry_add_size(&fit->header, sizeof(struct fit_entry));
382 }
383
384 /*
385 * In case there's a FIT_TYPE_BIOS_ACM entry, at least one
386 * FIT_TYPE_BIOS_STARTUP entry must exist.
387 *
388 * The caller has to provide valid arguments as those aren't verfied.
389 */
390 static void update_fit_bios_startup_entry(struct fit_table *fit,
391 struct fit_entry *entry,
392 const uint64_t sm_addr,
393 const uint32_t sm_size)
394 {
395 entry->address = sm_addr;
396 assert(sm_size % 16 == 0);
397 /*
398 * BIOS Startup code is defined as the code that gets control at the
399 * reset vector and continues the chain of trust in TCG-compliant
400 * fashion. In addition, this code may also configure memory and SMRAM.
401 */
402 fit_entry_update_size(entry, sm_size);
403 entry->type_checksum_valid = FIT_TYPE_BIOS_STARTUP;
404 entry->version = FIT_TXT_VERSION;
405 entry->checksum = 0;
406 fit_entry_add_size(&fit->header, sizeof(struct fit_entry));
407 }
408
409 /*
410 * There can be zero or one FIT_TYPE_BIOS_POLICY Record in the FIT.
411 * If the platform uses the hash comparison method and employs a
412 * failsafe bootblock, one FIT_TYPE_BIOS_POLICY entry is needed to
413 * contain the failsafe hash.
414 * If the platform uses the Signature verification method, one
415 * FIT_TYPE_BIOS_POLICY entry is needed. In this case, the entry
416 * contains the OEM key, hash of the BIOS and signature over the hash
417 * using the OEM key.
418 * In all other cases, the FIT_TYPE_BIOS_POLICY record is not required.
419 *
420 * The caller has to provide valid arguments as those aren't verfied.
421 */
422 static void update_fit_bios_policy_entry(struct fit_table *fit,
423 struct fit_entry *entry,
424 const uint64_t lcp_policy_addr,
425 const uint32_t lcp_policy_size)
426 {
427 entry->address = lcp_policy_addr;
428 fit_entry_update_size(entry, lcp_policy_size);
429 entry->type_checksum_valid = FIT_TYPE_BIOS_POLICY;
430 entry->version = FIT_TXT_VERSION;
431 entry->checksum = 0;
432 fit_entry_add_size(&fit->header, sizeof(struct fit_entry));
433 }
434
435 /*
436 * There can be zero or one FIT_TYPE_TXT_POLICY entries
437 *
438 * The caller has to provide valid arguments as those aren't verfied.
439 */
440 static void update_fit_txt_policy_entry(struct fit_table *fit,
441 struct fit_entry *entry,
442 uint64_t txt_policy_addr)
443 {
444 entry->address = txt_policy_addr;
445 /*
446 * Points to the flag indicating if TXT is enabled on this platform.
447 * If not present, TXT is not disabled by FIT.
448 */
449 entry->size_reserved = 0;
450 entry->type_checksum_valid = FIT_TYPE_TXT_POLICY;
451 entry->version = 0x1;
452 entry->checksum = 0;
453 fit_entry_add_size(&fit->header, sizeof(struct fit_entry));
454 }
455
456 /*
457 * There can be zero or one FIT_TYPE_BOOT_POLICY entries
458 *
459 * The caller has to provide valid arguments as those aren't verified.
460 */
461 static void update_fit_boot_policy_entry(struct fit_table *fit,
462 struct fit_entry *entry,
463 uint64_t boot_policy_addr,
464 uint32_t boot_policy_size)
465 {
466 entry->address = boot_policy_addr;
467 entry->type_checksum_valid = FIT_TYPE_BOOT_POLICY;
468 entry->size_reserved = boot_policy_size;
469 entry->version = FIT_TXT_VERSION;
470 entry->checksum = 0;
471 fit_entry_add_size(&fit->header, sizeof(struct fit_entry));
472 }
473
474 /*
475 * There can be zero or one FIT_TYPE_KEY_MANIFEST entries
476 *
477 * The caller has to provide valid arguments as those aren't verified.
478 */
479 static void update_fit_key_manifest_entry(struct fit_table *fit,
480 struct fit_entry *entry,
481 uint64_t key_manifest_addr,
482 uint32_t key_manifest_size)
483 {
484 entry->address = key_manifest_addr;
485
486 entry->type_checksum_valid = FIT_TYPE_KEY_MANIFEST;
487 entry->size_reserved = key_manifest_size;
488 entry->version = FIT_TXT_VERSION;
489 entry->checksum = 0;
490 fit_entry_add_size(&fit->header, sizeof(struct fit_entry));
491 }
492
493 /* Special case for ucode CBFS file, as it might contain more than one ucode */
494 int fit_add_microcode_file(struct fit_table *fit,
495 struct cbfs_image *image,
496 const char *blob_name,
497 fit_offset_converter_t offset_helper,
498 const size_t max_fit_entries)
499 {
500 struct microcode_entry *mcus;
501
502 size_t i;
503 size_t mcus_found;
504
505 mcus = malloc(sizeof(*mcus) * max_fit_entries);
506 if (!mcus) {
507 ERROR("Couldn't allocate memory for microcode entries.\n");
508 return 1;
509 }
510
511 if (parse_microcode_blob(image, blob_name, &mcus_found, mcus,
512 max_fit_entries)) {
513 free(mcus);
514 return 1;
515 }
516
517 for (i = 0; i < mcus_found; i++) {
518 if (fit_add_entry(fit,
519 offset_to_ptr(offset_helper, &image->buffer,
520 mcus[i].offset),
521 0,
522 FIT_TYPE_MICROCODE,
523 max_fit_entries)) {
524
525 free(mcus);
526 return 1;
527 }
528 }
529
530 free(mcus);
531 return 0;
532 }
533
534 static uint32_t *get_fit_ptr(struct buffer *bootblock, fit_offset_converter_t offset_fn,
535 uint32_t topswap_size)
536 {
537 return rom_buffer_pointer(bootblock,
538 ptr_to_offset(offset_fn, bootblock,
539 FIT_POINTER_LOCATION - topswap_size));
540 }
541
542 /* Set the FIT pointer to a FIT table. */
543 int set_fit_pointer(struct buffer *bootblock,
544 const uint32_t fit_address,
545 fit_offset_converter_t offset_fn,
546 uint32_t topswap_size)
547 {
548 struct fit_table *fit;
549 uint32_t *fit_pointer = get_fit_ptr(bootblock, offset_fn, topswap_size);
550
551 fit = rom_buffer_pointer(bootblock, ptr_to_offset(offset_fn, bootblock, fit_address));
552
553 if (fit_address < FIT_TABLE_LOWEST_ADDRESS) {
554 ERROR("FIT must be reside in the top 16MiB.\n");
555 return 1;
556 }
557
558 if (!fit_table_verified(fit)) {
559 ERROR("FIT not found at address.\n");
560 return 1;
561 }
562
563 fit_pointer[0] = fit_address;
564 fit_pointer[1] = 0;
565 return 0;
566 }
567
568 /*
569 * Return a pointer to the active FIT.
570 */
571 struct fit_table *fit_get_table(struct buffer *bootblock,
572 fit_offset_converter_t offset_fn,
573 uint32_t topswap_size)
574 {
575 struct fit_table *fit;
576 uint32_t *fit_pointer = get_fit_ptr(bootblock, offset_fn, topswap_size);
577
578 /* Ensure pointer is below 4GiB and within 16MiB of 4GiB */
579 if (fit_pointer[1] != 0 || fit_pointer[0] < FIT_TABLE_LOWEST_ADDRESS) {
580 ERROR("FIT not found.\n");
581 return NULL;
582 }
583
584 fit = rom_buffer_pointer(bootblock,
585 ptr_to_offset(offset_fn, bootblock, *fit_pointer));
586 if (!fit_table_verified(fit)) {
587 ERROR("FIT not found.\n");
588 return NULL;
589 }
590
591 return fit;
592 }
593
594 /*
595 * Dump the current FIT in human readable format to stdout.
596 */
597 int fit_dump(struct fit_table *fit)
598 {
599 size_t i;
600
601 if (!fit)
602 return 1;
603
604 printf("\n");
605 printf(" FIT table:\n");
606
607 if (fit_table_entries(fit) < 1) {
608 printf(" empty\n\n");
609 return 0;
610 }
611
612 printf(" %-6s %-20s %-16s %-8s\n", "Index", "Type", "Addr", "Size");
613
614 for (i = 0; i < fit_table_entries(fit); i++) {
615 const char *name;
616
617 switch (fit->entries[i].type_checksum_valid) {
618 case FIT_TYPE_MICROCODE:
619 name = "Microcode";
620 break;
621 case FIT_TYPE_BIOS_ACM:
622 name = "BIOS ACM";
623 break;
624 case FIT_TYPE_PLATFORM_BOOT_POLICY:
625 name = "Platform Boot Policy";
626 break;
627 case FIT_TYPE_BIOS_STARTUP:
628 name = "BIOS Startup Module";
629 break;
630 case FIT_TYPE_TPM_POLICY:
631 name = "TPM Policy";
632 break;
633 case FIT_TYPE_BIOS_POLICY:
634 name = "BIOS Policy";
635 break;
636 case FIT_TYPE_TXT_POLICY:
637 name = "TXT Policy";
638 break;
639 case FIT_TYPE_KEY_MANIFEST:
640 name = "Key Manifest";
641 break;
642 case FIT_TYPE_BOOT_POLICY:
643 name = "Boot Policy";
644 break;
645 case FIT_TYPE_CSE_SECURE_BOOT:
646 name = "CSE SecureBoot";
647 break;
648 case FIT_TYPE_TXTSX_POLICY:
649 name = "TXTSX policy";
650 break;
651 case FIT_TYPE_JMP_DEBUG_POLICY:
652 name = "JMP debug policy";
653 break;
654 case FIT_TYPE_UNUSED:
655 name = "unused";
656 break;
657 default:
658 name = "unknown";
659 }
660
661 printf(" %6zd %-20s 0x%08"PRIx64" 0x%08zx\n", i, name,
662 fit->entries[i].address,
663 fit_entry_size_bytes(&fit->entries[i]));
664 }
665 printf("\n");
666 return 0;
667 }
668
669 /*
670 * Remove all entries from table.
671 */
672 int fit_clear_table(struct fit_table *fit)
673 {
674 if (!fit)
675 return 1;
676
677 memset(fit->entries, 0,
678 sizeof(struct fit_entry) * fit_table_entries(fit));
679
680 /* Reset entry counter in header */
681 fit_entry_update_size(&fit->header, sizeof(fit->header));
682
683 update_fit_checksum(fit);
684
685 return 0;
686 }
687
688 /*
689 * Returns true if the FIT type is know and can be added to the table.
690 */
691 int fit_is_supported_type(const enum fit_type type)
692 {
693 switch (type) {
694 case FIT_TYPE_MICROCODE:
695 case FIT_TYPE_BIOS_ACM:
696 case FIT_TYPE_PLATFORM_BOOT_POLICY:
697 case FIT_TYPE_BIOS_STARTUP:
698 case FIT_TYPE_BIOS_POLICY:
699 case FIT_TYPE_TXT_POLICY:
700 case FIT_TYPE_KEY_MANIFEST:
701 case FIT_TYPE_BOOT_POLICY:
702 return 1;
703 case FIT_TYPE_TPM_POLICY:
704 default:
705 return 0;
706 }
707 }
708
709 /*
710 * Adds an known entry to the FIT.
711 * len is optional for same types and might be zero.
712 * offset is an absolute address in 32-bit protected mode address space.
713 */
714 int fit_add_entry(struct fit_table *fit,
715 const uint32_t offset,
716 const uint32_t len,
717 const enum fit_type type,
718 const size_t max_fit_entries)
719 {
720 struct fit_entry *entry;
721
722 if (!fit) {
723 ERROR("Internal error.\n");
724 return 1;
725 }
726
727 if (fit_free_space(fit, max_fit_entries) < 1) {
728 ERROR("No space left in FIT.\n");
729 return 1;
730 }
731
732 if (!fit_is_supported_type(type)) {
733 ERROR("Unsupported FIT type %u\n", type);
734 return 1;
735 }
736
737 DEBUG("Adding new entry type %u at offset %zd\n", type,
738 fit_table_entries(fit));
739
740 entry = get_next_free_entry(fit);
741
742 switch (type) {
743 case FIT_TYPE_MICROCODE:
744 update_fit_ucode_entry(fit, entry, offset);
745 break;
746 case FIT_TYPE_BIOS_ACM:
747 update_fit_bios_acm_entry(fit, entry, offset);
748 break;
749 case FIT_TYPE_PLATFORM_BOOT_POLICY:
750 update_fit_pbp_entry(fit, entry, offset);
751 break;
752 case FIT_TYPE_BIOS_STARTUP:
753 update_fit_bios_startup_entry(fit, entry, offset, len);
754 break;
755 case FIT_TYPE_BIOS_POLICY:
756 update_fit_bios_policy_entry(fit, entry, offset, len);
757 break;
758 case FIT_TYPE_TXT_POLICY:
759 update_fit_txt_policy_entry(fit, entry, offset);
760 break;
761 case FIT_TYPE_KEY_MANIFEST:
762 update_fit_key_manifest_entry(fit, entry, offset, len);
763 break;
764 case FIT_TYPE_BOOT_POLICY:
765 update_fit_boot_policy_entry(fit, entry, offset, len);
766 break;
767 default:
768 return 1;
769 }
770
771 sort_fit_table(fit);
772
773 update_fit_checksum(fit);
774
775 return 0;
776 }
777
778 /*
779 * Delete one entry from table.
780 */
781 int fit_delete_entry(struct fit_table *fit,
782 const size_t idx)
783 {
784 if (!fit) {
785 ERROR("Internal error.\n");
786 return 1;
787 }
788
789 if (idx >= fit_table_entries(fit)) {
790 ERROR("Index out of range.\n");
791 return 1;
792 }
793
794 memset(&fit->entries[idx], 0, sizeof(struct fit_entry));
795
796 fit->entries[idx].type_checksum_valid = FIT_TYPE_UNUSED;
797
798 sort_fit_table(fit);
799
800 /* The unused entry is now the last one */
801 fit_entry_add_size(&fit->header, -(int)sizeof(struct fit_entry));
802
803 update_fit_checksum(fit);
804
805 return 0;
806 }