From: Stefan Kerkmann <s.kerkmann@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
BAREBOX <barebox@lists.infradead.org>
Cc: Marco Felsch <m.felsch@pengutronix.de>,
Stefan Kerkmann <s.kerkmann@pengutronix.de>
Subject: [PATCH v3 01/10] nvmem: ocotp: add support to get/set srk_revoke sticky bit
Date: Thu, 23 Jan 2025 15:56:06 +0100 [thread overview]
Message-ID: <20250123-v2024-05-0-topic-hab-v3-1-e90d0e43c2de@pengutronix.de> (raw)
In-Reply-To: <20250123-v2024-05-0-topic-hab-v3-0-e90d0e43c2de@pengutronix.de>
From: Marco Felsch <m.felsch@pengutronix.de>
The i.MX8M* devices do have an sticky bit which indicates if the
srk_revoke fuse can be written. Add support to query and to set the lock
bit.
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
Signed-off-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>
---
drivers/nvmem/ocotp.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++
include/mach/imx/ocotp.h | 2 ++
2 files changed, 57 insertions(+)
diff --git a/drivers/nvmem/ocotp.c b/drivers/nvmem/ocotp.c
index c282efefa82422dc16839c52b65d9dd829edd358..c0517980fb18870002be01ca3240d41d662e0231 100644
--- a/drivers/nvmem/ocotp.c
+++ b/drivers/nvmem/ocotp.c
@@ -52,6 +52,7 @@
#define OCOTP_DATA 0x20
#define OCOTP_READ_CTRL 0x30
#define OCOTP_READ_FUSE_DATA 0x40
+#define OCOTP_SW_STICKY 0x50
#define MX7_OCOTP_DATA0 0x20
#define MX7_OCOTP_DATA1 0x30
@@ -89,6 +90,8 @@
#define OCOTP_TIMING_STROBE_PROG GENMASK(11, 0)
#define OCOTP_TIMING_WAIT GENMASK(27, 22)
+#define OCOTP_SW_STICKY_SRK_REVOKE_LOCK BIT(1)
+
#define OCOTP_READ_CTRL_READ_FUSE BIT(1)
#define OCOTP_OFFSET_TO_ADDR(o) (OCOTP_OFFSET_TO_INDEX(o) * 4)
@@ -147,6 +150,8 @@ struct imx_ocotp_data {
int (*set_timing)(struct ocotp_priv *priv);
int (*fuse_read)(struct ocotp_priv *priv, u32 addr, u32 *pdata);
int (*fuse_blow)(struct ocotp_priv *priv, u32 addr, u32 value);
+ bool (*srk_revoke_locked)(struct ocotp_priv *priv);
+ void (*lock_srk_revoke)(struct ocotp_priv *priv);
u8 mac_offsets[MAX_MAC_OFFSETS];
u8 mac_offsets_num;
struct imx8m_featctrl_data *feat;
@@ -273,6 +278,20 @@ static int imx6_ocotp_prepare(struct ocotp_priv *priv)
return 0;
}
+static bool imx8m_srk_revoke_locked(struct ocotp_priv *priv)
+{
+ return readl(priv->base + OCOTP_SW_STICKY) & OCOTP_SW_STICKY_SRK_REVOKE_LOCK;
+}
+
+static void imx8m_lock_srk_revoke(struct ocotp_priv *priv)
+{
+ u32 val;
+
+ val = readl(priv->base + OCOTP_SW_STICKY);
+ val |= OCOTP_SW_STICKY_SRK_REVOKE_LOCK;
+ writel(val, priv->base + OCOTP_SW_STICKY);
+}
+
static int imx6_fuse_read_addr(struct ocotp_priv *priv, u32 addr, u32 *pdata)
{
const u32 bm_ctrl_error = priv->data->ctrl->bm_error;
@@ -625,6 +644,36 @@ int imx_ocotp_sense_enable(bool enable)
return old_value;
}
+int imx_ocotp_srk_revoke_locked(void)
+{
+ int ret;
+
+ ret = imx_ocotp_ensure_probed();
+ if (ret)
+ return ret;
+
+ if (imx_ocotp->data->srk_revoke_locked)
+ return imx_ocotp->data->srk_revoke_locked(imx_ocotp);
+
+ return -ENOSYS;
+}
+
+int imx_ocotp_lock_srk_revoke(void)
+{
+ int ret;
+
+ ret = imx_ocotp_ensure_probed();
+ if (ret)
+ return ret;
+
+ if (imx_ocotp->data->lock_srk_revoke) {
+ imx_ocotp->data->lock_srk_revoke(imx_ocotp);
+ return 0;
+ }
+
+ return -ENOSYS;
+}
+
static void imx_ocotp_format_mac(u8 *dst, const u8 *src,
enum imx_ocotp_format_mac_direction dir)
{
@@ -985,6 +1034,8 @@ static struct imx_ocotp_data imx8mp_ocotp_data = {
.set_timing = imx6_ocotp_set_timing,
.fuse_blow = imx6_fuse_blow_addr,
.fuse_read = imx6_fuse_read_addr,
+ .srk_revoke_locked = imx8m_srk_revoke_locked,
+ .lock_srk_revoke = imx8m_lock_srk_revoke,
.ctrl = &ocotp_ctrl_reg_8mp,
};
@@ -1014,6 +1065,8 @@ static struct imx_ocotp_data imx8mm_ocotp_data = {
.set_timing = imx6_ocotp_set_timing,
.fuse_blow = imx6_fuse_blow_addr,
.fuse_read = imx6_fuse_read_addr,
+ .srk_revoke_locked = imx8m_srk_revoke_locked,
+ .lock_srk_revoke = imx8m_lock_srk_revoke,
.feat = &imx8mm_featctrl_data,
.ctrl = &ocotp_ctrl_reg_default,
};
@@ -1032,6 +1085,8 @@ static struct imx_ocotp_data imx8mn_ocotp_data = {
.set_timing = imx6_ocotp_set_timing,
.fuse_blow = imx6_fuse_blow_addr,
.fuse_read = imx6_fuse_read_addr,
+ .srk_revoke_locked = imx8m_srk_revoke_locked,
+ .lock_srk_revoke = imx8m_lock_srk_revoke,
.feat = &imx8mn_featctrl_data,
.ctrl = &ocotp_ctrl_reg_default,
};
diff --git a/include/mach/imx/ocotp.h b/include/mach/imx/ocotp.h
index 5f7b88f716a71544c9db919e3ef7b1d9917dc80b..7a516ff789b962b741782c888a47aaff8cb6e902 100644
--- a/include/mach/imx/ocotp.h
+++ b/include/mach/imx/ocotp.h
@@ -36,6 +36,8 @@ int imx_ocotp_read_field(uint32_t field, unsigned *value);
int imx_ocotp_write_field(uint32_t field, unsigned value);
int imx_ocotp_permanent_write(int enable);
int imx_ocotp_sense_enable(bool enable);
+int imx_ocotp_srk_revoke_locked(void);
+int imx_ocotp_lock_srk_revoke(void);
static inline u64 imx_ocotp_read_uid(void __iomem *ocotp)
{
--
2.39.5
next prev parent reply other threads:[~2025-01-23 15:01 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-23 14:56 [PATCH v3 00/10] i.MX8M HAB and OCOTP additions and fixes Stefan Kerkmann
2025-01-23 14:56 ` Stefan Kerkmann [this message]
2025-01-23 14:56 ` [PATCH v3 02/10] nvmem: ocotp: add support to query the field-return sticky bit Stefan Kerkmann
2025-01-23 14:56 ` [PATCH v3 03/10] hab: convert flags to use BIT() macro Stefan Kerkmann
2025-01-23 14:56 ` [PATCH v3 04/10] i.MX: HAB: add imx_hab_revoke_key support Stefan Kerkmann
2025-01-23 14:56 ` [PATCH v3 05/10] i.MX: HABv4: add more i.MX8M fuse defines Stefan Kerkmann
2025-01-23 14:56 ` [PATCH v3 06/10] i.MX8M: HABv4: add an option to allow key revocation Stefan Kerkmann
2025-01-23 14:56 ` [PATCH v3 07/10] i.MX8M: HABv4: add option to allow burning the field-return fuse Stefan Kerkmann
2025-01-23 14:56 ` [PATCH v3 08/10] i.MX: HAB: add imx_hab_field_return support Stefan Kerkmann
2025-01-23 14:56 ` [PATCH v3 09/10] i.mx8: ocotp: add GPx_LOCK defines Stefan Kerkmann
2025-01-23 14:56 ` [PATCH v3 10/10] hab: lock GP5 on i.MX8MP socs Stefan Kerkmann
2025-01-28 10:00 ` [PATCH v3 00/10] i.MX8M HAB and OCOTP additions and fixes 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=20250123-v2024-05-0-topic-hab-v3-1-e90d0e43c2de@pengutronix.de \
--to=s.kerkmann@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=m.felsch@pengutronix.de \
--cc=s.hauer@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