All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot
@ 2018-11-06 22:21 Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 01/25] cros_ec: Use uint instead of u8 for parameters Simon Glass
                   ` (42 more replies)
  0 siblings, 43 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

This series compiles a number of fixes and improvement to sandbox,
cros_ec, tpm and a few other pieces. This allows U-Boot to support
Chromium OS verified boot and assist with debugging of this.


Simon Glass (25):
  cros_ec: Use uint instead of u8 for parameters
  cros_ec: Add error logging on a few commands
  cros_ec: Fail if we cannot determine the flash burst size
  cros_ec: Align uclass data to a cache boundary
  cros_ec: Add new features for events and power
  sandbox: tpm: Allow debugging of data packages
  sandbox: log: Add a category for sandbox
  sandbox: Add a function to read a host file
  sandbox: cros_ec: exynos: Drop use of cros_ec_get_error()
  sandbox: Update some drivers to work in SPL/TPL
  spl: Support bootstage, log, hash and early malloc in TPL
  spl: Correct malloc debugging in board_init_r()
  spl: lz4: Allow use of lz4 compression in SPL
  binman: Add a way to enable debugging from the build
  binman: Drop an unnecessary comma in blob handling
  binman: Set the pathname correctly for ELF files
  tpm: Export the open/close functions
  tpm: Convert to use a device parameter
  video: Update video_set_default_colors() to support invert
  efi_loader: Don't enable in SPL/TPL by default
  string: Include the config header
  misc: Update read() and write() methods to return bytes xfered
  test: sf: Add a simple SPI flash test
  sf: Add a method to obtain the block-protect setting
  mmc: Add hardware partition support

 Makefile                              |   6 +-
 arch/arm/mach-stm32mp/cpu.c           |   4 +-
 arch/sandbox/cpu/os.c                 |  44 ++-
 arch/sandbox/dts/sandbox.dts          |  15 ++
 arch/sandbox/include/asm/test.h       |   8 +
 board/gdsys/a38x/controlcenterdc.c    |   8 +-
 board/gdsys/p1022/controlcenterd-id.c |  22 +-
 board/samsung/common/board.c          |  10 +-
 board/sandbox/sandbox.c               |   9 +-
 cmd/tpm-common.c                      |   8 +-
 cmd/tpm-v1.c                          | 122 +++++++--
 cmd/tpm-v2.c                          |  78 +++++-
 cmd/tpm_test.c                        | 371 +++++++++++++-------------
 common/Kconfig                        |  35 +++
 common/Makefile                       |  10 +-
 common/cros_ec.c                      |  12 -
 common/spl/spl.c                      |   2 +-
 drivers/clk/clk_vexpress_osc.c        |   4 +-
 drivers/misc/altera_sysid.c           |   2 +-
 drivers/misc/cros_ec.c                | 370 ++++++++++++++++++++++++-
 drivers/misc/cros_ec_sandbox.c        |   2 +-
 drivers/misc/misc_sandbox.c           |   4 +-
 drivers/misc/rockchip-efuse.c         |   2 +-
 drivers/misc/stm32mp_fuse.c           |  12 +
 drivers/mmc/mmc.c                     |  46 ++++
 drivers/mtd/spi/sandbox.c             |  10 +
 drivers/mtd/spi/sf-uclass.c           |   9 +
 drivers/mtd/spi/sf_internal.h         |   3 +
 drivers/mtd/spi/sf_probe.c            |   8 +
 drivers/mtd/spi/spi_flash.c           |  12 +
 drivers/tpm/tpm_tis_lpc.c             |  50 ++--
 drivers/tpm/tpm_tis_sandbox.c         |   6 +
 drivers/video/vidconsole-uclass.c     |   2 +-
 drivers/video/video-uclass.c          |  27 +-
 include/cros_ec.h                     |  89 ++++++
 include/log.h                         |   1 +
 include/misc.h                        |   8 +-
 include/mmc.h                         |  31 +++
 include/os.h                          |  14 +
 include/spi_flash.h                   |  27 ++
 include/tpm-common.h                  |  36 ++-
 include/tpm-v1.h                      |  97 ++++---
 include/tpm-v2.h                      |  49 ++--
 include/video.h                       |   5 +-
 lib/Kconfig                           |   8 +
 lib/Makefile                          |  10 +-
 lib/string.c                          |   1 +
 lib/tpm-common.c                      |  16 +-
 lib/tpm-utils.h                       |  21 +-
 lib/tpm-v1.c                          | 136 +++++-----
 lib/tpm-v2.c                          |  60 +++--
 test/dm/sf.c                          |  55 +++-
 tools/binman/README                   |   6 +
 tools/binman/etype/blob.py            |   2 +-
 tools/binman/etype/u_boot_elf.py      |   5 +-
 55 files changed, 1520 insertions(+), 490 deletions(-)

-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 01/25] cros_ec: Use uint instead of u8 for parameters
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 02/25] cros_ec: Add error logging on a few commands Simon Glass
                   ` (41 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

There is no advantage to using a u8 for function parameters. It forces
the compiler to mask values and can increase code size. Also the command
enum has been extended to 16 bits. Update the functions to use uint
instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c
index 190505c11c7..4013f50d592 100644
--- a/drivers/misc/cros_ec.c
+++ b/drivers/misc/cros_ec.c
@@ -227,7 +227,7 @@ static int send_command_proto3(struct cros_ec_dev *cdev,
 	return handle_proto3_response(cdev, dinp, din_len);
 }
 
-static int send_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
+static int send_command(struct cros_ec_dev *dev, uint cmd, int cmd_version,
 			const void *dout, int dout_len,
 			uint8_t **dinp, int din_len)
 {
@@ -330,7 +330,7 @@ static int ec_command_inptr(struct udevice *dev, uint8_t cmd,
  * @param din_len       Maximum size of response in bytes
  * @return number of bytes in response, or -ve on error
  */
-static int ec_command(struct udevice *dev, uint8_t cmd, int cmd_version,
+static int ec_command(struct udevice *dev, uint cmd, int cmd_version,
 		      const void *dout, int dout_len,
 		      void *din, int din_len)
 {
@@ -650,16 +650,14 @@ static int cros_ec_check_version(struct udevice *dev)
 	cdev->protocol_version = 3;
 	req.in_data = 0;
 	if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
-			     (uint8_t **)&resp, sizeof(*resp)) > 0) {
+			     (uint8_t **)&resp, sizeof(*resp)) > 0)
 		return 0;
-	}
 
 	/* Try sending a version 2 packet */
 	cdev->protocol_version = 2;
 	if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
-			     (uint8_t **)&resp, sizeof(*resp)) > 0) {
+			     (uint8_t **)&resp, sizeof(*resp)) > 0)
 		return 0;
-	}
 
 	/*
 	 * Fail if we're still here, since the EC doesn't understand any
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 02/25] cros_ec: Add error logging on a few commands
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 01/25] cros_ec: Use uint instead of u8 for parameters Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 03/25] cros_ec: Fail if we cannot determine the flash burst size Simon Glass
                   ` (40 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

Add some more logging to provide more information on failures.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c
index 4013f50d592..e0f3dfc98e0 100644
--- a/drivers/misc/cros_ec.c
+++ b/drivers/misc/cros_ec.c
@@ -13,6 +13,8 @@
  * is not reset.
  */
 
+#define LOG_CATEGORY UCLASS_CROS_EC
+
 #include <common.h>
 #include <command.h>
 #include <dm.h>
@@ -365,10 +367,14 @@ int cros_ec_scan_keyboard(struct udevice *dev, struct mbkp_keyscan *scan)
 int cros_ec_read_id(struct udevice *dev, char *id, int maxlen)
 {
 	struct ec_response_get_version *r;
+	int ret;
 
-	if (ec_command_inptr(dev, EC_CMD_GET_VERSION, 0, NULL, 0,
-			(uint8_t **)&r, sizeof(*r)) != sizeof(*r))
+	ret = ec_command_inptr(dev, EC_CMD_GET_VERSION, 0, NULL, 0,
+			       (uint8_t **)&r, sizeof(*r));
+	if (ret != sizeof(*r)) {
+		log_err("Got rc %d, expected %d\n", ret, sizeof(*r));
 		return -1;
+	}
 
 	if (maxlen > (int)sizeof(r->version_string_ro))
 		maxlen = sizeof(r->version_string_ro);
@@ -381,6 +387,7 @@ int cros_ec_read_id(struct udevice *dev, char *id, int maxlen)
 		memcpy(id, r->version_string_rw, maxlen);
 		break;
 	default:
+		log_err("Invalid EC image %d\n", r->current_image);
 		return -1;
 	}
 
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 03/25] cros_ec: Fail if we cannot determine the flash burst size
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 01/25] cros_ec: Use uint instead of u8 for parameters Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 02/25] cros_ec: Add error logging on a few commands Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 04/25] cros_ec: Align uclass data to a cache boundary Simon Glass
                   ` (39 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

This value is required for flashing to work correctly. Add a check for
it.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c
index e0f3dfc98e0..7daf16499aa 100644
--- a/drivers/misc/cros_ec.c
+++ b/drivers/misc/cros_ec.c
@@ -827,6 +827,9 @@ int cros_ec_flash_write(struct udevice *dev, const uint8_t *data,
 	uint32_t end, off;
 	int ret;
 
+	if (!burst)
+		return -EINVAL;
+
 	/*
 	 * TODO: round up to the nearest multiple of write size.  Can get away
 	 * without that on link right now because its write size is 4 bytes.
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 04/25] cros_ec: Align uclass data to a cache boundary
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (2 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 03/25] cros_ec: Fail if we cannot determine the flash burst size Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 05/25] cros_ec: Add new features for events and power Simon Glass
                   ` (38 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

The LPC driver expects its buffer to be word-aligned. Add the required
flag to the uclass driver to ensure this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c
index 7daf16499aa..828e50eb1cc 100644
--- a/drivers/misc/cros_ec.c
+++ b/drivers/misc/cros_ec.c
@@ -1152,4 +1152,5 @@ UCLASS_DRIVER(cros_ec) = {
 	.name		= "cros_ec",
 	.per_device_auto_alloc_size = sizeof(struct cros_ec_dev),
 	.post_bind	= dm_scan_fdt_dev,
+	.flags		= DM_UC_FLAG_ALLOC_PRIV_DMA,
 };
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 05/25] cros_ec: Add new features for events and power
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (3 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 04/25] cros_ec: Align uclass data to a cache boundary Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 06/25] sandbox: tpm: Allow debugging of data packages Simon Glass
                   ` (37 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

This adds new commands to the EC related to setting and clearing events
as well as controlling power-related settings.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec.c         | 345 ++++++++++++++++++++++++++++++++-
 drivers/misc/cros_ec_sandbox.c |   2 +-
 include/cros_ec.h              |  89 +++++++++
 3 files changed, 429 insertions(+), 7 deletions(-)

diff --git a/drivers/misc/cros_ec.c b/drivers/misc/cros_ec.c
index 828e50eb1cc..2dcdb3d8d61 100644
--- a/drivers/misc/cros_ec.c
+++ b/drivers/misc/cros_ec.c
@@ -43,6 +43,54 @@ enum {
 	CROS_EC_CMD_HASH_TIMEOUT_MS = 2000,
 };
 
+#define INVALID_HCMD 0xFF
+
+/*
+ * Map UHEPI masks to non UHEPI commands in order to support old EC FW
+ * which does not support UHEPI command.
+ */
+static const struct {
+	u8 set_cmd;
+	u8 clear_cmd;
+	u8 get_cmd;
+} event_map[] = {
+	[EC_HOST_EVENT_MAIN] = {
+		INVALID_HCMD, EC_CMD_HOST_EVENT_CLEAR,
+		INVALID_HCMD,
+	},
+	[EC_HOST_EVENT_B] = {
+		INVALID_HCMD, EC_CMD_HOST_EVENT_CLEAR_B,
+		EC_CMD_HOST_EVENT_GET_B,
+	},
+	[EC_HOST_EVENT_SCI_MASK] = {
+		EC_CMD_HOST_EVENT_SET_SCI_MASK, INVALID_HCMD,
+		EC_CMD_HOST_EVENT_GET_SCI_MASK,
+	},
+	[EC_HOST_EVENT_SMI_MASK] = {
+		EC_CMD_HOST_EVENT_SET_SMI_MASK, INVALID_HCMD,
+		EC_CMD_HOST_EVENT_GET_SMI_MASK,
+	},
+	[EC_HOST_EVENT_ALWAYS_REPORT_MASK] = {
+		INVALID_HCMD, INVALID_HCMD, INVALID_HCMD,
+	},
+	[EC_HOST_EVENT_ACTIVE_WAKE_MASK] = {
+		EC_CMD_HOST_EVENT_SET_WAKE_MASK, INVALID_HCMD,
+		EC_CMD_HOST_EVENT_GET_WAKE_MASK,
+	},
+	[EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX] = {
+		EC_CMD_HOST_EVENT_SET_WAKE_MASK, INVALID_HCMD,
+		EC_CMD_HOST_EVENT_GET_WAKE_MASK,
+	},
+	[EC_HOST_EVENT_LAZY_WAKE_MASK_S3] = {
+		EC_CMD_HOST_EVENT_SET_WAKE_MASK, INVALID_HCMD,
+		EC_CMD_HOST_EVENT_GET_WAKE_MASK,
+	},
+	[EC_HOST_EVENT_LAZY_WAKE_MASK_S5] = {
+		EC_CMD_HOST_EVENT_SET_WAKE_MASK, INVALID_HCMD,
+		EC_CMD_HOST_EVENT_GET_WAKE_MASK,
+	},
+};
+
 void cros_ec_dump_data(const char *name, int cmd, const uint8_t *data, int len)
 {
 #ifdef DEBUG
@@ -570,6 +618,36 @@ int cros_ec_info(struct udevice *dev, struct ec_response_mkbp_info *info)
 	return 0;
 }
 
+int cros_ec_get_event_mask(struct udevice *dev, uint type, uint32_t *mask)
+{
+	struct ec_response_host_event_mask rsp;
+	int ret;
+
+	ret = ec_command(dev, type, 0, NULL, 0, &rsp, sizeof(rsp));
+	if (ret < 0)
+		return ret;
+	else if (ret != sizeof(rsp))
+		return -EINVAL;
+
+	*mask = rsp.mask;
+
+	return 0;
+}
+
+int cros_ec_set_event_mask(struct udevice *dev, uint type, uint32_t mask)
+{
+	struct ec_params_host_event_mask req;
+	int ret;
+
+	req.mask = mask;
+
+	ret = ec_command(dev, type, 0, &req, sizeof(req), NULL, 0);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
 int cros_ec_get_host_events(struct udevice *dev, uint32_t *events_ptr)
 {
 	struct ec_response_host_event_mask *resp;
@@ -623,6 +701,17 @@ int cros_ec_flash_protect(struct udevice *dev, uint32_t set_mask,
 	return 0;
 }
 
+int cros_ec_entering_mode(struct udevice *dev, int mode)
+{
+	int rc;
+
+	rc = ec_command(dev, EC_CMD_ENTERING_MODE, 0, &mode, sizeof(mode),
+			NULL, 0);
+	if (rc)
+		return -1;
+	return 0;
+}
+
 static int cros_ec_check_version(struct udevice *dev)
 {
 	struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
@@ -852,6 +941,35 @@ int cros_ec_flash_write(struct udevice *dev, const uint8_t *data,
 	return 0;
 }
 
+/**
+ * Run verification on a slot
+ *
+ * @param me     CrosEc instance
+ * @param region Region to run verification on
+ * @return 0 if success or not applicable. Non-zero if verification failed.
+ */
+int cros_ec_efs_verify(struct udevice *dev, enum ec_flash_region region)
+{
+	struct ec_params_efs_verify p;
+	int rv;
+
+	log_info("EFS: EC is verifying updated image...\n");
+	p.region = region;
+
+	rv = ec_command(dev, EC_CMD_EFS_VERIFY, 0, &p, sizeof(p), NULL, 0);
+	if (rv >= 0) {
+		log_info("EFS: Verification success\n");
+		return 0;
+	}
+	if (rv == -EC_RES_INVALID_COMMAND) {
+		log_info("EFS: EC doesn't support EFS_VERIFY command\n");
+		return 0;
+	}
+	log_info("EFS: Verification failed\n");
+
+	return rv;
+}
+
 /**
  * Read a single block from the flash
  *
@@ -942,15 +1060,17 @@ int cros_ec_read_nvdata(struct udevice *dev, uint8_t *block, int size)
 	struct ec_params_vbnvcontext p;
 	int len;
 
-	if (size != EC_VBNV_BLOCK_SIZE)
+	if (size != EC_VBNV_BLOCK_SIZE && size != EC_VBNV_BLOCK_SIZE_V2)
 		return -EINVAL;
 
 	p.op = EC_VBNV_CONTEXT_OP_READ;
 
 	len = ec_command(dev, EC_CMD_VBNV_CONTEXT, EC_VER_VBNV_CONTEXT,
-			&p, sizeof(p), block, EC_VBNV_BLOCK_SIZE);
-	if (len < EC_VBNV_BLOCK_SIZE)
+			 &p, sizeof(uint32_t) + size, block, size);
+	if (len != size) {
+		log_err("Expected %d bytes, got %d\n", size, len);
 		return -EIO;
+	}
 
 	return 0;
 }
@@ -960,19 +1080,33 @@ int cros_ec_write_nvdata(struct udevice *dev, const uint8_t *block, int size)
 	struct ec_params_vbnvcontext p;
 	int len;
 
-	if (size != EC_VBNV_BLOCK_SIZE)
+	if (size != EC_VBNV_BLOCK_SIZE && size != EC_VBNV_BLOCK_SIZE_V2)
 		return -EINVAL;
 	p.op = EC_VBNV_CONTEXT_OP_WRITE;
-	memcpy(p.block, block, sizeof(p.block));
+	memcpy(p.block, block, size);
 
 	len = ec_command_inptr(dev, EC_CMD_VBNV_CONTEXT, EC_VER_VBNV_CONTEXT,
-			&p, sizeof(p), NULL, 0);
+			&p, sizeof(uint32_t) + size, NULL, 0);
 	if (len < 0)
 		return -1;
 
 	return 0;
 }
 
+int cros_ec_battery_cutoff(struct udevice *dev, uint8_t flags)
+{
+	struct ec_params_battery_cutoff p;
+	int len;
+
+	p.flags = flags;
+	len = ec_command(dev, EC_CMD_BATTERY_CUT_OFF, 1, &p, sizeof(p),
+			 NULL, 0);
+
+	if (len < 0)
+		return -1;
+	return 0;
+}
+
 int cros_ec_set_ldo(struct udevice *dev, uint8_t index, uint8_t state)
 {
 	struct ec_params_ldo_set params;
@@ -1147,6 +1281,205 @@ int cros_ec_i2c_tunnel(struct udevice *dev, int port, struct i2c_msg *in,
 	return 0;
 }
 
+int cros_ec_check_feature(struct udevice *dev, int feature)
+{
+	struct ec_response_get_features r;
+	int rv;
+
+	rv = ec_command(dev, EC_CMD_GET_FEATURES, 0, &r, sizeof(r), NULL, 0);
+	if (rv)
+		return rv;
+
+	if (feature >= 8 * sizeof(r.flags))
+		return -1;
+
+	return r.flags[feature / 32] & EC_FEATURE_MASK_0(feature);
+}
+
+/*
+ * Query the EC for specified mask indicating enabled events.
+ * The EC maintains separate event masks for SMI, SCI and WAKE.
+ */
+static int cros_ec_uhepi_cmd(struct udevice *dev, uint mask, uint action,
+			     uint64_t *value)
+{
+	int ret;
+	struct ec_params_host_event req;
+	struct ec_response_host_event rsp;
+
+	req.action = action;
+	req.mask_type = mask;
+	if (action != EC_HOST_EVENT_GET)
+		req.value = *value;
+	else
+		*value = 0;
+	ret = ec_command(dev, EC_CMD_HOST_EVENT, 0, &req, sizeof(req), &rsp,
+			 sizeof(rsp));
+
+	if (action != EC_HOST_EVENT_GET)
+		return ret;
+	if (ret == 0)
+		*value = rsp.value;
+
+	return ret;
+}
+
+static int cros_ec_handle_non_uhepi_cmd(struct udevice *dev, uint hcmd,
+					uint action, uint64_t *value)
+{
+	int ret = -1;
+	struct ec_params_host_event_mask req;
+	struct ec_response_host_event_mask rsp;
+
+	if (hcmd == INVALID_HCMD)
+		return ret;
+
+	if (action != EC_HOST_EVENT_GET)
+		req.mask = (uint32_t)*value;
+	else
+		*value = 0;
+
+	ret = ec_command(dev, hcmd, 0, &req, sizeof(req), &rsp, sizeof(rsp));
+	if (action != EC_HOST_EVENT_GET)
+		return ret;
+	if (ret == 0)
+		*value = rsp.mask;
+
+	return ret;
+}
+
+bool cros_ec_is_uhepi_supported(struct udevice *dev)
+{
+#define UHEPI_SUPPORTED 1
+#define UHEPI_NOT_SUPPORTED 2
+	static int uhepi_support;
+
+	if (!uhepi_support) {
+		uhepi_support = cros_ec_check_feature(dev,
+			EC_FEATURE_UNIFIED_WAKE_MASKS) > 0 ? UHEPI_SUPPORTED :
+			UHEPI_NOT_SUPPORTED;
+		log_debug("Chrome EC: UHEPI %s\n",
+			  uhepi_support == UHEPI_SUPPORTED ? "supported" :
+			  "not supported");
+	}
+	return uhepi_support == UHEPI_SUPPORTED;
+}
+
+static int cros_ec_get_mask(struct udevice *dev, uint type)
+{
+	u64 value = 0;
+
+	if (cros_ec_is_uhepi_supported(dev)) {
+		cros_ec_uhepi_cmd(dev, type, EC_HOST_EVENT_GET, &value);
+	} else {
+		assert(type < ARRAY_SIZE(event_map));
+		cros_ec_handle_non_uhepi_cmd(dev, event_map[type].get_cmd,
+					     EC_HOST_EVENT_GET, &value);
+	}
+	return value;
+}
+
+static int cros_ec_clear_mask(struct udevice *dev, uint type, u64 mask)
+{
+	if (cros_ec_is_uhepi_supported(dev))
+		return cros_ec_uhepi_cmd(dev, type, EC_HOST_EVENT_CLEAR, &mask);
+
+	assert(type < ARRAY_SIZE(event_map));
+
+	return cros_ec_handle_non_uhepi_cmd(dev, event_map[type].clear_cmd,
+					    EC_HOST_EVENT_CLEAR, &mask);
+}
+
+uint64_t cros_ec_get_events_b(struct udevice *dev)
+{
+	return cros_ec_get_mask(dev, EC_HOST_EVENT_B);
+}
+
+int cros_ec_clear_events_b(struct udevice *dev, uint64_t mask)
+{
+	log_debug("Chrome EC: clear events_b mask to 0x%016llx\n", mask);
+
+	return cros_ec_clear_mask(dev, EC_HOST_EVENT_B, mask);
+}
+
+int cros_ec_read_limit_power(struct udevice *dev, int *limit_powerp)
+{
+	struct ec_params_charge_state p;
+	struct ec_response_charge_state r;
+	int ret;
+
+	p.cmd = CHARGE_STATE_CMD_GET_PARAM;
+	p.get_param.param = CS_PARAM_LIMIT_POWER;
+	ret = ec_command(dev, EC_CMD_CHARGE_STATE, 0, &p, sizeof(p),
+			 &r, sizeof(r));
+
+	/*
+	 * If our EC doesn't support the LIMIT_POWER parameter, assume that
+	 * LIMIT_POWER is not requested.
+	 */
+	if (ret == -EC_RES_INVALID_PARAM || ret == -EC_RES_INVALID_COMMAND) {
+		log_warning("PARAM_LIMIT_POWER not supported by EC\n");
+		return -ENOSYS;
+	}
+
+	if (ret != sizeof(r.get_param))
+		return -EINVAL;
+
+	*limit_powerp = r.get_param.value;
+	return 0;
+}
+
+int cros_ec_config_powerbtn(struct udevice *dev, uint32_t flags)
+{
+	struct ec_params_config_power_button params;
+	int ret;
+
+	params.flags = flags;
+	ret = ec_command(dev, EC_CMD_CONFIG_POWER_BUTTON, 0,
+			 &params, sizeof(params), NULL, 0);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+int cros_ec_get_lid_shutdown_mask(struct udevice *dev)
+{
+	u32 mask;
+	int ret;
+
+	ret = cros_ec_get_event_mask(dev, EC_CMD_HOST_EVENT_GET_SMI_MASK,
+				     &mask);
+	if (ret < 0)
+		return ret;
+
+	return !!(mask & EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_CLOSED));
+}
+
+int cros_ec_set_lid_shutdown_mask(struct udevice *dev, int enable)
+{
+	u32 mask;
+	int ret;
+
+	ret = cros_ec_get_event_mask(dev, EC_CMD_HOST_EVENT_GET_SMI_MASK,
+				     &mask);
+	if (ret < 0)
+		return ret;
+
+	// Set lid close event state in the EC SMI event mask
+	if (enable)
+		mask |= EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_CLOSED);
+	else
+		mask &= ~EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_CLOSED);
+
+	ret = cros_ec_set_event_mask(dev, EC_CMD_HOST_EVENT_SET_SMI_MASK, mask);
+	if (ret < 0)
+		return ret;
+
+	printf("EC: %sabled lid close event\n", enable ? "en" : "dis");
+	return 0;
+}
+
 UCLASS_DRIVER(cros_ec) = {
 	.id		= UCLASS_CROS_EC,
 	.name		= "cros_ec",
diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c
index d741554d8a6..429f1a9b269 100644
--- a/drivers/misc/cros_ec_sandbox.c
+++ b/drivers/misc/cros_ec_sandbox.c
@@ -74,7 +74,7 @@ struct ec_keymatrix_entry {
  * @recovery_req: Keyboard recovery requested
  */
 struct ec_state {
-	uint8_t vbnv_context[EC_VBNV_BLOCK_SIZE];
+	u8 vbnv_context[EC_VBNV_BLOCK_SIZE_V2];
 	struct fdt_cros_ec ec_config;
 	uint8_t *flash_data;
 	int flash_data_len;
diff --git a/include/cros_ec.h b/include/cros_ec.h
index 4771e6b7d1c..f4b9b7a5c26 100644
--- a/include/cros_ec.h
+++ b/include/cros_ec.h
@@ -187,6 +187,14 @@ int cros_ec_flash_protect(struct udevice *dev, uint32_t set_mask,
 			  uint32_t set_flags,
 			  struct ec_response_flash_protect *resp);
 
+/**
+ * Notify EC of current boot mode
+ *
+ * @param dev		CROS-EC device
+ * @param vboot_mode    Verified boot mode
+ * @return 0 if ok, <0 on error
+ */
+int cros_ec_entering_mode(struct udevice *dev, int mode);
 
 /**
  * Run internal tests on the cros_ec interface.
@@ -397,4 +405,85 @@ struct i2c_msg;
 int cros_ec_i2c_tunnel(struct udevice *dev, int port, struct i2c_msg *msg,
 		       int nmsgs);
 
+/**
+ * cros_ec_get_events_b() - Get event mask B
+ *
+ * @return value of event mask, default value of 0 if it could not be read
+ */
+uint64_t cros_ec_get_events_b(struct udevice *dev);
+
+/**
+ * cros_ec_clear_events_b() - Clear even mask B
+ *
+ * Any pending events in the B range are cleared
+ *
+ * @return 0 if OK, -ve on error
+ */
+int cros_ec_clear_events_b(struct udevice *dev, uint64_t mask);
+
+/**
+ * cros_ec_efs_verify() - tell the EC to verify one of its images
+ *
+ * @param dev		CROS-EC device
+ * @param region	Flash region to query
+ * @return 0 if OK, -ve on error
+ */
+int cros_ec_efs_verify(struct udevice *dev, enum ec_flash_region region);
+
+/**
+ * cros_ec_battery_cutoff() - Request that the battery be cut off
+ *
+ * This tells the battery to stop supplying power. This is used before shipping
+ * a device to ensure that the battery remains charged while the device is
+ * shipped or sitting on the shelf waiting to be purchased.
+ *
+ * @param dev		CROS-EC device
+ * @param flags		Flags to use (EC_BATTERY_CUTOFF_FLAG_...)
+ * @return 0 if OK, -ve on error
+ */
+int cros_ec_battery_cutoff(struct udevice *dev, uint8_t flags);
+
+/**
+ * cros_ec_read_limit_power() - Check if power is limited by batter/charger
+ *
+ * Sometimes the battery is low and / or the device is connected to a charger
+ * that cannot supply much power.
+ *
+ * @param dev		CROS-EC device
+ * @param limit_powerp	Returns whether power is limited (0 or 1)
+ * @return 0 if OK, -ENOSYS if the EC does not support this comment, -EINVAL
+ *		if the EC returned an invalid response
+ */
+int cros_ec_read_limit_power(struct udevice *dev, int *limit_powerp);
+
+/**
+ * cros_ec_config_powerbtn() - Configure the behaviour of the power button
+ *
+ * @param dev		CROS-EC device
+ * @param flags		Flags to use (EC_POWER_BUTTON_...)
+ * @return 0 if OK, -ve on error
+ */
+int cros_ec_config_powerbtn(struct udevice *dev, uint32_t flags);
+
+/**
+ * cros_ec_get_lid_shutdown_mask() - Set the lid shutdown mask
+ *
+ * Determines whether a lid close event is reported
+ *
+ * @param dev		CROS-EC device
+ * @return shufdown mas if OK, -ve on error
+ */
+int cros_ec_get_lid_shutdown_mask(struct udevice *dev);
+
+/**
+ * cros_ec_set_lid_shutdown_mask() - Set the lid shutdown mask
+ *
+ * Set whether a lid close event is reported
+ *
+ * @param dev		CROS-EC device
+ * @param enable	true to enable reporting, false to disable
+ * @return shufdown mas if OK, -ve on error
+ */
+int cros_ec_set_lid_shutdown_mask(struct udevice *dev, int enable);
+
 #endif
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 06/25] sandbox: tpm: Allow debugging of data packages
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (4 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 05/25] cros_ec: Add new features for events and power Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 07/25] sandbox: log: Add a category for sandbox Simon Glass
                   ` (36 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

This is not normally useful, so change the code to avoid writing out every
data package. This can be enabled with #define DEBUG.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/tpm/tpm_tis_sandbox.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/tpm/tpm_tis_sandbox.c b/drivers/tpm/tpm_tis_sandbox.c
index 79517f015af..3336f559e57 100644
--- a/drivers/tpm/tpm_tis_sandbox.c
+++ b/drivers/tpm/tpm_tis_sandbox.c
@@ -187,9 +187,11 @@ static int sandbox_tpm_xfer(struct udevice *dev, const uint8_t *sendbuf,
 
 	code = get_unaligned_be32(sendbuf + sizeof(uint16_t) +
 				  sizeof(uint32_t));
+#ifdef DEBUG
 	printf("tpm: %zd bytes, recv_len %zd, cmd = %x\n", send_size,
 	       *recv_len, code);
 	print_buffer(0, sendbuf, 1, send_size, 0);
+#endif
 	switch (code) {
 	case TPM_CMD_GET_CAPABILITY:
 		type = get_unaligned_be32(sendbuf + 14);
@@ -306,6 +308,10 @@ static int sandbox_tpm_xfer(struct udevice *dev, const uint8_t *sendbuf,
 		printf("Unknown tpm command %02x\n", code);
 		return -ENOSYS;
 	}
+#ifdef DEBUG
+	printf("tpm: rx recv_len %zd\n", *recv_len);
+	print_buffer(0, recvbuf, 1, *recv_len, 0);
+#endif
 
 	return 0;
 }
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 07/25] sandbox: log: Add a category for sandbox
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (5 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 06/25] sandbox: tpm: Allow debugging of data packages Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 08/25] sandbox: Add a function to read a host file Simon Glass
                   ` (35 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

It seems useful to make sandbox its own log category since it is used for
so much testing. Add this as a new category.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/log.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/log.h b/include/log.h
index a872fc6ef5f..deab82966bd 100644
--- a/include/log.h
+++ b/include/log.h
@@ -47,6 +47,7 @@ enum log_category_t {
 	LOGC_DT,	/* Device-tree */
 	LOGC_EFI,	/* EFI implementation */
 	LOGC_ALLOC,	/* Memory allocation */
+	LOGC_SANDBOX,	/* Related to the sandbox board */
 
 	LOGC_COUNT,	/* Number of log categories */
 	LOGC_END,	/* Sentinel value for a list of log categories */
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 08/25] sandbox: Add a function to read a host file
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (6 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 07/25] sandbox: log: Add a category for sandbox Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 09/25] sandbox: cros_ec: exynos: Drop use of cros_ec_get_error() Simon Glass
                   ` (34 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

Add a way to read a file from the host filesystem. This can be useful for
reading test data, for example. Also fix up the writing function which was
not the right version, and drop the debugging lines.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/cpu/os.c | 44 ++++++++++++++++++++++++++++++++++++++++---
 include/os.h          | 14 ++++++++++++++
 2 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 325ded51d8a..3e0f4c30afe 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -98,9 +98,8 @@ void os_exit(int exit_code)
 	exit(exit_code);
 }
 
