blob: df86fda303507aa6b33169c861ef7170b5f19fba [file] [log] [blame] [edit]
/*
* Copyright (c) 2020 The Fuchsia Authors
*/
#include <common.h>
#include <command.h>
#include <factory_boot_kvs.h>
static int do_get(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
FbKvsResult ret;
FbKvsValueType type;
size_t size;
uintptr_t addr;
if (argc < 3 || !argv[1][0])
return CMD_RET_USAGE;
const char *key = argv[1];
addr = (uintptr_t)simple_strtoul(argv[2], NULL, 0);
if (!addr) {
printf("[factory boot:get] Invalid address for %s: %s\n", key, argv[2]);
return CMD_RET_USAGE;
}
/* factory_boot kvs has to be already initialized */
ret = FbKvsGetValueSize(key, &size);
if (ret != kFbKvsResultOk) {
printf("[factory boot:get] Failed to get the value size for %s: %d\n", key, ret);
return CMD_RET_FAILURE;
}
ret = FbKvsGetValueType(key, &type);
if (ret != kFbKvsResultOk) {
printf("[factory boot:get] Failed to get the value type for %s: %d\n", key, ret);
return CMD_RET_FAILURE;
}
switch (type) {
case kFbKvsTypeString:
ret = FbKvsGetString(key, (char *)addr, &size);
break;
case kFbKvsTypeLong:
ret = FbKvsGetLong(key, (int64_t *)addr);
break;
case kFbKvsTypeULong:
ret = FbKvsGetULong(key, (uint64_t *)addr);
break;
case kFbKvsTypeData:
ret = FbKvsGetData(key, (uint8_t *)addr, &size);
break;
default:
printf("[factory boot:get] Unknown type: %d\n", type);
return CMD_RET_FAILURE;
}
return CMD_RET_SUCCESS;
}
static cmd_tbl_t commands[] = {
U_BOOT_CMD_MKENT(get, /* maxargs = */ 3, /* repeatable = */ 0, do_get,
"", ""),
};
static int do_factory_boot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
cmd_tbl_t *cmd;
int ret;
if (argc < 2)
return CMD_RET_USAGE;
argc--;
argv++;
cmd = find_cmd_tbl(argv[0], commands, ARRAY_SIZE(commands));
if (!cmd || argc > cmd->maxargs)
return CMD_RET_USAGE;
ret = cmd->cmd(cmd, flag, argc, argv);
return cmd_process_error(cmdtp, ret);
}
U_BOOT_CMD(
factory_boot, /* maxargs = */ 4, /* repeatable = */ 0, do_factory_boot,
"Factory Boot KVS.",
"factory_boot get <name> [address]- Read a value of |name| to |address|.\n"
);