diff options
author | Brian J. Nemec <bnemec@chromium.org> | 2020-02-18 13:23:56 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-02-21 06:21:18 +0000 |
commit | 2f4c7fb74e849f67841746877da92c584cd09dfe (patch) | |
tree | ab25bb3a8eb3f7883a8ae868f506e838aa5d9045 /chip/stm32 | |
parent | 05b951525aa490284085cec80094a477a69dd6a6 (diff) | |
download | chrome-ec-2f4c7fb74e849f67841746877da92c584cd09dfe.tar.gz |
Servo: Adds persistent storage of MAC address
Adds a field to the persistent storage to store the
MAC address of the device. This is enabled on ServoV4
in order to store the MAC address for the integrated
ethernet port. Added a console command to set and load
this value.
BUG=b:149506580
TEST=Verified setting and loading the MAC address using:
'macaddr set 12:34:56:78:90:ab' and 'macaddr' or 'macaddr load'
Verified that MAC addresses over 19 characters long return
an error response and not update the MAC.
Verified no set serial number will return the uninitialized string.
Verified that the MAC address can be updated independently of serialno
Verified that the persist_state fields restore during firmware updates
Change-Id: I8425ce9e13322e99a4f59df444ea0dc73821aa6b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2063330
Tested-by: Brian Nemec <bnemec@chromium.org>
Reviewed-by: Wai-Hong Tam <waihong@google.com>
Commit-Queue: Brian Nemec <bnemec@chromium.org>
Diffstat (limited to 'chip/stm32')
-rw-r--r-- | chip/stm32/usb.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/chip/stm32/usb.c b/chip/stm32/usb.c index 54cd90dd46..7eb2363787 100644 --- a/chip/stm32/usb.c +++ b/chip/stm32/usb.c @@ -897,4 +897,62 @@ static int command_serialno(int argc, char **argv) DECLARE_CONSOLE_COMMAND(serialno, command_serialno, "load/set [value]", "Read and write USB serial number"); + #endif /* CONFIG_USB_SERIALNO */ + +#ifdef CONFIG_MAC_ADDR + +/* Save MAC address into pstate region. */ +static int usb_save_mac_addr(const char *mac_addr) +{ + int rv; + + if (!mac_addr) { + return EC_ERROR_INVAL; + } + + /* Save this new MAC address to flash. */ + rv = board_write_mac_addr(mac_addr); + if (rv) { + return rv; + } + + /* Load this new MAC address to memory. */ + if (board_read_mac_addr() != NULL) { + return EC_SUCCESS; + } else { + return EC_ERROR_UNKNOWN; + } +} + +static int command_macaddr(int argc, char **argv) +{ + const char* buf; + int rv = EC_SUCCESS; + + if (argc != 1) { + if ((strcasecmp(argv[1], "set") == 0) && + (argc == 3)) { + ccprintf("Saving MAC address\n"); + rv = usb_save_mac_addr(argv[2]); + } else if ((strcasecmp(argv[1], "load") == 0) && + (argc == 2)) { + ccprintf("Loading MAC address\n"); + } else { + return EC_ERROR_INVAL; + } + } + + buf = board_read_mac_addr(); + if (buf == NULL) { + buf = DEFAULT_MAC_ADDR; + } + ccprintf("MAC address: %s\n", buf); + return rv; +} + +DECLARE_CONSOLE_COMMAND(macaddr, command_macaddr, + "load/set [value]", + "Read and write MAC address"); + +#endif /* CONFIG_MAC_ADDR */ |