* [PATCH 0/2] allow to write protect single boot partition
@ 2022-04-25 13:59 Ying-Chun Liu
2022-04-25 13:59 ` [PATCH 1/2] drivers: mmc: write protect single boot area Ying-Chun Liu
2022-04-25 13:59 ` [PATCH 2/2] cmd: mmc: allow to write protect single boot partition Ying-Chun Liu
0 siblings, 2 replies; 3+ messages in thread
From: Ying-Chun Liu @ 2022-04-25 13:59 UTC (permalink / raw)
To: u-boot; +Cc: Ying-Chun Liu (PaulLiu)
From: "Ying-Chun Liu (PaulLiu)" <paul.liu@linaro.org>
Modify mmc wp command and mmc driver to allow write protect only
a single boot partition.
Ying-Chun Liu (PaulLiu) (2):
drivers: mmc: write protect single boot area
cmd: mmc: allow to write protect single boot partition
cmd/mmc.c | 18 +++++++++++++++---
drivers/mmc/mmc.c | 27 +++++++++++++++++++++++++++
include/mmc.h | 16 ++++++++++++++++
3 files changed, 58 insertions(+), 3 deletions(-)
--
2.35.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] drivers: mmc: write protect single boot area
2022-04-25 13:59 [PATCH 0/2] allow to write protect single boot partition Ying-Chun Liu
@ 2022-04-25 13:59 ` Ying-Chun Liu
2022-04-25 13:59 ` [PATCH 2/2] cmd: mmc: allow to write protect single boot partition Ying-Chun Liu
1 sibling, 0 replies; 3+ messages in thread
From: Ying-Chun Liu @ 2022-04-25 13:59 UTC (permalink / raw)
To: u-boot; +Cc: Ying-Chun Liu (PaulLiu), Peng Fan, Jaehoon Chung
From: "Ying-Chun Liu (PaulLiu)" <paul.liu@linaro.org>
Add features to write protect single boot area rather than all boot
areas.
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
---
drivers/mmc/mmc.c | 27 +++++++++++++++++++++++++++
include/mmc.h | 16 ++++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index f6ccd837aa..53f931e993 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -860,6 +860,33 @@ int mmc_boot_wp(struct mmc *mmc)
return mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BOOT_WP, 1);
}
+int mmc_boot_wp_single_partition(struct mmc *mmc, int partition)
+{
+ u8 value;
+ int ret;
+
+ value = EXT_CSD_BOOT_WP_B_PWR_WP_EN;
+
+ if (partition == 0) {
+ value |= EXT_CSD_BOOT_WP_B_SEC_WP_SEL;
+ ret = mmc_switch(mmc,
+ EXT_CSD_CMD_SET_NORMAL,
+ EXT_CSD_BOOT_WP,
+ value);
+ } else if (partition == 1) {
+ value |= EXT_CSD_BOOT_WP_B_SEC_WP_SEL;
+ value |= EXT_CSD_BOOT_WP_B_PWR_WP_SEC_SEL;
+ ret = mmc_switch(mmc,
+ EXT_CSD_CMD_SET_NORMAL,
+ EXT_CSD_BOOT_WP,
+ value);
+ } else {
+ ret = mmc_boot_wp(mmc);
+ }
+
+ return ret;
+}
+
#if !CONFIG_IS_ENABLED(MMC_TINY)
static int mmc_set_card_speed(struct mmc *mmc, enum bus_mode mode,
bool hsdowngrade)
diff --git a/include/mmc.h b/include/mmc.h
index 6bdcce881d..a1b3c49af4 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -308,6 +308,10 @@ static inline bool mmc_is_tuning_cmd(uint cmdidx)
#define EXT_CSD_HS_CTRL_REL (1 << 0) /* host controlled WR_REL_SET */
+#define EXT_CSD_BOOT_WP_B_SEC_WP_SEL (0x80) /* enable partition selector */
+#define EXT_CSD_BOOT_WP_B_PWR_WP_SEC_SEL (0x02) /* partition selector to protect */
+#define EXT_CSD_BOOT_WP_B_PWR_WP_EN (0x01) /* power-on write-protect */
+
#define EXT_CSD_WR_DATA_REL_USR (1 << 0) /* user data area WR_REL */
#define EXT_CSD_WR_DATA_REL_GP(x) (1 << ((x)+1)) /* GP part (x+1) WR_REL */
@@ -980,6 +984,18 @@ int mmc_send_ext_csd(struct mmc *mmc, u8 *ext_csd);
*/
int mmc_boot_wp(struct mmc *mmc);
+/**
+ * mmc_boot_wp_single_partition() - set write protection to a boot partition.
+ *
+ * This function sets a single boot partition to protect and leave the
+ * other partition writable.
+ *
+ * @param mmc the mmc device.
+ * @param partition 0 - first boot partition, 1 - second boot partition.
+ * @return 0 for success
+ */
+int mmc_boot_wp_single_partition(struct mmc *mmc, int partition);
+
static inline enum dma_data_direction mmc_get_dma_dir(struct mmc_data *data)
{
return data->flags & MMC_DATA_WRITE ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] cmd: mmc: allow to write protect single boot partition
2022-04-25 13:59 [PATCH 0/2] allow to write protect single boot partition Ying-Chun Liu
2022-04-25 13:59 ` [PATCH 1/2] drivers: mmc: write protect single boot area Ying-Chun Liu
@ 2022-04-25 13:59 ` Ying-Chun Liu
1 sibling, 0 replies; 3+ messages in thread
From: Ying-Chun Liu @ 2022-04-25 13:59 UTC (permalink / raw)
To: u-boot; +Cc: Ying-Chun Liu (PaulLiu), Peng Fan, Jaehoon Chung
From: "Ying-Chun Liu (PaulLiu)" <paul.liu@linaro.org>
add arguments for mmc wp to assign which boot partition to protect.
Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
---
cmd/mmc.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/cmd/mmc.c b/cmd/mmc.c
index 7464f8d00c..7f3e5da6cd 100644
--- a/cmd/mmc.c
+++ b/cmd/mmc.c
@@ -1046,6 +1046,7 @@ static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int flag,
{
int err;
struct mmc *mmc;
+ int part;
mmc = init_mmc_device(curr_device, false);
if (!mmc)
@@ -1054,7 +1055,14 @@ static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int flag,
printf("It is not an eMMC device\n");
return CMD_RET_FAILURE;
}
- err = mmc_boot_wp(mmc);
+
+ if (argc == 2) {
+ part = dectoul(argv[1], NULL);
+ err = mmc_boot_wp_single_partition(mmc, part);
+ } else {
+ err = mmc_boot_wp(mmc);
+ }
+
if (err)
return CMD_RET_FAILURE;
printf("boot areas protected\n");
@@ -1064,7 +1072,7 @@ static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int flag,
static struct cmd_tbl cmd_mmc[] = {
U_BOOT_CMD_MKENT(info, 1, 0, do_mmcinfo, "", ""),
U_BOOT_CMD_MKENT(read, 4, 1, do_mmc_read, "", ""),
- U_BOOT_CMD_MKENT(wp, 1, 0, do_mmc_boot_wp, "", ""),
+ U_BOOT_CMD_MKENT(wp, 2, 0, do_mmc_boot_wp, "", ""),
#if CONFIG_IS_ENABLED(MMC_WRITE)
U_BOOT_CMD_MKENT(write, 4, 0, do_mmc_write, "", ""),
U_BOOT_CMD_MKENT(erase, 3, 0, do_mmc_erase, "", ""),
@@ -1138,7 +1146,11 @@ U_BOOT_CMD(
" [MMC_LEGACY, MMC_HS, SD_HS, MMC_HS_52, MMC_DDR_52, UHS_SDR12, UHS_SDR25,\n"
" UHS_SDR50, UHS_DDR50, UHS_SDR104, MMC_HS_200, MMC_HS_400, MMC_HS_400_ES]\n"
"mmc list - lists available devices\n"
- "mmc wp - power on write protect boot partitions\n"
+ "mmc wp [PART] - power on write protect boot partitions\n"
+ " arguments:\n"
+ " PART - [0|1]\n"
+ " : 0 - first boot partition, 1 - second boot partition\n"
+ " if not assigned, write protect all boot partitions\n"
#if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING)
"mmc hwpartition <USER> <GP> <MODE> - does hardware partitioning\n"
" arguments (sizes in 512-byte blocks):\n"
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-04-25 13:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-25 13:59 [PATCH 0/2] allow to write protect single boot partition Ying-Chun Liu
2022-04-25 13:59 ` [PATCH 1/2] drivers: mmc: write protect single boot area Ying-Chun Liu
2022-04-25 13:59 ` [PATCH 2/2] cmd: mmc: allow to write protect single boot partition Ying-Chun Liu
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.