add command setserial and showserial
This commit is contained in:
parent
d54bbbc1e8
commit
0e514396fa
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
#include <command.h>
|
#include <command.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifdef CFG_CMD_SETMAC
|
#ifdef CFG_CMD_SETMAC
|
||||||
|
|
||||||
|
@ -30,6 +31,7 @@
|
||||||
#define ETH_ALEN 6
|
#define ETH_ALEN 6
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define SERIAL_LOCATION 0x20
|
||||||
extern flash_info_t flash_info[]; /* info for FLASH chips */
|
extern flash_info_t flash_info[]; /* info for FLASH chips */
|
||||||
|
|
||||||
static int mac_location[] = {
|
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;
|
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(
|
U_BOOT_CMD(
|
||||||
setmac, ARRAY_SIZE(mac_location)+2, 0, do_setmac,
|
setmac, ARRAY_SIZE(mac_location)+2, 0, do_setmac,
|
||||||
"setmac - Set ethernet MAC addresses\n",
|
"setmac - Set ethernet MAC addresses\n",
|
||||||
|
@ -256,4 +312,16 @@ U_BOOT_CMD(
|
||||||
"showmac - Show ethernet MAC addresses\n",
|
"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 */
|
#endif /* CFG_CMD_SETMAC */
|
||||||
|
|
Loading…
Reference in New Issue