summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/Kconfig8
-rw-r--r--cmd/Makefile2
-rw-r--r--cmd/bmp.c18
-rw-r--r--cmd/bootefi.c244
-rw-r--r--cmd/bootmenu.c5
-rw-r--r--cmd/cls.c35
-rw-r--r--cmd/eeprom.c21
-rw-r--r--cmd/fdt.c42
-rw-r--r--cmd/host.c5
-rw-r--r--cmd/sb.c65
-rw-r--r--cmd/tpm-common.c8
-rw-r--r--cmd/tpm-v1.c140
-rw-r--r--cmd/tpm-v2.c78
-rw-r--r--cmd/tpm_test.c327
14 files changed, 687 insertions, 311 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig
index e2973b3c514..b1cd1c96907 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1380,6 +1380,14 @@ config CMD_CONITRACE
Enable the 'conitrace' command which displays the codes received
from the console input as hexadecimal numbers.
+config CMD_CLS
+ bool "Enable clear screen command 'cls'"
+ depends on CFB_CONSOLE || DM_VIDEO || LCD || VIDEO
+ default y if LCD
+ help
+ Enable the 'cls' command which clears the screen contents
+ on video frame buffer.
+
config CMD_DISPLAY
bool "Enable the 'display' command, for character displays"
help
diff --git a/cmd/Makefile b/cmd/Makefile
index 0534ddc6797..49986437ba5 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -32,6 +32,7 @@ obj-$(CONFIG_CMD_BTRFS) += btrfs.o
obj-$(CONFIG_CMD_CACHE) += cache.o
obj-$(CONFIG_CMD_CBFS) += cbfs.o
obj-$(CONFIG_CMD_CLK) += clk.o
+obj-$(CONFIG_CMD_CLS) += cls.o
obj-$(CONFIG_CMD_CONFIG) += config.o
obj-$(CONFIG_CMD_CONITRACE) += conitrace.o
obj-$(CONFIG_CMD_CONSOLE) += console.o
@@ -115,6 +116,7 @@ obj-$(CONFIG_CMD_ROCKUSB) += rockusb.o
obj-$(CONFIG_SANDBOX) += host.o
obj-$(CONFIG_CMD_SATA) += sata.o
obj-$(CONFIG_CMD_NVME) += nvme.o
+obj-$(CONFIG_SANDBOX) += sb.o
obj-$(CONFIG_CMD_SF) += sf.o
obj-$(CONFIG_CMD_SCSI) += scsi.o disk.o
obj-$(CONFIG_CMD_SHA1SUM) += sha1sum.o
diff --git a/cmd/bmp.c b/cmd/bmp.c
index 02bdf48b4d4..b8af784590d 100644
--- a/cmd/bmp.c
+++ b/cmd/bmp.c
@@ -124,8 +124,14 @@ static int do_bmp_display(cmd_tbl_t * cmdtp, int flag, int argc, char * const ar
break;
case 4:
addr = simple_strtoul(argv[1], NULL, 16);
- x = simple_strtoul(argv[2], NULL, 10);
- y = simple_strtoul(argv[3], NULL, 10);
+ if (!strcmp(argv[2], "m"))
+ x = BMP_ALIGN_CENTER;
+ else
+ x = simple_strtoul(argv[2], NULL, 10);
+ if (!strcmp(argv[3], "m"))
+ y = BMP_ALIGN_CENTER;
+ else
+ y = simple_strtoul(argv[3], NULL, 10);
break;
default:
return CMD_RET_USAGE;
@@ -249,9 +255,11 @@ int bmp_display(ulong addr, int x, int y)
if (!ret) {
bool align = false;
-# ifdef CONFIG_SPLASH_SCREEN_ALIGN
- align = true;
-# endif /* CONFIG_SPLASH_SCREEN_ALIGN */
+ if (CONFIG_IS_ENABLED(SPLASH_SCREEN_ALIGN) ||
+ x == BMP_ALIGN_CENTER ||
+ y == BMP_ALIGN_CENTER)
+ align = true;
+
ret = video_bmp_display(dev, addr, x, y, align);
}
#elif defined(CONFIG_LCD)
diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 4d68d807480..38679ffc56a 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -148,16 +148,16 @@ static void set_load_options(struct efi_loaded_image *loaded_image_info,
/**
* copy_fdt() - Copy the device tree to a new location available to EFI
*
- * The FDT is relocated into a suitable location within the EFI memory map.
- * An additional 12KB is added to the space in case the device tree needs to be
+ * The FDT is copied to a suitable location within the EFI memory map.
+ * Additional 12 KiB are added to the space in case the device tree needs to be
* expanded later with fdt_open_into().
*
- * @fdt_addr: On entry, address of start of FDT. On exit, address of relocated
- * FDT start
- * @fdt_sizep: Returns new size of FDT, including
- * @return new relocated address of FDT
+ * @fdtp: On entry a pointer to the flattened device tree.
+ * On exit a pointer to the copy of the flattened device tree.
+ * FDT start
+ * Return: status code
*/
-static efi_status_t copy_fdt(ulong *fdt_addrp, ulong *fdt_sizep)
+static efi_status_t copy_fdt(void **fdtp)
{
unsigned long fdt_ram_start = -1L, fdt_pages;
efi_status_t ret = 0;
@@ -178,17 +178,19 @@ static efi_status_t copy_fdt(ulong *fdt_addrp, ulong *fdt_sizep)
}
/*
- * Give us at least 4KB of breathing room in case the device tree needs
- * to be expanded later. Round up to the nearest EFI page boundary.
+ * Give us at least 12 KiB of breathing room in case the device tree
+ * needs to be expanded later.
*/
- fdt = map_sysmem(*fdt_addrp, 0);
- fdt_size = fdt_totalsize(fdt);
- fdt_size += 4096 * 3;
- fdt_size = ALIGN(fdt_size + EFI_PAGE_SIZE - 1, EFI_PAGE_SIZE);
- fdt_pages = fdt_size >> EFI_PAGE_SHIFT;
-
- /* Safe fdt location is at 127MB */
- new_fdt_addr = fdt_ram_start + (127 * 1024 * 1024) + fdt_size;
+ fdt = *fdtp;
+ fdt_pages = efi_size_in_pages(fdt_totalsize(fdt) + 0x3000);
+ fdt_size = fdt_pages << EFI_PAGE_SHIFT;
+
+ /*
+ * Safe fdt location is at 127 MiB.
+ * On the sandbox convert from the sandbox address space.
+ */
+ new_fdt_addr = (uintptr_t)map_sysmem(fdt_ram_start + 0x7f00000 +
+ fdt_size, 0);
ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
EFI_RUNTIME_SERVICES_DATA, fdt_pages,
&new_fdt_addr);
@@ -203,13 +205,11 @@ static efi_status_t copy_fdt(ulong *fdt_addrp, ulong *fdt_sizep)
goto done;
}
}
-
- new_fdt = map_sysmem(new_fdt_addr, fdt_size);
+ new_fdt = (void *)(uintptr_t)new_fdt_addr;
memcpy(new_fdt, fdt, fdt_totalsize(fdt));
fdt_set_totalsize(new_fdt, fdt_size);
- *fdt_addrp = new_fdt_addr;
- *fdt_sizep = fdt_size;
+ *fdtp = (void *)(uintptr_t)new_fdt_addr;
done:
return ret;
}
@@ -277,7 +277,11 @@ static void efi_carve_out_dt_rsv(void *fdt)
if (fdt_get_mem_rsv(fdt, i, &addr, &size) != 0)
continue;
- pages = ALIGN(size, EFI_PAGE_SIZE) >> EFI_PAGE_SHIFT;
+ /* Convert from sandbox address space. */
+ addr = (uintptr_t)map_sysmem(addr, 0);
+
+ pages = efi_size_in_pages(size + (addr & EFI_PAGE_MASK));
+ addr &= ~EFI_PAGE_MASK;
if (!efi_add_memory_map(addr, pages, EFI_RESERVED_MEMORY_TYPE,
false))
printf("FDT memrsv map %d: Failed to add to map\n", i);
@@ -287,7 +291,6 @@ static void efi_carve_out_dt_rsv(void *fdt)
static efi_status_t efi_install_fdt(ulong fdt_addr)
{
bootm_headers_t img = { 0 };
- ulong fdt_pages, fdt_size, fdt_start;
efi_status_t ret;
void *fdt;
@@ -297,34 +300,58 @@ static efi_status_t efi_install_fdt(ulong fdt_addr)
return EFI_INVALID_PARAMETER;
}
+ /* Create memory reservation as indicated by the device tree */
+ efi_carve_out_dt_rsv(fdt);
+
/* Prepare fdt for payload */
- ret = copy_fdt(&fdt_addr, &fdt_size);
+ ret = copy_fdt(&fdt);
if (ret)
return ret;
- unmap_sysmem(fdt);
- fdt = map_sysmem(fdt_addr, 0);
- fdt_size = fdt_totalsize(fdt);
if (image_setup_libfdt(&img, fdt, 0, NULL)) {
printf("ERROR: failed to process device tree\n");
return EFI_LOAD_ERROR;
}
- efi_carve_out_dt_rsv(fdt);
-
/* Link to it in the efi tables */
ret = efi_install_configuration_table(&efi_guid_fdt, fdt);
if (ret != EFI_SUCCESS)
return EFI_OUT_OF_RESOURCES;
- /* And reserve the space in the memory map */
- fdt_start = fdt_addr;
- fdt_pages = fdt_size >> EFI_PAGE_SHIFT;
+ return ret;
+}
+
+static efi_status_t bootefi_run_prepare(const char *load_options_path,
+ struct efi_device_path *device_path,
+ struct efi_device_path *image_path,
+ struct efi_loaded_image_obj **image_objp,
+ struct efi_loaded_image **loaded_image_infop)
+{
+ efi_status_t ret;
- ret = efi_add_memory_map(fdt_start, fdt_pages,
- EFI_BOOT_SERVICES_DATA, true);
+ ret = efi_setup_loaded_image(device_path, image_path, image_objp,
+ loaded_image_infop);
+ if (ret != EFI_SUCCESS)
+ return ret;
- return ret;
+ /* Transfer environment variable as load options */
+ set_load_options(*loaded_image_infop, load_options_path);
+
+ return 0;
+}
+
+/**
+ * bootefi_run_finish() - finish up after running an EFI test
+ *
+ * @loaded_image_info: Pointer to a struct which holds the loaded image info
+ * @image_objj: Pointer to a struct which holds the loaded image object
+ */
+static void bootefi_run_finish(struct efi_loaded_image_obj *image_obj,
+ struct efi_loaded_image *loaded_image_info)
+{
+ efi_restore_gd();
+ free(loaded_image_info->load_options);
+ efi_delete_handle(&image_obj->header);
}
/**
@@ -345,7 +372,7 @@ static efi_status_t do_bootefi_exec(void *efi,
efi_handle_t mem_handle = NULL;
struct efi_device_path *memdp = NULL;
efi_status_t ret;
- struct efi_loaded_image_obj *image_handle = NULL;
+ struct efi_loaded_image_obj *image_obj = NULL;
struct efi_loaded_image *loaded_image_info = NULL;
EFIAPI efi_status_t (*entry)(efi_handle_t image_handle,
@@ -354,7 +381,7 @@ static efi_status_t do_bootefi_exec(void *efi,
/*
* Special case for efi payload not loaded from disk, such as
* 'bootefi hello' or for example payload loaded directly into
- * memory via jtag, etc:
+ * memory via JTAG, etc:
*/
if (!device_path && !image_path) {
printf("WARNING: using memory device/image path, this may confuse some payloads!\n");
@@ -367,27 +394,25 @@ static efi_status_t do_bootefi_exec(void *efi,
*/
ret = efi_create_handle(&mem_handle);
if (ret != EFI_SUCCESS)
- goto exit;
+ return ret; /* TODO: leaks device_path */
ret = efi_add_protocol(mem_handle, &efi_guid_device_path,
device_path);
if (ret != EFI_SUCCESS)
- goto exit;
+ goto err_add_protocol;
} else {
assert(device_path && image_path);
}
- ret = efi_setup_loaded_image(device_path, image_path, &image_handle,
- &loaded_image_info);
- if (ret != EFI_SUCCESS)
- goto exit;
+ ret = bootefi_run_prepare("bootargs", device_path, image_path,
+ &image_obj, &loaded_image_info);
+ if (ret)
+ goto err_prepare;
- /* Transfer environment variable bootargs as load options */
- set_load_options(loaded_image_info, "bootargs");
/* Load the EFI payload */
- entry = efi_load_pe(image_handle, efi, loaded_image_info);
+ entry = efi_load_pe(image_obj, efi, loaded_image_info);
if (!entry) {
ret = EFI_LOAD_ERROR;
- goto exit;
+ goto err_prepare;
}
if (memdp) {
@@ -405,9 +430,9 @@ static efi_status_t do_bootefi_exec(void *efi,
/* Call our payload! */
debug("%s:%d Jumping to 0x%lx\n", __func__, __LINE__, (long)entry);
- if (setjmp(&image_handle->exit_jmp)) {
- ret = image_handle->exit_status;
- goto exit;
+ if (setjmp(&image_obj->exit_jmp)) {
+ ret = image_obj->exit_status;
+ goto err_prepare;
}
#ifdef CONFIG_ARM64
@@ -418,7 +443,7 @@ static efi_status_t do_bootefi_exec(void *efi,
/* Move into EL2 and keep running there */
armv8_switch_to_el2((ulong)entry,
- (ulong)image_handle,
+ (ulong)&image_obj->header,
(ulong)&systab, 0, (ulong)efi_run_in_el2,
ES_TO_AARCH64);
@@ -435,7 +460,7 @@ static efi_status_t do_bootefi_exec(void *efi,
secure_ram_addr(_do_nonsec_entry)(
efi_run_in_hyp,
(uintptr_t)entry,
- (uintptr_t)image_handle,
+ (uintptr_t)&image_obj->header,
(uintptr_t)&systab);
/* Should never reach here, efi exits with longjmp */
@@ -443,18 +468,59 @@ static efi_status_t do_bootefi_exec(void *efi,
}
#endif
- ret = efi_do_enter(image_handle, &systab, entry);
+ ret = efi_do_enter(&image_obj->header, &systab, entry);
-exit:
+err_prepare:
/* image has returned, loaded-image obj goes *poof*: */
- if (image_handle)
- efi_delete_handle(&image_handle->parent);
+ bootefi_run_finish(image_obj, loaded_image_info);
+
+err_add_protocol:
if (mem_handle)
efi_delete_handle(mem_handle);
return ret;
}
+#ifdef CONFIG_CMD_BOOTEFI_SELFTEST
+/**
+ * bootefi_test_prepare() - prepare to run an EFI test
+ *
+ * This sets things up so we can call EFI functions. This involves preparing
+ * the 'gd' pointer and setting up the load ed image data structures.
+ *
+ * @image_objp: loaded_image_infop: Pointer to a struct which will hold the
+ * loaded image object. This struct will be inited by this function before
+ * use.
+ * @loaded_image_infop: Pointer to a struct which will hold the loaded image
+ * info. This struct will be inited by this function before use.
+ * @path: File path to the test being run (often just the test name with a
+ * backslash before it
+ * @test_func: Address of the test function that is being run
+ * @load_options_path: U-Boot environment variable to use as load options
+ * @return 0 if OK, -ve on error
+ */
+static efi_status_t bootefi_test_prepare
+ (struct efi_loaded_image_obj **image_objp,
+ struct efi_loaded_image **loaded_image_infop, const char *path,
+ ulong test_func, const char *load_options_path)
+{
+ /* Construct a dummy device path */
+ bootefi_device_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE,
+ (uintptr_t)test_func,
+ (uintptr_t)test_func);
+ if (!bootefi_device_path)
+ return EFI_OUT_OF_RESOURCES;
+ bootefi_image_path = efi_dp_from_file(NULL, 0, path);
+ if (!bootefi_image_path)
+ return EFI_OUT_OF_RESOURCES;
+
+ return bootefi_run_prepare(load_options_path, bootefi_device_path,
+ bootefi_image_path, image_objp,
+ loaded_image_infop);
+}
+
+#endif /* CONFIG_CMD_BOOTEFI_SELFTEST */
+
static int do_bootefi_bootmgr_exec(void)
{
struct efi_device_path *device_path, *file_path;
@@ -527,29 +593,17 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
#endif
#ifdef CONFIG_CMD_BOOTEFI_SELFTEST
if (!strcmp(argv[1], "selftest")) {
- struct efi_loaded_image_obj *image_handle;
+ struct efi_loaded_image_obj *image_obj;
struct efi_loaded_image *loaded_image_info;
- /* Construct a dummy device path. */
- bootefi_device_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE,
- (uintptr_t)&efi_selftest,
- (uintptr_t)&efi_selftest);
- bootefi_image_path = efi_dp_from_file(NULL, 0, "\\selftest");
-
- r = efi_setup_loaded_image(bootefi_device_path,
- bootefi_image_path, &image_handle,
- &loaded_image_info);
- if (r != EFI_SUCCESS)
+ if (bootefi_test_prepare(&image_obj, &loaded_image_info,
+ "\\selftest", (uintptr_t)&efi_selftest,
+ "efi_selftest"))
return CMD_RET_FAILURE;
- efi_save_gd();
- /* Transfer environment variable efi_selftest as load options */
- set_load_options(loaded_image_info, "efi_selftest");
/* Execute the test */
- r = efi_selftest(image_handle, &systab);
- efi_restore_gd();
- free(loaded_image_info->load_options);
- efi_delete_handle(&image_handle->parent);
+ r = efi_selftest(&image_obj->header, &systab);
+ bootefi_run_finish(image_obj, loaded_image_info);
return r != EFI_SUCCESS;
} else
#endif
@@ -608,45 +662,19 @@ U_BOOT_CMD(
void efi_set_bootdev(const char *dev, const char *devnr, const char *path)
{
- char filename[32] = { 0 }; /* dp->str is u16[32] long */
- char *s;
+ struct efi_device_path *device, *image;
+ efi_status_t ret;
/* efi_set_bootdev is typically called repeatedly, recover memory */
efi_free_pool(bootefi_device_path);
efi_free_pool(bootefi_image_path);
- /* If blk_get_device_part_str fails, avoid duplicate free. */
- bootefi_device_path = NULL;
- bootefi_image_path = NULL;
-
- if (strcmp(dev, "Net")) {
- struct blk_desc *desc;
- disk_partition_t fs_partition;
- int part;
-
- part = blk_get_device_part_str(dev, devnr, &desc, &fs_partition,
- 1);
- if (part < 0)
- return;
-
- bootefi_device_path = efi_dp_from_part(desc, part);
- } else {
-#ifdef CONFIG_NET
- bootefi_device_path = efi_dp_from_eth();
-#endif
- }
-
- if (!path)
- return;
- if (strcmp(dev, "Net")) {
- /* Add leading / to fs paths, because they're absolute */
- snprintf(filename, sizeof(filename), "/%s", path);
+ ret = efi_dp_from_name(dev, devnr, path, &device, &image);
+ if (ret == EFI_SUCCESS) {
+ bootefi_device_path = device;
+ bootefi_image_path = image;
} else {
- snprintf(filename, sizeof(filename), "%s", path);
+ bootefi_device_path = NULL;
+ bootefi_image_path = NULL;
}
- /* DOS style file path: */
- s = filename;
- while ((s = strchr(s, '/')))
- *s++ = '\\';
- bootefi_image_path = efi_dp_from_file(NULL, 0, filename);
}
diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
index 21f353ffd3c..979ac4a638d 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -253,6 +253,7 @@ static struct bootmenu_data *bootmenu_create(int delay)
int len;
char *sep;
+ char *default_str;
struct bootmenu_entry *entry;
menu = malloc(sizeof(struct bootmenu_data));
@@ -263,6 +264,10 @@ static struct bootmenu_data *bootmenu_create(int delay)
menu->active = 0;
menu->first = NULL;
+ default_str = env_get("bootmenu_default");
+ if (default_str)
+ menu->active = (int)simple_strtol(default_str, NULL, 10);
+
while ((option = bootmenu_getoption(i))) {
sep = strchr(option, '=');
if (!sep) {
diff --git a/cmd/cls.c b/cmd/cls.c
new file mode 100644
index 00000000000..f1ce6e8df1e
--- /dev/null
+++ b/cmd/cls.c
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2018
+ * DENX Software Engineering, Anatolij Gustschin <agust@denx.de>
+ *
+ * cls - clear screen command
+ */
+#include <common.h>
+#include <command.h>
+#include <dm.h>
+#include <lcd.h>
+#include <video.h>
+
+static int do_video_clear(cmd_tbl_t *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+#if defined(CONFIG_DM_VIDEO)
+ struct udevice *dev;
+
+ if (uclass_first_device_err(UCLASS_VIDEO, &dev))
+ return CMD_RET_FAILURE;
+
+ if (video_clear(dev))
+ return CMD_RET_FAILURE;
+#elif defined(CONFIG_CFB_CONSOLE)
+ video_clear();
+#elif defined(CONFIG_LCD)
+ lcd_clear();
+#else
+ return CMD_RET_FAILURE;
+#endif
+ return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(cls, 1, 1, do_video_clear, "clear screen", "");
diff --git a/cmd/eeprom.c b/cmd/eeprom.c
index 9136630ada4..6c29b33ba34 100644
--- a/cmd/eeprom.c
+++ b/cmd/eeprom.c
@@ -124,6 +124,23 @@ static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
{
int ret = 0;
+#if defined(CONFIG_DM_I2C) && defined(CONFIG_SYS_I2C_EEPROM_BUS)
+ struct udevice *dev;
+
+ ret = i2c_get_chip_for_busnum(CONFIG_SYS_I2C_EEPROM_BUS, addr[0],
+ alen - 1, &dev);
+ if (ret) {
+ printf("%s: Cannot find udev for a bus %d\n", __func__,
+ CONFIG_SYS_I2C_EEPROM_BUS);
+ return CMD_RET_FAILURE;
+ }
+
+ if (read)
+ ret = dm_i2c_read(dev, offset, buffer, len);
+ else
+ ret = dm_i2c_write(dev, offset, buffer, len);
+
+#else /* Non DM I2C support - will be removed */
#if defined(CONFIG_SYS_I2C_EEPROM_BUS)
i2c_set_bus_num(CONFIG_SYS_I2C_EEPROM_BUS);
#endif
@@ -132,9 +149,9 @@ static int eeprom_rw_block(unsigned offset, uchar *addr, unsigned alen,
ret = i2c_read(addr[0], offset, alen - 1, buffer, len);
else
ret = i2c_write(addr[0], offset, alen - 1, buffer, len);
-
+#endif /* CONFIG_DM_I2C && CONFIG_SYS_I2C_EEPROM_BUS */
if (ret)
- ret = 1;
+ ret = CMD_RET_FAILURE;
return ret;
}
diff --git a/cmd/fdt.c b/cmd/fdt.c
index 8a19a3fdbf2..10d8f3230bb 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -73,6 +73,40 @@ static int fdt_value_env_set(const void *nodep, int len, const char *var)
return 0;
}
+static const char * const fdt_member_table[] = {
+ "magic",
+ "totalsize",
+ "off_dt_struct",
+ "off_dt_strings",
+ "off_mem_rsvmap",
+ "version",
+ "last_comp_version",
+ "boot_cpuid_phys",
+ "size_dt_strings",
+ "size_dt_struct",
+};
+
+static int fdt_get_header_value(int argc, char * const argv[])
+{
+ fdt32_t *fdtp = (fdt32_t *)working_fdt;
+ ulong val;
+ int i;
+
+ if (argv[2][0] != 'g')
+ return CMD_RET_FAILURE;
+
+ for (i = 0; i < ARRAY_SIZE(fdt_member_table); i++) {
+ if (strcmp(fdt_member_table[i], argv[4]))
+ continue;
+
+ val = fdt32_to_cpu(fdtp[i]);
+ env_set_hex(argv[3], val);
+ return CMD_RET_SUCCESS;
+ }
+
+ return CMD_RET_FAILURE;
+}
+
/*
* Flattened Device Tree command, see the help for parameter definitions.
*/
@@ -202,7 +236,7 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
fdt_strerror(err));
return 1;
}
- working_fdt = newaddr;
+ set_working_fdt_addr((ulong)newaddr);
#ifdef CONFIG_OF_SYSTEM_SETUP
/* Call the board-specific fixup routine */
} else if (strncmp(argv[1], "sys", 3) == 0) {
@@ -491,6 +525,9 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
* Display header info
*/
} else if (argv[1][0] == 'h') {
+ if (argc == 5)
+ return fdt_get_header_value(argc, argv);
+
u32 version = fdt_version(working_fdt);
printf("magic:\t\t\t0x%x\n", fdt_magic(working_fdt));
printf("totalsize:\t\t0x%x (%d)\n", fdt_totalsize(working_fdt),
@@ -1090,7 +1127,8 @@ static char fdt_help_text[] =
"fdt set <path> <prop> [<val>] - Set <property> [to <val>]\n"
"fdt mknode <path> <node> - Create a new node after <path>\n"
"fdt rm <path> [<prop>] - Delete the node or <property>\n"
- "fdt header - Display header info\n"
+ "fdt header [get <var> <member>] - Display header info\n"
+ " get - get header member <member> and store it in <var>\n"
"fdt bootcpu <id> - Set boot cpuid\n"
"fdt memory <addr> <size> - Add/Update memory node\n"
"fdt rsvmem print - Show current mem reserves\n"
diff --git a/cmd/host.c b/cmd/host.c
index 645dba4de83..f7d3eae5b1a 100644
--- a/cmd/host.c
+++ b/cmd/host.c
@@ -168,11 +168,6 @@ static int do_host(cmd_tbl_t *cmdtp, int flag, int argc,
}
U_BOOT_CMD(
- sb, 8, 1, do_host,
- "Deprecated: use 'host' command instead.", ""
-);
-
-U_BOOT_CMD(
host, 8, 1, do_host,
"Miscellaneous host commands",
"load hostfs - <addr> <filename> [<bytes> <offset>] - "
diff --git a/cmd/sb.c b/cmd/sb.c
new file mode 100644
index 00000000000..5701e03797c
--- /dev/null
+++ b/cmd/sb.c
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2018, Google Inc.
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <spl.h>
+#include <asm/state.h>
+
+static int do_sb_handoff(cmd_tbl_t *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+#if CONFIG_IS_ENABLED(HANDOFF)
+ if (gd->spl_handoff)
+ printf("SPL handoff magic %lx\n", gd->spl_handoff->arch.magic);
+ else
+ printf("SPL handoff info not received\n");
+
+ return 0;
+#else
+ printf("Command not supported\n");
+
+ return CMD_RET_USAGE;
+#endif
+}
+
+static int do_sb_state(cmd_tbl_t *cmdtp, int flag, int argc,
+ char * const argv[])
+{
+ struct sandbox_state *state;
+
+ state = state_get_current();
+ state_show(state);
+
+ return 0;
+}
+
+static cmd_tbl_t cmd_sb_sub[] = {
+ U_BOOT_CMD_MKENT(handoff, 1, 0, do_sb_handoff, "", ""),
+ U_BOOT_CMD_MKENT(state, 1, 0, do_sb_state, "", ""),
+};
+
+static int do_sb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ cmd_tbl_t *c;
+
+ /* Skip past 'sb' */
+ argc--;
+ argv++;
+
+ c = find_cmd_tbl(argv[0], cmd_sb_sub, ARRAY_SIZE(cmd_sb_sub));
+ if (c)
+ return c->cmd(cmdtp, flag, argc, argv);
+ else
+ return CMD_RET_USAGE;
+}
+
+U_BOOT_CMD(
+ sb, 8, 1, do_sb,
+ "Sandbox status commands",
+ "handoff - Show handoff data received from SPL\n"
+ "sb state - Show sandbox state"
+);
diff --git a/cmd/tpm-common.c b/cmd/tpm-common.c
index 56443862c22..89f2aa001ba 100644
--- a/cmd/tpm-common.c
+++ b/cmd/tpm-common.c
@@ -264,10 +264,16 @@ int do_tpm_info(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
int do_tpm_init(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
+ struct udevice *dev;
+ int rc;
+
if (argc != 1)
return CMD_RET_USAGE;
+ rc = get_tpm(&dev);
+ if (rc)
+ return rc;
- return report_return_code(tpm_init());
+ return report_return_code(tpm_init(dev));
}
int do_tpm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
diff --git a/cmd/tpm-v1.c b/cmd/tpm-v1.c
index 69870002d4f..b75e0933a1c 100644
--- a/cmd/tpm-v1.c
+++ b/cmd/tpm-v1.c
@@ -14,7 +14,12 @@ static int do_tpm_startup(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
enum tpm_startup_type mode;
+ struct udevice *dev;
+ int rc;
+ rc = get_tpm(&dev);
+ if (rc)
+ return rc;
if (argc != 2)
return CMD_RET_USAGE;
if (!strcasecmp("TPM_ST_CLEAR", argv[1])) {
@@ -28,13 +33,19 @@ static int do_tpm_startup(cmd_tbl_t *cmdtp, int flag, int argc,
return CMD_RET_FAILURE;
}
- return report_return_code(tpm_startup(mode));
+ return report_return_code(tpm_startup(dev, mode));
}
static int do_tpm_nv_define_space(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
u32 index, perm, size;
+ struct udevice *dev;
+ int rc;
+
+ rc = get_tpm(&dev);
+ if (rc)
+ return rc;
if (argc != 4)
return CMD_RET_USAGE;
@@ -42,22 +53,27 @@ static int do_tpm_nv_define_space(cmd_tbl_t *cmdtp, int flag, int argc,
perm = simple_strtoul(argv[2], NULL, 0);
size = simple_strtoul(argv[3], NULL, 0);
- return report_return_code(tpm_nv_define_space(index, perm, size));
+ return report_return_code(tpm_nv_define_space(dev, index, perm, size));
}
static int do_tpm_nv_read_value(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
u32 index, count, rc;
+ struct udevice *dev;
void *data;
+ rc = get_tpm(&dev);
+ if (rc)
+ return rc;
+
if (argc != 4)
return CMD_RET_USAGE;
index = simple_strtoul(argv[1], NULL, 0);
data = (void *)simple_strtoul(argv[2], NULL, 0);
count = simple_strtoul(argv[3], NULL, 0);
- rc = tpm_nv_read_value(index, data, count);
+ rc = tpm_nv_read_value(dev, index, data, count);
if (!rc) {
puts("area content:\n");
print_byte_string(data, count);
@@ -69,10 +85,15 @@ static int do_tpm_nv_read_value(cmd_tbl_t *cmdtp, int flag, int argc,
static int do_tpm_nv_write_value(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
+ struct udevice *dev;
u32 index, rc;
size_t count;
void *data;
+ rc = get_tpm(&dev);
+ if (rc)
+ return rc;
+
if (argc != 3)
return CMD_RET_USAGE;
index = simple_strtoul(argv[1], NULL, 0);
@@ -82,7 +103,7 @@ static int do_tpm_nv_write_value(cmd_tbl_t *cmdtp, int flag, int argc,
return CMD_RET_FAILURE;
}
- rc = tpm_nv_write_value(index, data, count);
+ rc = tpm_nv_write_value(dev, index, data, count);
free(data);
return report_return_code(rc);
@@ -91,8 +112,13 @@ static int do_tpm_nv_write_value(cmd_tbl_t *cmdtp, int flag, int argc,
static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
- u32 index, rc;
u8 in_digest[20], out_digest[20];
+ struct udevice *dev;
+ u32 index, rc;
+
+ rc = get_tpm(&dev);
+ if (rc)
+ return rc;
if (argc != 3)
return CMD_RET_USAGE;
@@ -102,7 +128,7 @@ static int do_tpm_extend(cmd_tbl_t *cmdtp, int flag, int argc,
return CMD_RET_FAILURE;
}
- rc = tpm_extend(index, in_digest, out_digest);
+ rc = tpm_extend(dev, index, in_digest, out_digest);
if (!rc) {
puts("PCR value after execution of the command:\n");
print_byte_string(out_digest, sizeof(out_digest));
@@ -115,15 +141,20 @@ static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
u32 index, count, rc;
+ struct udevice *dev;
void *data;
+ rc = get_tpm(&dev);
+ if (rc)
+ return rc;
+
if (argc != 4)
return CMD_RET_USAGE;
index = simple_strtoul(argv[1], NULL, 0);
data = (void *)simple_strtoul(argv[2], NULL, 0);
count = simple_strtoul(argv[3], NULL, 0);
- rc = tpm_pcr_read(index, data, count);
+ rc = tpm_pcr_read(dev, index, data, count);
if (!rc) {
puts("Named PCR content:\n");
print_byte_string(data, count);
@@ -135,27 +166,38 @@ static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag, int argc,
static int do_tpm_tsc_physical_presence(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
+ struct udevice *dev;
u16 presence;
+ int rc;
+
+ rc = get_tpm(&dev);
+ if (rc)
+ return rc;
if (argc != 2)
return CMD_RET_USAGE;
presence = (u16)simple_strtoul(argv[1], NULL, 0);
- return report_return_code(tpm_tsc_physical_presence(presence));
+ return report_return_code(tpm_tsc_physical_presence(dev, presence));
}
static int do_tpm_read_pubek(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
+ struct udevice *dev;
u32 count, rc;
void *data;
+ rc = get_tpm(&dev);
+ if (rc)
+ return rc;
+
if (argc != 3)
return CMD_RET_USAGE;
data = (void *)simple_strtoul(argv[1], NULL, 0);
count = simple_strtoul(argv[2], NULL, 0);
- rc = tpm_read_pubek(data, count);
+ rc = tpm_read_pubek(dev, data, count);
if (!rc) {
puts("pubek value:\n");
print_byte_string(data, count);
@@ -167,13 +209,19 @@ static int do_tpm_read_pubek(cmd_tbl_t *cmdtp, int flag, int argc,
static int do_tpm_physical_set_deactivated(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
+ struct udevice *dev;
u8 state;
+ int rc;
+
+ rc = get_tpm(&dev);
+ if (rc)
+ return rc;
if (argc != 2)
return CMD_RET_USAGE;
state = (u8)simple_strtoul(argv[1], NULL, 0);
- return report_return_code(tpm_physical_set_deactivated(state));
+ return report_return_code(tpm_physical_set_deactivated(dev, state));
}
static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag, int argc,
@@ -182,6 +230,11 @@ static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag, int argc,
u32 cap_area, sub_cap, rc;
void *cap;
size_t count;
+ struct udevice *dev;
+
+ rc = get_tpm(&dev);
+ if (rc)
+ return rc;
if (argc != 5)
return CMD_RET_USAGE;
@@ -190,7 +243,7 @@ static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag, int argc,
cap = (void *)simple_strtoul(argv[3], NULL, 0);
count = simple_strtoul(argv[4], NULL, 0);
- rc = tpm_get_capability(cap_area, sub_cap, cap, count);
+ rc = tpm_get_capability(dev, cap_area, sub_cap, cap, count);
if (!rc) {
puts("capability information:\n");
print_byte_string(cap, count);
@@ -232,6 +285,12 @@ static int do_tpm_nv_define(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
u32 index, perm, size;
+ struct udevice *dev;
+ int rc;
+
+ rc = get_tpm(&dev);
+ if (rc)
+ return rc;
if (argc != 4)
return CMD_RET_USAGE;
@@ -243,14 +302,20 @@ static int do_tpm_nv_define(cmd_tbl_t *cmdtp, int flag, int argc,
index = simple_strtoul(argv[2], NULL, 0);
perm = simple_strtoul(argv[3], NULL, 0);
- return report_return_code(tpm_nv_define_space(index, perm, size));
+ return report_return_code(tpm_nv_define_space(dev, index, perm, size));
}
static int do_tpm_nv_read(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
u32 index, count, err;
+ struct udevice *dev;
void *data;
+ int rc;
+
+ rc = get_tpm(&dev);
+ if (rc)
+ return rc;
if (argc < 3)
return CMD_RET_USAGE;
@@ -263,7 +328,7 @@ static int do_tpm_nv_read(cmd_tbl_t *cmdtp, int flag, int argc,
return CMD_RET_USAGE;
}
- err = tpm_nv_read_value(index, data, count);
+ err = tpm_nv_read_value(dev, index, data, count);
if (!err) {
if (type_string_write_vars(argv[1], data, argv + 3)) {
printf("Couldn't write to variables\n");
@@ -279,7 +344,13 @@ static int do_tpm_nv_write(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
u32 index, count, err;
+ struct udevice *dev;
void *data;
+ int rc;
+
+ rc = get_tpm(&dev);
+ if (rc)
+ return rc;
if (argc < 3)
return CMD_RET_USAGE;
@@ -297,7 +368,7 @@ static int do_tpm_nv_write(cmd_tbl_t *cmdtp, int flag, int argc,
return CMD_RET_USAGE;
}
- err = tpm_nv_write_value(index, data, count);
+ err = tpm_nv_write_value(dev, index, data, count);
free(data);
return report_return_code(err);
@@ -309,8 +380,14 @@ static int do_tpm_oiap(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
u32 auth_handle, err;
+ struct udevice *dev;
+ int rc;
+
+ rc = get_tpm(&dev);
+ if (rc)
+ return rc;
- err = tpm_oiap(&auth_handle);
+ err = tpm_oiap(dev, &auth_handle);
return report_return_code(err);
}
@@ -324,6 +401,11 @@ static int do_tpm_load_key_by_sha1(cmd_tbl_t *cmdtp, int flag, int argc, char *
u8 usage_auth[DIGEST_LENGTH];
u8 parent_hash[DIGEST_LENGTH];
void *key;
+ struct udevice *dev;
+
+ rc = get_tpm(&dev);
+ if (rc)
+ return rc;
if (argc < 5)
return CMD_RET_USAGE;
@@ -360,6 +442,12 @@ static int do_tpm_load_key2_oiap(cmd_tbl_t *cmdtp, int flag, int argc,
u32 parent_handle, key_len, key_handle, err;
u8 usage_auth[DIGEST_LENGTH];
void *key;
+ struct udevice *dev;
+ int rc;
+
+ rc = get_tpm(&dev);
+ if (rc)
+ return rc;
if (argc < 5)
return CMD_RET_USAGE;
@@ -371,7 +459,7 @@ static int do_tpm_load_key2_oiap(cmd_tbl_t *cmdtp, int flag, int argc,
return CMD_RET_FAILURE;
parse_byte_string(argv[4], usage_auth, NULL);
- err = tpm_load_key2_oiap(parent_handle, key, key_len, usage_auth,
+ err = tpm_load_key2_oiap(dev, parent_handle, key, key_len, usage_auth,
&key_handle);
if (!err)
printf("Key handle is 0x%x\n", key_handle);
@@ -386,6 +474,12 @@ static int do_tpm_get_pub_key_oiap(cmd_tbl_t *cmdtp, int flag, int argc,
u8 usage_auth[DIGEST_LENGTH];
u8 pub_key_buffer[TPM_PUBKEY_MAX_LENGTH];
size_t pub_key_len = sizeof(pub_key_buffer);
+ struct udevice *dev;
+ int rc;
+
+ rc = get_tpm(&dev);
+ if (rc)
+ return rc;
if (argc < 3)
return CMD_RET_USAGE;
@@ -395,7 +489,7 @@ static int do_tpm_get_pub_key_oiap(cmd_tbl_t *cmdtp, int flag, int argc,
return CMD_RET_FAILURE;
parse_byte_string(argv[2], usage_auth, NULL);
- err = tpm_get_pub_key_oiap(key_handle, usage_auth, pub_key_buffer,
+ err = tpm_get_pub_key_oiap(dev, key_handle, usage_auth, pub_key_buffer,
&pub_key_len);
if (!err) {
printf("dump of received pub key structure:\n");
@@ -412,7 +506,13 @@ TPM_COMMAND_NO_ARG(tpm_end_oiap)
static int do_tpm_flush(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
+ struct udevice *dev;
int type = 0;
+ int rc;
+
+ rc = get_tpm(&dev);
+ if (rc)
+ return rc;
if (argc != 3)
return CMD_RET_USAGE;
@@ -451,7 +551,7 @@ static int do_tpm_flush(cmd_tbl_t *cmdtp, int flag, int argc,
uint i;
/* fetch list of already loaded resources in the TPM */
- err = tpm_get_capability(TPM_CAP_HANDLE, type, buf,
+ err = tpm_get_capability(dev, TPM_CAP_HANDLE, type, buf,
sizeof(buf));
if (err) {
printf("tpm_get_capability returned error %d.\n", err);
@@ -460,7 +560,7 @@ static int do_tpm_flush(cmd_tbl_t *cmdtp, int flag, int argc,
res_count = get_unaligned_be16(buf);
ptr = buf + 2;
for (i = 0; i < res_count; ++i, ptr += 4)
- tpm_flush_specific(get_unaligned_be32(ptr), type);
+ tpm_flush_specific(dev, get_unaligned_be32(ptr), type);
} else {
u32 handle = simple_strtoul(argv[2], NULL, 0);
@@ -468,7 +568,7 @@ static int do_tpm_flush(cmd_tbl_t *cmdtp, int flag, int argc,
printf("Illegal resource handle %s\n", argv[2]);
return -1;
}
- tpm_flush_specific(cpu_to_be32(handle), type);
+ tpm_flush_specific(dev, cpu_to_be32(handle), type);
}
return 0;
diff --git a/cmd/tpm-v2.c b/cmd/tpm-v2.c
index ffbf35a75c5..bb51834c478 100644
--- a/cmd/tpm-v2.c
+++ b/cmd/tpm-v2.c
@@ -16,7 +16,12 @@ static int do_tpm2_startup(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
enum tpm2_startup_types mode;
+ struct udevice *dev;
+ int ret;
+ ret = get_tpm(&dev);
+ if (ret)
+ return ret;
if (argc != 2)
return CMD_RET_USAGE;
@@ -29,14 +34,19 @@ static int do_tpm2_startup(cmd_tbl_t *cmdtp, int flag, int argc,
return CMD_RET_FAILURE;
}
- return report_return_code(tpm2_startup(mode));
+ return report_return_code(tpm2_startup(dev, mode));
}
static int do_tpm2_self_test(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
enum tpm2_yes_no full_test;
+ struct udevice *dev;
+ int ret;
+ ret = get_tpm(&dev);
+ if (ret)
+ return ret;
if (argc != 2)
return CMD_RET_USAGE;
@@ -49,7 +59,7 @@ static int do_tpm2_self_test(cmd_tbl_t *cmdtp, int flag, int argc,
return CMD_RET_FAILURE;
}
- return report_return_code(tpm2_self_test(full_test));
+ return report_return_code(tpm2_self_test(dev, full_test));
}
static int do_tpm2_clear(cmd_tbl_t *cmdtp, int flag, int argc,
@@ -58,6 +68,12 @@ static int do_tpm2_clear(cmd_tbl_t *cmdtp, int flag, int argc,
u32 handle = 0;
const char *pw = (argc < 3) ? NULL : argv[2];
const ssize_t pw_sz = pw ? strlen(pw) : 0;
+ struct udevice *dev;
+ int ret;
+
+ ret = get_tpm(&dev);
+ if (ret)
+ return ret;
if (argc < 2 || argc > 3)
return CMD_RET_USAGE;
@@ -72,7 +88,7 @@ static int do_tpm2_clear(cmd_tbl_t *cmdtp, int flag, int argc,
else
return CMD_RET_USAGE;
- return report_return_code(tpm2_clear(handle, pw, pw_sz));
+ return report_return_code(tpm2_clear(dev, handle, pw, pw_sz));
}
static int do_tpm2_pcr_extend(cmd_tbl_t *cmdtp, int flag, int argc,
@@ -88,7 +104,7 @@ static int do_tpm2_pcr_extend(cmd_tbl_t *cmdtp, int flag, int argc,
if (argc != 3)
return CMD_RET_USAGE;
- ret = uclass_first_device_err(UCLASS_TPM, &dev);
+ ret = get_tpm(&dev);
if (ret)
return ret;
@@ -99,7 +115,7 @@ static int do_tpm2_pcr_extend(cmd_tbl_t *cmdtp, int flag, int argc,
if (index >= priv->pcr_count)
return -EINVAL;
- rc = tpm2_pcr_extend(index, digest);
+ rc = tpm2_pcr_extend(dev, index, digest);
unmap_sysmem(digest);
@@ -119,7 +135,7 @@ static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag, int argc,
if (argc != 3)
return CMD_RET_USAGE;
- ret = uclass_first_device_err(UCLASS_TPM, &dev);
+ ret = get_tpm(&dev);
if (ret)
return ret;
@@ -133,7 +149,7 @@ static int do_tpm_pcr_read(cmd_tbl_t *cmdtp, int flag, int argc,
data = map_sysmem(simple_strtoul(argv[2], NULL, 0), 0);
- rc = tpm2_pcr_read(index, priv->pcr_select_min, data, &updates);
+ rc = tpm2_pcr_read(dev, index, priv->pcr_select_min, data, &updates);
if (!rc) {
printf("PCR #%u content (%d known updates):\n", index, updates);
print_byte_string(data, TPM2_DIGEST_LEN);
@@ -151,6 +167,12 @@ static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag, int argc,
u8 *data;
size_t count;
int i, j;
+ struct udevice *dev;
+ int ret;
+
+ ret = get_tpm(&dev);
+ if (ret)
+ return ret;
if (argc != 5)
return CMD_RET_USAGE;
@@ -160,7 +182,7 @@ static int do_tpm_get_capability(cmd_tbl_t *cmdtp, int flag, int argc,
data = map_sysmem(simple_strtoul(argv[3], NULL, 0), 0);
count = simple_strtoul(argv[4], NULL, 0);
- rc = tpm2_get_capability(capability, property, data, count);
+ rc = tpm2_get_capability(dev, capability, property, data, count);
if (rc)
goto unmap_data;
@@ -186,6 +208,12 @@ static int do_tpm_dam_reset(cmd_tbl_t *cmdtp, int flag, int argc,
{
const char *pw = (argc < 2) ? NULL : argv[1];
const ssize_t pw_sz = pw ? strlen(pw) : 0;
+ struct udevice *dev;
+ int ret;
+
+ ret = get_tpm(&dev);
+ if (ret)
+ return ret;
if (argc > 2)
return CMD_RET_USAGE;
@@ -193,7 +221,7 @@ static int do_tpm_dam_reset(cmd_tbl_t *cmdtp, int flag, int argc,
if (pw_sz > TPM2_DIGEST_LEN)
return -EINVAL;
- return report_return_code(tpm2_dam_reset(pw, pw_sz));
+ return report_return_code(tpm2_dam_reset(dev, pw, pw_sz));
}
static int do_tpm_dam_parameters(cmd_tbl_t *cmdtp, int flag, int argc,
@@ -208,6 +236,12 @@ static int do_tpm_dam_parameters(cmd_tbl_t *cmdtp, int flag, int argc,
unsigned long int max_tries;
unsigned long int recovery_time;
unsigned long int lockout_recovery;
+ struct udevice *dev;
+ int ret;
+
+ ret = get_tpm(&dev);
+ if (ret)
+ return ret;
if (argc < 4 || argc > 5)
return CMD_RET_USAGE;
@@ -229,7 +263,7 @@ static int do_tpm_dam_parameters(cmd_tbl_t *cmdtp, int flag, int argc,
log(LOGC_NONE, LOGL_INFO, "- recoveryTime: %lu\n", recovery_time);
log(LOGC_NONE, LOGL_INFO, "- lockoutRecovery: %lu\n", lockout_recovery);
- return report_return_code(tpm2_dam_parameters(pw, pw_sz, max_tries,
+ return report_return_code(tpm2_dam_parameters(dev, pw, pw_sz, max_tries,
recovery_time,
lockout_recovery));
}
@@ -242,6 +276,12 @@ static int do_tpm_change_auth(cmd_tbl_t *cmdtp, int flag, int argc,
const char *oldpw = (argc == 3) ? NULL : argv[3];
const ssize_t newpw_sz = strlen(newpw);
const ssize_t oldpw_sz = oldpw ? strlen(oldpw) : 0;
+ struct udevice *dev;
+ int ret;
+
+ ret = get_tpm(&dev);
+ if (ret)
+ return ret;
if (argc < 3 || argc > 4)
return CMD_RET_USAGE;
@@ -260,7 +300,7 @@ static int do_tpm_change_auth(cmd_tbl_t *cmdtp, int flag, int argc,
else
return CMD_RET_USAGE;
- return report_return_code(tpm2_change_auth(handle, newpw, newpw_sz,
+ return report_return_code(tpm2_change_auth(dev, handle, newpw, newpw_sz,
oldpw, oldpw_sz));
}
@@ -271,6 +311,12 @@ static int do_tpm_pcr_setauthpolicy(cmd_tbl_t *cmdtp, int flag, int argc,
char *key = argv[2];
const char *pw = (argc < 4) ? NULL : argv[3];
const ssize_t pw_sz = pw ? strlen(pw) : 0;
+ struct udevice *dev;
+ int ret;
+
+ ret = get_tpm(&dev);
+ if (ret)
+ return ret;
if (strlen(key) != TPM2_DIGEST_LEN)
return -EINVAL;
@@ -278,7 +324,7 @@ static int do_tpm_pcr_setauthpolicy(cmd_tbl_t *cmdtp, int flag, int argc,
if (argc < 3 || argc > 4)
return CMD_RET_USAGE;
- return report_return_code(tpm2_pcr_setauthpolicy(pw, pw_sz, index,
+ return report_return_code(tpm2_pcr_setauthpolicy(dev, pw, pw_sz, index,
key));
}
@@ -290,6 +336,12 @@ static int do_tpm_pcr_setauthvalue(cmd_tbl_t *cmdtp, int flag,
const ssize_t key_sz = strlen(key);
const char *pw = (argc < 4) ? NULL : argv[3];
const ssize_t pw_sz = pw ? strlen(pw) : 0;
+ struct udevice *dev;
+ int ret;
+
+ ret = get_tpm(&dev);
+ if (ret)
+ return ret;
if (strlen(key) != TPM2_DIGEST_LEN)
return -EINVAL;
@@ -297,7 +349,7 @@ static int do_tpm_pcr_setauthvalue(cmd_tbl_t *cmdtp, int flag,
if (argc < 3 || argc > 4)
return CMD_RET_USAGE;
- return report_return_code(tpm2_pcr_setauthvalue(pw, pw_sz, index,
+ return report_return_code(tpm2_pcr_setauthvalue(dev, pw, pw_sz, index,
key, key_sz));
}
diff --git a/cmd/tpm_test.c b/cmd/tpm_test.c
index f21ad5d3cf9..56a5aa4aa5e 100644
--- a/cmd/tpm_test.c
+++ b/cmd/tpm_test.c
@@ -7,6 +7,7 @@
#include <command.h>
#include <environment.h>
#include <tpm-v1.h>
+#include "tpm-user-utils.h"
/* Prints error and returns on failure */
#define TPM_CHECK(tpm_command) do { \
@@ -28,26 +29,26 @@
#define PHYS_PRESENCE 4
#define PRESENCE 8
-static uint32_t TlclStartupIfNeeded(void)
+static uint32_t TlclStartupIfNeeded(struct udevice *dev)
{
- uint32_t result = tpm_startup(TPM_ST_CLEAR);
+ uint32_t result = tpm_startup(dev, TPM_ST_CLEAR);
return result == TPM_INVALID_POSTINIT ? TPM_SUCCESS : result;
}
-static int test_timer(void)
+static int test_timer(struct udevice *dev)
{
printf("get_timer(0) = %lu\n", get_timer(0));
return 0;
}
-static uint32_t tpm_get_flags(uint8_t *disable, uint8_t *deactivated,
- uint8_t *nvlocked)
+static uint32_t tpm_get_flags(struct udevice *dev, uint8_t *disable,
+ uint8_t *deactivated, uint8_t *nvlocked)
{
struct tpm_permanent_flags pflags;
uint32_t result;
- result = tpm_get_permanent_flags(&pflags);
+ result = tpm_get_permanent_flags(dev, &pflags);
if (result)
return result;
if (disable)
@@ -62,79 +63,79 @@ static uint32_t tpm_get_flags(uint8_t *disable, uint8_t *deactivated,
return 0;
}
-static uint32_t tpm_nv_write_value_lock(uint32_t index)
+static uint32_t tpm_nv_write_value_lock(struct udevice *dev, uint32_t index)
{
debug("TPM: Write lock 0x%x\n", index);
- return tpm_nv_write_value(index, NULL, 0);
+ return tpm_nv_write_value(dev, index, NULL, 0);
}
-static int tpm_is_owned(void)
+static int tpm_is_owned(struct udevice *dev)
{
uint8_t response[TPM_PUBEK_SIZE];
uint32_t result;
- result = tpm_read_pubek(response, sizeof(response));
+ result = tpm_read_pubek(dev, response, sizeof(response));
return result != TPM_SUCCESS;
}
-static int test_early_extend(void)
+static int test_early_extend(struct udevice *dev)
{
uint8_t value_in[20];
uint8_t value_out[20];
printf("Testing earlyextend ...");
- tpm_init();
- TPM_CHECK(tpm_startup(TPM_ST_CLEAR));
- TPM_CHECK(tpm_continue_self_test());
- TPM_CHECK(tpm_extend(1, value_in, value_out));
+ tpm_init(dev);
+ TPM_CHECK(tpm_startup(dev, TPM_ST_CLEAR));
+ TPM_CHECK(tpm_continue_self_test(dev));
+ TPM_CHECK(tpm_extend(dev, 1, value_in, value_out));
printf("done\n");
return 0;
}
-static int test_early_nvram(void)
+static int test_early_nvram(struct udevice *dev)
{
uint32_t x;
printf("Testing earlynvram ...");
- tpm_init();
- TPM_CHECK(tpm_startup(TPM_ST_CLEAR));
- TPM_CHECK(tpm_continue_self_test());
- TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
- TPM_CHECK(tpm_nv_read_value(INDEX0, (uint8_t *)&x, sizeof(x)));
+ tpm_init(dev);
+ TPM_CHECK(tpm_startup(dev, TPM_ST_CLEAR));
+ TPM_CHECK(tpm_continue_self_test(dev));
+ TPM_CHECK(tpm_tsc_physical_presence(dev, PRESENCE));
+ TPM_CHECK(tpm_nv_read_value(dev, INDEX0, (uint8_t *)&x, sizeof(x)));
printf("done\n");
return 0;
}
-static int test_early_nvram2(void)
+static int test_early_nvram2(struct udevice *dev)
{
uint32_t x;
printf("Testing earlynvram2 ...");
- tpm_init();
- TPM_CHECK(tpm_startup(TPM_ST_CLEAR));
- TPM_CHECK(tpm_continue_self_test());
- TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
- TPM_CHECK(tpm_nv_write_value(INDEX0, (uint8_t *)&x, sizeof(x)));
+ tpm_init(dev);
+ TPM_CHECK(tpm_startup(dev, TPM_ST_CLEAR));
+ TPM_CHECK(tpm_continue_self_test(dev));
+ TPM_CHECK(tpm_tsc_physical_presence(dev, PRESENCE));
+ TPM_CHECK(tpm_nv_write_value(dev, INDEX0, (uint8_t *)&x, sizeof(x)));
printf("done\n");
return 0;
}
-static int test_enable(void)
+static int test_enable(struct udevice *dev)
{
uint8_t disable = 0, deactivated = 0;
printf("Testing enable ...\n");
- tpm_init();
- TPM_CHECK(TlclStartupIfNeeded());
- TPM_CHECK(tpm_self_test_full());
- TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
- TPM_CHECK(tpm_get_flags(&disable, &deactivated, NULL));
+ tpm_init(dev);
+ TPM_CHECK(TlclStartupIfNeeded(dev));
+ TPM_CHECK(tpm_self_test_full(dev));
+ TPM_CHECK(tpm_tsc_physical_presence(dev, PRESENCE));
+ TPM_CHECK(tpm_get_flags(dev, &disable, &deactivated, NULL));
printf("\tdisable is %d, deactivated is %d\n", disable, deactivated);
- TPM_CHECK(tpm_physical_enable());
- TPM_CHECK(tpm_physical_set_deactivated(0));
- TPM_CHECK(tpm_get_flags(&disable, &deactivated, NULL));
+ TPM_CHECK(tpm_physical_enable(dev));
+ TPM_CHECK(tpm_physical_set_deactivated(dev, 0));
+ TPM_CHECK(tpm_get_flags(dev, &disable, &deactivated, NULL));
printf("\tdisable is %d, deactivated is %d\n", disable, deactivated);
if (disable == 1 || deactivated == 1)
printf("\tfailed to enable or activate\n");
@@ -147,27 +148,27 @@ static int test_enable(void)
reset_cpu(0); \
} while (0)
-static int test_fast_enable(void)
+static int test_fast_enable(struct udevice *dev)
{
uint8_t disable = 0, deactivated = 0;
int i;
printf("Testing fastenable ...\n");
- tpm_init();
- TPM_CHECK(TlclStartupIfNeeded());
- TPM_CHECK(tpm_self_test_full());
- TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
- TPM_CHECK(tpm_get_flags(&disable, &deactivated, NULL));
+ tpm_init(dev);
+ TPM_CHECK(TlclStartupIfNeeded(dev));
+ TPM_CHECK(tpm_self_test_full(dev));
+ TPM_CHECK(tpm_tsc_physical_presence(dev, PRESENCE));
+ TPM_CHECK(tpm_get_flags(dev, &disable, &deactivated, NULL));
printf("\tdisable is %d, deactivated is %d\n", disable, deactivated);
for (i = 0; i < 2; i++) {
- TPM_CHECK(tpm_force_clear());
- TPM_CHECK(tpm_get_flags(&disable, &deactivated, NULL));
+ TPM_CHECK(tpm_force_clear(dev));
+ TPM_CHECK(tpm_get_flags(dev, &disable, &deactivated, NULL));
printf("\tdisable is %d, deactivated is %d\n", disable,
deactivated);
assert(disable == 1 && deactivated == 1);
- TPM_CHECK(tpm_physical_enable());
- TPM_CHECK(tpm_physical_set_deactivated(0));
- TPM_CHECK(tpm_get_flags(&disable, &deactivated, NULL));
+ TPM_CHECK(tpm_physical_enable(dev));
+ TPM_CHECK(tpm_physical_set_deactivated(dev, 0));
+ TPM_CHECK(tpm_get_flags(dev, &disable, &deactivated, NULL));
printf("\tdisable is %d, deactivated is %d\n", disable,
deactivated);
assert(disable == 0 && deactivated == 0);
@@ -176,105 +177,109 @@ static int test_fast_enable(void)
return 0;
}
-static int test_global_lock(void)
+static int test_global_lock(struct udevice *dev)
{
uint32_t zero = 0;
uint32_t result;
uint32_t x;
printf("Testing globallock ...\n");
- tpm_init();
- TPM_CHECK(TlclStartupIfNeeded());
- TPM_CHECK(tpm_self_test_full());
- TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
- TPM_CHECK(tpm_nv_read_value(INDEX0, (uint8_t *)&x, sizeof(x)));
- TPM_CHECK(tpm_nv_write_value(INDEX0, (uint8_t *)&zero,
+ tpm_init(dev);
+ TPM_CHECK(TlclStartupIfNeeded(dev));
+ TPM_CHECK(tpm_self_test_full(dev));
+ TPM_CHECK(tpm_tsc_physical_presence(dev, PRESENCE));
+ TPM_CHECK(tpm_nv_read_value(dev, INDEX0, (uint8_t *)&x, sizeof(x)));
+ TPM_CHECK(tpm_nv_write_value(dev, INDEX0, (uint8_t *)&zero,
sizeof(uint32_t)));
- TPM_CHECK(tpm_nv_read_value(INDEX1, (uint8_t *)&x, sizeof(x)));
- TPM_CHECK(tpm_nv_write_value(INDEX1, (uint8_t *)&zero,
+ TPM_CHECK(tpm_nv_read_value(dev, INDEX1, (uint8_t *)&x, sizeof(x)));
+ TPM_CHECK(tpm_nv_write_value(dev, INDEX1, (uint8_t *)&zero,
sizeof(uint32_t)));
- TPM_CHECK(tpm_set_global_lock());
+ TPM_CHECK(tpm_set_global_lock(dev));
/* Verifies that write to index0 fails */
x = 1;
- result = tpm_nv_write_value(INDEX0, (uint8_t *)&x, sizeof(x));
+ result = tpm_nv_write_value(dev, INDEX0, (uint8_t *)&x, sizeof(x));
assert(result == TPM_AREA_LOCKED);
- TPM_CHECK(tpm_nv_read_value(INDEX0, (uint8_t *)&x, sizeof(x)));
+ TPM_CHECK(tpm_nv_read_value(dev, INDEX0, (uint8_t *)&x, sizeof(x)));
assert(x == 0);
/* Verifies that write to index1 is still possible */
x = 2;
- TPM_CHECK(tpm_nv_write_value(INDEX1, (uint8_t *)&x, sizeof(x)));
- TPM_CHECK(tpm_nv_read_value(INDEX1, (uint8_t *)&x, sizeof(x)));
+ TPM_CHECK(tpm_nv_write_value(dev, INDEX1, (uint8_t *)&x, sizeof(x)));
+ TPM_CHECK(tpm_nv_read_value(dev, INDEX1, (uint8_t *)&x, sizeof(x)));
assert(x == 2);
/* Turns off PP */
- tpm_tsc_physical_presence(PHYS_PRESENCE);
+ tpm_tsc_physical_presence(dev, PHYS_PRESENCE);
/* Verifies that write to index1 fails */
x = 3;
- result = tpm_nv_write_value(INDEX1, (uint8_t *)&x, sizeof(x));
+ result = tpm_nv_write_value(dev, INDEX1, (uint8_t *)&x, sizeof(x));
assert(result == TPM_BAD_PRESENCE);
- TPM_CHECK(tpm_nv_read_value(INDEX1, (uint8_t *)&x, sizeof(x)));
+ TPM_CHECK(tpm_nv_read_value(dev, INDEX1, (uint8_t *)&x, sizeof(x)));
assert(x == 2);
printf("\tdone\n");
return 0;
}
-static int test_lock(void)
+static int test_lock(struct udevice *dev)
{
printf("Testing lock ...\n");
- tpm_init();
- tpm_startup(TPM_ST_CLEAR);
- tpm_self_test_full();
- tpm_tsc_physical_presence(PRESENCE);
- tpm_nv_write_value_lock(INDEX0);
+ tpm_init(dev);
+ tpm_startup(dev, TPM_ST_CLEAR);
+ tpm_self_test_full(dev);
+ tpm_tsc_physical_presence(dev, PRESENCE);
+ tpm_nv_write_value_lock(dev, INDEX0);
printf("\tLocked 0x%x\n", INDEX0);
printf("\tdone\n");
return 0;
}
-static void initialise_spaces(void)
+static void initialise_spaces(struct udevice *dev)
{
uint32_t zero = 0;
uint32_t perm = TPM_NV_PER_WRITE_STCLEAR | TPM_NV_PER_PPWRITE;
printf("\tInitialising spaces\n");
- tpm_nv_set_locked(); /* useful only the first time */
- tpm_nv_define_space(INDEX0, perm, 4);
- tpm_nv_write_value(INDEX0, (uint8_t *)&zero, 4);
- tpm_nv_define_space(INDEX1, perm, 4);
- tpm_nv_write_value(INDEX1, (uint8_t *)&zero, 4);
- tpm_nv_define_space(INDEX2, perm, 4);
- tpm_nv_write_value(INDEX2, (uint8_t *)&zero, 4);
- tpm_nv_define_space(INDEX3, perm, 4);
- tpm_nv_write_value(INDEX3, (uint8_t *)&zero, 4);
+ tpm_nv_set_locked(dev); /* useful only the first time */
+ tpm_nv_define_space(dev, INDEX0, perm, 4);
+ tpm_nv_write_value(dev, INDEX0, (uint8_t *)&zero, 4);
+ tpm_nv_define_space(dev, INDEX1, perm, 4);
+ tpm_nv_write_value(dev, INDEX1, (uint8_t *)&zero, 4);
+ tpm_nv_define_space(dev, INDEX2, perm, 4);
+ tpm_nv_write_value(dev, INDEX2, (uint8_t *)&zero, 4);
+ tpm_nv_define_space(dev, INDEX3, perm, 4);
+ tpm_nv_write_value(dev, INDEX3, (uint8_t *)&zero, 4);
perm = TPM_NV_PER_READ_STCLEAR | TPM_NV_PER_WRITE_STCLEAR |
TPM_NV_PER_PPWRITE;
- tpm_nv_define_space(INDEX_INITIALISED, perm, 1);
+ tpm_nv_define_space(dev, INDEX_INITIALISED, perm, 1);
}
-static int test_readonly(void)
+static int test_readonly(struct udevice *dev)
{
uint8_t c;
uint32_t index_0, index_1, index_2, index_3;
int read0, read1, read2, read3;
printf("Testing readonly ...\n");
- tpm_init();
- tpm_startup(TPM_ST_CLEAR);
- tpm_self_test_full();
- tpm_tsc_physical_presence(PRESENCE);
+ tpm_init(dev);
+ tpm_startup(dev, TPM_ST_CLEAR);
+ tpm_self_test_full(dev);
+ tpm_tsc_physical_presence(dev, PRESENCE);
/*
* Checks if initialisation has completed by trying to read-lock a
* space that's created at the end of initialisation
*/
- if (tpm_nv_read_value(INDEX_INITIALISED, &c, 0) == TPM_BADINDEX) {
+ if (tpm_nv_read_value(dev, INDEX_INITIALISED, &c, 0) == TPM_BADINDEX) {
/* The initialisation did not complete */
- initialise_spaces();
+ initialise_spaces(dev);
}
/* Checks if spaces are OK or messed up */
- read0 = tpm_nv_read_value(INDEX0, (uint8_t *)&index_0, sizeof(index_0));
- read1 = tpm_nv_read_value(INDEX1, (uint8_t *)&index_1, sizeof(index_1));
- read2 = tpm_nv_read_value(INDEX2, (uint8_t *)&index_2, sizeof(index_2));
- read3 = tpm_nv_read_value(INDEX3, (uint8_t *)&index_3, sizeof(index_3));
+ read0 = tpm_nv_read_value(dev, INDEX0, (uint8_t *)&index_0,
+ sizeof(index_0));
+ read1 = tpm_nv_read_value(dev, INDEX1, (uint8_t *)&index_1,
+ sizeof(index_1));
+ read2 = tpm_nv_read_value(dev, INDEX2, (uint8_t *)&index_2,
+ sizeof(index_2));
+ read3 = tpm_nv_read_value(dev, INDEX3, (uint8_t *)&index_3,
+ sizeof(index_3));
if (read0 || read1 || read2 || read3) {
printf("Invalid contents\n");
return 0;
@@ -285,12 +290,14 @@ static int test_readonly(void)
* I really wish I could use the imperative.
*/
index_0 += 1;
- if (tpm_nv_write_value(INDEX0, (uint8_t *)&index_0, sizeof(index_0) !=
+ if (tpm_nv_write_value(dev, INDEX0, (uint8_t *)&index_0,
+ sizeof(index_0) !=
TPM_SUCCESS)) {
pr_err("\tcould not write index 0\n");
}
- tpm_nv_write_value_lock(INDEX0);
- if (tpm_nv_write_value(INDEX0, (uint8_t *)&index_0, sizeof(index_0)) ==
+ tpm_nv_write_value_lock(dev, INDEX0);
+ if (tpm_nv_write_value(dev, INDEX0, (uint8_t *)&index_0,
+ sizeof(index_0)) ==
TPM_SUCCESS)
pr_err("\tindex 0 is not locked\n");
@@ -298,49 +305,49 @@ static int test_readonly(void)
return 0;
}
-static int test_redefine_unowned(void)
+static int test_redefine_unowned(struct udevice *dev)
{
uint32_t perm;
uint32_t result;
uint32_t x;
printf("Testing redefine_unowned ...");
- tpm_init();
- TPM_CHECK(TlclStartupIfNeeded());
- TPM_CHECK(tpm_self_test_full());
- TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
- assert(!tpm_is_owned());
+ tpm_init(dev);
+ TPM_CHECK(TlclStartupIfNeeded(dev));
+ TPM_CHECK(tpm_self_test_full(dev));
+ TPM_CHECK(tpm_tsc_physical_presence(dev, PRESENCE));
+ assert(!tpm_is_owned(dev));
/* Ensures spaces exist. */
- TPM_CHECK(tpm_nv_read_value(INDEX0, (uint8_t *)&x, sizeof(x)));
- TPM_CHECK(tpm_nv_read_value(INDEX1, (uint8_t *)&x, sizeof(x)));
+ TPM_CHECK(tpm_nv_read_value(dev, INDEX0, (uint8_t *)&x, sizeof(x)));
+ TPM_CHECK(tpm_nv_read_value(dev, INDEX1, (uint8_t *)&x, sizeof(x)));
/* Redefines spaces a couple of times. */
perm = TPM_NV_PER_PPWRITE | TPM_NV_PER_GLOBALLOCK;
- TPM_CHECK(tpm_nv_define_space(INDEX0, perm, 2 * sizeof(uint32_t)));
- TPM_CHECK(tpm_nv_define_space(INDEX0, perm, sizeof(uint32_t)));
+ TPM_CHECK(tpm_nv_define_space(dev, INDEX0, perm, 2 * sizeof(uint32_t)));
+ TPM_CHECK(tpm_nv_define_space(dev, INDEX0, perm, sizeof(uint32_t)));
perm = TPM_NV_PER_PPWRITE;
- TPM_CHECK(tpm_nv_define_space(INDEX1, perm, 2 * sizeof(uint32_t)));
- TPM_CHECK(tpm_nv_define_space(INDEX1, perm, sizeof(uint32_t)));
+ TPM_CHECK(tpm_nv_define_space(dev, INDEX1, perm, 2 * sizeof(uint32_t)));
+ TPM_CHECK(tpm_nv_define_space(dev, INDEX1, perm, sizeof(uint32_t)));
/* Sets the global lock */
- tpm_set_global_lock();
+ tpm_set_global_lock(dev);
/* Verifies that index0 cannot be redefined */
- result = tpm_nv_define_space(INDEX0, perm, sizeof(uint32_t));
+ result = tpm_nv_define_space(dev, INDEX0, perm, sizeof(uint32_t));
assert(result == TPM_AREA_LOCKED);
/* Checks that index1 can */
- TPM_CHECK(tpm_nv_define_space(INDEX1, perm, 2 * sizeof(uint32_t)));
- TPM_CHECK(tpm_nv_define_space(INDEX1, perm, sizeof(uint32_t)));
+ TPM_CHECK(tpm_nv_define_space(dev, INDEX1, perm, 2 * sizeof(uint32_t)));
+ TPM_CHECK(tpm_nv_define_space(dev, INDEX1, perm, sizeof(uint32_t)));
/* Turns off PP */
- tpm_tsc_physical_presence(PHYS_PRESENCE);
+ tpm_tsc_physical_presence(dev, PHYS_PRESENCE);
/* Verifies that neither index0 nor index1 can be redefined */
- result = tpm_nv_define_space(INDEX0, perm, sizeof(uint32_t));
+ result = tpm_nv_define_space(dev, INDEX0, perm, sizeof(uint32_t));
assert(result == TPM_BAD_PRESENCE);
- result = tpm_nv_define_space(INDEX1, perm, sizeof(uint32_t));
+ result = tpm_nv_define_space(dev, INDEX1, perm, sizeof(uint32_t));
assert(result == TPM_BAD_PRESENCE);
printf("done\n");
@@ -350,38 +357,39 @@ static int test_redefine_unowned(void)
#define PERMPPGL (TPM_NV_PER_PPWRITE | TPM_NV_PER_GLOBALLOCK)
#define PERMPP TPM_NV_PER_PPWRITE
-static int test_space_perm(void)
+static int test_space_perm(struct udevice *dev)
{
uint32_t perm;
printf("Testing spaceperm ...");
- tpm_init();
- TPM_CHECK(TlclStartupIfNeeded());
- TPM_CHECK(tpm_continue_self_test());
- TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
- TPM_CHECK(tpm_get_permissions(INDEX0, &perm));
+ tpm_init(dev);
+ TPM_CHECK(TlclStartupIfNeeded(dev));
+ TPM_CHECK(tpm_continue_self_test(dev));
+ TPM_CHECK(tpm_tsc_physical_presence(dev, PRESENCE));
+ TPM_CHECK(tpm_get_permissions(dev, INDEX0, &perm));
assert((perm & PERMPPGL) == PERMPPGL);
- TPM_CHECK(tpm_get_permissions(INDEX1, &perm));
+ TPM_CHECK(tpm_get_permissions(dev, INDEX1, &perm));
assert((perm & PERMPP) == PERMPP);
printf("done\n");
return 0;
}
-static int test_startup(void)
+static int test_startup(struct udevice *dev)
{
uint32_t result;
+
printf("Testing startup ...\n");
- tpm_init();
- result = tpm_startup(TPM_ST_CLEAR);
+ tpm_init(dev);
+ result = tpm_startup(dev, TPM_ST_CLEAR);
if (result != 0 && result != TPM_INVALID_POSTINIT)
printf("\ttpm startup failed with 0x%x\n", result);
- result = tpm_get_flags(NULL, NULL, NULL);
+ result = tpm_get_flags(dev, NULL, NULL, NULL);
if (result != 0)
printf("\ttpm getflags failed with 0x%x\n", result);
printf("\texecuting SelfTestFull\n");
- tpm_self_test_full();
- result = tpm_get_flags(NULL, NULL, NULL);
+ tpm_self_test_full(dev);
+ result = tpm_get_flags(dev, NULL, NULL, NULL);
if (result != 0)
printf("\ttpm getflags failed with 0x%x\n", result);
printf("\tdone\n");
@@ -410,45 +418,48 @@ static int test_startup(void)
} while (0)
-static int test_timing(void)
+static int test_timing(struct udevice *dev)
{
- uint32_t x;
uint8_t in[20], out[20];
+ uint32_t x;
printf("Testing timing ...");
- tpm_init();
- TTPM_CHECK(TlclStartupIfNeeded(), 50);
- TTPM_CHECK(tpm_continue_self_test(), 100);
- TTPM_CHECK(tpm_self_test_full(), 1000);
- TTPM_CHECK(tpm_tsc_physical_presence(PRESENCE), 100);
- TTPM_CHECK(tpm_nv_write_value(INDEX0, (uint8_t *)&x, sizeof(x)), 100);
- TTPM_CHECK(tpm_nv_read_value(INDEX0, (uint8_t *)&x, sizeof(x)), 100);
- TTPM_CHECK(tpm_extend(0, in, out), 200);
- TTPM_CHECK(tpm_set_global_lock(), 50);
- TTPM_CHECK(tpm_tsc_physical_presence(PHYS_PRESENCE), 100);
+ tpm_init(dev);
+ TTPM_CHECK(TlclStartupIfNeeded(dev), 50);
+ TTPM_CHECK(tpm_continue_self_test(dev), 100);
+ TTPM_CHECK(tpm_self_test_full(dev), 1000);
+ TTPM_CHECK(tpm_tsc_physical_presence(dev, PRESENCE), 100);
+ TTPM_CHECK(tpm_nv_write_value(dev, INDEX0, (uint8_t *)&x, sizeof(x)),
+ 100);
+ TTPM_CHECK(tpm_nv_read_value(dev, INDEX0, (uint8_t *)&x, sizeof(x)),
+ 100);
+ TTPM_CHECK(tpm_extend(dev, 0, in, out), 200);
+ TTPM_CHECK(tpm_set_global_lock(dev), 50);
+ TTPM_CHECK(tpm_tsc_physical_presence(dev, PHYS_PRESENCE), 100);
printf("done\n");
return 0;
}
#define TPM_MAX_NV_WRITES_NOOWNER 64
-static int test_write_limit(void)
+static int test_write_limit(struct udevice *dev)
{
- printf("Testing writelimit ...\n");
- int i;
uint32_t result;
+ int i;
- tpm_init();
- TPM_CHECK(TlclStartupIfNeeded());
- TPM_CHECK(tpm_self_test_full());
- TPM_CHECK(tpm_tsc_physical_presence(PRESENCE));
- TPM_CHECK(tpm_force_clear());
- TPM_CHECK(tpm_physical_enable());
- TPM_CHECK(tpm_physical_set_deactivated(0));
+ printf("Testing writelimit ...\n");
+ tpm_init(dev);
+ TPM_CHECK(TlclStartupIfNeeded(dev));
+ TPM_CHECK(tpm_self_test_full(dev));
+ TPM_CHECK(tpm_tsc_physical_presence(dev, PRESENCE));
+ TPM_CHECK(tpm_force_clear(dev));
+ TPM_CHECK(tpm_physical_enable(dev));
+ TPM_CHECK(tpm_physical_set_deactivated(dev, 0));
for (i = 0; i < TPM_MAX_NV_WRITES_NOOWNER + 2; i++) {
printf("\twriting %d\n", i);
- result = tpm_nv_write_value(INDEX0, (uint8_t *)&i, sizeof(i));
+ result = tpm_nv_write_value(dev, INDEX0, (uint8_t *)&i,
+ sizeof(i));
switch (result) {
case TPM_SUCCESS:
break;
@@ -461,12 +472,12 @@ static int test_write_limit(void)
}
/* Reset write count */
- TPM_CHECK(tpm_force_clear());
- TPM_CHECK(tpm_physical_enable());
- TPM_CHECK(tpm_physical_set_deactivated(0));
+ TPM_CHECK(tpm_force_clear(dev));
+ TPM_CHECK(tpm_physical_enable(dev));
+ TPM_CHECK(tpm_physical_set_deactivated(dev, 0));
/* Try writing again. */
- TPM_CHECK(tpm_nv_write_value(INDEX0, (uint8_t *)&i, sizeof(i)));
+ TPM_CHECK(tpm_nv_write_value(dev, INDEX0, (uint8_t *)&i, sizeof(i)));
printf("\tdone\n");
return 0;
}
@@ -475,7 +486,13 @@ static int test_write_limit(void)
int do_test_##XFUNC(cmd_tbl_t *cmd_tbl, int flag, int argc, \
char * const argv[]) \
{ \
- return test_##XFUNC(); \
+ struct udevice *dev; \
+ int ret; \
+\
+ ret = get_tpm(&dev); \
+ if (ret) \
+ return ret; \
+ return test_##XFUNC(dev); \
}
#define VOIDENT(XNAME) \