From 03f4d521a7fa711b963b0e1822e92eac16a691b1 Mon Sep 17 00:00:00 2001 From: Hung-Te Lin Date: Wed, 5 Mar 2014 16:27:43 +0800 Subject: [PATCH] vendorcode: Update ChromeOS VPD Parser. Merge recent changes in ChromeOS VPD that allows non-memory-mapped firmware to load VPD easier and faster (ref: https://chromium-review.googlesource.com/188134 ). BRANCH=none BUG=none TEST=emerge-panther chromeos-coreboot-panther Change-Id: I3ee0b89c703f476f3d77cdde52cc7588724f7686 Reviewed-on: https://chromium-review.googlesource.com/188743 Tested-by: Hung-Te Lin Reviewed-by: Yung-chieh Lo Reviewed-by: David Hendricks Commit-Queue: Hung-Te Lin --- src/vendorcode/google/chromeos/lib_vpd.h | 1 + src/vendorcode/google/chromeos/vpd_decode.c | 6 +- src/vendorcode/google/chromeos/vpd_tables.h | 114 ++++++++++++++++++++ 3 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 src/vendorcode/google/chromeos/vpd_tables.h diff --git a/src/vendorcode/google/chromeos/lib_vpd.h b/src/vendorcode/google/chromeos/lib_vpd.h index 96038a223d..e08cb3a654 100644 --- a/src/vendorcode/google/chromeos/lib_vpd.h +++ b/src/vendorcode/google/chromeos/lib_vpd.h @@ -18,6 +18,7 @@ enum { enum { VPD_TYPE_TERMINATOR = 0, VPD_TYPE_STRING, + VPD_TYPE_INFO = 0xfe, VPD_TYPE_IMPLICIT_TERMINATOR = 0xff, }; diff --git a/src/vendorcode/google/chromeos/vpd_decode.c b/src/vendorcode/google/chromeos/vpd_decode.c index d4ea2cf1cc..545fd8106f 100644 --- a/src/vendorcode/google/chromeos/vpd_decode.c +++ b/src/vendorcode/google/chromeos/vpd_decode.c @@ -51,6 +51,7 @@ int decodeVpdString( type = input_buf[*consumed]; switch (type) { + case VPD_TYPE_INFO: case VPD_TYPE_STRING: (*consumed)++; @@ -75,7 +76,10 @@ int decodeVpdString( value = &input_buf[*consumed]; *consumed += value_len; - return callback(key, key_len, value, value_len, callback_arg); + if (type == VPD_TYPE_STRING) + return callback(key, key_len, value, value_len, callback_arg); + + return VPD_OK; default: return VPD_FAIL; diff --git a/src/vendorcode/google/chromeos/vpd_tables.h b/src/vendorcode/google/chromeos/vpd_tables.h new file mode 100644 index 0000000000..d58b5e846d --- /dev/null +++ b/src/vendorcode/google/chromeos/vpd_tables.h @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2014 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Ported from mosys project (http://code.google.com/p/mosys/). + */ + +#ifndef __LIB_VPD_TABLES_H__ +#define __LIB_VPD_TABLES_H__ + +#include + +#define VPD_ENTRY_MAGIC "_SM_" +#define VPD_INFO_MAGIC \ + "\xfe" /* type: VPD header */ \ + "\x09" /* key length, 9 = 1 + 8 */ \ + "\x01" /* info version, 1 */ \ + "gVpdInfo" /* signature, 8 bytes */ \ + "\x04" /* value length */ + +/* Google specific VPD info */ +struct google_vpd_info { + union { + struct { + uint8_t type; + uint8_t key_len; + uint8_t info_ver; + uint8_t signature[8]; + uint8_t value_len; + } tlv; + uint8_t magic[12]; + } header; + uint32_t size; +} __attribute__((packed)); + +/* Entry */ +struct vpd_entry { + uint8_t anchor_string[4]; + uint8_t entry_cksum; + uint8_t entry_length; + uint8_t major_ver; + uint8_t minor_ver; + uint16_t max_size; + uint8_t entry_rev; + uint8_t format_area[5]; + uint8_t inter_anchor_string[5]; + uint8_t inter_anchor_cksum; + uint16_t table_length; + uint32_t table_address; + uint16_t table_entry_count; + uint8_t bcd_revision; +} __attribute__ ((packed)); + +/* Header */ +struct vpd_header { + uint8_t type; + uint8_t length; + uint16_t handle; +} __attribute__ ((packed)); + +/* Type 0 - firmware information */ +struct vpd_table_firmware { + uint8_t vendor; + uint8_t version; + uint16_t start_address; + uint8_t release_date; + uint8_t rom_size_64k_blocks; + uint32_t characteristics; + uint8_t extension[2]; /* v2.4+ */ + uint8_t major_ver; /* v2.4+ */ + uint8_t minor_ver; /* v2.4+ */ + uint8_t ec_major_ver; /* v2.4+ */ + uint8_t ec_minor_ver; /* v2.4+ */ +} __attribute__ ((packed)); + +/* Type 1 - system information */ +struct vpd_table_system { + uint8_t manufacturer; + uint8_t name; + uint8_t version; + uint8_t serial_number; + uint8_t uuid[16]; + uint8_t wakeup_type; + uint8_t sku_number; /* v2.4+ */ + uint8_t family; /* v2.4+ */ +} __attribute__ ((packed)); + +/* Type 127 - end of table */ +struct vpd_table_eot { + struct vpd_header header; +} __attribute__ ((packed)); + +/* Type 241 - binary blob pointer */ +struct vpd_table_binary_blob_pointer { + uint8_t struct_major_version; + uint8_t struct_minor_version; + uint8_t vendor; + uint8_t description; + uint8_t major_version; + uint8_t minor_version; + uint8_t variant; + uint8_t reserved[5]; + uint8_t uuid[16]; + uint32_t offset; + uint32_t size; +} __attribute__ ((packed)); + +/* The length and number of strings defined here is not a limitation of VPD. + * These numbers were deemed good enough during development. */ +#define VPD_MAX_STRINGS 10 +#define VPD_MAX_STRING_LENGTH 64 + +#endif /* __LIB_VPD_TABLES_H__ */