-int os_write_file(const char *name, const void *buf, int size)
+int os_write_file(const char *fname, const void *buf, int size)
 {
-	char fname[256];
 	int fd;
 
 	fd = os_open(fname, OS_O_WRONLY | OS_O_CREAT | OS_O_TRUNC);
@@ -110,14 +109,53 @@ int os_write_file(const char *name, const void *buf, int size)
 	}
 	if (os_write(fd, buf, size) != size) {
 		printf("Cannot write to file '%s'\n", fname);
+		os_close(fd);
 		return -EIO;
 	}
 	os_close(fd);
-	printf("Write '%s', size %#x (%d)\n", name, size, size);
 
 	return 0;
 }
 
+int os_read_file(const char *fname, void **bufp, int *sizep)
+{
+	off_t size;
+	int ret = -EIO;
+	int fd;
+
+	fd = os_open(fname, OS_O_RDONLY);
+	if (fd < 0) {
+		printf("Cannot open file '%s'\n", fname);
+		goto err;
+	}
+	size = os_lseek(fd, 0, OS_SEEK_END);
+	if (size < 0) {
+		printf("Cannot seek to end of file '%s'\n", fname);
+		goto err;
+	}
+	if (os_lseek(fd, 0, OS_SEEK_SET) < 0) {
+		printf("Cannot seek to start of file '%s'\n", fname);
+		goto err;
+	}
+	*bufp = os_malloc(size);
+	if (!*bufp) {
+		printf("Not enough memory to read file '%s'\n", fname);
+		ret = -ENOMEM;
+		goto err;
+	}
+	if (os_read(fd, *bufp, size) != size) {
+		printf("Cannot read from file '%s'\n", fname);
+		goto err;
+	}
+	os_close(fd);
+	*sizep = size;
+
+	return 0;
+err:
+	os_close(fd);
+	return ret;
+}
+
 /* Restore tty state when we exit */
 static struct termios orig_term;
 static bool term_setup;
diff --git a/include/os.h b/include/os.h
index 28eb6252849..6f33b08cf0b 100644
--- a/include/os.h
+++ b/include/os.h
@@ -350,4 +350,18 @@ int os_mprotect_allow(void *start, size_t len);
  */
 int os_write_file(const char *name, const void *buf, int size);
 
+/**
+ * os_read_file() - Read a file from the host filesystem
+ *
+ * This can be useful when reading test data into sandbox for use by test
+ * routines. The data is allocated using os_malloc() and should be freed by
+ * the caller.
+ *
+ * @name:	File path to read from
+ * @bufp:	Returns buffer containing data read
+ * @sizep:	Returns size of data
+ * @return 0 if OK, -ve on error
+ */
+int os_read_file(const char *name, void **bufp, int *sizep);
+
 #endif
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 09/25] sandbox: cros_ec: exynos: Drop use of cros_ec_get_error()
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (7 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 08/25] sandbox: Add a function to read a host file Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-07  2:27   ` Minkyu Kang
  2018-11-22 20:20   ` sjg at google.com
  2018-11-06 22:21 ` [U-Boot] [PATCH 10/25] sandbox: Update some drivers to work in SPL/TPL Simon Glass
                   ` (33 subsequent siblings)
  42 siblings, 2 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

This function is really just a call to uclass_get_device() and there is no
reason why the caller cannot do it. Update sandbox and snow accordingly.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 board/samsung/common/board.c | 10 ++++++----
 board/sandbox/sandbox.c      |  9 ++++++---
 common/cros_ec.c             | 12 ------------
 3 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/board/samsung/common/board.c b/board/samsung/common/board.c
