From: Neil Armstrong Date: Tue, 6 Aug 2019 15:21:02 +0000 (+0200) Subject: arm: meson: add sm cmd to retrieve SoC serial X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=559e6256f855e61f987598a18ed4f2e20bc530e7;p=u-boot.git arm: meson: add sm cmd to retrieve SoC serial The Secure Monitor offers multiple services, like returning the SoC unique serial number, already used to generate an unique MAC address. This adds a new, Amlogic specific, "sm" cmd with a "serial" subcommand to write the SoC unique serial to memory. This "cm" command will be extended in further patches. Signed-off-by: Neil Armstrong --- diff --git a/arch/arm/mach-meson/sm.c b/arch/arm/mach-meson/sm.c index 05b7f0bdf2..99fa17d9a8 100644 --- a/arch/arm/mach-meson/sm.c +++ b/arch/arm/mach-meson/sm.c @@ -77,3 +77,51 @@ int meson_sm_get_serial(void *buffer, size_t size) return 0; } + +static int do_sm_serial(cmd_tbl_t *cmdtp, int flag, int argc, + char *const argv[]) +{ + ulong address; + int ret; + + if (argc < 2) + return CMD_RET_USAGE; + + address = simple_strtoul(argv[1], NULL, 0); + + ret = meson_sm_get_serial((void *)address, SM_CHIP_ID_SIZE); + if (ret) + return CMD_RET_FAILURE; + + return CMD_RET_SUCCESS; +} + +static cmd_tbl_t cmd_sm_sub[] = { + U_BOOT_CMD_MKENT(serial, 2, 1, do_sm_serial, "", ""), +}; + +static int do_sm(cmd_tbl_t *cmdtp, int flag, int argc, + char *const argv[]) +{ + cmd_tbl_t *c; + + if (argc < 2) + return CMD_RET_USAGE; + + /* Strip off leading 'sm' command argument */ + argc--; + argv++; + + c = find_cmd_tbl(argv[0], &cmd_sm_sub[0], ARRAY_SIZE(cmd_sm_sub)); + + if (c) + return c->cmd(cmdtp, flag, argc, argv); + else + return CMD_RET_USAGE; +} + +U_BOOT_CMD( + sm, 5, 0, do_sm, + "Secure Monitor Control", + "serial
- read chip unique id to memory address" +);