vpd: process WiFi MACs along with ethernet MACs
coreboot is expected to read all MAC addresses from the VPD and put them in the coreboot table entry, depthcharge is expected to associate different MAC addresses with different kernel device tree nodes. This patch adds processing of wifi_macX keys. The order of MAC addresses in the coreboot table is such that the wifi_macX entries follow ethrnet_macX entries, ordered by X. BRANCH=none BUG=chrome-os-partner:36584 TEST=with the rest patches applied verified the contents of the kernel device tree on an urara board. Change-Id: I6523e168d2fea201a4956bc2a2d605b07ddac452 Signed-off-by: Patrick Georgi <pgeorgi@chromium.org> Original-Commit-Id: 36c12ee1d3ce9d2797902f0e098651067c2283ed Original-Change-Id: Ib87e4815243f34ab258325839cbc12d16120bf89 Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/262843 Original-Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: http://review.coreboot.org/9896 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
This commit is contained in:
parent
65f08d50ae
commit
375f3928a4
|
@ -23,68 +23,88 @@
|
||||||
|
|
||||||
#include <vendorcode/google/chromeos/cros_vpd.h>
|
#include <vendorcode/google/chromeos/cros_vpd.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Decode string representation of the MAC address (a string of 12 hex
|
||||||
|
* symbols) into binary. 'key_name' is the name of the VPD field, it's used if
|
||||||
|
* it is necessary to report an input data format problem.
|
||||||
|
*/
|
||||||
|
static void decode_mac(struct mac_address *mac,
|
||||||
|
const char *mac_addr_str,
|
||||||
|
const char *key_name)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < sizeof(mac->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:%s\n",
|
||||||
|
__func__, (uint8_t)c, key_name,
|
||||||
|
mac_addr_str);
|
||||||
|
c = 0;
|
||||||
|
}
|
||||||
|
n <<= 4;
|
||||||
|
n |= c;
|
||||||
|
}
|
||||||
|
mac->mac_addr[i] = n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void lb_table_add_macs_from_vpd(struct lb_header *header)
|
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
|
* Mac addresses in the VPD can be stored in two groups, for ethernet
|
||||||
* key is "ethernet_mac{0..9}", up to 10 values.
|
* and WiFi, with keys 'ethernet_macX and wifi_macX.
|
||||||
*/
|
*/
|
||||||
static const char mac_addr_key_base[] = "ethernet_mac0";
|
const char *mac_addr_key_bases[] = {"ethernet_mac0", "wifi_mac0"};
|
||||||
char mac_addr_key[sizeof(mac_addr_key_base)];
|
char mac_addr_key[20]; /* large enough for either key */
|
||||||
char mac_addr_str[13]; /* 12 symbols and the trailing zero. */
|
char mac_addr_str[13]; /* 12 symbols and the trailing zero. */
|
||||||
int count;
|
int i, count;
|
||||||
struct lb_macs *macs = NULL;
|
struct lb_macs *macs = NULL;
|
||||||
const int index_of_index = sizeof(mac_addr_key) - 2;
|
|
||||||
|
|
||||||
/*
|
/* Make sure the copy is always zero terminated. */
|
||||||
* MAC addresses are stored in the VPD as strings of hex numbers,
|
mac_addr_key[sizeof(mac_addr_key) - 1] = '\0';
|
||||||
* which need to be converted into binary for storing in the coreboot
|
|
||||||
* table.
|
|
||||||
*/
|
|
||||||
strcpy(mac_addr_key, mac_addr_key_base);
|
|
||||||
count = 0;
|
count = 0;
|
||||||
do {
|
for (i = 0; i < ARRAY_SIZE(mac_addr_key_bases); i++) {
|
||||||
int i;
|
int index_of_index;
|
||||||
|
|
||||||
if (!cros_vpd_gets(mac_addr_key, mac_addr_str,
|
strncpy(mac_addr_key, mac_addr_key_bases[i],
|
||||||
sizeof(mac_addr_str)))
|
sizeof(mac_addr_key) - 1);
|
||||||
break; /* No more MAC addresses in VPD */
|
index_of_index = strlen(mac_addr_key) - 1;
|
||||||
|
|
||||||
if (!macs) {
|
do {
|
||||||
macs = (struct lb_macs *)lb_new_record(header);
|
/*
|
||||||
macs->tag = LB_TAG_MAC_ADDRS;
|
* If there are no more MAC addresses of this template
|
||||||
}
|
* in the VPD - move on.
|
||||||
|
*/
|
||||||
|
if (!cros_vpd_gets(mac_addr_key, mac_addr_str,
|
||||||
|
sizeof(mac_addr_str)))
|
||||||
|
break;
|
||||||
|
|
||||||
/* MAC address in symbolic form is in mac_addr_str. */
|
if (!macs) {
|
||||||
for (i = 0; i < sizeof(macs->mac_addrs[0].mac_addr); i++) {
|
macs = (struct lb_macs *)lb_new_record(header);
|
||||||
int j;
|
macs->tag = LB_TAG_MAC_ADDRS;
|
||||||
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);
|
|
||||||
|
|
||||||
|
decode_mac(macs->mac_addrs + count,
|
||||||
|
mac_addr_str,
|
||||||
|
mac_addr_key);
|
||||||
|
|
||||||
|
count++;
|
||||||
|
mac_addr_key[index_of_index]++;
|
||||||
|
} while (count < 10);
|
||||||
|
}
|
||||||
if (!count)
|
if (!count)
|
||||||
return; /* No MAC addresses in the VPD. */
|
return; /* No MAC addresses in the VPD. */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue