From: Sascha Hauer <s.hauer@pengutronix.de>
To: "open list:BAREBOX" <barebox@lists.infradead.org>
Cc: Rouven Czerwinski <r.czerwinski@pengutronix.de>
Subject: [PATCH v2 03/10] mci: detect RPMB partitions
Date: Wed, 19 Mar 2025 16:30:54 +0100 [thread overview]
Message-ID: <20250319-rpmb-v2-3-a8801fb35cd4@pengutronix.de> (raw)
In-Reply-To: <20250319-rpmb-v2-0-a8801fb35cd4@pengutronix.de>
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@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
next prev parent reply other threads:[~2025-03-19 15:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-19 15:30 [PATCH v2 00/10] Add RPMB support Sascha Hauer
2025-03-19 15:30 ` [PATCH v2 01/10] mci: implement mci_set_blockcount() Sascha Hauer
2025-03-19 15:30 ` [PATCH v2 02/10] mci: export some functions for RPMB support Sascha Hauer
2025-03-19 15:30 ` Sascha Hauer [this message]
2025-03-19 15:30 ` [PATCH v2 04/10] mci: add " Sascha Hauer
2025-03-19 15:53 ` Ahmad Fatoum
2025-03-19 15:30 ` [PATCH v2 05/10] tee: optee: probe successfully even when no devices are found Sascha Hauer
2025-03-19 15:30 ` [PATCH v2 06/10] tee: optee: implement shared mem alloc/free RPC commands Sascha Hauer
2025-03-19 15:30 ` [PATCH v2 07/10] tee: optee: implement RPMB support Sascha Hauer
2025-03-19 15:30 ` [PATCH v2 08/10] tee: optee: implement AVB named persistent values support Sascha Hauer
2025-03-19 15:31 ` [PATCH v2 09/10] commands: add avb_pvalue command Sascha Hauer
2025-03-19 15:31 ` [PATCH v2 10/10] ARM: omap: remove unused file Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250319-rpmb-v2-3-a8801fb35cd4@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=r.czerwinski@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox