Skip to contentSkip to conversation

sandbox: Changes and improvements to support verified boot

PATCH New Simon Glass 2 participants 8 messages Nov 18, 2018 – Nov 29, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover sandbox: Changes and improvements to support verified boot

This series compiles a number of fixes and improvement sto 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.

Changes in v2:
- Split out from main TPM patch
- Split out from main TPM patch
- Correct missing conversions in tpm-v1.c
- Complete transition for gdsys powerpc boards
- Drop changes previously applied
- Drop patch 'efi_loader: Don't enable in SPL/TPL by default'

Simon Glass (5):
tpm: Add a delay on start-up
tpm: Add a constant for the minimum supported digest size
tpm: Export the open/close functions
tpm: Convert to use a device parameter
mmc: Add hardware partition support

 board/gdsys/a38x/controlcenterdc.c    |  25 +-
 board/gdsys/a38x/hre.c                |  66 +++---
 board/gdsys/a38x/hre.h                |   2 +-
 board/gdsys/a38x/keyprogram.c         |  12 +-
 board/gdsys/a38x/keyprogram.h         |   4 +-
 board/gdsys/p1022/controlcenterd-id.c | 117 +++++----
 cmd/tpm-common.c                      |   8 +-
 cmd/tpm-v1.c                          | 140 +++++++++--
 cmd/tpm-v2.c                          |  78 +++++-
 cmd/tpm_test.c                        | 327 ++++++++++++++------------
 drivers/mmc/mmc.c                     |  46 ++++
 drivers/tpm/tpm_tis_lpc.c             |  50 ++--
 include/mmc.h                         |  31 +++
 include/tpm-common.h                  |  36 ++-
 include/tpm-v1.h                      |  97 +++++---
 include/tpm-v2.h                      |  49 ++--
 lib/tpm-common.c                      |  16 +-
 lib/tpm-utils.h                       |  21 +-
 lib/tpm-v1.c                          | 142 +++++------
 lib/tpm-v2.c                          |  60 ++---
 20 files changed, 858 insertions(+), 469 deletions(-)
Signature · 1 line
2.19.1.1215.g8438c0b245-goog
#1 lore raw

PATCH v2 1/5 tpm: Add a delay on start-up

Some TPMs hang on startup without a short delay after getting the lock. Add a small delay to cope with this.

---

Changes in v2:
- Split out from main TPM patch

 drivers/tpm/tpm_tis_lpc.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/tpm/tpm_tis_lpc.c +3 -0
index e993fd9f833..79e952146c2 100644
@@ -408,6 +408,9 @@ 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;
Signature · 1 line
2.19.1.1215.g8438c0b245-goog
#2 lore raw

PATCH v2 2/5 tpm: Add a constant for the minimum supported digest size

In reply to Simon Glass

When SHA1 is used we need 20 bytes for the digest size. Add a constant so that clients can make use of this, e.g. to allocate local buffers.

---

Changes in v2:
- Split out from main TPM patch

 include/tpm-common.h | 2 ++
 1 file changed, 2 insertions(+)
include/tpm-common.h +2 -0
index 5f8bc6bc528..449ad4c96e1 100644
@@ -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
Signature · 1 line
2.19.1.1215.g8438c0b245-goog
#3 lore raw

PATCH v2 2/5 tpm: Add a constant for the minimum supported digest size

When SHA1 is used we need 20 bytes for the digest size. Add a constant so that clients can make use of this, e.g. to allocate local buffers.

---

Changes in v2:
- Split out from main TPM patch

 include/tpm-common.h | 2 ++
 1 file changed, 2 insertions(+)

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

#4 lore raw

PATCH v2 3/5 tpm: Export the open/close functions

In reply to Simon Glass

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).

---

Changes in v2: None

 drivers/tpm/tpm_tis_lpc.c | 47 ++++++++++++++++++++++-----------------
 include/tpm-common.h      | 18 +++++++++++++++
 lib/tpm-utils.h           | 18 ---------------
 3 files changed, 45 insertions(+), 38 deletions(-)
drivers/tpm/tpm_tis_lpc.c +27 -20
index 79e952146c2..d76d7ca75af 100644
@@ -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);
 
