Angel Pons | 3ef916f | 2020-04-02 23:49:13 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stephen Barber | b396a66 | 2015-03-11 15:53:10 -0700 | [diff] [blame] | 2 | |
| 3 | #include <boot/coreboot_tables.h> |
| 4 | #include <console/console.h> |
| 5 | #include <assert.h> |
| 6 | #include <string.h> |
| 7 | |
Patrick Rudolph | 28cee59 | 2018-03-08 15:43:12 +0100 | [diff] [blame] | 8 | #include <drivers/vpd/vpd.h> |
Stephen Barber | b396a66 | 2015-03-11 15:53:10 -0700 | [diff] [blame] | 9 | |
| 10 | void lb_table_add_serialno_from_vpd(struct lb_header *header) |
| 11 | { |
| 12 | struct lb_string *serialno_rec = NULL; |
| 13 | const char serialno_key[] = "serial_number"; |
| 14 | char serialno[32]; |
| 15 | size_t len; |
| 16 | |
Patrick Rudolph | 28cee59 | 2018-03-08 15:43:12 +0100 | [diff] [blame] | 17 | if (!vpd_gets(serialno_key, serialno, |
Jonathan Zhang | a9117ed | 2020-05-28 11:02:13 -0700 | [diff] [blame] | 18 | sizeof(serialno), VPD_RO_THEN_RW)) { |
Stephen Barber | b396a66 | 2015-03-11 15:53:10 -0700 | [diff] [blame] | 19 | printk(BIOS_ERR, "no serial number in vpd\n"); |
| 20 | return; |
| 21 | } |
| 22 | printk(BIOS_DEBUG, "serial number is %s\n", serialno); |
| 23 | len = strlen(serialno) + 1; |
| 24 | ASSERT(len <= 32); |
| 25 | |
| 26 | serialno_rec = (struct lb_string *)lb_new_record(header); |
| 27 | serialno_rec->tag = LB_TAG_SERIALNO; |
| 28 | |
| 29 | serialno_rec->size = ALIGN_UP(sizeof(*serialno_rec) + len, 8); |
| 30 | memcpy(&serialno_rec->string, serialno, len); |
| 31 | } |