index c4b6baedf04..fc2a219e384 100644
--- a/board/samsung/common/board.c
+++ b/board/samsung/common/board.c
@@ -306,14 +306,16 @@ int checkboard(void)
 #ifdef CONFIG_BOARD_LATE_INIT
 int board_late_init(void)
 {
-	stdio_print_current_devices();
+	struct udevice *dev;
+	int ret;
 
-	if (cros_ec_get_error()) {
+	stdio_print_current_devices();
+	ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
+	if (ret) {
 		/* Force console on */
 		gd->flags &= ~GD_FLG_SILENT;
 
-		printf("cros-ec communications failure %d\n",
-		       cros_ec_get_error());
+		printf("cros-ec communications failure %d\n", ret);
 		puts("\nPlease reset with Power+Refresh\n\n");
 		panic("Cannot init cros-ec device");
 		return -1;
diff --git a/board/sandbox/sandbox.c b/board/sandbox/sandbox.c
index 0e87674826a..56b1005e374 100644
--- a/board/sandbox/sandbox.c
+++ b/board/sandbox/sandbox.c
@@ -59,12 +59,15 @@ int board_init(void)
 #ifdef CONFIG_BOARD_LATE_INIT
 int board_late_init(void)
 {
-	if (cros_ec_get_error()) {
+	struct udevice *dev;
+	int ret;
+
+	ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
+	if (ret) {
 		/* Force console on */
 		gd->flags &= ~GD_FLG_SILENT;
 
-		printf("cros-ec communications failure %d\n",
-		       cros_ec_get_error());
+		printf("cros-ec communications failure %d\n", ret);
 		puts("\nPlease reset with Power+Refresh\n\n");
 		panic("Cannot init cros-ec device");
 		return -1;
diff --git a/common/cros_ec.c b/common/cros_ec.c
index 4ca15e19d5f..e66471ebd1b 100644
--- a/common/cros_ec.c
+++ b/common/cros_ec.c
@@ -25,15 +25,3 @@ struct udevice *board_get_cros_ec_dev(void)
 	}
 	return dev;
 }
-
-int cros_ec_get_error(void)
-{
-	struct udevice *dev;
-	int ret;
-
-	ret = uclass_get_device(UCLASS_CROS_EC, 0, &dev);
-	if (ret && ret != -ENODEV)
-		return ret;
-
-	return 0;
-}
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 10/25] sandbox: Update some drivers to work in SPL/TPL
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (8 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 09/25] sandbox: cros_ec: exynos: Drop use of cros_ec_get_error() Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 11/25] spl: Support bootstage, log, hash and early malloc in TPL Simon Glass
                   ` (32 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

At present sandbox drivers are mostly not used before relocation. Some of
these are needed by Chromium OS verified boot, since it uses sandbox TPL,
so update them accordingly.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/dts/sandbox.dts | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index fb866e88079..1cda911d1f0 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -20,6 +20,7 @@
 
 	cros_ec: cros-ec {
 		reg = <0 0>;
+		u-boot,dm-pre-reloc;
 		compatible = "google,cros-ec-sandbox";
 
 		/*
@@ -27,6 +28,7 @@
 		 * that the STM32L flash erases to 0, not 0xff.
 		 */
 		flash {
+			u-boot,dm-pre-reloc;
 			image-pos = <0x08000000>;
 			size = <0x20000>;
 			erase-value = <0>;
@@ -59,6 +61,7 @@
 	};
 
 	gpio_a: gpios at 0 {
+		u-boot,dm-pre-reloc;
 		gpio-controller;
 		compatible = "sandbox,gpio";
 		#gpio-cells = <1>;
@@ -67,6 +70,7 @@
 	};
 
 	gpio_b: gpios at 1 {
+		u-boot,dm-pre-reloc;
 		gpio-controller;
 		compatible = "sandbox,gpio";
 		#gpio-cells = <2>;
@@ -178,12 +182,14 @@
 	};
 
 	spi at 0 {
+		u-boot,dm-pre-reloc;
 		#address-cells = <1>;
 		#size-cells = <0>;
 		reg = <0 0>;
 		compatible = "sandbox,spi";
 		cs-gpios = <0>, <&gpio_a 0>;
 		firmware_storage_spi: flash at 0 {
+			u-boot,dm-pre-reloc;
 			reg = <0>;
 			compatible = "spansion,m25p16", "sandbox,spi-flash";
 			spi-max-frequency = <40000000>;
@@ -239,6 +245,7 @@
 	};
 
 	tpm {
+		u-boot,dm-pre-reloc;
 		compatible = "google,sandbox-tpm";
 	};
 
@@ -256,6 +263,7 @@
 
 	/* Needs to be available prior to relocation */
 	uart0: serial {
+		u-boot,dm-spl;
 		compatible = "sandbox,serial";
 		sandbox,text-colour = "cyan";
 		pinctrl-names = "default";
@@ -350,3 +358,10 @@
 
 #include "cros-ec-keyboard.dtsi"
 #include "sandbox_pmic.dtsi"
+
+&cros_ec {
+	u-boot,dm-pre-reloc;
+	keyboard-controller {
+		u-boot,dm-pre-reloc;
+	};
+};
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 11/25] spl: Support bootstage, log, hash and early malloc in TPL
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (9 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 10/25] sandbox: Update some drivers to work in SPL/TPL Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 12/25] spl: Correct malloc debugging in board_init_r() Simon Glass
                   ` (31 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

At present these features are supported in SPL but not TPL. Update the
Kconfig and Makefile to allow this.

Also add a few Makefile comments to make earier to track what is going on.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 common/Kconfig  | 35 +++++++++++++++++++++++++++++++++++
 common/Makefile | 10 +++++++---
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index d7300c212f5..ba460d9150d 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -27,6 +27,15 @@ config SPL_BOOTSTAGE
 	  information when SPL finishes and load it when U-Boot proper starts
 	  up.
 
+config TPL_BOOTSTAGE
+	bool "Boot timing and reported in TPL"
+	depends on BOOTSTAGE
+	help
+	  Enable recording of boot time in SPL. To make this visible to U-Boot
+	  proper, enable BOOTSTAGE_STASH as well. This will stash the timing
+	  information when TPL finishes and load it when U-Boot proper starts
+	  up.
+
 config BOOTSTAGE_REPORT
 	bool "Display a detailed boot timing report before booting the OS"
 	depends on BOOTSTAGE
@@ -444,6 +453,16 @@ config LOG
 
 config SPL_LOG
 	bool "Enable logging support in SPL"
+	depends on LOG
+	help
+	  This enables support for logging of status and debug messages. These
+	  can be displayed on the console, recorded in a memory buffer, or
+	  discarded if not needed. Logging supports various categories and
+	  levels of severity.
+
+config TPL_LOG
+	bool "Enable logging support in TPL"
+	depends on LOG
 	help
 	  This enables support for logging of status and debug messages. These
 	  can be displayed on the console, recorded in a memory buffer, or
@@ -660,6 +679,22 @@ config AVB_VERIFY
 	    * Helpers to access MMC, similar to drivers/fastboot/fb_mmc.c.
 	    * Helpers to alloc/init/free avb ops.
 
+config SPL_HASH
+	bool # "Support hashing API (SHA1, SHA256, etc.)"
+	help
+	  This provides a way to hash data in memory using various supported
+	  algorithms (such as SHA1, MD5, CRC32). The API is defined in hash.h
+	  and the algorithms it supports are defined in common/hash.c. See
+	  also CMD_HASH for command-line access.
+
+config TPL_HASH
+	bool # "Support hashing API (SHA1, SHA256, etc.)"
+	help
+	  This provides a way to hash data in memory using various supported
+	  algorithms (such as SHA1, MD5, CRC32). The API is defined in hash.h
+	  and the algorithms it supports are defined in common/hash.c. See
+	  also CMD_HASH for command-line access.
+
 endmenu
 
 menu "Update support"
diff --git a/common/Makefile b/common/Makefile
index 7473b850115..d933c8afec7 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -68,6 +68,7 @@ obj-$(CONFIG_DFU_OVER_USB) += dfu.o
 endif
 obj-$(CONFIG_SPL_DFU_SUPPORT) += cli_hush.o
 obj-$(CONFIG_SPL_HASH_SUPPORT) += hash.o
+obj-$(CONFIG_TPL_HASH_SUPPORT) += hash.o
 obj-$(CONFIG_SPL_YMODEM_SUPPORT) += xyzModem.o
 obj-$(CONFIG_SPL_LOAD_FIT) += common_fit.o
 obj-$(CONFIG_SPL_NET_SUPPORT) += miiphyutil.o
@@ -76,7 +77,8 @@ ifdef CONFIG_SPL_USB_HOST_SUPPORT
 obj-$(CONFIG_SPL_USB_SUPPORT) += usb.o usb_hub.o
 obj-$(CONFIG_USB_STORAGE) += usb_storage.o
 endif
-endif
+endif # CONFIG_SPL_BUILD
+
 #others
 obj-$(CONFIG_DDR_SPD) += ddr_spd.o
 obj-$(CONFIG_SPD_EEPROM) += ddr_spd.o
@@ -90,14 +92,16 @@ obj-$(CONFIG_SPL_SERIAL_SUPPORT) += console.o
 endif
 else
 obj-y += console.o
-endif
+endif # CONFIG_SPL_BUILD
+
 obj-$(CONFIG_CROS_EC) += cros_ec.o
 obj-y += dlmalloc.o
 ifdef CONFIG_SYS_MALLOC_F
-ifneq ($(CONFIG_$(SPL_)SYS_MALLOC_F_LEN),0)
+ifneq ($(CONFIG_$(SPL_TPL_)SYS_MALLOC_F_LEN),0)
 obj-y += malloc_simple.o
 endif
 endif
+
 obj-y += image.o
 obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 12/25] spl: Correct malloc debugging in board_init_r()
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (10 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 11/25] spl: Support bootstage, log, hash and early malloc in TPL Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-07  6:22   ` Simon Goldschmidt
  2018-11-06 22:21 ` [U-Boot] [PATCH 13/25] spl: lz4: Allow use of lz4 compression in SPL Simon Glass
                   ` (30 subsequent siblings)
  42 siblings, 1 reply; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

SPL does not support %#x in printf() strings so we must write out the 0x
explicitly. Update the code for this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 common/spl/spl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/spl/spl.c b/common/spl/spl.c
index 292e659c9ac..c855bb7ca4a 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -554,7 +554,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 		debug("Unsupported OS image.. Jumping nevertheless..\n");
 	}
 #if CONFIG_VAL(SYS_MALLOC_F_LEN) && !defined(CONFIG_SYS_SPL_MALLOC_SIZE)
-	debug("SPL malloc() used %#lx bytes (%ld KB)\n", gd->malloc_ptr,
+	debug("SPL malloc() used 0x%lx bytes (%ld KB)\n", gd->malloc_ptr,
 	      gd->malloc_ptr / 1024);
 #endif
 #ifdef CONFIG_BOOTSTAGE_STASH
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 13/25] spl: lz4: Allow use of lz4 compression in SPL
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (11 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 12/25] spl: Correct malloc debugging in board_init_r() Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 14/25] binman: Add a way to enable debugging from the build Simon Glass
                   ` (29 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

In some cases U-Boot is compressed and it is useful to be able to
decompress it in SPL. Add a Kconfig and Makefile change to allow this.
Note that this does not actually implement decompression.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 lib/Kconfig  | 8 ++++++++
 lib/Makefile | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/lib/Kconfig b/lib/Kconfig
index 847e797a3a4..0333ab172fa 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -301,6 +301,14 @@ config LZO
 	help
 	  This enables support for LZO compression algorithm.r
 
+config SPL_LZ4
+	bool "Enable LZ4 decompression support in SPL"
+	help
+	  This enables support for tge LZ4 decompression algorithm in SPL. LZ4
+	  is a lossless data compression algorithm that is focused on
+	  fast compression and decompression speed. It belongs to the LZ77
+	  family of byte-oriented compression schemes.
+
 config SPL_LZO
 	bool "Enable LZO decompression support in SPL"
 	help
diff --git a/lib/Makefile b/lib/Makefile
index fb6944128aa..4d2e22027d0 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -38,7 +38,6 @@ obj-$(CONFIG_IMAGE_SPARSE) += image-sparse.o
 obj-y += initcall.o
 obj-$(CONFIG_LMB) += lmb.o
 obj-y += ldiv.o
-obj-$(CONFIG_LZ4) += lz4_wrapper.o
 obj-$(CONFIG_MD5) += md5.o
 obj-y += net_utils.o
 obj-$(CONFIG_PHYSMEM) += physmem.o
@@ -64,6 +63,7 @@ obj-$(CONFIG_SHA256) += sha256.o
 obj-$(CONFIG_$(SPL_)ZLIB) += zlib/
 obj-$(CONFIG_$(SPL_)GZIP) += gunzip.o
 obj-$(CONFIG_$(SPL_)LZO) += lzo/
+obj-$(CONFIG_$(SPL_)LZ4) += lz4_wrapper.o
 
 obj-$(CONFIG_LIBAVB) += libavb/
 
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 14/25] binman: Add a way to enable debugging from the build
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (12 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 13/25] spl: lz4: Allow use of lz4 compression in SPL Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 15/25] binman: Drop an unnecessary comma in blob handling Simon Glass
                   ` (28 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

When the build fails due to something wrong in binman it is sometimes
useful to get a full backtrace showing the location of the failure. Add
a BINMAN_DEBUG environment variable to support this along with some
documentation.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 Makefile            | 6 ++++--
 tools/binman/README | 6 ++++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 250eb6c3c39..c7df436a161 100644
--- a/Makefile
+++ b/Makefile
@@ -1048,9 +1048,11 @@ u-boot.ldr:	u-boot
 
 # binman
 # ---------------------------------------------------------------------------
+# Use 'make BINMAN_DEBUG=1' to enable debugging
 quiet_cmd_binman = BINMAN  $@
-cmd_binman = $(srctree)/tools/binman/binman -d u-boot.dtb -O . \
-		-I . -I $(srctree)/board/$(BOARDDIR) $<
+cmd_binman = $(srctree)/tools/binman/binman -u -d u-boot.dtb -O . -m \
+		-I . -I $(srctree) -I $(srctree)/board/$(BOARDDIR) \
+		$(if $(BINMAN_DEBUG),-D) $(BINMAN_$(@F)) $<
 
 OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex
 
diff --git a/tools/binman/README b/tools/binman/README
index b64dedf2ebc..04ed2b799c8 100644
--- a/tools/binman/README
+++ b/tools/binman/README
@@ -723,6 +723,12 @@ If you need to specify a particular device-tree compiler to use, you can define
 the DTC environment variable. This can be useful when the system dtc is too
 old.
 
+To enable a full backtrace and other debugging features in binman, pass
+BINMAN_DEBUG=1 to your build:
+
+   make sandbox_defconfig
+   make BINMAN_DEBUG=1
+
 
 History / Credits
 -----------------
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 15/25] binman: Drop an unnecessary comma in blob handling
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (13 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 14/25] binman: Add a way to enable debugging from the build Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 16/25] binman: Set the pathname correctly for ELF files Simon Glass
                   ` (27 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

This comma is not needed. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/binman/etype/blob.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py
index 642a0e482a7..ae80bbee530 100644
--- a/tools/binman/etype/blob.py
+++ b/tools/binman/etype/blob.py
@@ -60,7 +60,7 @@ class Entry_blob(Entry):
             except AttributeError:
                 data = lz4.compress(data)
             '''
-            data = tools.Run('lz4', '-c', self._pathname, )
+            data = tools.Run('lz4', '-c', self._pathname)
         self.SetContents(data)
         return True
 
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 16/25] binman: Set the pathname correctly for ELF files
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (14 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 15/25] binman: Drop an unnecessary comma in blob handling Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 17/25] tpm: Export the open/close functions Simon Glass
                   ` (26 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

At present, stripped files don't have the right pathname which means that
blob compression cannot be used. Fix this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/binman/etype/u_boot_elf.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/tools/binman/etype/u_boot_elf.py b/tools/binman/etype/u_boot_elf.py
index 134b6cc15b4..f83860dc0a8 100644
--- a/tools/binman/etype/u_boot_elf.py
+++ b/tools/binman/etype/u_boot_elf.py
@@ -30,9 +30,8 @@ class Entry_u_boot_elf(Entry_blob):
             out_fname = tools.GetOutputFilename('%s.stripped' % uniq)
             tools.WriteFile(out_fname, tools.ReadFile(self._pathname))
             tools.Run('strip', out_fname)
-            self.SetContents(tools.ReadFile(out_fname))
-        else:
-            self.SetContents(tools.ReadFile(self._pathname))
+            self._pathname = out_fname
+        Entry_blob.ReadBlobContents(self)
         return True
 
     def GetDefaultFilename(self):
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 17/25] tpm: Export the open/close functions
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (15 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 16/25] binman: Set the pathname correctly for ELF files Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-07  7:52   ` Miquel Raynal
  2018-11-06 22:21 ` [U-Boot] [PATCH 18/25] tpm: Convert to use a device parameter Simon Glass
                   ` (25 subsequent siblings)
  42 siblings, 1 reply; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

At present these functions are not accessible outside the TPM library, but
in some cases we need to call them. Export them in the header file and add
a define for the SHA1 digest size.

Also adjust tpm_open() to call tpm_close() first so that the TPM is in a
known state before opening (e.g. by a previous phase of U-Boot).

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/tpm/tpm_tis_lpc.c | 50 +++++++++++++++++++++++----------------
 include/tpm-common.h      | 20 ++++++++++++++++
 lib/tpm-utils.h           | 18 --------------
 3 files changed, 50 insertions(+), 38 deletions(-)

diff --git a/drivers/tpm/tpm_tis_lpc.c b/drivers/tpm/tpm_tis_lpc.c
index e993fd9f833..d76d7ca75af 100644
--- a/drivers/tpm/tpm_tis_lpc.c
+++ b/drivers/tpm/tpm_tis_lpc.c
@@ -388,6 +388,27 @@ static int tis_readresponse(struct udevice *dev, u8 *buffer, size_t len)
 	return offset;
 }
 
+static int tpm_tis_lpc_close(struct udevice *dev)
+{
+	struct tpm_tis_lpc_priv *priv = dev_get_priv(dev);
+	struct tpm_locality *regs = priv->regs;
+	u8 locality = 0;
+
+	if (tpm_read_word(priv, &regs[locality].access) &
+	    TIS_ACCESS_ACTIVE_LOCALITY) {
+		tpm_write_word(priv, TIS_ACCESS_ACTIVE_LOCALITY,
+			       &regs[locality].access);
+
+		if (tis_wait_reg(priv, &regs[locality].access,
+				 TIS_ACCESS_ACTIVE_LOCALITY, 0) == -ETIMEDOUT) {
+			printf("%s:%d - failed to release locality %d\n",
+			       __FILE__, __LINE__, locality);
+			return -ETIMEDOUT;
+		}
+	}
+	return 0;
+}
+
 static int tpm_tis_lpc_open(struct udevice *dev)
 {
 	struct tpm_tis_lpc_priv *priv = dev_get_priv(dev);
@@ -395,6 +416,12 @@ static int tpm_tis_lpc_open(struct udevice *dev)
 	u8 locality = 0; /* we use locality zero for everything. */
 	int ret;
 
+	ret = tpm_tis_lpc_close(dev);
+	if (ret) {
+		printf("%s: Failed to close TPM\n", __func__);
+		return ret;
+	}
+
 	/* now request access to locality. */
 	tpm_write_word(priv, TIS_ACCESS_REQUEST_USE, &regs[locality].access);
 
@@ -408,29 +435,12 @@ static int tpm_tis_lpc_open(struct udevice *dev)
 		return ret;
 	}
 
+	/* Certain TPMs need some delay here or they hang */
+	udelay(10);
+
 	tpm_write_word(priv, TIS_STS_COMMAND_READY,
 		       &regs[locality].tpm_status);
-	return 0;
-}
-
-static int tpm_tis_lpc_close(struct udevice *dev)
-{
-	struct tpm_tis_lpc_priv *priv = dev_get_priv(dev);
-	struct tpm_locality *regs = priv->regs;
-	u8 locality = 0;
-
-	if (tpm_read_word(priv, &regs[locality].access) &
-	    TIS_ACCESS_ACTIVE_LOCALITY) {
-		tpm_write_word(priv, TIS_ACCESS_ACTIVE_LOCALITY,
-			       &regs[locality].access);
 
-		if (tis_wait_reg(priv, &regs[locality].access,
-				 TIS_ACCESS_ACTIVE_LOCALITY, 0) == -ETIMEDOUT) {
-			printf("%s:%d - failed to release locality %d\n",
-			       __FILE__, __LINE__, locality);
-			return -ETIMEDOUT;
-		}
-	}
 	return 0;
 }
 
diff --git a/include/tpm-common.h b/include/tpm-common.h
index 5f8bc6bc528..f8c5569003e 100644
--- a/include/tpm-common.h
+++ b/include/tpm-common.h
@@ -26,6 +26,8 @@ enum tpm_duration {
 /* Max buffer size supported by our tpm */
 #define TPM_DEV_BUFSIZE		1260
 
+#define TPM_PCR_MINIMUM_DIGEST_SIZE 20
+
 /**
  * enum tpm_version - The version of the TPM stack to be used
  * @TPM_V1:		Use TPM v1.x stack
@@ -179,6 +181,24 @@ int do_##cmd(cmd_tbl_t *cmdtp, int flag,		\
 	return report_return_code(cmd());		\
 }
 
+/**
+ * tpm_open() - Request access to locality 0 for the caller
+ *
+ * After all commands have been completed the caller is supposed to
+ * call tpm_close().
+ *
+ * Returns 0 on success, -ve on failure.
+ */
+int tpm_open(struct udevice *dev);
+
+/**
+ * tpm_close() - Close the current session
+ *
+ * Releasing the locked locality. Returns 0 on success, -ve 1 on
+ * failure (in case lock removal did not succeed).
+ */
+int tpm_close(struct udevice *dev);
+
 /**
  * tpm_get_desc() - Get a text description of the TPM
  *
diff --git a/lib/tpm-utils.h b/lib/tpm-utils.h
index a9cb7dc7ee5..ac95f262f56 100644
--- a/lib/tpm-utils.h
+++ b/lib/tpm-utils.h
@@ -18,24 +18,6 @@
 #define tpm_u16(x) __MSB(x), __LSB(x)
 #define tpm_u32(x) tpm_u16((x) >> 16), tpm_u16((x) & 0xFFFF)
 
-/**
- * tpm_open() - Request access to locality 0 for the caller
- *
- * After all commands have been completed the caller is supposed to
- * call tpm_close().
- *
- * Returns 0 on success, -ve on failure.
- */
-int tpm_open(struct udevice *dev);
-
-/**
- * tpm_close() - Close the current session
- *
- * Releasing the locked locality. Returns 0 on success, -ve 1 on
- * failure (in case lock removal did not succeed).
- */
-int tpm_close(struct udevice *dev);
-
 /**
  * Pack data into a byte string.  The data types are specified in
  * the format string: 'b' means unsigned byte, 'w' unsigned word,
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 18/25] tpm: Convert to use a device parameter
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (16 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 17/25] tpm: Export the open/close functions Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-07  7:56   ` Miquel Raynal
  2018-11-06 22:21 ` [U-Boot] [PATCH 19/25] video: Update video_set_default_colors() to support invert Simon Glass
                   ` (24 subsequent siblings)
  42 siblings, 1 reply; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

At present many TPM calls assume there is only one TPM in the system and
look up this TPM themselves. This is inconsistent with driver model, which
expects all driver methods to have a device parameter. Update the code to
correct this.

Also move to u8/32 instead of uint8_t/uint32_t to keep checkpatch happy.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 board/gdsys/a38x/controlcenterdc.c    |   8 +-
 board/gdsys/p1022/controlcenterd-id.c |  22 +-
 cmd/tpm-common.c                      |   8 +-
 cmd/tpm-v1.c                          | 122 +++++++--
 cmd/tpm-v2.c                          |  78 +++++-
 cmd/tpm_test.c                        | 371 +++++++++++++-------------
 include/tpm-common.h                  |  16 +-
 include/tpm-v1.h                      |  97 ++++---
 include/tpm-v2.h                      |  49 ++--
 lib/tpm-common.c                      |  16 +-
 lib/tpm-utils.h                       |   3 +-
 lib/tpm-v1.c                          | 136 +++++-----
 lib/tpm-v2.c                          |  60 +++--
 13 files changed, 611 insertions(+), 375 deletions(-)

diff --git a/board/gdsys/a38x/controlcenterdc.c b/board/gdsys/a38x/controlcenterdc.c
index 824a08f12af..be69f877f03 100644
--- a/board/gdsys/a38x/controlcenterdc.c
+++ b/board/gdsys/a38x/controlcenterdc.c
@@ -266,11 +266,15 @@ int board_fix_fdt(void *rw_fdt_blob)
 
 int last_stage_init(void)
 {
+	struct udevice *tpm;
+	int ret;
+
 #ifndef CONFIG_SPL_BUILD
 	ccdc_eth_init();
 #endif
-	if (tpm_init() || tpm_startup(TPM_ST_CLEAR) ||
-	    tpm_continue_self_test()) {
+	ret = get_tpm(&tpm);
+	if (ret || tpm_init(tpm) || tpm_startup(tpm, TPM_ST_CLEAR) ||
+	    tpm_continue_self_test(tpm)) {
 		return 1;
 	}
 
diff --git a/board/gdsys/p1022/controlcenterd-id.c b/board/gdsys/p1022/controlcenterd-id.c
index 7e082dff052..814e4f401de 100644
--- a/board/gdsys/p1022/controlcenterd-id.c
+++ b/board/gdsys/p1022/controlcenterd-id.c
@@ -969,19 +969,25 @@ end:
 #ifdef CCDM_FIRST_STAGE
 static int first_stage_init(void)
 {
-	int res = 0;
+	struct udevice *tpm;
+	int ret;
+
 	puts("CCDM S1\n");
-	if (tpm_init() || tpm_startup(TPM_ST_CLEAR))
+#ifndef CONFIG_SPL_BUILD
+	ccdc_eth_init();
+#endif
+	ret = get_tpm(&tpm);
+	if (ret || tpm_init(tpm) || tpm_startup(tpm, TPM_ST_CLEAR))
 		return 1;
-	res = first_stage_actions();
+	ret = first_stage_actions();
 #ifndef CCDM_SECOND_STAGE
-	if (!res) {
+	if (!ret) {
 		if (bl2_entry)
 			(*bl2_entry)();
-		res = 1;
+		ret = 1;
 	}
 #endif
-	return res;
+	return ret;
 }
 #endif
 
@@ -1021,10 +1027,12 @@ static int second_stage_init(void)
 	char *mac_path = NULL;
 	ulong image_addr;
 	loff_t image_size;
+	struct udevice *tpm;
 	uint32_t err;
 
 	printf("CCDM S2\n");
-	if (tpm_init())
+	ret = get_tpm(&tpm);
+	if (ret || tpm_init(tpm))
 		return 1;
 	err = tpm_startup(TPM_ST_CLEAR);
 	if (err != TPM_INVALID_POSTINIT)
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..465f7400721 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,11 @@ 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;
+
+	rc = get_tpm(&dev);
+	if (rc)
+		return rc;
 
 	if (argc < 5)
 		return CMD_RET_USAGE;
@@ -386,6 +473,11 @@ 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;
+
+	rc = get_tpm(&dev);
+	if (rc)
+		return rc;
 
 	if (argc < 3)
 		return CMD_RET_USAGE;
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..c396b29f523 100644
--- a/cmd/tpm_test.c
+++ b/cmd/tpm_test.c
@@ -7,10 +7,11 @@
 #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 { \
-	uint32_t result; \
+	u32 result; \
 	\
 	result = (tpm_command); \
 	if (result != TPM_SUCCESS) { \
@@ -28,26 +29,27 @@
 #define PHYS_PRESENCE		4
 #define PRESENCE		8
 
-static uint32_t TlclStartupIfNeeded(void)
+static u32 TlclStartupIfNeeded(struct udevice *dev)
 {
-	uint32_t result = tpm_startup(TPM_ST_CLEAR);
+	u32 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 u32 tpm_get_flags(struct udevice *dev, u8 *disable,
+			 u8 *deactivated, u8 *nvlocked)
 {
 	struct tpm_permanent_flags pflags;
-	uint32_t result;
+	u32 result;
 
-	result = tpm_get_permanent_flags(&pflags);
+	result = tpm_get_permanent_flags(dev, &pflags);
 	if (result)
 		return result;
 	if (disable)
@@ -62,79 +64,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 u32 tpm_nv_write_value_lock(struct udevice *dev, u32 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;
+	u8 response[TPM_PUBEK_SIZE];
+	u32 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];
+	u8 value_in[20];
+	u8 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;
+	u32 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, (u8 *)&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;
+	u32 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, (u8 *)&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;
+	u8 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 +149,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;
+	u8 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 +178,103 @@ 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;
+	u32 zero = 0;
+	u32 result;
+	u32 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,
-				     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,
-				     sizeof(uint32_t)));
-	TPM_CHECK(tpm_set_global_lock());
+	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, (u8 *)&x, sizeof(x)));
+	TPM_CHECK(tpm_nv_write_value(dev, INDEX0, (u8 *)&zero, sizeof(u32)));
+	TPM_CHECK(tpm_nv_read_value(dev, INDEX1, (u8 *)&x, sizeof(x)));
+	TPM_CHECK(tpm_nv_write_value(dev, INDEX1, (u8 *)&zero, sizeof(u32)));
+	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, (u8 *)&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, (u8 *)&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, (u8 *)&x, sizeof(x)));
+	TPM_CHECK(tpm_nv_read_value(dev, INDEX1, (u8 *)&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, (u8 *)&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, (u8 *)&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;
+	u32 zero = 0;
+	u32 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, (u8 *)&zero, 4);
+	tpm_nv_define_space(dev, INDEX1, perm, 4);
+	tpm_nv_write_value(dev, INDEX1, (u8 *)&zero, 4);
+	tpm_nv_define_space(dev, INDEX2, perm, 4);
+	tpm_nv_write_value(dev, INDEX2, (u8 *)&zero, 4);
+	tpm_nv_define_space(dev, INDEX3, perm, 4);
+	tpm_nv_write_value(dev, INDEX3, (u8 *)&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;
+	u8 c;
+	u32 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@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, (u8 *)&index_0, sizeof(index_0));
+	read1 = tpm_nv_read_value(dev, INDEX1, (u8 *)&index_1, sizeof(index_1));
+	read2 = tpm_nv_read_value(dev, INDEX2, (u8 *)&index_2, sizeof(index_2));
+	read3 = tpm_nv_read_value(dev, INDEX3, (u8 *)&index_3, sizeof(index_3));
 	if (read0 || read1 || read2 || read3) {
 		printf("Invalid contents\n");
 		return 0;
@@ -285,12 +285,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, (u8 *)&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, (u8 *)&index_0,
+			       sizeof(index_0)) ==
 			TPM_SUCCESS)
 		pr_err("\tindex 0 is not locked\n");
 
@@ -298,49 +300,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;
+	u32 perm;
+	u32 result;
+	u32 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, (u8 *)&x, sizeof(x)));
+	TPM_CHECK(tpm_nv_read_value(dev, INDEX1, (u8 *)&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(u32)));
+	TPM_CHECK(tpm_nv_define_space(dev, INDEX0, perm, sizeof(u32)));
 	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(u32)));
+	TPM_CHECK(tpm_nv_define_space(dev, INDEX1, perm, sizeof(u32)));
 
 	/* 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(u32));
 	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(u32)));
+	TPM_CHECK(tpm_nv_define_space(dev, INDEX1, perm, sizeof(u32)));
 
 	/* 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(u32));
 	assert(result == TPM_BAD_PRESENCE);
-	result = tpm_nv_define_space(INDEX1, perm, sizeof(uint32_t));
+	result = tpm_nv_define_space(dev, INDEX1, perm, sizeof(u32));
 	assert(result == TPM_BAD_PRESENCE);
 
 	printf("done\n");
@@ -350,38 +352,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;
+	u32 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;
+	u32 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");
@@ -394,7 +397,7 @@ static int test_startup(void)
  */
 #define TTPM_CHECK(op, time_limit) do { \
 	ulong start, time; \
-	uint32_t __result; \
+	u32 __result; \
 	\
 	start = get_timer(0); \
 	__result = op; \
@@ -410,45 +413,45 @@ 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];
+	u8 in[20], out[20];
+	u32 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, (u8 *)&x, sizeof(x)), 100);
+	TTPM_CHECK(tpm_nv_read_value(dev, INDEX0, (u8 *)&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");
+	u32 result;
 	int i;
-	uint32_t result;
 
-	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, (u8 *)&i, sizeof(i));
 		switch (result) {
 		case TPM_SUCCESS:
 			break;
@@ -461,12 +464,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, (u8 *)&i, sizeof(i)));
 	printf("\tdone\n");
 	return 0;
 }
@@ -475,7 +478,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) \
diff --git a/include/tpm-common.h b/include/tpm-common.h
index f8c5569003e..3d88b44db7a 100644
--- a/include/tpm-common.h
+++ b/include/tpm-common.h
@@ -176,9 +176,15 @@ struct tpm_ops {
 int do_##cmd(cmd_tbl_t *cmdtp, int flag,		\
 	     int argc, char * const argv[])		\
 {							\
+	struct udevice *dev;				\
+	int rc;						\
+							\
+	rc = get_tpm(&dev);				\
+	if (rc)						\
+		return rc;				\
 	if (argc != 1)					\
 		return CMD_RET_USAGE;			\
-	return report_return_code(cmd());		\
+	return report_return_code(cmd(dev));		\
 }
 
 /**
@@ -187,6 +193,7 @@ int do_##cmd(cmd_tbl_t *cmdtp, int flag,		\
  * After all commands have been completed the caller is supposed to
  * call tpm_close().
  *
+ * @dev - TPM device
  * Returns 0 on success, -ve on failure.
  */
 int tpm_open(struct udevice *dev);
@@ -196,6 +203,9 @@ int tpm_open(struct udevice *dev);
  *
  * Releasing the locked locality. Returns 0 on success, -ve 1 on
  * failure (in case lock removal did not succeed).
+ *
+ * @dev - TPM device
+ * Returns 0 on success, -ve on failure.
  */
 int tpm_close(struct udevice *dev);
 
@@ -222,6 +232,7 @@ int tpm_get_desc(struct udevice *dev, char *buf, int size);
  * Note that the outgoing data is inspected to determine command type
  * (ordinal) and a timeout is used for that command type.
  *
+ * @dev - TPM device
  * @sendbuf - buffer of the data to send
  * @send_size size of the data to send
  * @recvbuf - memory to save the response to
@@ -236,9 +247,10 @@ int tpm_xfer(struct udevice *dev, const u8 *sendbuf, size_t send_size,
 /**
  * Initialize TPM device.  It must be called before any TPM commands.
  *
+ * @dev - TPM device
  * @return 0 on success, non-0 on error.
  */
-int tpm_init(void);
+int tpm_init(struct udevice *dev);
 
 /**
  * Retrieve the array containing all the v1 (resp. v2) commands.
diff --git a/include/tpm-v1.h b/include/tpm-v1.h
index be2eca946fb..45b7a4831d4 100644
--- a/include/tpm-v1.h
+++ b/include/tpm-v1.h
@@ -282,64 +282,72 @@ struct __packed tpm_nv_data_public {
 /**
  * Issue a TPM_Startup command.
  *
+ * @param dev		TPM device
  * @param mode		TPM startup mode
  * @return return code of the operation
  */
-u32 tpm_startup(enum tpm_startup_type mode);
+u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode);
 
 /**
  * Issue a TPM_SelfTestFull command.
  *
+ * @param dev		TPM device
  * @return return code of the operation
  */
-u32 tpm_self_test_full(void);
+u32 tpm_self_test_full(struct udevice *dev);
 
 /**
  * Issue a TPM_ContinueSelfTest command.
  *
+ * @param dev		TPM device
  * @return return code of the operation
  */
-u32 tpm_continue_self_test(void);
+u32 tpm_continue_self_test(struct udevice *dev);
 
 /**
  * Issue a TPM_NV_DefineSpace command.  The implementation is limited
  * to specify TPM_NV_ATTRIBUTES and size of the area.  The area index
  * could be one of the special value listed in enum tpm_nv_index.
  *
+ * @param dev		TPM device
  * @param index		index of the area
  * @param perm		TPM_NV_ATTRIBUTES of the area
  * @param size		size of the area
  * @return return code of the operation
  */
-u32 tpm_nv_define_space(u32 index, u32 perm, u32 size);
+u32 tpm_nv_define_space(struct udevice *dev, u32 index, u32 perm, u32 size);
 
 /**
  * Issue a TPM_NV_ReadValue command.  This implementation is limited
  * to read the area from offset 0.  The area index could be one of
  * the special value listed in enum tpm_nv_index.
  *
+ * @param dev		TPM device
  * @param index		index of the area
  * @param data		output buffer of the area contents
  * @param count		size of output buffer
  * @return return code of the operation
  */
-u32 tpm_nv_read_value(u32 index, void *data, u32 count);
+u32 tpm_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count);
 
 /**
  * Issue a TPM_NV_WriteValue command.  This implementation is limited
  * to write the area from offset 0.  The area index could be one of
  * the special value listed in enum tpm_nv_index.
  *
+ * @param dev		TPM device
  * @param index		index of the area
  * @param data		input buffer to be wrote to the area
  * @param length	length of data bytes of input buffer
  * @return return code of the operation
  */
-u32 tpm_nv_write_value(u32 index, const void *data, u32 length);
+u32 tpm_nv_write_value(struct udevice *dev, u32 index, const void *data,
+		       u32 length);
 
 /**
  * Issue a TPM_Extend command.
  *
+ * @param dev		TPM device
  * @param index		index of the PCR
  * @param in_digest	160-bit value representing the event to be
  *			recorded
@@ -347,69 +355,78 @@ u32 tpm_nv_write_value(u32 index, const void *data, u32 length);
  *			command
  * @return return code of the operation
  */
-u32 tpm_extend(u32 index, const void *in_digest, void *out_digest);
+u32 tpm_extend(struct udevice *dev, u32 index, const void *in_digest,
+	       void *out_digest);
 
 /**
  * Issue a TPM_PCRRead command.
  *
+ * @param dev		TPM device
  * @param index		index of the PCR
  * @param data		output buffer for contents of the named PCR
  * @param count		size of output buffer
  * @return return code of the operation
  */
-u32 tpm_pcr_read(u32 index, void *data, size_t count);
+u32 tpm_pcr_read(struct udevice *dev, u32 index, void *data, size_t count);
 
 /**
  * Issue a TSC_PhysicalPresence command.  TPM physical presence flag
  * is bit-wise OR'ed of flags listed in enum tpm_physical_presence.
  *
+ * @param dev		TPM device
  * @param presence	TPM physical presence flag
  * @return return code of the operation
  */
-u32 tpm_tsc_physical_presence(u16 presence);
+u32 tpm_tsc_physical_presence(struct udevice *dev, u16 presence);
 
 /**
  * Issue a TPM_ReadPubek command.
  *
+ * @param dev		TPM device
  * @param data		output buffer for the public endorsement key
  * @param count		size of output buffer
  * @return return code of the operation
  */
-u32 tpm_read_pubek(void *data, size_t count);
+u32 tpm_read_pubek(struct udevice *dev, void *data, size_t count);
 
 /**
  * Issue a TPM_ForceClear command.
  *
+ * @param dev		TPM device
  * @return return code of the operation
  */
-u32 tpm_force_clear(void);
+u32 tpm_force_clear(struct udevice *dev);
 
 /**
  * Issue a TPM_PhysicalEnable command.
  *
+ * @param dev		TPM device
  * @return return code of the operation
  */
-u32 tpm_physical_enable(void);
+u32 tpm_physical_enable(struct udevice *dev);
 
 /**
  * Issue a TPM_PhysicalDisable command.
  *
+ * @param dev		TPM device
  * @return return code of the operation
  */
-u32 tpm_physical_disable(void);
+u32 tpm_physical_disable(struct udevice *dev);
 
 /**
  * Issue a TPM_PhysicalSetDeactivated command.
  *
+ * @param dev		TPM device
  * @param state		boolean state of the deactivated flag
  * @return return code of the operation
  */
-u32 tpm_physical_set_deactivated(u8 state);
+u32 tpm_physical_set_deactivated(struct udevice *dev, u8 state);
 
 /**
  * Issue a TPM_GetCapability command.  This implementation is limited
  * to query sub_cap index that is 4-byte wide.
  *
+ * @param dev		TPM device
  * @param cap_area	partition of capabilities
  * @param sub_cap	further definition of capability, which is
  *			limited to be 4-byte wide
@@ -417,15 +434,17 @@ u32 tpm_physical_set_deactivated(u8 state);
  * @param count		size of output buffer
  * @return return code of the operation
  */
-u32 tpm_get_capability(u32 cap_area, u32 sub_cap, void *cap, size_t count);
+u32 tpm_get_capability(struct udevice *dev, u32 cap_area, u32 sub_cap,
+		       void *cap, size_t count);
 
 /**
  * Issue a TPM_FlushSpecific command for a AUTH resource.
  *
+ * @param dev		TPM device
  * @param auth_handle	handle of the auth session
  * @return return code of the operation
  */
-u32 tpm_terminate_auth_session(u32 auth_handle);
+u32 tpm_terminate_auth_session(struct udevice *dev, u32 auth_handle);
 
 /**
  * Issue a TPM_OIAP command to setup an object independent authorization
@@ -434,22 +453,25 @@ u32 tpm_terminate_auth_session(u32 auth_handle);
  * If there was already an OIAP session active it is terminated and a new
  * session is set up.
  *
+ * @param dev		TPM device
  * @param auth_handle	pointer to the (new) auth handle or NULL.
  * @return return code of the operation
  */
-u32 tpm_oiap(u32 *auth_handle);
+u32 tpm_oiap(struct udevice *dev, u32 *auth_handle);
 
 /**
  * Ends an active OIAP session.
  *
+ * @param dev		TPM device
  * @return return code of the operation
  */
-u32 tpm_end_oiap(void);
+u32 tpm_end_oiap(struct udevice *dev);
 
 /**
  * Issue a TPM_LoadKey2 (Auth1) command using an OIAP session for authenticating
  * the usage of the parent key.
  *
+ * @param dev		TPM device
  * @param parent_handle	handle of the parent key.
  * @param key		pointer to the key structure (TPM_KEY or TPM_KEY12).
  * @param key_length	size of the key structure
@@ -457,13 +479,15 @@ u32 tpm_end_oiap(void);
  * @param key_handle	pointer to the key handle
  * @return return code of the operation
  */
-u32 tpm_load_key2_oiap(u32 parent_handle, const void *key, size_t key_length,
-		       const void *parent_key_usage_auth, u32 *key_handle);
+u32 tpm_load_key2_oiap(struct udevice *dev, u32 parent_handle, const void *key,
+		       size_t key_length, const void *parent_key_usage_auth,
+		       u32 *key_handle);
 
 /**
  * Issue a TPM_GetPubKey (Auth1) command using an OIAP session for
  * authenticating the usage of the key.
  *
+ * @param dev		TPM device
  * @param key_handle	handle of the key
  * @param usage_auth	usage auth for the key
  * @param pubkey	pointer to the pub key buffer; may be NULL if the pubkey
@@ -473,45 +497,51 @@ u32 tpm_load_key2_oiap(u32 parent_handle, const void *key, size_t key_length,
  *			of the stored TPM_PUBKEY structure (iff pubkey != NULL).
  * @return return code of the operation
  */
-u32 tpm_get_pub_key_oiap(u32 key_handle, const void *usage_auth, void *pubkey,
+u32 tpm_get_pub_key_oiap(struct udevice *dev, u32 key_handle,
+			 const void *usage_auth, void *pubkey,
 			 size_t *pubkey_len);
 
 /**
  * Get the TPM permanent flags value
  *
+ * @param dev		TPM device
  * @param pflags	Place to put permanent flags
  * @return return code of the operation
  */
-u32 tpm_get_permanent_flags(struct tpm_permanent_flags *pflags);
+u32 tpm_get_permanent_flags(struct udevice *dev,
+			    struct tpm_permanent_flags *pflags);
 
 /**
  * Get the TPM permissions
  *
+ * @param dev		TPM device
  * @param perm		Returns permissions value
  * @return return code of the operation
  */
-u32 tpm_get_permissions(u32 index, u32 *perm);
+u32 tpm_get_permissions(struct udevice *dev, u32 index, u32 *perm);
 
 /**
  * Flush a resource with a given handle and type from the TPM
  *
+ * @param dev		TPM device
  * @param key_handle           handle of the resource
  * @param resource_type                type of the resource
  * @return return code of the operation
  */
-u32 tpm_flush_specific(u32 key_handle, u32 resource_type);
+u32 tpm_flush_specific(struct udevice *dev, u32 key_handle, u32 resource_type);
 
 #ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
 /**
  * Search for a key by usage AuthData and the hash of the parent's pub key.
  *
+ * @param dev		TPM device
  * @param auth	        Usage auth of the key to search for
  * @param pubkey_digest	SHA1 hash of the pub key structure of the key
  * @param[out] handle	The handle of the key (Non-null iff found)
  * @return 0 if key was found in TPM; != 0 if not.
  */
-u32 tpm_find_key_sha1(const u8 auth[20], const u8 pubkey_digest[20],
-		      u32 *handle);
+u32 tpm_find_key_sha1(struct udevice *dev, const u8 auth[20],
+		      const u8 pubkey_digest[20], u32 *handle);
 #endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
 
 /**
@@ -519,38 +549,43 @@ u32 tpm_find_key_sha1(const u8 auth[20], const u8 pubkey_digest[20],
  * that the TPM may legally return fewer bytes than requested by retrying
  * until @p count bytes have been received.
  *
+ * @param dev		TPM device
  * @param data		output buffer for the random bytes
  * @param count		size of output buffer
  * @return return code of the operation
  */
-u32 tpm_get_random(void *data, u32 count);
+u32 tpm_get_random(struct udevice *dev, void *data, u32 count);
 
 /**
  * tpm_finalise_physical_presence() - Finalise physical presence
  *
+ * @param dev		TPM device
  * @return return code of the operation (0 = success)
  */
-u32 tpm_finalise_physical_presence(void);
+u32 tpm_finalise_physical_presence(struct udevice *dev);
 
 /**
  * tpm_nv_set_locked() - lock the non-volatile space
  *
+ * @param dev		TPM device
  * @return return code of the operation (0 = success)
  */
-u32 tpm_nv_set_locked(void);
+u32 tpm_nv_set_locked(struct udevice *dev);
 
 /**
  * tpm_set_global_lock() - set the global lock
  *
+ * @param dev		TPM device
  * @return return code of the operation (0 = success)
  */
-u32 tpm_set_global_lock(void);
+u32 tpm_set_global_lock(struct udevice *dev);
 
 /**
  * tpm_resume() - start up the TPM from resume (after suspend)
  *
+ * @param dev		TPM device
  * @return return code of the operation (0 = success)
  */
-u32 tpm_resume(void);
+u32 tpm_resume(struct udevice *dev);
 
 #endif /* __TPM_V1_H */
diff --git a/include/tpm-v2.h b/include/tpm-v2.h
index c77b416182e..2f2e66de195 100644
--- a/include/tpm-v2.h
+++ b/include/tpm-v2.h
@@ -131,45 +131,51 @@ enum tpm2_algorithms {
 /**
  * Issue a TPM2_Startup command.
  *
+ * @dev		TPM device
  * @mode	TPM startup mode
  *
  * @return code of the operation
  */
-u32 tpm2_startup(enum tpm2_startup_types mode);
+u32 tpm2_startup(struct udevice *dev, enum tpm2_startup_types mode);
 
 /**
  * Issue a TPM2_SelfTest command.
  *
+ * @dev		TPM device
  * @full_test	Asking to perform all tests or only the untested ones
  *
  * @return code of the operation
  */
-u32 tpm2_self_test(enum tpm2_yes_no full_test);
+u32 tpm2_self_test(struct udevice *dev, enum tpm2_yes_no full_test);
 
 /**
  * Issue a TPM2_Clear command.
  *
+ * @dev		TPM device
  * @handle	Handle
  * @pw		Password
  * @pw_sz	Length of the password
  *
  * @return code of the operation
  */
-u32 tpm2_clear(u32 handle, const char *pw, const ssize_t pw_sz);
+u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw,
+	       const ssize_t pw_sz);
 
 /**
  * Issue a TPM2_PCR_Extend command.
  *
+ * @dev		TPM device
  * @index	Index of the PCR
  * @digest	Value representing the event to be recorded
  *
  * @return code of the operation
  */
-u32 tpm2_pcr_extend(u32 index, const uint8_t *digest);
+u32 tpm2_pcr_extend(struct udevice *dev, u32 index, const uint8_t *digest);
 
 /**
  * Issue a TPM2_PCR_Read command.
  *
+ * @dev		TPM device
  * @idx		Index of the PCR
  * @idx_min_sz	Minimum size in bytes of the pcrSelect array
  * @data	Output buffer for contents of the named PCR
@@ -177,13 +183,14 @@ u32 tpm2_pcr_extend(u32 index, const uint8_t *digest);
  *
  * @return code of the operation
  */
-u32 tpm2_pcr_read(u32 idx, unsigned int idx_min_sz, void *data,
-		  unsigned int *updates);
+u32 tpm2_pcr_read(struct udevice *dev, u32 idx, unsigned int idx_min_sz,
+		  void *data, unsigned int *updates);
 
 /**
  * Issue a TPM2_GetCapability command.  This implementation is limited
  * to query property index that is 4-byte wide.
  *
+ * @dev		TPM device
  * @capability	Partition of capabilities
  * @property	Further definition of capability, limited to be 4 bytes wide
  * @buf		Output buffer for capability information
@@ -191,22 +198,24 @@ u32 tpm2_pcr_read(u32 idx, unsigned int idx_min_sz, void *data,
  *
  * @return code of the operation
  */
-u32 tpm2_get_capability(u32 capability, u32 property, void *buf,
-			size_t prop_count);
+u32 tpm2_get_capability(struct udevice *dev, u32 capability, u32 property,
+			void *buf, size_t prop_count);
 
 /**
  * Issue a TPM2_DictionaryAttackLockReset command.
  *
+ * @dev		TPM device
  * @pw		Password
  * @pw_sz	Length of the password
  *
  * @return code of the operation
  */
-u32 tpm2_dam_reset(const char *pw, const ssize_t pw_sz);
+u32 tpm2_dam_reset(struct udevice *dev, const char *pw, const ssize_t pw_sz);
 
 /**
  * Issue a TPM2_DictionaryAttackParameters command.
  *
+ * @dev		TPM device
  * @pw		Password
  * @pw_sz	Length of the password
  * @max_tries	Count of authorizations before lockout
@@ -215,13 +224,15 @@ u32 tpm2_dam_reset(const char *pw, const ssize_t pw_sz);
  *
  * @return code of the operation
  */
-u32 tpm2_dam_parameters(const char *pw, const ssize_t pw_sz,
-			unsigned int max_tries, unsigned int recovery_time,
+u32 tpm2_dam_parameters(struct udevice *dev, const char *pw,
+			const ssize_t pw_sz, unsigned int max_tries,
+			unsigned int recovery_time,
 			unsigned int lockout_recovery);
 
 /**
  * Issue a TPM2_HierarchyChangeAuth command.
  *
+ * @dev		TPM device
  * @handle	Handle
  * @newpw	New password
  * @newpw_sz	Length of the new password
@@ -230,12 +241,14 @@ u32 tpm2_dam_parameters(const char *pw, const ssize_t pw_sz,
  *
  * @return code of the operation
  */
-int tpm2_change_auth(u32 handle, const char *newpw, const ssize_t newpw_sz,
-		     const char *oldpw, const ssize_t oldpw_sz);
+int tpm2_change_auth(struct udevice *dev, u32 handle, const char *newpw,
+		     const ssize_t newpw_sz, const char *oldpw,
+		     const ssize_t oldpw_sz);
 
 /**
  * Issue a TPM_PCR_SetAuthPolicy command.
  *
+ * @dev		TPM device
  * @pw		Platform password
  * @pw_sz	Length of the password
  * @index	Index of the PCR
@@ -243,12 +256,13 @@ int tpm2_change_auth(u32 handle, const char *newpw, const ssize_t newpw_sz,
  *
  * @return code of the operation
  */
-u32 tpm2_pcr_setauthpolicy(const char *pw, const ssize_t pw_sz, u32 index,
-			   const char *key);
+u32 tpm2_pcr_setauthpolicy(struct udevice *dev, const char *pw,
+			   const ssize_t pw_sz, u32 index, const char *key);
 
 /**
  * Issue a TPM_PCR_SetAuthValue command.
  *
+ * @dev		TPM device
  * @pw		Platform password
  * @pw_sz	Length of the password
  * @index	Index of the PCR
@@ -257,7 +271,8 @@ u32 tpm2_pcr_setauthpolicy(const char *pw, const ssize_t pw_sz, u32 index,
  *
  * @return code of the operation
  */
-u32 tpm2_pcr_setauthvalue(const char *pw, const ssize_t pw_sz, u32 index,
-			  const char *key, const ssize_t key_sz);
+u32 tpm2_pcr_setauthvalue(struct udevice *dev, const char *pw,
+			  const ssize_t pw_sz, u32 index, const char *key,
+			  const ssize_t key_sz);
 
 #endif /* __TPM_V2_H */
diff --git a/lib/tpm-common.c b/lib/tpm-common.c
index a440639cec3..6afe59b1fec 100644
--- a/lib/tpm-common.c
+++ b/lib/tpm-common.c
@@ -151,9 +151,9 @@ u32 tpm_return_code(const void *response)
 	return get_unaligned_be32(response + return_code_offset);
 }
 
-u32 tpm_sendrecv_command(const void *command, void *response, size_t *size_ptr)
+u32 tpm_sendrecv_command(struct udevice *dev, const void *command,
+			 void *response, size_t *size_ptr)
 {
-	struct udevice *dev;
 	int err, ret;
 	u8 response_buffer[COMMAND_BUFFER_SIZE];
 	size_t response_length;
@@ -166,9 +166,6 @@ u32 tpm_sendrecv_command(const void *command, void *response, size_t *size_ptr)
 		response_length = sizeof(response_buffer);
 	}
 
-	ret = uclass_first_device_err(UCLASS_TPM, &dev);
-	if (ret)
-		return ret;
 	err = tpm_xfer(dev, command, tpm_command_size(command),
 		       response, &response_length);
 
@@ -188,14 +185,7 @@ u32 tpm_sendrecv_command(const void *command, void *response, size_t *size_ptr)
 	return ret;
 }
 
-int tpm_init(void)
+int tpm_init(struct udevice *dev)
 {
-	struct udevice *dev;
-	int err;
-
-	err = uclass_first_device_err(UCLASS_TPM, &dev);
-	if (err)
-		return err;
-
 	return tpm_open(dev);
 }
diff --git a/lib/tpm-utils.h b/lib/tpm-utils.h
index ac95f262f56..d680d140884 100644
--- a/lib/tpm-utils.h
+++ b/lib/tpm-utils.h
@@ -78,6 +78,7 @@ u32 tpm_return_code(const void *response);
  *			is a bidirectional
  * @return return code of the TPM response
  */
-u32 tpm_sendrecv_command(const void *command, void *response, size_t *size_ptr);
+u32 tpm_sendrecv_command(struct udevice *dev, const void *command,
+			 void *response, size_t *size_ptr);
 
 #endif /* __TPM_UTILS_H */
diff --git a/lib/tpm-v1.c b/lib/tpm-v1.c
index 9d45c3d3bf6..e1b1bf7b5be 100644
--- a/lib/tpm-v1.c
+++ b/lib/tpm-v1.c
@@ -31,7 +31,7 @@ static struct session_data oiap_session = {0, };
 
 #endif /* CONFIG_TPM_AUTH_SESSIONS */
 
-u32 tpm_startup(enum tpm_startup_type mode)
+u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode)
 {
 	const u8 command[12] = {
 		0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 0x99, 0x0, 0x0,
@@ -44,49 +44,49 @@ u32 tpm_startup(enum tpm_startup_type mode)
 			     mode_offset, mode))
 		return TPM_LIB_ERROR;
 
-	return tpm_sendrecv_command(buf, NULL, NULL);
+	return tpm_sendrecv_command(dev, buf, NULL, NULL);
 }
 
-u32 tpm_resume(void)
+u32 tpm_resume(struct udevice *dev)
 {
-	return tpm_startup(TPM_ST_STATE);
+	return tpm_startup(dev, TPM_ST_STATE);
 }
 
-u32 tpm_self_test_full(void)
+u32 tpm_self_test_full(struct udevice *dev)
 {
 	const u8 command[10] = {
 		0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x50,
 	};
-	return tpm_sendrecv_command(command, NULL, NULL);
+	return tpm_sendrecv_command(dev, command, NULL, NULL);
 }
 
-u32 tpm_continue_self_test(void)
+u32 tpm_continue_self_test(struct udevice *dev)
 {
 	const u8 command[10] = {
 		0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x53,
 	};
-	return tpm_sendrecv_command(command, NULL, NULL);
+	return tpm_sendrecv_command(dev, command, NULL, NULL);
 }
 
-u32 tpm_clear_and_reenable(void)
+u32 tpm_clear_and_reenable(struct udevice *dev)
 {
 	u32 ret;
 
 	log_info("TPM: Clear and re-enable\n");
-	ret = tpm_force_clear();
+	ret = tpm_force_clear(dev);
 	if (ret != TPM_SUCCESS) {
 		log_err("Can't initiate a force clear\n");
 		return ret;
 	}
 
 #if IS_ENABLED(CONFIG_TPM_V1)
-	ret = tpm_physical_enable();
+	ret = tpm_physical_enable(dev);
 	if (ret != TPM_SUCCESS) {
 		log_err("TPM: Can't set enabled state\n");
 		return ret;
 	}
 
-	ret = tpm_physical_set_deactivated(0);
+	ret = tpm_physical_set_deactivated(dev, 0);
 	if (ret != TPM_SUCCESS) {
 		log_err("TPM: Can't set deactivated state\n");
 		return ret;
@@ -96,7 +96,7 @@ u32 tpm_clear_and_reenable(void)
 	return TPM_SUCCESS;
 }
 
-u32 tpm_nv_define_space(u32 index, u32 perm, u32 size)
+u32 tpm_nv_define_space(struct udevice *dev, u32 index, u32 perm, u32 size)
 {
 	const u8 command[101] = {
 		0x0, 0xc1,		/* TPM_TAG */
@@ -136,15 +136,15 @@ u32 tpm_nv_define_space(u32 index, u32 perm, u32 size)
 			     size_offset, size))
 		return TPM_LIB_ERROR;
 
-	return tpm_sendrecv_command(buf, NULL, NULL);
+	return tpm_sendrecv_command(dev, buf, NULL, NULL);
 }
 
-u32 tpm_nv_set_locked(void)
+u32 tpm_nv_set_locked(struct udevice *dev)
 {
-	return tpm_nv_define_space(TPM_NV_INDEX_LOCK, 0, 0);
+	return tpm_nv_define_space(dev, TPM_NV_INDEX_LOCK, 0, 0);
 }
 
-u32 tpm_nv_read_value(u32 index, void *data, u32 count)
+u32 tpm_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count)
 {
 	const u8 command[22] = {
 		0x0, 0xc1, 0x0, 0x0, 0x0, 0x16, 0x0, 0x0, 0x0, 0xcf,
@@ -163,7 +163,7 @@ u32 tpm_nv_read_value(u32 index, void *data, u32 count)
 			     index_offset, index,
 			     length_offset, count))
 		return TPM_LIB_ERROR;
-	err = tpm_sendrecv_command(buf, response, &response_length);
+	err = tpm_sendrecv_command(dev, buf, response, &response_length);
 	if (err)
 		return err;
 	if (unpack_byte_string(response, response_length, "d",
@@ -178,7 +178,8 @@ u32 tpm_nv_read_value(u32 index, void *data, u32 count)
 	return 0;
 }
 
-u32 tpm_nv_write_value(u32 index, const void *data, u32 length)
+u32 tpm_nv_write_value(struct udevice *dev, u32 index, const void *data,
+		       u32 length)
 {
 	const u8 command[256] = {
 		0x0, 0xc1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xcd,
@@ -201,21 +202,22 @@ u32 tpm_nv_write_value(u32 index, const void *data, u32 length)
 			     length_offset, length,
 			     data_offset, data, length))
 		return TPM_LIB_ERROR;
-	err = tpm_sendrecv_command(buf, response, &response_length);
+	err = tpm_sendrecv_command(dev, buf, response, &response_length);
 	if (err)
 		return err;
 
 	return 0;
 }
 
-uint32_t tpm_set_global_lock(void)
+uint32_t tpm_set_global_lock(struct udevice *dev)
 {
 	u32 x;
 
-	return tpm_nv_write_value(TPM_NV_INDEX_0, (uint8_t *)&x, 0);
+	return tpm_nv_write_value(dev, TPM_NV_INDEX_0, (uint8_t *)&x, 0);
 }
 
-u32 tpm_extend(u32 index, const void *in_digest, void *out_digest)
+u32 tpm_extend(struct udevice *dev, u32 index, const void *in_digest,
+	       void *out_digest)
 {
 	const u8 command[34] = {
 		0x0, 0xc1, 0x0, 0x0, 0x0, 0x22, 0x0, 0x0, 0x0, 0x14,
@@ -234,7 +236,7 @@ u32 tpm_extend(u32 index, const void *in_digest, void *out_digest)
 			     in_digest_offset, in_digest,
 			     PCR_DIGEST_LENGTH))
 		return TPM_LIB_ERROR;
-	err = tpm_sendrecv_command(buf, response, &response_length);
+	err = tpm_sendrecv_command(dev, buf, response, &response_length);
 	if (err)
 		return err;
 
@@ -246,7 +248,7 @@ u32 tpm_extend(u32 index, const void *in_digest, void *out_digest)
 	return 0;
 }
 
-u32 tpm_pcr_read(u32 index, void *data, size_t count)
+u32 tpm_pcr_read(struct udevice *dev, u32 index, void *data, size_t count)
 {
 	const u8 command[14] = {
 		0x0, 0xc1, 0x0, 0x0, 0x0, 0xe, 0x0, 0x0, 0x0, 0x15,
@@ -264,7 +266,7 @@ u32 tpm_pcr_read(u32 index, void *data, size_t count)
 			     0, command, sizeof(command),
 			     index_offset, index))
 		return TPM_LIB_ERROR;
-	err = tpm_sendrecv_command(buf, response, &response_length);
+	err = tpm_sendrecv_command(dev, buf, response, &response_length);
 	if (err)
 		return err;
 	if (unpack_byte_string(response, response_length, "s",
@@ -274,7 +276,7 @@ u32 tpm_pcr_read(u32 index, void *data, size_t count)
 	return 0;
 }
 
-u32 tpm_tsc_physical_presence(u16 presence)
+u32 tpm_tsc_physical_presence(struct udevice *dev, u16 presence)
 {
 	const u8 command[12] = {
 		0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x40, 0x0, 0x0, 0xa, 0x0, 0x0,
@@ -287,19 +289,19 @@ u32 tpm_tsc_physical_presence(u16 presence)
 			     presence_offset, presence))
 		return TPM_LIB_ERROR;
 
-	return tpm_sendrecv_command(buf, NULL, NULL);
+	return tpm_sendrecv_command(dev, buf, NULL, NULL);
 }
 
-u32 tpm_finalise_physical_presence(void)
+u32 tpm_finalise_physical_presence(struct udevice *dev)
 {
 	const u8 command[12] = {
 		0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x40, 0x0, 0x0, 0xa, 0x2, 0xa0,
 	};
 
-	return tpm_sendrecv_command(command, NULL, NULL);
+	return tpm_sendrecv_command(dev, command, NULL, NULL);
 }
 
-u32 tpm_read_pubek(void *data, size_t count)
+u32 tpm_read_pubek(struct udevice *dev, void *data, size_t count)
 {
 	const u8 command[30] = {
 		0x0, 0xc1, 0x0, 0x0, 0x0, 0x1e, 0x0, 0x0, 0x0, 0x7c,
@@ -312,7 +314,7 @@ u32 tpm_read_pubek(void *data, size_t count)
 	u32 data_size;
 	u32 err;
 
-	err = tpm_sendrecv_command(command, response, &response_length);
+	err = tpm_sendrecv_command(dev, command, response, &response_length);
 	if (err)
 		return err;
 	if (unpack_byte_string(response, response_length, "d",
@@ -330,34 +332,34 @@ u32 tpm_read_pubek(void *data, size_t count)
 	return 0;
 }
 
-u32 tpm_force_clear(void)
+u32 tpm_force_clear(struct udevice *dev)
 {
 	const u8 command[10] = {
 		0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x5d,
 	};
 
-	return tpm_sendrecv_command(command, NULL, NULL);
+	return tpm_sendrecv_command(dev, command, NULL, NULL);
 }
 
-u32 tpm_physical_enable(void)
+u32 tpm_physical_enable(struct udevice *dev)
 {
 	const u8 command[10] = {
 		0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x6f,
 	};
 
-	return tpm_sendrecv_command(command, NULL, NULL);
+	return tpm_sendrecv_command(dev, command, NULL, NULL);
 }
 
-u32 tpm_physical_disable(void)
+u32 tpm_physical_disable(struct udevice *dev)
 {
 	const u8 command[10] = {
 		0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x70,
 	};
 
-	return tpm_sendrecv_command(command, NULL, NULL);
+	return tpm_sendrecv_command(dev, command, NULL, NULL);
 }
 
-u32 tpm_physical_set_deactivated(u8 state)
+u32 tpm_physical_set_deactivated(struct udevice *dev, u8 state)
 {
 	const u8 command[11] = {
 		0x0, 0xc1, 0x0, 0x0, 0x0, 0xb, 0x0, 0x0, 0x0, 0x72,
@@ -370,10 +372,11 @@ u32 tpm_physical_set_deactivated(u8 state)
 			     state_offset, state))
 		return TPM_LIB_ERROR;
 
-	return tpm_sendrecv_command(buf, NULL, NULL);
+	return tpm_sendrecv_command(dev, buf, NULL, NULL);
 }
 
-u32 tpm_get_capability(u32 cap_area, u32 sub_cap, void *cap, size_t count)
+u32 tpm_get_capability(struct udevice *dev, u32 cap_area, u32 sub_cap,
+		       void *cap, size_t count)
 {
 	const u8 command[22] = {
 		0x0, 0xc1,		/* TPM_TAG */
@@ -397,7 +400,7 @@ u32 tpm_get_capability(u32 cap_area, u32 sub_cap, void *cap, size_t count)
 			     cap_area_offset, cap_area,
 			     sub_cap_offset, sub_cap))
 		return TPM_LIB_ERROR;
-	err = tpm_sendrecv_command(buf, response, &response_length);
+	err = tpm_sendrecv_command(dev, buf, response, &response_length);
 	if (err)
 		return err;
 	if (unpack_byte_string(response, response_length, "d",
@@ -412,7 +415,8 @@ u32 tpm_get_capability(u32 cap_area, u32 sub_cap, void *cap, size_t count)
 	return 0;
 }
 
-u32 tpm_get_permanent_flags(struct tpm_permanent_flags *pflags)
+u32 tpm_get_permanent_flags(struct udevice *dev,
+			    struct tpm_permanent_flags *pflags)
 {
 	const u8 command[22] = {
 		0x0, 0xc1,		/* TPM_TAG */
@@ -429,7 +433,7 @@ u32 tpm_get_permanent_flags(struct tpm_permanent_flags *pflags)
 	u32 err;
 	u32 data_size;
 
-	err = tpm_sendrecv_command(command, response, &response_length);
+	err = tpm_sendrecv_command(dev, command, response, &response_length);
 	if (err)
 		return err;
 	if (unpack_byte_string(response, response_length, "d",
@@ -450,7 +454,7 @@ u32 tpm_get_permanent_flags(struct tpm_permanent_flags *pflags)
 	return 0;
 }
 
-u32 tpm_get_permissions(u32 index, u32 *perm)
+u32 tpm_get_permissions(struct udevice *dev, u32 index, u32 *perm)
 {
 	const u8 command[22] = {
 		0x0, 0xc1,		/* TPM_TAG */
@@ -468,7 +472,7 @@ u32 tpm_get_permissions(u32 index, u32 *perm)
 	if (pack_byte_string(buf, sizeof(buf), "d", 0, command, sizeof(command),
 			     index_offset, index))
 		return TPM_LIB_ERROR;
-	err = tpm_sendrecv_command(buf, response, &response_length);
+	err = tpm_sendrecv_command(dev, buf, response, &response_length);
 	if (err)
 		return err;
 	if (unpack_byte_string(response, response_length, "d",
@@ -479,7 +483,7 @@ u32 tpm_get_permissions(u32 index, u32 *perm)
 }
 
 #ifdef CONFIG_TPM_FLUSH_RESOURCES
-u32 tpm_flush_specific(u32 key_handle, u32 resource_type)
+u32 tpm_flush_specific(struct udevice *dev, u32 key_handle, u32 resource_type)
 {
 	const u8 command[18] = {
 		0x00, 0xc1,             /* TPM_TAG */
@@ -500,7 +504,7 @@ u32 tpm_flush_specific(u32 key_handle, u32 resource_type)
 			     resource_type_offset, resource_type))
 		return TPM_LIB_ERROR;
 
-	err = tpm_sendrecv_command(buf, response, &response_length);
+	err = tpm_sendrecv_command(dev, buf, response, &response_length);
 	if (err)
 		return err;
 	return 0;
@@ -638,7 +642,7 @@ static u32 verify_response_auth(u32 command_code, const void *response,
 	return TPM_SUCCESS;
 }
 
-u32 tpm_terminate_auth_session(u32 auth_handle)
+u32 tpm_terminate_auth_session(struct udevice *dev, u32 auth_handle)
 {
 	const u8 command[18] = {
 		0x00, 0xc1,		/* TPM_TAG */
@@ -657,19 +661,19 @@ u32 tpm_terminate_auth_session(u32 auth_handle)
 	if (oiap_session.valid && oiap_session.handle == auth_handle)
 		oiap_session.valid = 0;
 
-	return tpm_sendrecv_command(request, NULL, NULL);
+	return tpm_sendrecv_command(dev, request, NULL, NULL);
 }
 
-u32 tpm_end_oiap(void)
+u32 tpm_end_oiap(struct udevice *dev)
 {
 	u32 err = TPM_SUCCESS;
 
 	if (oiap_session.valid)
-		err = tpm_terminate_auth_session(oiap_session.handle);
+		err = tpm_terminate_auth_session(dev, oiap_session.handle);
 	return err;
 }
 
-u32 tpm_oiap(u32 *auth_handle)
+u32 tpm_oiap(struct udevice *dev, u32 *auth_handle)
 {
 	const u8 command[10] = {
 		0x00, 0xc1,		/* TPM_TAG */
@@ -683,7 +687,7 @@ u32 tpm_oiap(u32 *auth_handle)
 	u32 err;
 
 	if (oiap_session.valid)
-		tpm_terminate_auth_session(oiap_session.handle);
+		tpm_terminate_auth_session(dev, oiap_session.handle);
 
 	err = tpm_sendrecv_command(command, response, &response_length);
 	if (err)
@@ -699,8 +703,9 @@ u32 tpm_oiap(u32 *auth_handle)
 	return 0;
 }
 
-u32 tpm_load_key2_oiap(u32 parent_handle, const void *key, size_t key_length,
-		       const void *parent_key_usage_auth, u32 *key_handle)
+u32 tpm_load_key2_oiap(struct udevice *dev, u32 parent_handle, const void *key,
+		       size_t key_length, const void *parent_key_usage_auth,
+		       u32 *key_handle)
 {
 	const u8 command[14] = {
 		0x00, 0xc2,		/* TPM_TAG */
@@ -739,7 +744,7 @@ u32 tpm_load_key2_oiap(u32 parent_handle, const void *key, size_t key_length,
 				  parent_key_usage_auth);
 	if (err)
 		return err;
-	err = tpm_sendrecv_command(request, response, &response_length);
+	err = tpm_sendrecv_command(dev, request, response, &response_length);
 	if (err) {
 		if (err == TPM_AUTHFAIL)
 			oiap_session.valid = 0;
@@ -764,7 +769,8 @@ u32 tpm_load_key2_oiap(u32 parent_handle, const void *key, size_t key_length,
 	return 0;
 }
 
-u32 tpm_get_pub_key_oiap(u32 key_handle, const void *usage_auth, void *pubkey,
+u32 tpm_get_pub_key_oiap(struct udevice *dev, u32 key_handle,
+			 const void *usage_auth, void *pubkey,
 			 size_t *pubkey_len)
 {
 	const u8 command[14] = {
@@ -799,7 +805,7 @@ u32 tpm_get_pub_key_oiap(u32 key_handle, const void *usage_auth, void *pubkey,
 				  request + sizeof(command), usage_auth);
 	if (err)
 		return err;
-	err = tpm_sendrecv_command(request, response, &response_length);
+	err = tpm_sendrecv_command(dev, request, response, &response_length);
 	if (err) {
 		if (err == TPM_AUTHFAIL)
 			oiap_session.valid = 0;
@@ -829,8 +835,8 @@ u32 tpm_get_pub_key_oiap(u32 key_handle, const void *usage_auth, void *pubkey,
 }
 
 #ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
-u32 tpm_find_key_sha1(const u8 auth[20], const u8 pubkey_digest[20],
-		      u32 *handle)
+u32 tpm_find_key_sha1(struct udevice *dev, const u8 auth[20],
+		      const u8 pubkey_digest[20], u32 *handle)
 {
 	u16 key_count;
 	u32 key_handles[10];
@@ -842,7 +848,8 @@ u32 tpm_find_key_sha1(const u8 auth[20], const u8 pubkey_digest[20],
 	unsigned int i;
 
 	/* fetch list of already loaded keys in the TPM */
-	err = tpm_get_capability(TPM_CAP_HANDLE, TPM_RT_KEY, buf, sizeof(buf));
+	err = tpm_get_capability(dev, TPM_CAP_HANDLE, TPM_RT_KEY, buf,
+				 sizeof(buf));
 	if (err)
 		return -1;
 	key_count = get_unaligned_be16(buf);
@@ -870,7 +877,7 @@ u32 tpm_find_key_sha1(const u8 auth[20], const u8 pubkey_digest[20],
 
 #endif /* CONFIG_TPM_AUTH_SESSIONS */
 
-u32 tpm_get_random(void *data, u32 count)
+u32 tpm_get_random(struct udevice *dev, void *data, u32 count)
 {
 	const u8 command[14] = {
 		0x0, 0xc1,		/* TPM_TAG */
@@ -894,7 +901,8 @@ u32 tpm_get_random(void *data, u32 count)
 				     0, command, sizeof(command),
 				     length_offset, this_bytes))
 			return TPM_LIB_ERROR;
-		err = tpm_sendrecv_command(buf, response, &response_length);
+		err = tpm_sendrecv_command(dev, buf, response,
+					   &response_length);
 		if (err)
 			return err;
 		if (unpack_byte_string(response, response_length, "d",
diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
index f1bbca8e7aa..f89592d6e2f 100644
--- a/lib/tpm-v2.c
+++ b/lib/tpm-v2.c
@@ -10,7 +10,7 @@
 #include <tpm-v2.h>
 #include "tpm-utils.h"
 
-u32 tpm2_startup(enum tpm2_startup_types mode)
+u32 tpm2_startup(struct udevice *dev, enum tpm2_startup_types mode)
 {
 	const u8 command_v2[12] = {
 		tpm_u16(TPM2_ST_NO_SESSIONS),
@@ -24,14 +24,14 @@ u32 tpm2_startup(enum tpm2_startup_types mode)
 	 * Note TPM2_Startup command will return RC_SUCCESS the first time,
 	 * but will return RC_INITIALIZE otherwise.
 	 */
-	ret = tpm_sendrecv_command(command_v2, NULL, NULL);
+	ret = tpm_sendrecv_command(dev, command_v2, NULL, NULL);
 	if (ret && ret != TPM2_RC_INITIALIZE)
 		return ret;
 
 	return 0;
 }
 
-u32 tpm2_self_test(enum tpm2_yes_no full_test)
+u32 tpm2_self_test(struct udevice *dev, enum tpm2_yes_no full_test)
 {
 	const u8 command_v2[12] = {
 		tpm_u16(TPM2_ST_NO_SESSIONS),
@@ -40,10 +40,11 @@ u32 tpm2_self_test(enum tpm2_yes_no full_test)
 		full_test,
 	};
 
-	return tpm_sendrecv_command(command_v2, NULL, NULL);
+	return tpm_sendrecv_command(dev, command_v2, NULL, NULL);
 }
 
-u32 tpm2_clear(u32 handle, const char *pw, const ssize_t pw_sz)
+u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw,
+	       const ssize_t pw_sz)
 {
 	u8 command_v2[COMMAND_BUFFER_SIZE] = {
 		tpm_u16(TPM2_ST_SESSIONS),	/* TAG */
@@ -75,10 +76,10 @@ u32 tpm2_clear(u32 handle, const char *pw, const ssize_t pw_sz)
 	if (ret)
 		return TPM_LIB_ERROR;
 
-	return tpm_sendrecv_command(command_v2, NULL, NULL);
+	return tpm_sendrecv_command(dev, command_v2, NULL, NULL);
 }
 
-u32 tpm2_pcr_extend(u32 index, const uint8_t *digest)
+u32 tpm2_pcr_extend(struct udevice *dev, u32 index, const uint8_t *digest)
 {
 	u8 command_v2[COMMAND_BUFFER_SIZE] = {
 		tpm_u16(TPM2_ST_SESSIONS),	/* TAG */
@@ -113,11 +114,11 @@ u32 tpm2_pcr_extend(u32 index, const uint8_t *digest)
 	if (ret)
 		return TPM_LIB_ERROR;
 
-	return tpm_sendrecv_command(command_v2,	NULL, NULL);
+	return tpm_sendrecv_command(dev, command_v2, NULL, NULL);
 }
 
-u32 tpm2_pcr_read(u32 idx, unsigned int idx_min_sz, void *data,
-		  unsigned int *updates)
+u32 tpm2_pcr_read(struct udevice *dev, u32 idx, unsigned int idx_min_sz,
+		  void *data, unsigned int *updates)
 {
 	u8 idx_array_sz = max(idx_min_sz, DIV_ROUND_UP(idx, 8));
 	u8 command_v2[COMMAND_BUFFER_SIZE] = {
@@ -142,7 +143,7 @@ u32 tpm2_pcr_read(u32 idx, unsigned int idx_min_sz, void *data,
 			     17 + pcr_sel_idx, pcr_sel_bit))
 		return TPM_LIB_ERROR;
 
-	ret = tpm_sendrecv_command(command_v2, response, &response_len);
+	ret = tpm_sendrecv_command(dev, command_v2, response, &response_len);
 	if (ret)
 		return ret;
 
@@ -158,8 +159,8 @@ u32 tpm2_pcr_read(u32 idx, unsigned int idx_min_sz, void *data,
 	return 0;
 }
 
-u32 tpm2_get_capability(u32 capability, u32 property, void *buf,
-			size_t prop_count)
+u32 tpm2_get_capability(struct udevice *dev, u32 capability, u32 property,
+			void *buf, size_t prop_count)
 {
 	u8 command_v2[COMMAND_BUFFER_SIZE] = {
 		tpm_u16(TPM2_ST_NO_SESSIONS),		/* TAG */
@@ -175,7 +176,7 @@ u32 tpm2_get_capability(u32 capability, u32 property, void *buf,
 	unsigned int properties_off;
 	int ret;
 
-	ret = tpm_sendrecv_command(command_v2, response, &response_len);
+	ret = tpm_sendrecv_command(dev, command_v2, response, &response_len);
 	if (ret)
 		return ret;
 
@@ -191,7 +192,7 @@ u32 tpm2_get_capability(u32 capability, u32 property, void *buf,
 	return 0;
 }
 
-u32 tpm2_dam_reset(const char *pw, const ssize_t pw_sz)
+u32 tpm2_dam_reset(struct udevice *dev, const char *pw, const ssize_t pw_sz)
 {
 	u8 command_v2[COMMAND_BUFFER_SIZE] = {
 		tpm_u16(TPM2_ST_SESSIONS),	/* TAG */
@@ -223,11 +224,12 @@ u32 tpm2_dam_reset(const char *pw, const ssize_t pw_sz)
 	if (ret)
 		return TPM_LIB_ERROR;
 
-	return tpm_sendrecv_command(command_v2, NULL, NULL);
+	return tpm_sendrecv_command(dev, command_v2, NULL, NULL);
 }
 
-u32 tpm2_dam_parameters(const char *pw, const ssize_t pw_sz,
-			unsigned int max_tries, unsigned int recovery_time,
+u32 tpm2_dam_parameters(struct udevice *dev, const char *pw,
+			const ssize_t pw_sz, unsigned int max_tries,
+			unsigned int recovery_time,
 			unsigned int lockout_recovery)
 {
 	u8 command_v2[COMMAND_BUFFER_SIZE] = {
@@ -271,11 +273,12 @@ u32 tpm2_dam_parameters(const char *pw, const ssize_t pw_sz,
 	if (ret)
 		return TPM_LIB_ERROR;
 
-	return tpm_sendrecv_command(command_v2, NULL, NULL);
+	return tpm_sendrecv_command(dev, command_v2, NULL, NULL);
 }
 
-int tpm2_change_auth(u32 handle, const char *newpw, const ssize_t newpw_sz,
-		     const char *oldpw, const ssize_t oldpw_sz)
+int tpm2_change_auth(struct udevice *dev, u32 handle, const char *newpw,
+		     const ssize_t newpw_sz, const char *oldpw,
+		     const ssize_t oldpw_sz)
 {
 	unsigned int offset = 27;
 	u8 command_v2[COMMAND_BUFFER_SIZE] = {
@@ -315,11 +318,11 @@ int tpm2_change_auth(u32 handle, const char *newpw, const ssize_t newpw_sz,
 	if (ret)
 		return TPM_LIB_ERROR;
 
-	return tpm_sendrecv_command(command_v2, NULL, NULL);
+	return tpm_sendrecv_command(dev, command_v2, NULL, NULL);
 }
 
-u32 tpm2_pcr_setauthpolicy(const char *pw, const ssize_t pw_sz, u32 index,
-			   const char *key)
+u32 tpm2_pcr_setauthpolicy(struct udevice *dev, const char *pw,
+			   const ssize_t pw_sz, u32 index, const char *key)
 {
 	u8 command_v2[COMMAND_BUFFER_SIZE] = {
 		tpm_u16(TPM2_ST_SESSIONS),	/* TAG */
@@ -370,11 +373,12 @@ u32 tpm2_pcr_setauthpolicy(const char *pw, const ssize_t pw_sz, u32 index,
 	if (ret)
 		return TPM_LIB_ERROR;
 
-	return tpm_sendrecv_command(command_v2, NULL, NULL);
+	return tpm_sendrecv_command(dev, command_v2, NULL, NULL);
 }
 
-u32 tpm2_pcr_setauthvalue(const char *pw, const ssize_t pw_sz, u32 index,
-			  const char *key, const ssize_t key_sz)
+u32 tpm2_pcr_setauthvalue(struct udevice *dev, const char *pw,
+			  const ssize_t pw_sz, u32 index, const char *key,
+			  const ssize_t key_sz)
 {
 	u8 command_v2[COMMAND_BUFFER_SIZE] = {
 		tpm_u16(TPM2_ST_SESSIONS),	/* TAG */
@@ -415,5 +419,5 @@ u32 tpm2_pcr_setauthvalue(const char *pw, const ssize_t pw_sz, u32 index,
 	if (ret)
 		return TPM_LIB_ERROR;
 
-	return tpm_sendrecv_command(command_v2, NULL, NULL);
+	return tpm_sendrecv_command(dev, command_v2, NULL, NULL);
 }
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 19/25] video: Update video_set_default_colors() to support invert
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (17 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 18/25] tpm: Convert to use a device parameter Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 20/25] efi_loader: Don't enable in SPL/TPL by default Simon Glass
                   ` (23 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

It is useful to be able to invert the colours in some cases so that the
text matches the background colour. Add a parameter to the function to
support this.

It is strange that function takes a private data structure from another
driver as an argument. It seems better to pass the device and have the
function internally work out how to find its required information.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/video/vidconsole-uclass.c |  2 +-
 drivers/video/video-uclass.c      | 27 +++++++++++++++++++--------
 include/video.h                   |  5 +++--
 3 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index 1874887f2f3..d7568bc79a5 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -344,7 +344,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch)
 			switch (val) {
 			case 0:
 				/* all attributes off */
-				video_set_default_colors(vid_priv);
+				video_set_default_colors(dev->parent, false);
 				break;
 			case 1:
 				/* bold */
diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index 44dfa71b6f4..b6551b69d3a 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -115,18 +115,29 @@ int video_clear(struct udevice *dev)
 	return 0;
 }
 
-void video_set_default_colors(struct video_priv *priv)
+void video_set_default_colors(struct udevice *dev, bool invert)
 {
+	struct video_priv *priv = dev_get_uclass_priv(dev);
+	int fore, back;
+
 #ifdef CONFIG_SYS_WHITE_ON_BLACK
 	/* White is used when switching to bold, use light gray here */
-	priv->fg_col_idx = VID_LIGHT_GRAY;
-	priv->colour_fg = vid_console_color(priv, VID_LIGHT_GRAY);
-	priv->colour_bg = vid_console_color(priv, VID_BLACK);
+	fore = VID_LIGHT_GRAY;
+	back = VID_BLACK;
 #else
-	priv->fg_col_idx = VID_BLACK;
-	priv->colour_fg = vid_console_color(priv, VID_BLACK);
-	priv->colour_bg = vid_console_color(priv, VID_WHITE);
+	fore = VID_BLACK;
+	back = VID_WHITE;
 #endif
+	if (invert) {
+		int temp;
+
+		temp = fore;
+		fore = back;
+		back = temp;
+	}
+	priv->fg_col_idx = fore;
+	priv->colour_fg = vid_console_color(priv, fore);
+	priv->colour_bg = vid_console_color(priv, back);
 }
 
 /* Flush video activity to the caches */
@@ -219,7 +230,7 @@ static int video_post_probe(struct udevice *dev)
 	priv->fb_size = priv->line_length * priv->ysize;
 
 	/* Set up colors  */
-	video_set_default_colors(priv);
+	video_set_default_colors(dev, false);
 
 	if (!CONFIG_IS_ENABLED(NO_FB_CLEAR))
 		video_clear(dev);
diff --git a/include/video.h b/include/video.h
index 75200f0e452..3f9139eea44 100644
--- a/include/video.h
+++ b/include/video.h
@@ -191,9 +191,10 @@ void video_set_flush_dcache(struct udevice *dev, bool flush);
 /**
  * Set default colors and attributes
  *
- * @priv	device information
+ * @dev:	video device
+ * @invert	true to invert colours
  */
-void video_set_default_colors(struct video_priv *priv);
+void video_set_default_colors(struct udevice *dev, bool invert);
 
 #endif /* CONFIG_DM_VIDEO */
 
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 20/25] efi_loader: Don't enable in SPL/TPL by default
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (18 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 19/25] video: Update video_set_default_colors() to support invert Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-14 13:28   ` Alexander Graf
  2018-11-06 22:21 ` [U-Boot] [PATCH 21/25] string: Include the config header Simon Glass
                   ` (22 subsequent siblings)
  42 siblings, 1 reply; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

Generally this functionality is not useful in SPL or TPL. Update the
Makefile so that it is not built.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 lib/Makefile | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/Makefile b/lib/Makefile
index 4d2e22027d0..4dba3628e78 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -5,10 +5,10 @@
 
 ifndef CONFIG_SPL_BUILD
 
-obj-$(CONFIG_EFI) += efi/
-obj-$(CONFIG_EFI_LOADER) += efi_driver/
-obj-$(CONFIG_EFI_LOADER) += efi_loader/
-obj-$(CONFIG_EFI_LOADER) += efi_selftest/
+obj-$(CONFIG_$(SPL_TPL_)EFI) += efi/
+obj-$(CONFIG_$(SPL_TPL_)EFI_LOADER) += efi_driver/
+obj-$(CONFIG_$(SPL_TPL_)EFI_LOADER) += efi_loader/
+obj-$(CONFIG_$(SPL_TPL_)EFI_LOADER) += efi_selftest/
 obj-$(CONFIG_LZMA) += lzma/
 obj-$(CONFIG_BZIP2) += bzip2/
 obj-$(CONFIG_TIZEN) += tizen/
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 21/25] string: Include the config header
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (19 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 20/25] efi_loader: Don't enable in SPL/TPL by default Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 22/25] misc: Update read() and write() methods to return bytes xfered Simon Glass
                   ` (21 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

At present the config header is not included in this file, but it does use
a CONFIG option. Fix it.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 lib/string.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/string.c b/lib/string.c
index c4ca944bb42..af17c16f616 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -15,6 +15,7 @@
  *    reentrant and should be faster). Use only strsep() in new code, please.
  */
 
+#include <config.h>
 #include <linux/types.h>
 #include <linux/string.h>
 #include <linux/ctype.h>
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 22/25] misc: Update read() and write() methods to return bytes xfered
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (20 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 21/25] string: Include the config header Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-08 11:03   ` Patrick DELAUNAY
  2018-11-22 20:20   ` sjg at google.com
  2018-11-06 22:21 ` [U-Boot] [PATCH 23/25] test: sf: Add a simple SPI flash test Simon Glass
                   ` (20 subsequent siblings)
  42 siblings, 2 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

At present these functions return 0 on success. For some devices we want
to know how many bytes were transferred. It seems useful to adjust the API
to be more like the POSIX read() and write() functions.

Update these two methods, a test and all users.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/arm/mach-stm32mp/cpu.c    |  4 ++--
 drivers/clk/clk_vexpress_osc.c |  4 ++--
 drivers/misc/altera_sysid.c    |  2 +-
 drivers/misc/misc_sandbox.c    |  4 ++--
 drivers/misc/rockchip-efuse.c  |  2 +-
 drivers/misc/stm32mp_fuse.c    | 12 ++++++++++++
 include/misc.h                 |  8 ++++----
 7 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/arch/arm/mach-stm32mp/cpu.c b/arch/arm/mach-stm32mp/cpu.c
index 0e01f8e6138..b8933587adb 100644
--- a/arch/arm/mach-stm32mp/cpu.c
+++ b/arch/arm/mach-stm32mp/cpu.c
@@ -306,7 +306,7 @@ static int setup_mac_address(void)
 
 	ret = misc_read(dev, BSEC_OTP_MAC * 4 + STM32_BSEC_OTP_OFFSET,
 			otp, sizeof(otp));
-	if (ret)
+	if (ret < 0)
 		return ret;
 
 	for (i = 0; i < 6; i++)
@@ -344,7 +344,7 @@ static int setup_serial_number(void)
 
 	ret = misc_read(dev, BSEC_OTP_SERIAL * 4 + STM32_BSEC_OTP_OFFSET,
 			otp, sizeof(otp));
-	if (ret)
+	if (ret < 0)
 		return ret;
 
 	sprintf(serial_string, "%08x%08x%08x", otp[0], otp[1], otp[2]);
diff --git a/drivers/clk/clk_vexpress_osc.c b/drivers/clk/clk_vexpress_osc.c
index 7fef4b2e312..c692a6d0b89 100644
--- a/drivers/clk/clk_vexpress_osc.c
+++ b/drivers/clk/clk_vexpress_osc.c
@@ -29,7 +29,7 @@ static ulong vexpress_osc_clk_get_rate(struct clk *clk)
 
 	data = CLK_FUNCTION | priv->osc;
 	err = misc_read(vexpress_cfg, 0, &data, sizeof(data));
-	if (err)
+	if (err < 0)
 		return err;
 
 	return data;
@@ -53,7 +53,7 @@ static ulong vexpress_osc_clk_set_rate(struct clk *clk, ulong rate)
 	buffer[0] = CLK_FUNCTION | priv->osc;
 	buffer[1] = rate;
 	err = misc_write(vexpress_cfg, 0, buffer, 2 * sizeof(u32));
-	if (err)
+	if (err < 0)
 		return err;
 
 	return rate;
diff --git a/drivers/misc/altera_sysid.c b/drivers/misc/altera_sysid.c
index 883b2a35e07..eff33f7343d 100644
--- a/drivers/misc/altera_sysid.c
+++ b/drivers/misc/altera_sysid.c
@@ -35,7 +35,7 @@ void display_sysid(void)
 	if (ret)
 		return;
 	ret = misc_read(dev, 0, &sysid, sizeof(sysid));
-	if (ret)
+	if (ret < 0)
 		return;
 
 	stamp = sysid[1];
diff --git a/drivers/misc/misc_sandbox.c b/drivers/misc/misc_sandbox.c
index e4164f76fba..f7c5b2e25fa 100644
--- a/drivers/misc/misc_sandbox.c
+++ b/drivers/misc/misc_sandbox.c
@@ -20,7 +20,7 @@ int misc_sandbox_read(struct udevice *dev, int offset, void *buf, int size)
 
 	memcpy(buf, priv->mem + offset, size);
 
-	return 0;
+	return size;
 }
 
 int misc_sandbox_write(struct udevice *dev, int offset, const void *buf,
@@ -30,7 +30,7 @@ int misc_sandbox_write(struct udevice *dev, int offset, const void *buf,
 
 	memcpy(priv->mem + offset, buf, size);
 
-	return 0;
+	return size;
 }
 
 int misc_sandbox_ioctl(struct udevice *dev, unsigned long request, void *buf)
diff --git a/drivers/misc/rockchip-efuse.c b/drivers/misc/rockchip-efuse.c
index 8a213c9e270..2520c6a38ed 100644
--- a/drivers/misc/rockchip-efuse.c
+++ b/drivers/misc/rockchip-efuse.c
@@ -65,7 +65,7 @@ static int dump_efuses(cmd_tbl_t *cmdtp, int flag,
 	}
 
 	ret = misc_read(dev, 0, &fuses, sizeof(fuses));
-	if (ret) {
+	if (ret < 0) {
 		printf("%s: misc_read failed\n", __func__);
 		return 0;
 	}
diff --git a/drivers/misc/stm32mp_fuse.c b/drivers/misc/stm32mp_fuse.c
index 2d661351a17..33943a231b1 100644
--- a/drivers/misc/stm32mp_fuse.c
+++ b/drivers/misc/stm32mp_fuse.c
@@ -29,6 +29,9 @@ int fuse_read(u32 bank, u32 word, u32 *val)
 			return ret;
 		ret = misc_read(dev, word * 4 + STM32_BSEC_SHADOW_OFFSET,
 				val, 4);
+		if (ret < 0)
+			return ret;
+		ret = 0;
 		break;
 
 	default:
@@ -54,6 +57,9 @@ int fuse_prog(u32 bank, u32 word, u32 val)
 			return ret;
 		ret = misc_write(dev, word * 4 + STM32_BSEC_OTP_OFFSET,
 				 &val, 4);
+		if (ret < 0)
+			return ret;
+		ret = 0;
 		break;
 
 	default:
@@ -78,6 +84,9 @@ int fuse_sense(u32 bank, u32 word, u32 *val)
 		if (ret)
 			return ret;
 		ret = misc_read(dev, word * 4 + STM32_BSEC_OTP_OFFSET, val, 4);
+		if (ret < 0)
+			return ret;
+		ret = 0;
 		break;
 
 	default:
@@ -103,6 +112,9 @@ int fuse_override(u32 bank, u32 word, u32 val)
 			return ret;
 		ret = misc_write(dev, word * 4 + STM32_BSEC_SHADOW_OFFSET,
 				 &val, 4);
+		if (ret < 0)
+			return ret;
+		ret = 0;
 		break;
 
 	default:
diff --git a/include/misc.h b/include/misc.h
index 50515852b25..12d1325ee26 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -13,7 +13,7 @@
  * @buf: pointer to data buffer
  * @size: data size in bytes to read the device
  *
- * Return: 0 if OK, -ve on error
+ * Return: number of bytes read if OK (may be 0 if EOF), -ve on error
  */
 int misc_read(struct udevice *dev, int offset, void *buf, int size);
 
@@ -24,7 +24,7 @@ int misc_read(struct udevice *dev, int offset, void *buf, int size);
  * @buf: pointer to data buffer
  * @size: data size in bytes to write the device
  *
- * Return: 0 if OK, -ve on error
+ * Return: number of bytes written if OK (may be < @size), -ve on error
  */
 int misc_write(struct udevice *dev, int offset, void *buf, int size);
 
@@ -90,7 +90,7 @@ struct misc_ops {
 	 * @buf: pointer to data buffer
 	 * @size: data size in bytes to read the device
 	 *
-	 * Return: 0 if OK, -ve on error
+	 * Return: number of bytes read if OK (may be 0 if EOF), -ve on error
 	 */
 	int (*read)(struct udevice *dev, int offset, void *buf, int size);
 
@@ -101,7 +101,7 @@ struct misc_ops {
 	 * @buf: pointer to data buffer
 	 * @size: data size in bytes to write the device
 	 *
-	 * Return: 0 if OK, -ve on error
+	 * Return: number of bytes written if OK (may be < @size), -ve on error
 	 */
 	int (*write)(struct udevice *dev, int offset, const void *buf,
 		     int size);
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 23/25] test: sf: Add a simple SPI flash test
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (21 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 22/25] misc: Update read() and write() methods to return bytes xfered Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 24/25] sf: Add a method to obtain the block-protect setting Simon Glass
                   ` (19 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

The current test is a functional test, covering all the way from the
command line to the sandbox SPI driver. This is useful, but it is easier
to diagnose failures with a smaller test.

Add a simple test which reads and writes data and checks that it is stored
and retrieved correctly.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 test/dm/sf.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/test/dm/sf.c b/test/dm/sf.c
index 35241b9f574..b23e7f8edd4 100644
--- a/test/dm/sf.c
+++ b/test/dm/sf.c
@@ -6,6 +6,8 @@
 #include <common.h>
 #include <dm.h>
 #include <fdtdec.h>
+#include <mapmem.h>
+#include <os.h>
 #include <spi.h>
 #include <spi_flash.h>
 #include <asm/state.h>
@@ -13,8 +15,48 @@
 #include <dm/util.h>
 #include <test/ut.h>
 
-/* Test that sandbox SPI flash works correctly */
+/* Simple test of sandbox SPI flash */
 static int dm_test_spi_flash(struct unit_test_state *uts)
+{
+	struct udevice *dev, *emul;
+	int full_size = 0x200000;
+	int size = 0x10000;
+	u8 *src, *dst;
+	int i;
+
+	src = map_sysmem(0x20000, full_size);
+	ut_assertok(os_write_file("spi.bin", src, full_size));
+	ut_assertok(uclass_first_device_err(UCLASS_SPI_FLASH, &dev));
+
+	dst = map_sysmem(0x20000 + full_size, full_size);
+	ut_assertok(spi_flash_read_dm(dev, 0, size, dst));
+	ut_assertok(memcmp(src, dst, size));
+
+	/* Erase */
+	ut_assertok(spi_flash_erase_dm(dev, 0, size));
+	ut_assertok(spi_flash_read_dm(dev, 0, size, dst));
+	for (i = 0; i < size; i++)
+		ut_asserteq(dst[i], 0xff);
+
+	/* Write some new data */
+	for (i = 0; i < size; i++)
+		src[i] = i;
+	ut_assertok(spi_flash_write_dm(dev, 0, size, src));
+	ut_assertok(spi_flash_read_dm(dev, 0, size, dst));
+	ut_assertok(memcmp(src, dst, size));
+
+	/*
+	 * Since we are about to destroy all devices, we must tell sandbox
+	 * to forget the emulation device
+	 */
+	sandbox_sf_unbind_emul(state_get_current(), 0, 0);
+
+	return 0;
+}
+DM_TEST(dm_test_spi_flash, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Functional test that sandbox SPI flash works correctly */
+static int dm_test_spi_flash_func(struct unit_test_state *uts)
 {
 	/*
 	 * Create an empty test file and run the SPI flash tests. This is a
@@ -39,4 +81,4 @@ static int dm_test_spi_flash(struct unit_test_state *uts)
 
 	return 0;
 }
-DM_TEST(dm_test_spi_flash, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+DM_TEST(dm_test_spi_flash_func, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 24/25] sf: Add a method to obtain the block-protect setting
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (22 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 23/25] test: sf: Add a simple SPI flash test Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-06 22:21 ` [U-Boot] [PATCH 25/25] mmc: Add hardware partition support Simon Glass
                   ` (18 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

It is useful to obtain the block-protect setting of the SPI flash, so we
know whether it is fully open or (perhaps partially) write-protected. Add
a method for this. Update the sandbox driver to process this operation and
add a test.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/include/asm/test.h |  8 ++++++++
 drivers/mtd/spi/sandbox.c       | 10 ++++++++++
 drivers/mtd/spi/sf-uclass.c     |  9 +++++++++
 drivers/mtd/spi/sf_internal.h   |  3 +++
 drivers/mtd/spi/sf_probe.c      |  8 ++++++++
 drivers/mtd/spi/spi_flash.c     | 12 ++++++++++++
 include/spi_flash.h             | 27 +++++++++++++++++++++++++++
 test/dm/sf.c                    |  9 +++++++++
 8 files changed, 86 insertions(+)

diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h
index 8e60f80ae7f..5e818392959 100644
--- a/arch/sandbox/include/asm/test.h
+++ b/arch/sandbox/include/asm/test.h
@@ -113,4 +113,12 @@ int sandbox_osd_get_mem(struct udevice *dev, u8 *buf, size_t buflen);
 int sandbox_pwm_get_config(struct udevice *dev, uint channel, uint *period_nsp,
 			   uint *duty_nsp, bool *enablep, bool *polarityp);
 
+/**
+ * sandbox_sf_set_block_protect() - Set the BP bits of the status register
+ *
+ * @dev: Device to update
+ * @bp_mask: BP bits to set (bits 2:0, so a value of 0 to 7)
+ */
+void sandbox_sf_set_block_protect(struct udevice *dev, int bp_mask);
+
 #endif
diff --git a/drivers/mtd/spi/sandbox.c b/drivers/mtd/spi/sandbox.c
index 7fef754c634..7b9891cb981 100644
--- a/drivers/mtd/spi/sandbox.c
+++ b/drivers/mtd/spi/sandbox.c
@@ -57,6 +57,8 @@ static const char *sandbox_sf_state_name(enum sandbox_sf_state state)
 /* Bits for the status register */
 #define STAT_WIP	(1 << 0)
 #define STAT_WEL	(1 << 1)
+#define STAT_BP_SHIFT	2
+#define STAT_BP_MASK	(7 << STAT_BP_SHIFT)
 
 /* Assume all SPI flashes have 3 byte addresses since they do atm */
 #define SF_ADDR_LEN	3
@@ -102,6 +104,14 @@ struct sandbox_spi_flash_plat_data {
 	int cs;
 };
 
+void sandbox_sf_set_block_protect(struct udevice *dev, int bp_mask)
+{
+	struct sandbox_spi_flash *sbsf = dev_get_priv(dev);
+
+	sbsf->status &= ~STAT_BP_MASK;
+	sbsf->status |= bp_mask << STAT_BP_SHIFT;
+}
+
 /**
  * This is a very strange probe function. If it has platform data (which may
  * have come from the device tree) then this function gets the filename and
diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c
index 662525f016f..719a2fd23ae 100644
--- a/drivers/mtd/spi/sf-uclass.c
+++ b/drivers/mtd/spi/sf-uclass.c
@@ -28,6 +28,15 @@ int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len)
 	return log_ret(sf_get_ops(dev)->erase(dev, offset, len));
 }
 
+int spl_flash_get_sw_write_prot(struct udevice *dev)
+{
+	struct dm_spi_flash_ops *ops = sf_get_ops(dev);
+
+	if (!ops->get_sw_write_prot)
+		return -ENOSYS;
+	return log_ret(ops->get_sw_write_prot(dev));
+}
+
 /*
  * TODO(sjg at chromium.org): This is an old-style function. We should remove
  * it when all SPI flash drivers use dm
diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
index 26f5c7c995e..46a50444175 100644
--- a/drivers/mtd/spi/sf_internal.h
+++ b/drivers/mtd/spi/sf_internal.h
@@ -170,6 +170,9 @@ int spi_flash_cmd_write(struct spi_slave *spi, const u8 *cmd, size_t cmd_len,
 /* Flash erase(sectors) operation, support all possible erase commands */
 int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len);
 
+/* Get software write-protect value (BP bits) */
+int spi_flash_cmd_get_sw_write_prot(struct spi_flash *flash);
+
 /* Lock stmicro spi flash region */
 int stm_lock(struct spi_flash *flash, u32 ofs, size_t len);
 
diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index 94fde2ae7a3..5a2e932de8f 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -124,6 +124,13 @@ static int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len)
 	return spi_flash_cmd_erase_ops(flash, offset, len);
 }
 
+static int spi_flash_std_get_sw_write_prot(struct udevice *dev)
+{
+	struct spi_flash *flash = dev_get_uclass_priv(dev);
+
+	return spi_flash_cmd_get_sw_write_prot(flash);
+}
+
 static int spi_flash_std_probe(struct udevice *dev)
 {
 	struct spi_slave *slave = dev_get_parent_priv(dev);
@@ -141,6 +148,7 @@ static const struct dm_spi_flash_ops spi_flash_std_ops = {
 	.read = spi_flash_std_read,
 	.write = spi_flash_std_write,
 	.erase = spi_flash_std_erase,
+	.get_sw_write_prot = spi_flash_std_get_sw_write_prot,
 };
 
 static const struct udevice_id spi_flash_std_ids[] = {
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
index a87bacd4ac7..0c2392f28a4 100644
--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -110,6 +110,18 @@ static int write_cr(struct spi_flash *flash, u8 wc)
 }
 #endif
 
+int spi_flash_cmd_get_sw_write_prot(struct spi_flash *flash)
+{
+	u8 status;
+	int ret;
+
+	ret = read_sr(flash, &status);
+	if (ret)
+		return ret;
+
+	return (status >> 2) & 7;
+}
+
 #ifdef CONFIG_SPI_FLASH_BAR
 /*
  * This "clean_bar" is necessary in a situation when one was accessing
diff --git a/include/spi_flash.h b/include/spi_flash.h
index 0ec98fb55df..e427e960d54 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -112,6 +112,19 @@ struct dm_spi_flash_ops {
 	int (*write)(struct udevice *dev, u32 offset, size_t len,
 		     const void *buf);
 	int (*erase)(struct udevice *dev, u32 offset, size_t len);
+	/**
+	 * get_sw_write_prot() - Check state of software write-protect feature
+	 *
+	 * SPI flash chips can lock a region of the flash defined by a
+	 * 'protected area'. This function checks if this protected area is
+	 * defined.
+	 *
+	 * @dev:	SPI flash device
+	 * @return 0 if no region is write-protected, 1 if a region is
+	 *	write-protected, -ENOSYS if the driver does not implement this,
+	 *	other -ve value on error
+	 */
+	int (*get_sw_write_prot)(struct udevice *dev);
 };
 
 /* Access the serial operations for a device */
@@ -153,6 +166,20 @@ int spi_flash_write_dm(struct udevice *dev, u32 offset, size_t len,
  */
 int spi_flash_erase_dm(struct udevice *dev, u32 offset, size_t len);
 
+/**
+ * spl_flash_get_sw_write_prot() - Check state of software write-protect feature
+ *
+ * SPI flash chips can lock a region of the flash defined by a
+ * 'protected area'. This function checks if this protected area is
+ * defined.
+ *
+ * @dev:	SPI flash device
+ * @return 0 if no region is write-protected, 1 if a region is
+ *	write-protected, -ENOSYS if the driver does not implement this,
+ *	other -ve value on error
+ */
+int spl_flash_get_sw_write_prot(struct udevice *dev);
+
 int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
 			   unsigned int max_hz, unsigned int spi_mode,
 			   struct udevice **devp);
diff --git a/test/dm/sf.c b/test/dm/sf.c
index b23e7f8edd4..35dce4e4c98 100644
--- a/test/dm/sf.c
+++ b/test/dm/sf.c
@@ -11,6 +11,7 @@
 #include <spi.h>
 #include <spi_flash.h>
 #include <asm/state.h>
+#include <asm/test.h>
 #include <dm/test.h>
 #include <dm/util.h>
 #include <test/ut.h>
@@ -45,6 +46,14 @@ static int dm_test_spi_flash(struct unit_test_state *uts)
 	ut_assertok(spi_flash_read_dm(dev, 0, size, dst));
 	ut_assertok(memcmp(src, dst, size));
 
+	/* Try the write-protect stuff */
+	ut_assertok(uclass_first_device_err(UCLASS_SPI_EMUL, &emul));
+	ut_asserteq(0, spl_flash_get_sw_write_prot(dev));
+	sandbox_sf_set_block_protect(emul, 1);
+	ut_asserteq(1, spl_flash_get_sw_write_prot(dev));
+	sandbox_sf_set_block_protect(emul, 0);
+	ut_asserteq(0, spl_flash_get_sw_write_prot(dev));
+
 	/*
 	 * Since we are about to destroy all devices, we must tell sandbox
 	 * to forget the emulation device
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 25/25] mmc: Add hardware partition support
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (23 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 24/25] sf: Add a method to obtain the block-protect setting Simon Glass
@ 2018-11-06 22:21 ` Simon Glass
  2018-11-07  7:38   ` Faiz Abbas
  2018-11-22 20:20 ` [U-Boot] [PATCH 23/25] test: sf: Add a simple SPI flash test sjg at google.com
                   ` (17 subsequent siblings)
  42 siblings, 1 reply; 58+ messages in thread
From: Simon Glass @ 2018-11-06 22:21 UTC (permalink / raw)
  To: u-boot

MMC devices support multiple partitions, defined by the hardware. At
present U-Boot can only access partition zero. Add support for selecting
other partitions.

Also add a way to check if a partition is write-protected.
Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/mmc/mmc.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 include/mmc.h     | 31 +++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+)

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index d6b9cdc9922..5b542524338 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -1128,6 +1128,52 @@ int mmc_hwpart_config(struct mmc *mmc,
 
 	return 0;
 }
+
+int mmc_hwpart_access(struct mmc *mmc, int part)
+{
+	int err;
+	struct mmc_cmd cmd;
+
+	cmd.cmdidx = MMC_CMD_SWITCH;
+	cmd.resp_type = MMC_RSP_R1b;
+
+	/* Clear partition access bits */
+	cmd.cmdarg = (MMC_SWITCH_MODE_CLEAR_BITS << 24) |
+			(EXT_CSD_PART_CONF << 16) |
+			(EXT_CSD_PARTITION_ACCESS(0x7) << 8);
+
+	err = mmc_send_cmd(mmc, &cmd, NULL);
+	if (err) {
+		debug("Failed to clear partition access bits\n");
+		return err;
+	}
+
+	/* Set partition access bits */
+	cmd.cmdarg = (MMC_SWITCH_MODE_SET_BITS << 24) |
+			(EXT_CSD_PART_CONF << 16) |
+			(EXT_CSD_PARTITION_ACCESS(part) << 8);
+
+	err = mmc_send_cmd(mmc, &cmd, NULL);
+	if (err) {
+		debug("Failed to change partition\n");
+		return err;
+	}
+
+	return 0;
+}
+
+int mmc_get_boot_wp(struct mmc *mmc)
+{
+	ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN);
+	int err;
+
+	err = mmc_send_ext_csd(mmc, ext_csd);
+	if (err)
+		return err;
+
+	return ext_csd[EXT_CSD_BOOT_WP] & (EXT_CSD_BOOT_WP_PWR_WP_EN
+			| EXT_CSD_BOOT_WP_PERM_WP_EN);
+}
 #endif
 
 #if !CONFIG_IS_ENABLED(DM_MMC)
diff --git a/include/mmc.h b/include/mmc.h
index 95548e94c4d..1d0f978f8af 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -215,6 +215,7 @@ static inline bool mmc_is_tuning_cmd(uint cmdidx)
 #define EXT_CSD_WR_REL_PARAM		166	/* R */
 #define EXT_CSD_WR_REL_SET		167	/* R/W */
 #define EXT_CSD_RPMB_MULT		168	/* RO */
+#define EXT_CSD_BOOT_WP			173	/* R/W */
 #define EXT_CSD_ERASE_GROUP_DEF		175	/* R/W */
 #define EXT_CSD_BOOT_BUS_WIDTH		177
 #define EXT_CSD_PART_CONF		179	/* R/W */
@@ -279,6 +280,15 @@ static inline bool mmc_is_tuning_cmd(uint cmdidx)
 #define EXT_CSD_EXTRACT_BOOT_PART(x)		(((x) >> 3) & 0x7)
 #define EXT_CSD_EXTRACT_PARTITION_ACCESS(x)	((x) & 0x7)
 
+/* Enable boot power-on write protect */
+#define EXT_CSD_BOOT_WP_PWR_WP_EN	BIT(0)
+/* Enable boot permanent write protect */
+#define EXT_CSD_BOOT_WP_PERM_WP_EN	BIT(2)
+/* Disable use of boot power-on write protect */
+#define EXT_CSD_BOOT_WP_PWR_WP_DIS	BIT(6)
+/* Bit 1 (Power-on) or Bit 3 (Permanent) selects the partition to protect */
+#define EXT_CSD_BOOT_WP_PART_SELECT	BIT(7)
+
 #define EXT_CSD_BOOT_BUS_WIDTH_MODE(x)	(x << 3)
 #define EXT_CSD_BOOT_BUS_WIDTH_RESET(x)	(x << 2)
 #define EXT_CSD_BOOT_BUS_WIDTH_WIDTH(x)	(x)
@@ -735,6 +745,27 @@ int mmc_switch_part(struct mmc *mmc, unsigned int part_num);
 int mmc_hwpart_config(struct mmc *mmc, const struct mmc_hwpart_conf *conf,
 		      enum mmc_hwpart_conf_mode mode);
 
+/**
+ * Get boot partition write protect status
+ *
+ * @param mmc	MMC to get status of
+ * @return	0 if WP is not asserted, non-zero if WP is asserted
+ */
+int mmc_get_boot_wp(struct mmc *mmc);
+
+/**
+ * Change MMC Partition
+ *
+ * Switch access to partition specified in part.  Unlike mmc_boot_part_access,
+ * this function will not affect the configured boot partition or boot ack
+ * settings.
+ *
+ * @param mmc	MMC to configure
+ * @param part	Partition to access (one of PARTITION_ACCESS from spec)
+ * #return 0 on success, -ve on error
+ */
+int mmc_hwpart_access(struct mmc *mmc, int part);
+
 #if !CONFIG_IS_ENABLED(DM_MMC)
 int mmc_getcd(struct mmc *mmc);
 int board_mmc_getcd(struct mmc *mmc);
-- 
2.19.1.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 09/25] sandbox: cros_ec: exynos: Drop use of cros_ec_get_error()
  2018-11-06 22:21 ` [U-Boot] [PATCH 09/25] sandbox: cros_ec: exynos: Drop use of cros_ec_get_error() Simon Glass
@ 2018-11-07  2:27   ` Minkyu Kang
  2018-11-22 20:20   ` sjg at google.com
  1 sibling, 0 replies; 58+ messages in thread
From: Minkyu Kang @ 2018-11-07  2:27 UTC (permalink / raw)
  To: u-boot

On 07/11/18 07:21, Simon Glass wrote:
> This function is really just a call to uclass_get_device() and there is no
> reason why the caller cannot do it. Update sandbox and snow accordingly.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 
>  board/samsung/common/board.c | 10 ++++++----
>  board/sandbox/sandbox.c      |  9 ++++++---
>  common/cros_ec.c             | 12 ------------
>  3 files changed, 12 insertions(+), 19 deletions(-)
> 

Acked-by: Minkyu Kang <mk7.kang@samsung.com>

Thanks,
Minkyu Kang.

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 12/25] spl: Correct malloc debugging in board_init_r()
  2018-11-06 22:21 ` [U-Boot] [PATCH 12/25] spl: Correct malloc debugging in board_init_r() Simon Glass
@ 2018-11-07  6:22   ` Simon Goldschmidt
  2018-11-07 17:09     ` Simon Glass
  0 siblings, 1 reply; 58+ messages in thread
From: Simon Goldschmidt @ 2018-11-07  6:22 UTC (permalink / raw)
  To: u-boot

On Tue, Nov 6, 2018 at 11:22 PM Simon Glass <sjg@chromium.org> wrote:
>
> SPL does not support %#x in printf() strings so we must write out the 0x
> explicitly. Update the code for this.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>

This has already been covered by my patch here:
https://patchwork.ozlabs.org/patch/992555/

However, my patch fixes three more places of debug printf formatters
not supported in SPL.

Anyway:
Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>

> ---
>
>  common/spl/spl.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/common/spl/spl.c b/common/spl/spl.c
> index 292e659c9ac..c855bb7ca4a 100644
> --- a/common/spl/spl.c
> +++ b/common/spl/spl.c
> @@ -554,7 +554,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
>                 debug("Unsupported OS image.. Jumping nevertheless..\n");
>         }
>  #if CONFIG_VAL(SYS_MALLOC_F_LEN) && !defined(CONFIG_SYS_SPL_MALLOC_SIZE)
> -       debug("SPL malloc() used %#lx bytes (%ld KB)\n", gd->malloc_ptr,
> +       debug("SPL malloc() used 0x%lx bytes (%ld KB)\n", gd->malloc_ptr,
>               gd->malloc_ptr / 1024);
>  #endif
>  #ifdef CONFIG_BOOTSTAGE_STASH
> --
> 2.19.1.930.g4563a0d9d0-goog
>

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 25/25] mmc: Add hardware partition support
  2018-11-06 22:21 ` [U-Boot] [PATCH 25/25] mmc: Add hardware partition support Simon Glass
@ 2018-11-07  7:38   ` Faiz Abbas
  2018-11-18 21:23     ` Simon Glass
  0 siblings, 1 reply; 58+ messages in thread
From: Faiz Abbas @ 2018-11-07  7:38 UTC (permalink / raw)
  To: u-boot

Hi Simon,

On Wednesday 07 November 2018 03:51 AM, Simon Glass wrote:
> MMC devices support multiple partitions, defined by the hardware. At
> present U-Boot can only access partition zero. Add support for selecting
> other partitions.
> 

There is already support to switch to another hardware partition.

See: mmc_select_hwpart()

Is this not the same thing?

Thanks,
Faiz

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 17/25] tpm: Export the open/close functions
  2018-11-06 22:21 ` [U-Boot] [PATCH 17/25] tpm: Export the open/close functions Simon Glass
@ 2018-11-07  7:52   ` Miquel Raynal
  2018-11-18 21:23     ` Simon Glass
  2018-11-29 17:42     ` sjg at google.com
  0 siblings, 2 replies; 58+ messages in thread
From: Miquel Raynal @ 2018-11-07  7:52 UTC (permalink / raw)
  To: u-boot

Hi Simon,

Simon Glass <sjg@chromium.org> wrote on Tue,  6 Nov 2018 15:21:34 -0700:

> At present these functions are not accessible outside the TPM library, but
> in some cases we need to call them.

I was not aware, what is the use case? I don't get it.

> Export them in the header file and add
> a define for the SHA1 digest size.
> 
> Also adjust tpm_open() to call tpm_close() first so that the TPM is in a
> known state before opening (e.g. by a previous phase of U-Boot).
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 

[...]

> @@ -408,29 +435,12 @@ static int tpm_tis_lpc_open(struct udevice *dev)
>  		return ret;
>  	}
>  
> +	/* Certain TPMs need some delay here or they hang */
> +	udelay(10);
> +
>  	tpm_write_word(priv, TIS_STS_COMMAND_READY,
>  		       &regs[locality].tpm_status);

This is not in the commit message.

Perhaps, due to the nature of the changes, this patch would be best
split in 2 or 3?


Thanks,
Miquèl

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 18/25] tpm: Convert to use a device parameter
  2018-11-06 22:21 ` [U-Boot] [PATCH 18/25] tpm: Convert to use a device parameter Simon Glass
@ 2018-11-07  7:56   ` Miquel Raynal
  0 siblings, 0 replies; 58+ messages in thread
From: Miquel Raynal @ 2018-11-07  7:56 UTC (permalink / raw)
  To: u-boot

Hi Simon,

Simon Glass <sjg@chromium.org> wrote on Tue,  6 Nov 2018 15:21:35 -0700:

> At present many TPM calls assume there is only one TPM in the system and
> look up this TPM themselves. This is inconsistent with driver model, which
> expects all driver methods to have a device parameter. Update the code to
> correct this.
> 
> Also move to u8/32 instead of uint8_t/uint32_t to keep checkpatch happy.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---

Thanks for the cleanup!

Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>


Thanks,
Miquèl

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 12/25] spl: Correct malloc debugging in board_init_r()
  2018-11-07  6:22   ` Simon Goldschmidt
@ 2018-11-07 17:09     ` Simon Glass
  0 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-07 17:09 UTC (permalink / raw)
  To: u-boot

Hi Simon,

On 6 November 2018 at 23:22, Simon Goldschmidt
<simon.k.r.goldschmidt@gmail.com> wrote:
> On Tue, Nov 6, 2018 at 11:22 PM Simon Glass <sjg@chromium.org> wrote:
>>
>> SPL does not support %#x in printf() strings so we must write out the 0x
>> explicitly. Update the code for this.
>>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
>
> This has already been covered by my patch here:
> https://patchwork.ozlabs.org/patch/992555/
>
> However, my patch fixes three more places of debug printf formatters
> not supported in SPL.
>
> Anyway:
> Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
>

Yes, we should grab your one. Will mark this one superseded.

Regards,
Simon

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 22/25] misc: Update read() and write() methods to return bytes xfered
  2018-11-06 22:21 ` [U-Boot] [PATCH 22/25] misc: Update read() and write() methods to return bytes xfered Simon Glass
@ 2018-11-08 11:03   ` Patrick DELAUNAY
  2018-11-22 20:20   ` sjg at google.com
  1 sibling, 0 replies; 58+ messages in thread
From: Patrick DELAUNAY @ 2018-11-08 11:03 UTC (permalink / raw)
  To: u-boot

Hi Simon, 

> From: Simon Glass <sjg@chromium.org>
> Sent: mardi 6 novembre 2018 23:22
> Subject: [PATCH 22/25] misc: Update read() and write() methods to return bytes
> 
> At present these functions return 0 on success. For some devices we want to
> know how many bytes were transferred. It seems useful to adjust the API to be
> more like the POSIX read() and write() functions.
> 
> Update these two methods, a test and all users.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 
>  arch/arm/mach-stm32mp/cpu.c    |  4 ++--
>  drivers/clk/clk_vexpress_osc.c |  4 ++--
>  drivers/misc/altera_sysid.c    |  2 +-
>  drivers/misc/misc_sandbox.c    |  4 ++--
>  drivers/misc/rockchip-efuse.c  |  2 +-
>  drivers/misc/stm32mp_fuse.c    | 12 ++++++++++++
>  include/misc.h                 |  8 ++++----
>  7 files changed, 24 insertions(+), 12 deletions(-)

Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 20/25] efi_loader: Don't enable in SPL/TPL by default
  2018-11-06 22:21 ` [U-Boot] [PATCH 20/25] efi_loader: Don't enable in SPL/TPL by default Simon Glass
@ 2018-11-14 13:28   ` Alexander Graf
  2018-11-18 21:23     ` Simon Glass
  0 siblings, 1 reply; 58+ messages in thread
From: Alexander Graf @ 2018-11-14 13:28 UTC (permalink / raw)
  To: u-boot

On 11/06/2018 11:21 PM, Simon Glass wrote:
> Generally this functionality is not useful in SPL or TPL. Update the
> Makefile so that it is not built.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>   lib/Makefile | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/lib/Makefile b/lib/Makefile
> index 4d2e22027d0..4dba3628e78 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -5,10 +5,10 @@
>   
>   ifndef CONFIG_SPL_BUILD
>   
> -obj-$(CONFIG_EFI) += efi/
> -obj-$(CONFIG_EFI_LOADER) += efi_driver/
> -obj-$(CONFIG_EFI_LOADER) += efi_loader/
> -obj-$(CONFIG_EFI_LOADER) += efi_selftest/
> +obj-$(CONFIG_$(SPL_TPL_)EFI) += efi/
> +obj-$(CONFIG_$(SPL_TPL_)EFI_LOADER) += efi_driver/
> +obj-$(CONFIG_$(SPL_TPL_)EFI_LOADER) += efi_loader/
> +obj-$(CONFIG_$(SPL_TPL_)EFI_LOADER) += efi_selftest/

This is already in the "ifndef CONFIG_SPL_BUILD" segment.

I'd rather like to see you remove that whole ifndef section including 
lzma, bzip2, tizen etc and convert (at least most of it) to the SPL_TPL_ 
magic you applied here.


Alex

>   obj-$(CONFIG_LZMA) += lzma/
>   obj-$(CONFIG_BZIP2) += bzip2/
>   obj-$(CONFIG_TIZEN) += tizen/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 17/25] tpm: Export the open/close functions
  2018-11-07  7:52   ` Miquel Raynal
@ 2018-11-18 21:23     ` Simon Glass
  2018-11-29 17:42     ` sjg at google.com
  1 sibling, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-18 21:23 UTC (permalink / raw)
  To: u-boot

Hi Miquel,

On Wed, 7 Nov 2018 at 00:52, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
>
> Hi Simon,
>
> Simon Glass <sjg@chromium.org> wrote on Tue,  6 Nov 2018 15:21:34 -0700:
>
> > At present these functions are not accessible outside the TPM library, but
> > in some cases we need to call them.
>
> I was not aware, what is the use case? I don't get it.

I believe this is for when TPL sets up the TPM but we need to access
it again in U-Boot proper, so close it before opening it again. I'm
not 100% sure though.

>
> > Export them in the header file and add
> > a define for the SHA1 digest size.
> >
> > Also adjust tpm_open() to call tpm_close() first so that the TPM is in a
> > known state before opening (e.g. by a previous phase of U-Boot).
> >
> > Signed-off-by: Simon Glass <sjg@chromium.org>
> > ---
> >
>
> [...]
>
> > @@ -408,29 +435,12 @@ static int tpm_tis_lpc_open(struct udevice *dev)
> >               return ret;
> >       }
> >
> > +     /* Certain TPMs need some delay here or they hang */
> > +     udelay(10);
> > +
> >       tpm_write_word(priv, TIS_STS_COMMAND_READY,
> >                      &regs[locality].tpm_status);
>
> This is not in the commit message.
>
> Perhaps, due to the nature of the changes, this patch would be best
> split in 2 or 3?

OK will do.

Regards,
Simon

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 25/25] mmc: Add hardware partition support
  2018-11-07  7:38   ` Faiz Abbas
@ 2018-11-18 21:23     ` Simon Glass
  0 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-18 21:23 UTC (permalink / raw)
  To: u-boot

Hi Faiz,
On Wed, 7 Nov 2018 at 00:36, Faiz Abbas <faiz_abbas@ti.com> wrote:
>
> Hi Simon,
>
> On Wednesday 07 November 2018 03:51 AM, Simon Glass wrote:
> > MMC devices support multiple partitions, defined by the hardware. At
> > present U-Boot can only access partition zero. Add support for selecting
> > other partitions.
> >
>
> There is already support to switch to another hardware partition.
>
> See: mmc_select_hwpart()
>
> Is this not the same thing?

That is in the legacy MMC code and will be removed soon. I thought
these functions were already present, but didn't think to look in
mmc_legacy.c

So I think we do need this patch, or something like it.

Regards,
Simon

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 20/25] efi_loader: Don't enable in SPL/TPL by default
  2018-11-14 13:28   ` Alexander Graf
@ 2018-11-18 21:23     ` Simon Glass
  0 siblings, 0 replies; 58+ messages in thread
From: Simon Glass @ 2018-11-18 21:23 UTC (permalink / raw)
  To: u-boot

Hi Alex,

On Wed, 14 Nov 2018 at 06:28, Alexander Graf <agraf@suse.de> wrote:
>
> On 11/06/2018 11:21 PM, Simon Glass wrote:
> > Generally this functionality is not useful in SPL or TPL. Update the
> > Makefile so that it is not built.
> >
> > Signed-off-by: Simon Glass <sjg@chromium.org>
> > ---
> >
> >   lib/Makefile | 8 ++++----
> >   1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/lib/Makefile b/lib/Makefile
> > index 4d2e22027d0..4dba3628e78 100644
> > --- a/lib/Makefile
> > +++ b/lib/Makefile
> > @@ -5,10 +5,10 @@
> >
> >   ifndef CONFIG_SPL_BUILD
> >
> > -obj-$(CONFIG_EFI) += efi/
> > -obj-$(CONFIG_EFI_LOADER) += efi_driver/
> > -obj-$(CONFIG_EFI_LOADER) += efi_loader/
> > -obj-$(CONFIG_EFI_LOADER) += efi_selftest/
> > +obj-$(CONFIG_$(SPL_TPL_)EFI) += efi/
> > +obj-$(CONFIG_$(SPL_TPL_)EFI_LOADER) += efi_driver/
> > +obj-$(CONFIG_$(SPL_TPL_)EFI_LOADER) += efi_loader/
> > +obj-$(CONFIG_$(SPL_TPL_)EFI_LOADER) += efi_selftest/
>
> This is already in the "ifndef CONFIG_SPL_BUILD" segment.
>
> I'd rather like to see you remove that whole ifndef section including
> lzma, bzip2, tizen etc and convert (at least most of it) to the SPL_TPL_
> magic you applied here.

Actually we can drop this patch. I wrote it thinking I might want to
control whether EFI_LOADER is in SPL, but in fact in the end I didn't
need to. Sorry for the noise.

Regards,
Simon

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 24/25] sf: Add a method to obtain the block-protect setting
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (25 preceding siblings ...)
  2018-11-22 20:20 ` [U-Boot] [PATCH 23/25] test: sf: Add a simple SPI flash test sjg at google.com
@ 2018-11-22 20:20 ` sjg at google.com
  2018-11-22 20:20 ` [U-Boot] [PATCH 21/25] string: Include the config header sjg at google.com
                   ` (15 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-22 20:20 UTC (permalink / raw)
  To: u-boot

It is useful to obtain the block-protect setting of the SPI flash, so we
know whether it is fully open or (perhaps partially) write-protected. Add
a method for this. Update the sandbox driver to process this operation and
add a test.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/include/asm/test.h |  8 ++++++++
 drivers/mtd/spi/sandbox.c       | 10 ++++++++++
 drivers/mtd/spi/sf-uclass.c     |  9 +++++++++
 drivers/mtd/spi/sf_internal.h   |  3 +++
 drivers/mtd/spi/sf_probe.c      |  8 ++++++++
 drivers/mtd/spi/spi_flash.c     | 12 ++++++++++++
 include/spi_flash.h             | 27 +++++++++++++++++++++++++++
 test/dm/sf.c                    |  9 +++++++++
 8 files changed, 86 insertions(+)

Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 23/25] test: sf: Add a simple SPI flash test
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (24 preceding siblings ...)
  2018-11-06 22:21 ` [U-Boot] [PATCH 25/25] mmc: Add hardware partition support Simon Glass
@ 2018-11-22 20:20 ` sjg at google.com
  2018-11-22 20:20 ` [U-Boot] [PATCH 24/25] sf: Add a method to obtain the block-protect setting sjg at google.com
                   ` (16 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-22 20:20 UTC (permalink / raw)
  To: u-boot

The current test is a functional test, covering all the way from the
command line to the sandbox SPI driver. This is useful, but it is easier
to diagnose failures with a smaller test.

Add a simple test which reads and writes data and checks that it is stored
and retrieved correctly.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 test/dm/sf.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)

Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 21/25] string: Include the config header
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (26 preceding siblings ...)
  2018-11-22 20:20 ` [U-Boot] [PATCH 24/25] sf: Add a method to obtain the block-protect setting sjg at google.com
@ 2018-11-22 20:20 ` sjg at google.com
  2018-11-22 20:20 ` [U-Boot] [PATCH 16/25] binman: Set the pathname correctly for ELF files sjg at google.com
                   ` (14 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-22 20:20 UTC (permalink / raw)
  To: u-boot

At present the config header is not included in this file, but it does use
a CONFIG option. Fix it.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 lib/string.c | 1 +
 1 file changed, 1 insertion(+)

Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 22/25] misc: Update read() and write() methods to return bytes xfered
  2018-11-06 22:21 ` [U-Boot] [PATCH 22/25] misc: Update read() and write() methods to return bytes xfered Simon Glass
  2018-11-08 11:03   ` Patrick DELAUNAY
@ 2018-11-22 20:20   ` sjg at google.com
  1 sibling, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-22 20:20 UTC (permalink / raw)
  To: u-boot

Hi Simon,

> From: Simon Glass <sjg@chromium.org>
> Sent: mardi 6 novembre 2018 23:22
> Subject: [PATCH 22/25] misc: Update read() and write() methods to return bytes
>
> At present these functions return 0 on success. For some devices we want to
> know how many bytes were transferred. It seems useful to adjust the API to be
> more like the POSIX read() and write() functions.
>
> Update these two methods, a test and all users.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  arch/arm/mach-stm32mp/cpu.c    |  4 ++--
>  drivers/clk/clk_vexpress_osc.c |  4 ++--
>  drivers/misc/altera_sysid.c    |  2 +-
>  drivers/misc/misc_sandbox.c    |  4 ++--
>  drivers/misc/rockchip-efuse.c  |  2 +-
>  drivers/misc/stm32mp_fuse.c    | 12 ++++++++++++
>  include/misc.h                 |  8 ++++----
>  7 files changed, 24 insertions(+), 12 deletions(-)

Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>

Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 19/25] video: Update video_set_default_colors() to support invert
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (28 preceding siblings ...)
  2018-11-22 20:20 ` [U-Boot] [PATCH 16/25] binman: Set the pathname correctly for ELF files sjg at google.com
@ 2018-11-22 20:20 ` sjg at google.com
  2018-11-22 20:20 ` [U-Boot] [PATCH 15/25] binman: Drop an unnecessary comma in blob handling sjg at google.com
                   ` (12 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-22 20:20 UTC (permalink / raw)
  To: u-boot

It is useful to be able to invert the colours in some cases so that the
text matches the background colour. Add a parameter to the function to
support this.

It is strange that function takes a private data structure from another
driver as an argument. It seems better to pass the device and have the
function internally work out how to find its required information.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/video/vidconsole-uclass.c |  2 +-
 drivers/video/video-uclass.c      | 27 +++++++++++++++++++--------
 include/video.h                   |  5 +++--
 3 files changed, 23 insertions(+), 11 deletions(-)

Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 16/25] binman: Set the pathname correctly for ELF files
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (27 preceding siblings ...)
  2018-11-22 20:20 ` [U-Boot] [PATCH 21/25] string: Include the config header sjg at google.com
@ 2018-11-22 20:20 ` sjg at google.com
  2018-11-22 20:20 ` [U-Boot] [PATCH 19/25] video: Update video_set_default_colors() to support invert sjg at google.com
                   ` (13 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-22 20:20 UTC (permalink / raw)
  To: u-boot

At present, stripped files don't have the right pathname which means that
blob compression cannot be used. Fix this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/binman/etype/u_boot_elf.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 15/25] binman: Drop an unnecessary comma in blob handling
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (29 preceding siblings ...)
  2018-11-22 20:20 ` [U-Boot] [PATCH 19/25] video: Update video_set_default_colors() to support invert sjg at google.com
@ 2018-11-22 20:20 ` sjg at google.com
  2018-11-22 20:20 ` [U-Boot] [PATCH 14/25] binman: Add a way to enable debugging from the build sjg at google.com
                   ` (11 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-22 20:20 UTC (permalink / raw)
  To: u-boot

This comma is not needed. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/binman/etype/blob.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 14/25] binman: Add a way to enable debugging from the build
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (30 preceding siblings ...)
  2018-11-22 20:20 ` [U-Boot] [PATCH 15/25] binman: Drop an unnecessary comma in blob handling sjg at google.com
@ 2018-11-22 20:20 ` sjg at google.com
  2018-11-22 20:20 ` [U-Boot] [PATCH 13/25] spl: lz4: Allow use of lz4 compression in SPL sjg at google.com
                   ` (10 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-22 20:20 UTC (permalink / raw)
  To: u-boot

When the build fails due to something wrong in binman it is sometimes
useful to get a full backtrace showing the location of the failure. Add
a BINMAN_DEBUG environment variable to support this along with some
documentation.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 Makefile            | 6 ++++--
 tools/binman/README | 6 ++++++
 2 files changed, 10 insertions(+), 2 deletions(-)

Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 13/25] spl: lz4: Allow use of lz4 compression in SPL
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (31 preceding siblings ...)
  2018-11-22 20:20 ` [U-Boot] [PATCH 14/25] binman: Add a way to enable debugging from the build sjg at google.com
@ 2018-11-22 20:20 ` sjg at google.com
  2018-11-22 20:20 ` [U-Boot] [PATCH 11/25] spl: Support bootstage, log, hash and early malloc in TPL sjg at google.com
                   ` (9 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-22 20:20 UTC (permalink / raw)
  To: u-boot

In some cases U-Boot is compressed and it is useful to be able to
decompress it in SPL. Add a Kconfig and Makefile change to allow this.
Note that this does not actually implement decompression.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 lib/Kconfig  | 8 ++++++++
 lib/Makefile | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 11/25] spl: Support bootstage, log, hash and early malloc in TPL
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (32 preceding siblings ...)
  2018-11-22 20:20 ` [U-Boot] [PATCH 13/25] spl: lz4: Allow use of lz4 compression in SPL sjg at google.com
@ 2018-11-22 20:20 ` sjg at google.com
  2018-11-22 20:20 ` [U-Boot] [PATCH 10/25] sandbox: Update some drivers to work in SPL/TPL sjg at google.com
                   ` (8 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-22 20:20 UTC (permalink / raw)
  To: u-boot

At present these features are supported in SPL but not TPL. Update the
Kconfig and Makefile to allow this.

Also add a few Makefile comments to make earier to track what is going on.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 common/Kconfig  | 35 +++++++++++++++++++++++++++++++++++
 common/Makefile | 10 +++++++---
 2 files changed, 42 insertions(+), 3 deletions(-)

Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 10/25] sandbox: Update some drivers to work in SPL/TPL
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (33 preceding siblings ...)
  2018-11-22 20:20 ` [U-Boot] [PATCH 11/25] spl: Support bootstage, log, hash and early malloc in TPL sjg at google.com
@ 2018-11-22 20:20 ` sjg at google.com
  2018-11-22 20:20 ` [U-Boot] [PATCH 07/25] sandbox: log: Add a category for sandbox sjg at google.com
                   ` (7 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-22 20:20 UTC (permalink / raw)
  To: u-boot

At present sandbox drivers are mostly not used before relocation. Some of
these are needed by Chromium OS verified boot, since it uses sandbox TPL,
so update them accordingly.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/dts/sandbox.dts | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 09/25] sandbox: cros_ec: exynos: Drop use of cros_ec_get_error()
  2018-11-06 22:21 ` [U-Boot] [PATCH 09/25] sandbox: cros_ec: exynos: Drop use of cros_ec_get_error() Simon Glass
  2018-11-07  2:27   ` Minkyu Kang
@ 2018-11-22 20:20   ` sjg at google.com
  1 sibling, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-22 20:20 UTC (permalink / raw)
  To: u-boot

On 07/11/18 07:21, Simon Glass wrote:
> This function is really just a call to uclass_get_device() and there is no
> reason why the caller cannot do it. Update sandbox and snow accordingly.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  board/samsung/common/board.c | 10 ++++++----
>  board/sandbox/sandbox.c      |  9 ++++++---
>  common/cros_ec.c             | 12 ------------
>  3 files changed, 12 insertions(+), 19 deletions(-)
>

Acked-by: Minkyu Kang <mk7.kang@samsung.com>

Thanks,
Minkyu Kang.


Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 07/25] sandbox: log: Add a category for sandbox
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (34 preceding siblings ...)
  2018-11-22 20:20 ` [U-Boot] [PATCH 10/25] sandbox: Update some drivers to work in SPL/TPL sjg at google.com
@ 2018-11-22 20:20 ` sjg at google.com
  2018-11-22 20:20 ` [U-Boot] [PATCH 08/25] sandbox: Add a function to read a host file sjg at google.com
                   ` (6 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-22 20:20 UTC (permalink / raw)
  To: u-boot

It seems useful to make sandbox its own log category since it is used for
so much testing. Add this as a new category.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/log.h | 1 +
 1 file changed, 1 insertion(+)

Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 08/25] sandbox: Add a function to read a host file
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (35 preceding siblings ...)
  2018-11-22 20:20 ` [U-Boot] [PATCH 07/25] sandbox: log: Add a category for sandbox sjg at google.com
@ 2018-11-22 20:20 ` sjg at google.com
  2018-11-22 20:20 ` [U-Boot] [PATCH 06/25] sandbox: tpm: Allow debugging of data packages sjg at google.com
                   ` (5 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-22 20:20 UTC (permalink / raw)
  To: u-boot

Add a way to read a file from the host filesystem. This can be useful for
reading test data, for example. Also fix up the writing function which was
not the right version, and drop the debugging lines.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/cpu/os.c | 44 ++++++++++++++++++++++++++++++++++++++++---
 include/os.h          | 14 ++++++++++++++
 2 files changed, 55 insertions(+), 3 deletions(-)

Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 06/25] sandbox: tpm: Allow debugging of data packages
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (36 preceding siblings ...)
  2018-11-22 20:20 ` [U-Boot] [PATCH 08/25] sandbox: Add a function to read a host file sjg at google.com
@ 2018-11-22 20:20 ` sjg at google.com
  2018-11-22 20:20 ` [U-Boot] [PATCH 05/25] cros_ec: Add new features for events and power sjg at google.com
                   ` (4 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-22 20:20 UTC (permalink / raw)
  To: u-boot

This is not normally useful, so change the code to avoid writing out every
data package. This can be enabled with #define DEBUG.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/tpm/tpm_tis_sandbox.c | 6 ++++++
 1 file changed, 6 insertions(+)

Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 05/25] cros_ec: Add new features for events and power
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (37 preceding siblings ...)
  2018-11-22 20:20 ` [U-Boot] [PATCH 06/25] sandbox: tpm: Allow debugging of data packages sjg at google.com
@ 2018-11-22 20:20 ` sjg at google.com
  2018-11-22 20:20 ` [U-Boot] [PATCH 03/25] cros_ec: Fail if we cannot determine the flash burst size sjg at google.com
                   ` (3 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-22 20:20 UTC (permalink / raw)
  To: u-boot

This adds new commands to the EC related to setting and clearing events
as well as controlling power-related settings.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec.c         | 345 ++++++++++++++++++++++++++++++++-
 drivers/misc/cros_ec_sandbox.c |   2 +-
 include/cros_ec.h              |  89 +++++++++
 3 files changed, 429 insertions(+), 7 deletions(-)

Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 04/25] cros_ec: Align uclass data to a cache boundary
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (39 preceding siblings ...)
  2018-11-22 20:20 ` [U-Boot] [PATCH 03/25] cros_ec: Fail if we cannot determine the flash burst size sjg at google.com
@ 2018-11-22 20:20 ` sjg at google.com
  2018-11-22 20:20 ` [U-Boot] [PATCH 02/25] cros_ec: Add error logging on a few commands sjg at google.com
  2018-11-22 20:20 ` [U-Boot] [PATCH 01/25] cros_ec: Use uint instead of u8 for parameters sjg at google.com
  42 siblings, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-22 20:20 UTC (permalink / raw)
  To: u-boot

The LPC driver expects its buffer to be word-aligned. Add the required
flag to the uclass driver to ensure this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec.c | 1 +
 1 file changed, 1 insertion(+)

Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 03/25] cros_ec: Fail if we cannot determine the flash burst size
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (38 preceding siblings ...)
  2018-11-22 20:20 ` [U-Boot] [PATCH 05/25] cros_ec: Add new features for events and power sjg at google.com
@ 2018-11-22 20:20 ` sjg at google.com
  2018-11-22 20:20 ` [U-Boot] [PATCH 04/25] cros_ec: Align uclass data to a cache boundary sjg at google.com
                   ` (2 subsequent siblings)
  42 siblings, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-22 20:20 UTC (permalink / raw)
  To: u-boot

This value is required for flashing to work correctly. Add a check for
it.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec.c | 3 +++
 1 file changed, 3 insertions(+)

Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 02/25] cros_ec: Add error logging on a few commands
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (40 preceding siblings ...)
  2018-11-22 20:20 ` [U-Boot] [PATCH 04/25] cros_ec: Align uclass data to a cache boundary sjg at google.com
@ 2018-11-22 20:20 ` sjg at google.com
  2018-11-22 20:20 ` [U-Boot] [PATCH 01/25] cros_ec: Use uint instead of u8 for parameters sjg at google.com
  42 siblings, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-22 20:20 UTC (permalink / raw)
  To: u-boot

Add some more logging to provide more information on failures.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 01/25] cros_ec: Use uint instead of u8 for parameters
  2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
                   ` (41 preceding siblings ...)
  2018-11-22 20:20 ` [U-Boot] [PATCH 02/25] cros_ec: Add error logging on a few commands sjg at google.com
@ 2018-11-22 20:20 ` sjg at google.com
  42 siblings, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-22 20:20 UTC (permalink / raw)
  To: u-boot

There is no advantage to using a u8 for function parameters. It forces
the compiler to mask values and can increase code size. Also the command
enum has been extended to 16 bits. Update the functions to use uint
instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/misc/cros_ec.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [U-Boot] [PATCH 17/25] tpm: Export the open/close functions
  2018-11-07  7:52   ` Miquel Raynal
  2018-11-18 21:23     ` Simon Glass
@ 2018-11-29 17:42     ` sjg at google.com
  1 sibling, 0 replies; 58+ messages in thread
From: sjg at google.com @ 2018-11-29 17:42 UTC (permalink / raw)
  To: u-boot

Hi Miquel,

On Wed, 7 Nov 2018 at 00:52, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
>
> Hi Simon,
>
> Simon Glass <sjg@chromium.org> wrote on Tue,  6 Nov 2018 15:21:34 -0700:
>
> > At present these functions are not accessible outside the TPM library, but
> > in some cases we need to call them.
>
> I was not aware, what is the use case? I don't get it.

I believe this is for when TPL sets up the TPM but we need to access
it again in U-Boot proper, so close it before opening it again. I'm
not 100% sure though.

>
> > Export them in the header file and add
> > a define for the SHA1 digest size.
> >
> > Also adjust tpm_open() to call tpm_close() first so that the TPM is in a
> > known state before opening (e.g. by a previous phase of U-Boot).
> >
> > Signed-off-by: Simon Glass <sjg@chromium.org>
> > ---
> >
>
> [...]
>
> > @@ -408,29 +435,12 @@ static int tpm_tis_lpc_open(struct udevice *dev)
> >               return ret;
> >       }
> >
> > +     /* Certain TPMs need some delay here or they hang */
> > +     udelay(10);
> > +
> >       tpm_write_word(priv, TIS_STS_COMMAND_READY,
> >                      &regs[locality].tpm_status);
>
> This is not in the commit message.
>
> Perhaps, due to the nature of the changes, this patch would be best
> split in 2 or 3?

OK will do.

Regards,
Simon

Applied to u-boot-dm/master, thanks!

^ permalink raw reply	[flat|nested] 58+ messages in thread

end of thread, other threads:[~2018-11-29 17:42 UTC | newest]

Thread overview: 58+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-06 22:21 [U-Boot] [PATCH 00/25] sandbox: Changes and improvements to support verified boot Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 01/25] cros_ec: Use uint instead of u8 for parameters Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 02/25] cros_ec: Add error logging on a few commands Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 03/25] cros_ec: Fail if we cannot determine the flash burst size Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 04/25] cros_ec: Align uclass data to a cache boundary Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 05/25] cros_ec: Add new features for events and power Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 06/25] sandbox: tpm: Allow debugging of data packages Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 07/25] sandbox: log: Add a category for sandbox Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 08/25] sandbox: Add a function to read a host file Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 09/25] sandbox: cros_ec: exynos: Drop use of cros_ec_get_error() Simon Glass
2018-11-07  2:27   ` Minkyu Kang
2018-11-22 20:20   ` sjg at google.com
2018-11-06 22:21 ` [U-Boot] [PATCH 10/25] sandbox: Update some drivers to work in SPL/TPL Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 11/25] spl: Support bootstage, log, hash and early malloc in TPL Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 12/25] spl: Correct malloc debugging in board_init_r() Simon Glass
2018-11-07  6:22   ` Simon Goldschmidt
2018-11-07 17:09     ` Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 13/25] spl: lz4: Allow use of lz4 compression in SPL Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 14/25] binman: Add a way to enable debugging from the build Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 15/25] binman: Drop an unnecessary comma in blob handling Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 16/25] binman: Set the pathname correctly for ELF files Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 17/25] tpm: Export the open/close functions Simon Glass
2018-11-07  7:52   ` Miquel Raynal
2018-11-18 21:23     ` Simon Glass
2018-11-29 17:42     ` sjg at google.com
2018-11-06 22:21 ` [U-Boot] [PATCH 18/25] tpm: Convert to use a device parameter Simon Glass
2018-11-07  7:56   ` Miquel Raynal
2018-11-06 22:21 ` [U-Boot] [PATCH 19/25] video: Update video_set_default_colors() to support invert Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 20/25] efi_loader: Don't enable in SPL/TPL by default Simon Glass
2018-11-14 13:28   ` Alexander Graf
2018-11-18 21:23     ` Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 21/25] string: Include the config header Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 22/25] misc: Update read() and write() methods to return bytes xfered Simon Glass
2018-11-08 11:03   ` Patrick DELAUNAY
2018-11-22 20:20   ` sjg at google.com
2018-11-06 22:21 ` [U-Boot] [PATCH 23/25] test: sf: Add a simple SPI flash test Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 24/25] sf: Add a method to obtain the block-protect setting Simon Glass
2018-11-06 22:21 ` [U-Boot] [PATCH 25/25] mmc: Add hardware partition support Simon Glass
2018-11-07  7:38   ` Faiz Abbas
2018-11-18 21:23     ` Simon Glass
2018-11-22 20:20 ` [U-Boot] [PATCH 23/25] test: sf: Add a simple SPI flash test sjg at google.com
2018-11-22 20:20 ` [U-Boot] [PATCH 24/25] sf: Add a method to obtain the block-protect setting sjg at google.com
2018-11-22 20:20 ` [U-Boot] [PATCH 21/25] string: Include the config header sjg at google.com
2018-11-22 20:20 ` [U-Boot] [PATCH 16/25] binman: Set the pathname correctly for ELF files sjg at google.com
2018-11-22 20:20 ` [U-Boot] [PATCH 19/25] video: Update video_set_default_colors() to support invert sjg at google.com
2018-11-22 20:20 ` [U-Boot] [PATCH 15/25] binman: Drop an unnecessary comma in blob handling sjg at google.com
2018-11-22 20:20 ` [U-Boot] [PATCH 14/25] binman: Add a way to enable debugging from the build sjg at google.com
2018-11-22 20:20 ` [U-Boot] [PATCH 13/25] spl: lz4: Allow use of lz4 compression in SPL sjg at google.com
2018-11-22 20:20 ` [U-Boot] [PATCH 11/25] spl: Support bootstage, log, hash and early malloc in TPL sjg at google.com
2018-11-22 20:20 ` [U-Boot] [PATCH 10/25] sandbox: Update some drivers to work in SPL/TPL sjg at google.com
2018-11-22 20:20 ` [U-Boot] [PATCH 07/25] sandbox: log: Add a category for sandbox sjg at google.com
2018-11-22 20:20 ` [U-Boot] [PATCH 08/25] sandbox: Add a function to read a host file sjg at google.com
2018-11-22 20:20 ` [U-Boot] [PATCH 06/25] sandbox: tpm: Allow debugging of data packages sjg at google.com
2018-11-22 20:20 ` [U-Boot] [PATCH 05/25] cros_ec: Add new features for events and power sjg at google.com
2018-11-22 20:20 ` [U-Boot] [PATCH 03/25] cros_ec: Fail if we cannot determine the flash burst size sjg at google.com
2018-11-22 20:20 ` [U-Boot] [PATCH 04/25] cros_ec: Align uclass data to a cache boundary sjg at google.com
2018-11-22 20:20 ` [U-Boot] [PATCH 02/25] cros_ec: Add error logging on a few commands sjg at google.com
2018-11-22 20:20 ` [U-Boot] [PATCH 01/25] cros_ec: Use uint instead of u8 for parameters sjg at google.com

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.