From 0e514396fa5ff2d2410e50854f103b2c23e8d841 Mon Sep 17 00:00:00 2001 From: Alexander Couzens Date: Mon, 6 Apr 2015 17:14:29 +0200 Subject: [PATCH] add command setserial and showserial --- u-boot/common/cmd_setmac.c | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/u-boot/common/cmd_setmac.c b/u-boot/common/cmd_setmac.c index 394db4bb78..0ace1a0e9d 100644 --- a/u-boot/common/cmd_setmac.c +++ b/u-boot/common/cmd_setmac.c @@ -23,6 +23,7 @@ #include #include +#include #ifdef CFG_CMD_SETMAC @@ -30,6 +31,7 @@ #define ETH_ALEN 6 #endif +#define SERIAL_LOCATION 0x20 extern flash_info_t flash_info[]; /* info for FLASH chips */ static int mac_location[] = { @@ -239,6 +241,60 @@ int do_showmac(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return CMD_RET_SUCCESS; } +int do_setserial(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + u8 buffer[CFG_FLASH_SECTOR_SIZE]; + int32_t *serial; + int32_t serialnumber; + int rc; + + if (argc != 2) + return CMD_RET_FAILURE; + + serialnumber = atoi(argv[1]); + if (serialnumber <= 0) { + printf("Invalid serialnumber. <= 0!\n"); + return CMD_RET_FAILURE; + } + + /* read */ + memcpy(buffer, (void *)BOARDCAL, CFG_FLASH_SECTOR_SIZE); + + /* set serial number */ + serial = (int32_t *) (buffer + SERIAL_LOCATION); + *serial = serialnumber; + + /* erase */ + rc = flash_erase(flash_info, CAL_SECTOR, CAL_SECTOR); + if (rc) { + printf("Write mac failed because flash_erase failed! rc %d\n", rc); + return 1; + } + + /* write */ + rc = write_buff(flash_info, buffer, BOARDCAL, CFG_FLASH_SECTOR_SIZE); + if (rc) { + printf("Write mac failed because write_buff failed! rc %d\n", rc); + return 1; + } + + return CMD_RET_SUCCESS; +} + + +int do_showserial(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + int i = 0; + u8 buffer[CFG_FLASH_SECTOR_SIZE]; + int32_t *serial; + memcpy(buffer, (void *)BOARDCAL, CFG_FLASH_SECTOR_SIZE); + + serial = buffer + SERIAL_LOCATION; + printf("serial %d\n", serial); + + return CMD_RET_SUCCESS; +} + U_BOOT_CMD( setmac, ARRAY_SIZE(mac_location)+2, 0, do_setmac, "setmac - Set ethernet MAC addresses\n", @@ -256,4 +312,16 @@ U_BOOT_CMD( "showmac - Show ethernet MAC addresses\n", ); +U_BOOT_CMD( + setserial, 2, 0, do_setserial, + "setserial - Set the serial number\n", + "setserial serial\n" +); + +U_BOOT_CMD( + showserial, 1, 0, do_showserial, + "showserial - Show serial number\n", +); + + #endif /* CFG_CMD_SETMAC */