@@ -413,27 +440,7 @@ static int tpm_tis_lpc_open(struct udevice *dev)
 
 	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;
 }
 
include/tpm-common.h +18 -0
index 449ad4c96e1..f8c5569003e 100644
@@ -181,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
  *
lib/tpm-utils.h +0 -18
index a9cb7dc7ee5..ac95f262f56 100644
@@ -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,
Signature · 1 line
2.19.1.1215.g8438c0b245-goog
#5 lore raw

PATCH v2 4/5 tpm: Convert to use a device parameter

In reply to Simon Glass

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.

---

Changes in v2:
- Correct missing conversions in tpm-v1.c
- Complete transition for gdsys powerpc boards

 board/gdsys/a38x/controlcenterdc.c    |  25 +-
 board/gdsys/a38x/hre.c                |  66 +++---
 board/gdsys/a38x/hre.h                |   2 +-
 board/gdsys/a38x/keyprogram.c         |  12 +-
 board/gdsys/a38x/keyprogram.h         |   4 +-
 board/gdsys/p1022/controlcenterd-id.c | 117 +++++----
 cmd/tpm-common.c                      |   8 +-
 cmd/tpm-v1.c                          | 140 +++++++++--
 cmd/tpm-v2.c                          |  78 +++++-
 cmd/tpm_test.c                        | 327 ++++++++++++++------------
 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                          | 142 +++++------
 lib/tpm-v2.c                          |  60 ++---
 17 files changed, 731 insertions(+), 431 deletions(-)
board/gdsys/a38x/controlcenterdc.c +21 -4
index 824a08f12af..dd4c083fbd3 100644
@@ -34,6 +34,19 @@ DECLARE_GLOBAL_DATA_PTR;
 #define DB_GP_88F68XX_GPP_POL_LOW	0x0
 #define DB_GP_88F68XX_GPP_POL_MID	0x0
 
+static int get_tpm(struct udevice **devp)
+{
+	int rc;
+
+	rc = uclass_first_device_err(UCLASS_TPM, devp);
+	if (rc) {
+		printf("Could not find TPM (ret=%d)\n", rc);
+		return CMD_RET_FAILURE;
+	}
+
+	return 0;
+}
+
 /*
  * Define the DDR layout / topology here in the board file. This will
  * be used by the DDR3 init code in the SPL U-Boot version to configure
@@ -266,18 +279,22 @@ 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;
 	}
 
 	mdelay(37);
 
-	flush_keys();
-	load_and_run_keyprog();
+	flush_keys(tpm);
+	load_and_run_keyprog(tpm);
 
 	return 0;
 }
board/gdsys/a38x/hre.c +39 -27

203 lines not on this page · raw message

board/gdsys/a38x/hre.h +1 -1
index b562928a64c..da983aa452a 100644
@@ -32,6 +32,6 @@ enum {
 };
 
 int hre_verify_program(struct key_program *prg);
-int hre_run_program(const uint8_t *code, size_t code_size);
+int hre_run_program(struct udevice *tpm, const uint8_t *code, size_t code_size);
 
 #endif /* __HRE_H */
board/gdsys/a38x/keyprogram.c +7 -5
index 1fb5306b50f..291edc340df 100644
@@ -12,7 +12,7 @@
 
 #include "hre.h"
 
-int flush_keys(void)
+int flush_keys(struct udevice *tpm)
 {
 	u16 key_count;
 	u8 buf[288];
@@ -21,13 +21,15 @@ int flush_keys(void)
 	uint 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(tpm, TPM_CAP_HANDLE, TPM_RT_KEY, buf,
+				 sizeof(buf));
 	if (err)
 		return -1;
 	key_count = get_unaligned_be16(buf);
 	ptr = buf + 2;
 	for (i = 0; i < key_count; ++i, ptr += 4) {
-		err = tpm_flush_specific(get_unaligned_be32(ptr), TPM_RT_KEY);
+		err = tpm_flush_specific(tpm, get_unaligned_be32(ptr),
+					 TPM_RT_KEY);
 		if (err && err != TPM_KEY_OWNER_CONTROL)
 			return err;
 	}
@@ -121,7 +123,7 @@ struct key_program *parse_and_check_keyprog(u8 *progdata)
 	return result;
 }
 
