Patrick Georgi (pgeorgi(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/9403
-gerrit
commit 2c8fe1d31f45edbf9579ff5a792a02e09ff3c41e
Author: Vadim Bendebury <vbendeb(a)chromium.org>
Date: Wed Oct 22 17:39:24 2014 -0700
chromeos: add another VPD access API
The new API allows to find VPD objects in the VPD cache. There is no
need for the caller to allocate or free the per object memory.
The existing API (cros_vpd_gets) now uses the new function as well.
BRANCH=storm
BUG=chrome-os-partner:32611
TEST=verified that MAC addresses still show up in the device tree on
the booted storm device
Change-Id: Id06be315981cdaa2285fc1ec61b96b62b1178a4b
Signed-off-by: Patrick Georgi <pgeorgi(a)chromium.org>
Original-Commit-Id: 99a34344448a5521cee8ad3918aefb1fde28417d
Original-Change-Id: I6c0b11bb844d6235930124d642da632319142d88
Original-Signed-off-by: Vadim Bendebury <vbendeb(a)chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/225258
Original-Reviewed-by: Hung-Te Lin <hungte(a)chromium.org>
---
src/vendorcode/google/chromeos/cros_vpd.c | 26 +++++++++++++++++++++-----
src/vendorcode/google/chromeos/cros_vpd.h | 16 ++++++++++++++++
2 files changed, 37 insertions(+), 5 deletions(-)
diff --git a/src/vendorcode/google/chromeos/cros_vpd.c b/src/vendorcode/google/chromeos/cros_vpd.c
index df2b5bf..c0e4830 100644
--- a/src/vendorcode/google/chromeos/cros_vpd.c
+++ b/src/vendorcode/google/chromeos/cros_vpd.c
@@ -99,7 +99,7 @@ static int vpd_gets_callback(const uint8_t *key, int32_t key_len,
return VPD_FAIL;
}
-char *cros_vpd_gets(const char *key, char *buffer, int size)
+const void *cros_vpd_find(const char *key, int *size)
{
uint8_t *vpd_address = NULL;
int32_t vpd_size = 0;
@@ -121,10 +121,26 @@ char *cros_vpd_gets(const char *key, char *buffer, int size)
if (!arg.matched)
return NULL;
- if (size < arg.value_len + 1)
- size = arg.value_len + 1;
- memcpy(buffer, arg.value, size - 1);
- buffer[size - 1] = '\0';
+ *size = arg.value_len;
+ return arg.value;
+}
+
+char *cros_vpd_gets(const char *key, char *buffer, int size)
+{
+ const void *string_address;
+ int string_size;
+
+ string_address = cros_vpd_find(key, &string_size);
+
+ if (!string_address)
+ return NULL;
+
+ if (size > (string_size + 1)) {
+ strcpy(buffer, string_address);
+ } else {
+ memcpy(buffer, string_address, size - 1);
+ buffer[size - 1] = '\0';
+ }
return buffer;
}
diff --git a/src/vendorcode/google/chromeos/cros_vpd.h b/src/vendorcode/google/chromeos/cros_vpd.h
index 674dbf6..19658c2 100644
--- a/src/vendorcode/google/chromeos/cros_vpd.h
+++ b/src/vendorcode/google/chromeos/cros_vpd.h
@@ -18,4 +18,20 @@
*/
char *cros_vpd_gets(const char *key, char *buffer, int size);
+/*
+ * Find VPD value by key.
+ *
+ * Searches for a VPD entry in the VPD cache. If found, places the size of the
+ * entry into '*size' and returns the pointer to the entry data.
+ *
+ * This function presumes that VPD is cached in DRAM (which is the case in the
+ * current implementation) and as such returns the pointer into the cache. The
+ * user is not supposed to modify the data, and does not have to free the
+ * memory.
+ *
+ * Returns NULL if key is not found.
+ */
+
+const void *cros_vpd_find(const char *key, int *size);
+
#endif /* __CROS_VPD_H__ */
Patrick Georgi (pgeorgi(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/9401
-gerrit
commit c4bfc5b01c8a1a4f0bd84c7056507827608e0d30
Author: Julius Werner <jwerner(a)chromium.org>
Date: Wed Sep 24 15:40:49 2014 -0700
gpio: Remove non-ternary tristate mode, make ternaries easier
The function to read board IDs from tristate GPIOs currently supports
two output modes: a normal base-3 integer, or a custom format where
every two bits represent one tristate pin. Each board decides which
representation to use on its own, which is inconsistent and provides
another possible gotcha to trip over when reading unfamiliar code.
The two-bits-per-pin format creates the additional problem that a
complete list of IDs (such as some boards use to build board-ID tables)
necessarily has "holes" in them (since 0b11 does not correspond to a
possible pin state), which makes them extremely tricky to write, read
and expand. It's also very unintuitive in my opinion, although it was
intended to make it easier to read individual pin states from a hex
representation.
This patch switches all boards over to base-3 and removes the other
format to improve consistency. The tristate reading function will just
print the pin states as they are read to make it easier to debug them,
and we add a new BASE3() macro that can generate ternary numbers from
pin states. Also change the order of all static initializers of board ID
pin lists to write the most significant bit first, hoping that this can
help clear up confusion about the endianness of the pins.
CQ-DEPEND=CL:219902
BUG=None
TEST=Booted on a Nyan_Blaze (with board ID 1, unfortunately the only one
I have). Compiled on Daisy, Peach_Pit, Nyan, Nyan_Big, Nyan_Blaze, Rush,
Rush_Ryu, Storm, Veryon_Pinky and Falco for good measure.
Change-Id: I3ce5a0829f260db7d7df77e6788c2c6d13901b8f
Signed-off-by: Patrick Georgi <pgeorgi(a)chromium.org>
Original-Commit-Id: 2fa9545ac431c9af111ee4444d593ee4cf49554d
Original-Change-Id: I6133cdaf01ed6590ae07e88d9e85a33dc013211a
Original-Signed-off-by: Julius Werner <jwerner(a)chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/219901
Original-Reviewed-by: Aaron Durbin <adurbin(a)chromium.org>
---
src/include/base3.h | 48 +++++++++++++++++++++++++++++
src/include/gpio.h | 14 +++------
src/lib/tristate_gpios.c | 15 +++++----
src/mainboard/google/nyan_big/boardid.c | 8 ++---
src/mainboard/google/nyan_blaze/boardid.c | 8 ++---
src/mainboard/google/rush_ryu/boardid.c | 46 ++++++++-------------------
src/mainboard/google/storm/boardid.c | 4 +--
src/mainboard/google/veyron_pinky/boardid.c | 10 ++----
8 files changed, 87 insertions(+), 66 deletions(-)
diff --git a/src/include/base3.h b/src/include/base3.h
new file mode 100644
index 0000000..e92cc8b
--- /dev/null
+++ b/src/include/base3.h
@@ -0,0 +1,48 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2014 Google Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __SRC_INCLUDE_BASE3_H__
+#define __SRC_INCLUDE_BASE3_H__
+
+/* We translate a floating pin (Z) as the ternary digit 2. */
+#define Z 2
+
+/*
+ * This provides a variadic macro BASE3() that can be used to translate a set of
+ * pin states into its base-3 integer representation, even in the context of a
+ * static initializer. You can call it with any number of up to 6 arguments,
+ * e.g. BASE3(1, Z) -> 5 or BASE3(0, Z, 1, 0) -> 21. Just don't look too closely
+ * at how the sausage is made. (Pay extra attention to typos when expanding it!)
+ */
+#define _BASE3_IMPL_1(arg0, arg1, arg2, arg3, arg4, arg5) arg0
+#define _BASE3_IMPL_2(arg0, arg1, arg2, arg3, arg4, arg5) \
+ (arg1 + (3 * _BASE3_IMPL_1(arg0, arg1, arg2, arg3, arg4, arg5)))
+#define _BASE3_IMPL_3(arg0, arg1, arg2, arg3, arg4, arg5) \
+ (arg2 + (3 * _BASE3_IMPL_2(arg0, arg1, arg2, arg3, arg4, arg5)))
+#define _BASE3_IMPL_4(arg0, arg1, arg2, arg3, arg4, arg5) \
+ (arg3 + (3 * _BASE3_IMPL_3(arg0, arg1, arg2, arg3, arg4, arg5)))
+#define _BASE3_IMPL_5(arg0, arg1, arg2, arg3, arg4, arg5) \
+ (arg4 + (3 * _BASE3_IMPL_4(arg0, arg1, arg2, arg3, arg4, arg5)))
+#define _BASE3_IMPL_6(arg0, arg1, arg2, arg3, arg4, arg5) \
+ (arg5 + (3 * _BASE3_IMPL_5(arg0, arg1, arg2, arg3, arg4, arg5)))
+#define _BASE3_IMPL(arg0, arg1, arg2, arg3, arg4, arg5, NARGS, ...) \
+ _BASE3_IMPL##NARGS(arg0, arg1, arg2, arg3, arg4, arg5)
+#define BASE3(...) _BASE3_IMPL(__VA_ARGS__, _6, _5, _4, _3, _2, _1)
+
+#endif /* __SRC_INCLUDE_BASE3_H__ */
diff --git a/src/include/gpio.h b/src/include/gpio.h
index af06697..b2a341d 100644
--- a/src/include/gpio.h
+++ b/src/include/gpio.h
@@ -36,17 +36,13 @@ void gpio_output(gpio_t gpio, int value);
/*
* Read the value presented by the set of GPIOs, when each pin is interpreted
- * as a number in 0..2 range depending on the external pullup situation.
+ * as a base-3 digit (LOW = 0, HIGH = 1, Z/floating = 2).
+ * Example: X1 = Z, X2 = 1 -> gpio_get_tristates({GPIO(X1), GPIO(X2)}) = 5
+ * BASE3() from <base3.h> can generate numbers to compare the result to.
*
- * Depending on the third parameter, the return value is either a set of two
- * bit fields, each representing one GPIO value, or a number where each GPIO is
- * included multiplied by 3^gpio_num, resulting in a true tertiary value.
- *
- * gpio[]: pin positions to read. little-endian (less significant value first).
+ * gpio[]: pin positions to read. gpio[0] is less significant than gpio[1].
* num_gpio: number of pins to read.
- * tertiary: 1: pins are interpreted as a quad coded tertiary.
- * 0: pins are interpreted as a set of two bit fields.
*/
-int gpio_get_tristates(gpio_t gpio[], int num_gpio, int tertiary);
+int gpio_get_tristates(gpio_t gpio[], int num_gpio);
#endif /* __SRC_INCLUDE_GPIO_H__ */
diff --git a/src/lib/tristate_gpios.c b/src/lib/tristate_gpios.c
index 5ee5580..0967a8f 100644
--- a/src/lib/tristate_gpios.c
+++ b/src/lib/tristate_gpios.c
@@ -17,10 +17,12 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <base3.h>
+#include <console/console.h>
#include <delay.h>
#include <gpio.h>
-int gpio_get_tristates(gpio_t gpio[], int num_gpio, int tertiary)
+int gpio_get_tristates(gpio_t gpio[], int num_gpio)
{
/*
* GPIOs which are tied to stronger external pull up or pull down
@@ -31,6 +33,7 @@ int gpio_get_tristates(gpio_t gpio[], int num_gpio, int tertiary)
* internally pulled to.
*/
+ static const char tristate_char[] = {[0] = '0', [1] = '1', [Z] = 'Z'};
int temp;
int index;
int id = 0;
@@ -62,14 +65,14 @@ int gpio_get_tristates(gpio_t gpio[], int num_gpio, int tertiary)
* 1: pull up
* 2: floating
*/
+ printk(BIOS_DEBUG, "Reading tristate GPIOs: ");
for (index = num_gpio - 1; index >= 0; --index) {
- if (tertiary)
- id *= 3;
- else
- id <<= 2;
temp = gpio_get(gpio[index]);
- id += ((value[index] ^ temp) << 1) | temp;
+ temp |= ((value[index] ^ temp) << 1);
+ printk(BIOS_DEBUG, "%c ", tristate_char[temp]);
+ id = (id * 3) + temp;
}
+ printk(BIOS_DEBUG, "= %d\n", id);
/* Disable pull up / pull down to conserve power */
for (index = 0; index < num_gpio; ++index)
diff --git a/src/mainboard/google/nyan_big/boardid.c b/src/mainboard/google/nyan_big/boardid.c
index 00f646d..b420f5a 100644
--- a/src/mainboard/google/nyan_big/boardid.c
+++ b/src/mainboard/google/nyan_big/boardid.c
@@ -25,13 +25,13 @@
uint8_t board_id(void)
{
static int id = -1;
+ gpio_t gpio[] = {[3] = GPIO(X4), [2] = GPIO(X1), /* X4 is MSB */
+ [1] = GPIO(T1), [0] = GPIO(Q3),}; /* Q3 is LSB */
if (id < 0) {
- gpio_t gpio[] = {GPIO(Q3), GPIO(T1), GPIO(X1), GPIO(X4)};
+ id = gpio_get_tristates(gpio, ARRAY_SIZE(gpio));
- id = gpio_get_tristates(gpio, ARRAY_SIZE(gpio), 0);
-
- printk(BIOS_SPEW, "Board TRISTATE ID: %#x.\n", id);
+ printk(BIOS_SPEW, "Board TRISTATE ID: %d.\n", id);
}
return id;
diff --git a/src/mainboard/google/nyan_blaze/boardid.c b/src/mainboard/google/nyan_blaze/boardid.c
index 00f646d..b420f5a 100644
--- a/src/mainboard/google/nyan_blaze/boardid.c
+++ b/src/mainboard/google/nyan_blaze/boardid.c
@@ -25,13 +25,13 @@
uint8_t board_id(void)
{
static int id = -1;
+ gpio_t gpio[] = {[3] = GPIO(X4), [2] = GPIO(X1), /* X4 is MSB */
+ [1] = GPIO(T1), [0] = GPIO(Q3),}; /* Q3 is LSB */
if (id < 0) {
- gpio_t gpio[] = {GPIO(Q3), GPIO(T1), GPIO(X1), GPIO(X4)};
+ id = gpio_get_tristates(gpio, ARRAY_SIZE(gpio));
- id = gpio_get_tristates(gpio, ARRAY_SIZE(gpio), 0);
-
- printk(BIOS_SPEW, "Board TRISTATE ID: %#x.\n", id);
+ printk(BIOS_SPEW, "Board TRISTATE ID: %d.\n", id);
}
return id;
diff --git a/src/mainboard/google/rush_ryu/boardid.c b/src/mainboard/google/rush_ryu/boardid.c
index ba3a4be..5b4c1cd 100644
--- a/src/mainboard/google/rush_ryu/boardid.c
+++ b/src/mainboard/google/rush_ryu/boardid.c
@@ -17,35 +17,13 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <base3.h>
#include <boardid.h>
#include <console/console.h>
#include <stdlib.h>
#include "gpio.h"
-/*
- * +------------------+---------+
- * | BD_ID_STRAP[1:0] | PHASE |
- * +------------------+---------+
- * | 00 | PROTO0 |
- * +------------------+---------+
- * | 01 | PROTO1 |
- * +------------------+---------+
- * | 0Z | EVT |
- * +------------------+---------+
- * | 10 | DVT |
- * +------------------+---------+
- * | 11 | PVT |
- * +------------------+---------+
- * | 1Z | MP |
- * +------------------+---------+
- * | Z0 | |
- * +------------------+---------+
- * | Z1 | |
- * +------------------+---------+
- * | ZZ | |
- * +------------------+---------+
- */
struct id_to_str {
const char *str;
int tri_state_value;
@@ -53,15 +31,15 @@ struct id_to_str {
};
static const struct id_to_str bdid_map[] = {
- { "PROTO 0", 0x00, BOARD_ID_PROTO_0 },
- { "PROTO 1", 0x01, BOARD_ID_PROTO_1 },
- { "EVT", 0x02, BOARD_ID_EVT },
- { "DVT", 0x04, BOARD_ID_DVT },
- { "PVT", 0x05, BOARD_ID_PVT },
- { "MP", 0x06, BOARD_ID_MP },
- { "Z0", 0x08, -1 },
- { "Z1", 0x09, -1 },
- { "ZZ", 0x0a, -1 },
+ { "PROTO 0", BASE3(0, 0), BOARD_ID_PROTO_0 },
+ { "PROTO 1", BASE3(0, 1), BOARD_ID_PROTO_1 },
+ { "EVT", BASE3(0, Z), BOARD_ID_EVT },
+ { "DVT", BASE3(1, 0), BOARD_ID_DVT },
+ { "PVT", BASE3(1, 1), BOARD_ID_PVT },
+ { "MP", BASE3(1, Z), BOARD_ID_MP },
+ { "Z0", BASE3(Z, 0), -1 },
+ { "Z1", BASE3(Z, 1), -1 },
+ { "ZZ", BASE3(Z, Z), -1 },
};
uint8_t board_id(void)
@@ -72,9 +50,9 @@ uint8_t board_id(void)
const char *idstr = "Unknown";
int i;
int tristate_id;
- gpio_t gpio[] = { BD_ID0, BD_ID1 };
+ gpio_t gpio[] = {[1] = BD_ID1, [0] = BD_ID0}; /* ID0 is LSB */
- tristate_id = gpio_get_tristates(gpio, ARRAY_SIZE(gpio), 0);
+ tristate_id = gpio_get_tristates(gpio, ARRAY_SIZE(gpio));
for (i = 0; i < ARRAY_SIZE(bdid_map); i++) {
if (tristate_id != bdid_map[i].tri_state_value)
diff --git a/src/mainboard/google/storm/boardid.c b/src/mainboard/google/storm/boardid.c
index 878598b..c32567e 100644
--- a/src/mainboard/google/storm/boardid.c
+++ b/src/mainboard/google/storm/boardid.c
@@ -42,10 +42,10 @@ static int board_id_value = -1;
static uint8_t get_board_id(void)
{
uint8_t bid;
- gpio_t hw_rev_gpios[] = {29, 30, 68};
+ gpio_t hw_rev_gpios[] = {[2] = 68, [1] = 30, [0] = 29}; /* 29 is LSB */
int offset = 19;
- bid = gpio_get_tristates(hw_rev_gpios, ARRAY_SIZE(hw_rev_gpios), 1);
+ bid = gpio_get_tristates(hw_rev_gpios, ARRAY_SIZE(hw_rev_gpios));
bid = (bid + offset) % 27;
printk(BIOS_INFO, "Board ID %d\n", bid);
diff --git a/src/mainboard/google/veyron_pinky/boardid.c b/src/mainboard/google/veyron_pinky/boardid.c
index d8f4a3d..8d3e183 100644
--- a/src/mainboard/google/veyron_pinky/boardid.c
+++ b/src/mainboard/google/veyron_pinky/boardid.c
@@ -25,12 +25,8 @@
uint8_t board_id(void)
{
static int id = -1;
- static const gpio_t pins[] = {
- { .port = 2, .bank = GPIO_A, .idx = 0 },
- { .port = 2, .bank = GPIO_A, .idx = 1 },
- { .port = 2, .bank = GPIO_A, .idx = 2 },
- { .port = 2, .bank = GPIO_A, .idx = 7 },
- };
+ static const gpio_t pins[] = {[3] = GPIO(2, A, 7), [2] = GPIO(2, A, 2),
+ [1] = GPIO(2, A, 1), [0] = GPIO(2, A, 0)}; /* GPIO2_A0 is LSB */
if (id < 0) {
int i;
@@ -40,7 +36,7 @@ uint8_t board_id(void)
gpio_input(pins[i]);
id |= gpio_get(pins[i]) << i;
}
- printk(BIOS_SPEW, "Board ID: %#x.\n", id);
+ printk(BIOS_SPEW, "Board ID: %d.\n", id);
}
return id;
Patrick Georgi (pgeorgi(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/9399
-gerrit
commit 71ec63cba74c7018ccf317fc804d5a2b1c3aeeab
Author: Vadim Bendebury <vbendeb(a)chromium.org>
Date: Thu Oct 16 13:26:59 2014 -0700
storm: retrieve MAC address from VPD
Retrieving MAC address from VPD should be the board responsibility,
add a call to the recently introduced function.
BRANCH=storm
BUG=chromium:417117
TEST=verified that MAC addresses still show up in the device tree on
storm
Change-Id: Ib8ddc88ccd859e0b36e65aaaeb5c9473077c8c02
Signed-off-by: Patrick Georgi <pgeorgi(a)chromium.org>
Original-Commit-Id: 285cb256e619ef41c7f11680b3fa5310b1d93cf1
Original-Change-Id: I3913b10a425d8e8621b832567871ed4861756381
Original-Signed-off-by: Vadim Bendebury <vbendeb(a)chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/223797
Original-Reviewed-by: Julius Werner <jwerner(a)chromium.org>
---
src/mainboard/google/storm/mainboard.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/mainboard/google/storm/mainboard.c b/src/mainboard/google/storm/mainboard.c
index acadce5..d6dc72e 100644
--- a/src/mainboard/google/storm/mainboard.c
+++ b/src/mainboard/google/storm/mainboard.c
@@ -136,6 +136,9 @@ void lb_board(struct lb_header *header)
dma->size = sizeof(*dma);
dma->range_start = (uintptr_t)_dma_coherent;
dma->range_size = _dma_coherent_size;
+
+ /* Retrieve the switch interface MAC addressses. */
+ lb_table_add_macs_from_vpd(header);
}
static int read_gpio(gpio_t gpio_num)
Patrick Georgi (pgeorgi(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/9398
-gerrit
commit d48ada2ac600d50c84d9b7d32316483993e03877
Author: Vadim Bendebury <vbendeb(a)chromium.org>
Date: Thu Oct 16 13:02:37 2014 -0700
chromeos: move VPD MAC address retrieval function
Retrieval of the MAC address from the VPD is a Chrome OS specific
feature, required just on one platform so far. There is no need to
look for the MAC address in the VPD on all other Chrome OS boards.
BRANCH=storm
BUG=chromium:417117
TEST=with the upcoming patch applied verified that MAC addresses still
show up in the device tree on storm
Change-Id: If5fd4895bffc758563df7d21f38995f0c8594330
Signed-off-by: Patrick Georgi <pgeorgi(a)chromium.org>
Original-Commit-Id: fb4906ac559634321a01b4814f338611b9e98b2b
Original-Change-Id: I8e6f8dc38294d3ab11965931be575360fd12b2fc
Original-Signed-off-by: Vadim Bendebury <vbendeb(a)chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/223796
Original-Reviewed-by: Julius Werner <jwerner(a)chromium.org>
---
src/include/boot/coreboot_tables.h | 6 ++
src/lib/coreboot_table.c | 73 ----------------------
src/vendorcode/google/chromeos/Makefile.inc | 2 +-
src/vendorcode/google/chromeos/vpd_mac.c | 93 +++++++++++++++++++++++++++++
4 files changed, 100 insertions(+), 74 deletions(-)
diff --git a/src/include/boot/coreboot_tables.h b/src/include/boot/coreboot_tables.h
index 0efb8fd..db55ada 100644
--- a/src/include/boot/coreboot_tables.h
+++ b/src/include/boot/coreboot_tables.h
@@ -366,6 +366,12 @@ void lb_add_console(uint16_t consoletype, void *data);
/* Define this in mainboard.c to add board-specific table entries. */
void lb_board(struct lb_header *header);
+/*
+ * Function to retrieve MAC address(es) from the VPD and store them in the
+ * coreboot table.
+ */
+void lb_table_add_macs_from_vpd(struct lb_header *header);
+
struct lb_record *lb_new_record(struct lb_header *header);
#endif /* COREBOOT_TABLES_H */
diff --git a/src/lib/coreboot_table.c b/src/lib/coreboot_table.c
index a8b5edf..365283f 100644
--- a/src/lib/coreboot_table.c
+++ b/src/lib/coreboot_table.c
@@ -38,7 +38,6 @@
#endif
#include <vendorcode/google/chromeos/chromeos.h>
#include <vendorcode/google/chromeos/gnvs.h>
-#include <vendorcode/google/chromeos/cros_vpd.h>
#endif
#if CONFIG_ARCH_X86
#include <cpu/x86/mtrr.h>
@@ -158,75 +157,6 @@ void fill_lb_gpio(struct lb_gpio *gpio, int num,
}
#if CONFIG_CHROMEOS
-static void lb_macs(struct lb_header *header)
-{
- /*
- * In case there is one or more MAC addresses stored in the VPD, the
- * key is "ethernet_mac{0..9}", up to 10 values.
- */
- static const char mac_addr_key_base[] = "ethernet_mac0";
- char mac_addr_key[sizeof(mac_addr_key_base)];
- char mac_addr_str[13]; /* 12 symbols and the trailing zero. */
- int count;
- struct lb_macs *macs = NULL;
- const int index_of_index = sizeof(mac_addr_key) - 2;
-
- /*
- * MAC addresses are stored in the VPD as strings of hex numbers,
- * which need to be converted into binary for storing in the coreboot
- * table.
- */
- strcpy(mac_addr_key, mac_addr_key_base);
- count = 0;
- do {
- int i;
-
- if (!cros_vpd_gets(mac_addr_key, mac_addr_str,
- sizeof(mac_addr_str)))
- break; /* No more MAC addresses in VPD */
-
- if (!macs) {
- macs = (struct lb_macs *)lb_new_record(header);
- macs->tag = LB_TAG_MAC_ADDRS;
- }
-
- /* MAC address in symbolic form is in mac_addr_str. */
- for (i = 0; i < sizeof(macs->mac_addrs[0].mac_addr); i++) {
- int j;
- uint8_t n = 0;
-
- for (j = 0; j < 2; j++) {
- char c = mac_addr_str[i * 2 + j];
-
- if (isxdigit(c)) {
- if (isdigit(c))
- c -= '0';
- else
- c = tolower(c) - 'a' + 10;
- } else {
- printk(BIOS_ERR,
- "%s: non hexadecimal symbol "
- "%#2.2x in the VPD field %s\n",
- __func__, (uint8_t)c,
- mac_addr_key);
- c = 0;
- }
- n <<= 4;
- n |= c;
- }
- macs->mac_addrs[count].mac_addr[i] = n;
- }
- count++;
- mac_addr_key[index_of_index] = '0' + count;
- } while (count < 10);
-
- if (!count)
- return; /* No MAC addresses in the VPD. */
-
- macs->count = count;
- macs->size = sizeof(*macs) + count * sizeof(struct mac_address);
-}
-
static void lb_gpios(struct lb_header *header)
{
struct lb_gpios *gpios;
@@ -517,9 +447,6 @@ unsigned long write_coreboot_table(
/* pass along the vboot_handoff address. */
lb_vboot_handoff(head);
-
- /* Retrieve mac addresses from VPD, if any. */
- lb_macs(head);
#endif
/* Add board ID if available */
diff --git a/src/vendorcode/google/chromeos/Makefile.inc b/src/vendorcode/google/chromeos/Makefile.inc
index f43a87e..da1db8b 100644
--- a/src/vendorcode/google/chromeos/Makefile.inc
+++ b/src/vendorcode/google/chromeos/Makefile.inc
@@ -29,7 +29,7 @@ ramstage-y += fmap.c
ramstage-$(CONFIG_CHROMEOS_RAMOOPS) += ramoops.c
smm-y += fmap.c
romstage-y += vpd_decode.c cros_vpd.c
-ramstage-y += vpd_decode.c cros_vpd.c
+ramstage-y += vpd_decode.c cros_vpd.c vpd_mac.c
ifeq ($(MOCK_TPM),1)
CFLAGS_common += -DMOCK_TPM=1
diff --git a/src/vendorcode/google/chromeos/vpd_mac.c b/src/vendorcode/google/chromeos/vpd_mac.c
new file mode 100644
index 0000000..ad4174c
--- /dev/null
+++ b/src/vendorcode/google/chromeos/vpd_mac.c
@@ -0,0 +1,93 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2014 Google Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <boot/coreboot_tables.h>
+#include <console/console.h>
+#include <string.h>
+
+#include <vendorcode/google/chromeos/cros_vpd.h>
+
+void lb_table_add_macs_from_vpd(struct lb_header *header)
+{
+ /*
+ * In case there is one or more MAC addresses stored in the VPD, the
+ * key is "ethernet_mac{0..9}", up to 10 values.
+ */
+ static const char mac_addr_key_base[] = "ethernet_mac0";
+ char mac_addr_key[sizeof(mac_addr_key_base)];
+ char mac_addr_str[13]; /* 12 symbols and the trailing zero. */
+ int count;
+ struct lb_macs *macs = NULL;
+ const int index_of_index = sizeof(mac_addr_key) - 2;
+
+ /*
+ * MAC addresses are stored in the VPD as strings of hex numbers,
+ * which need to be converted into binary for storing in the coreboot
+ * table.
+ */
+ strcpy(mac_addr_key, mac_addr_key_base);
+ count = 0;
+ do {
+ int i;
+
+ if (!cros_vpd_gets(mac_addr_key, mac_addr_str,
+ sizeof(mac_addr_str)))
+ break; /* No more MAC addresses in VPD */
+
+ if (!macs) {
+ macs = (struct lb_macs *)lb_new_record(header);
+ macs->tag = LB_TAG_MAC_ADDRS;
+ }
+
+ /* MAC address in symbolic form is in mac_addr_str. */
+ for (i = 0; i < sizeof(macs->mac_addrs[0].mac_addr); i++) {
+ int j;
+ uint8_t n = 0;
+
+ for (j = 0; j < 2; j++) {
+ char c = mac_addr_str[i * 2 + j];
+
+ if (isxdigit(c)) {
+ if (isdigit(c))
+ c -= '0';
+ else
+ c = tolower(c) - 'a' + 10;
+ } else {
+ printk(BIOS_ERR,
+ "%s: non hexadecimal symbol "
+ "%#2.2x in the VPD field %s\n",
+ __func__, (uint8_t)c,
+ mac_addr_key);
+ c = 0;
+ }
+ n <<= 4;
+ n |= c;
+ }
+ macs->mac_addrs[count].mac_addr[i] = n;
+ }
+ count++;
+ mac_addr_key[index_of_index] = '0' + count;
+ } while (count < 10);
+
+ if (!count)
+ return; /* No MAC addresses in the VPD. */
+
+ macs->count = count;
+ macs->size = sizeof(*macs) + count * sizeof(struct mac_address);
+}