[PATCH v2 03/10] mci: detect RPMB partitions
Sascha Hauer
s.hauer at pengutronix.de
Wed Mar 19 08:30:54 PDT 2025
Detect RPMB partitions and initialize a struct mci_part for them. We do
not actually register the RPMB partitions as we can't access them with
regular mci_do_block_op() and we would only access encrypted data anyway.
Right now we assume that only one RPMB is present in a system which
covers the 99% case. Should there be multiple RPMBs found we issue a
warning message as there is no way to specify which one shall be used,
the first one found will be used which may vary depending on probe
order.
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
drivers/mci/mci-core.c | 20 ++++++++++++++++++++
include/mci.h | 7 ++++++-
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index b7ea0df3cb..3bf0f15def 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -671,6 +671,9 @@ static void mci_part_add(struct mci *mci, uint64_t size,
part->part_cfg = part_cfg;
part->idx = idx;
+ if (area_type == MMC_BLK_DATA_AREA_RPMB)
+ mci->rpmb_part = part;
+
if (area_type == MMC_BLK_DATA_AREA_MAIN) {
cdev_set_of_node(&part->blk.cdev, mci->host->hw_dev->of_node);
part->blk.cdev.flags |= DEVFS_IS_MCI_MAIN_PART_DEV;
@@ -822,6 +825,20 @@ static int mmc_change_freq(struct mci *mci)
mci->boot_ack_enable = (mci->ext_csd_part_config >> 6) & 0x1;
}
+ if (mci->ext_csd[EXT_CSD_REV] >= 5) {
+ if (mci->ext_csd[EXT_CSD_RPMB_SIZE_MULT]) {
+ char *name, *partname;
+
+ partname = basprintf("rpmb");
+ name = basprintf("%s.%s", mci->cdevname, partname);
+
+ mci_part_add(mci, mci->ext_csd[EXT_CSD_RPMB_SIZE_MULT] << 17,
+ EXT_CSD_PART_CONFIG_ACC_RPMB,
+ name, partname, 0, false,
+ MMC_BLK_DATA_AREA_RPMB);
+ }
+ }
+
if (IS_ENABLED(CONFIG_MCI_MMC_GPP_PARTITIONS))
mmc_extract_gpp_partitions(mci);
@@ -2601,6 +2618,9 @@ static int mci_register_partition(struct mci_part *part)
part->blk.ops = &mci_ops;
part->blk.type = IS_SD(mci) ? BLK_TYPE_SD : BLK_TYPE_MMC;
+ if (part->area_type == MMC_BLK_DATA_AREA_RPMB)
+ return 0;
+
rc = blockdevice_register(&part->blk);
if (rc != 0) {
dev_err(&mci->dev, "Failed to register MCI/SD blockdevice\n");
diff --git a/include/mci.h b/include/mci.h
index 8084df813a..08a3e46f7d 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -347,6 +347,7 @@
*/
#define EXT_CSD_PART_CONFIG_ACC_MASK (0x7)
#define EXT_CSD_PART_CONFIG_ACC_BOOT0 (0x1)
+#define EXT_CSD_PART_CONFIG_ACC_RPMB (0x3)
#define EXT_CSD_PART_CONFIG_ACC_GPP0 (0x4)
#define EXT_CSD_CMD_SET_NORMAL (1<<0)
@@ -606,9 +607,11 @@ struct mci_host {
#define MMC_NUM_BOOT_PARTITION 2
#define MMC_NUM_GP_PARTITION 4
#define MMC_NUM_USER_PARTITION 1
+#define MMC_NUM_RPMB_PARTITION 1
#define MMC_NUM_PHY_PARTITION (MMC_NUM_BOOT_PARTITION + \
MMC_NUM_GP_PARTITION + \
- MMC_NUM_USER_PARTITION)
+ MMC_NUM_USER_PARTITION + \
+ MMC_NUM_RPMB_PARTITION)
struct mci_part {
struct block_device blk; /**< the blockdevice for the card */
@@ -674,6 +677,8 @@ struct mci {
int boot_ack_enable;
struct mci_part part[MMC_NUM_PHY_PARTITION];
+ struct mci_part *rpmb_part;
+
int nr_parts;
char *cdevname;
--
2.39.5
More information about the barebox
mailing list