-int load_and_run_keyprog(void)
+int load_and_run_keyprog(struct udevice *tpm)
 {
 	char *cmd = NULL;
 	u8 *binprog = NULL;
@@ -144,7 +146,7 @@ int load_and_run_keyprog(void)
 	if (!prog)
 		return 1;
 
-	if (hre_run_program(prog->code, prog->code_size)) {
+	if (hre_run_program(tpm, prog->code, prog->code_size)) {
 		free(prog);
 		return 1;
 	}
board/gdsys/a38x/keyprogram.h +2 -2
index a4877c73a8e..06889c67e46 100644
@@ -7,7 +7,7 @@
 #ifndef __KEYPROGRAM_H
 #define __KEYPROGRAM_H
 
-int load_and_run_keyprog(void);
-int flush_keys(void);
+int load_and_run_keyprog(struct udevice *tpm);
+int flush_keys(struct udevice *tpm);
 
 #endif /* __KEYPROGRAM_H */
board/gdsys/p1022/controlcenterd-id.c +73 -44

305 lines not on this page · raw message

cmd/tpm-common.c +7 -1
index 56443862c22..89f2aa001ba 100644
@@ -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[])
cmd/tpm-v1.c +120 -20

371 lines not on this page · raw message

cmd/tpm-v2.c +65 -13

212 lines not on this page · raw message

cmd/tpm_test.c +172 -155

578 lines not on this page · raw message

include/tpm-common.h +14 -2
index f8c5569003e..3d88b44db7a 100644
@@ -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.
include/tpm-v1.h +66 -31

332 lines not on this page · raw message

include/tpm-v2.h +32 -17

156 lines not on this page · raw message

lib/tpm-common.c +3 -13
index a440639cec3..6afe59b1fec 100644
@@ -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);
 }
lib/tpm-utils.h +2 -1
index ac95f262f56..d680d140884 100644
@@ -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 */
lib/tpm-v1.c +75 -67

442 lines not on this page · raw message

lib/tpm-v2.c +32 -28

162 lines not on this page · raw message

Signature · 1 line
2.19.1.1215.g8438c0b245-goog
#6 lore raw

PATCH v2 4/5 tpm: Convert to use a device parameter

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.

---

Changes in v2:
- Correct missing conversions in tpm-v1.c
- Complete transition for gdsys powerpc boards

 board/gdsys/a38x/controlcenterdc.c    |  25 +-
 board/gdsys/a38x/hre.c                |  66 +++---
 board/gdsys/a38x/hre.h                |   2 +-
 board/gdsys/a38x/keyprogram.c         |  12 +-
 board/gdsys/a38x/keyprogram.h         |   4 +-
 board/gdsys/p1022/controlcenterd-id.c | 117 +++++----
 cmd/tpm-common.c                      |   8 +-
 cmd/tpm-v1.c                          | 140 +++++++++--
 cmd/tpm-v2.c                          |  78 +++++-
 cmd/tpm_test.c                        | 327 ++++++++++++++------------
 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                          | 142 +++++------
 lib/tpm-v2.c                          |  60 ++---
 17 files changed, 731 insertions(+), 431 deletions(-)

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

#7 lore raw

PATCH v2 5/5 mmc: Add hardware partition support

In reply to Simon Glass

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.

Note: There is existing support for this in the legacy MMC code, but this is being removed soon.

Process-logs: sort, uniq

---

Changes in v2:
- Drop changes previously applied
- Drop patch 'efi_loader: Don't enable in SPL/TPL by default'

 drivers/mmc/mmc.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 include/mmc.h     | 31 +++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+)
drivers/mmc/mmc.c +46 -0
index d6b9cdc9922..5b542524338 100644
@@ -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)
include/mmc.h +31 -0
index 95548e94c4d..1d0f978f8af 100644
@@ -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);
Signature · 1 line
2.19.1.1215.g8438c0b245-goog