[meta-freescale] [PATCH 1/1] arm: imx: fsl_otp: make fuses (OTP memory) read-only
Alexander Holler
holler at ahsoftware.de
Fri Nov 7 01:43:35 PST 2014
Nothing in userspace should be able to kill the HW.
Not even just as root and for sure not that easy.
For obvious reason, I haven't tested this patch thoroughly.
Reported-by: Jon Nettleton <jon.nettleton at gmail.com>
Signed-off-by: Alexander Holler <holler at ahsoftware.de>
---
drivers/char/fsl_otp.c | 57 +-------------------------------------------------
1 file changed, 1 insertion(+), 56 deletions(-)
diff --git a/drivers/char/fsl_otp.c b/drivers/char/fsl_otp.c
index face297..d9d1c59 100644
--- a/drivers/char/fsl_otp.c
+++ b/drivers/char/fsl_otp.c
@@ -151,60 +151,6 @@ out:
return ret ? 0 : sprintf(buf, "0x%x\n", value);
}
-static int otp_write_bits(int addr, u32 data, u32 magic)
-{
- u32 c; /* for control register */
-
- /* init the control register */
- c = __raw_readl(otp_base + HW_OCOTP_CTRL);
- c &= ~BM_OCOTP_CTRL_ADDR;
- c |= BF(addr, OCOTP_CTRL_ADDR);
- c |= BF(magic, OCOTP_CTRL_WR_UNLOCK);
- __raw_writel(c, otp_base + HW_OCOTP_CTRL);
-
- /* init the data register */
- __raw_writel(data, otp_base + HW_OCOTP_DATA);
- otp_wait_busy(0);
-
- mdelay(2); /* Write Postamble */
-
- return 0;
-}
-
-static ssize_t fsl_otp_store(struct kobject *kobj, struct kobj_attribute *attr,
- const char *buf, size_t count)
-{
- unsigned int index = attr - otp_kattr;
- u32 value;
- int ret;
-
- sscanf(buf, "0x%x", &value);
-
- ret = clk_prepare_enable(otp_clk);
- if (ret)
- return 0;
-
- mutex_lock(&otp_mutex);
-
- set_otp_timing();
- ret = otp_wait_busy(0);
- if (ret)
- goto out;
-
- otp_write_bits(index, value, 0x3e77);
-
- /* Reload all the shadow registers */
- __raw_writel(BM_OCOTP_CTRL_RELOAD_SHADOWS,
- otp_base + HW_OCOTP_CTRL_SET);
- udelay(1);
- otp_wait_busy(BM_OCOTP_CTRL_RELOAD_SHADOWS);
-
-out:
- mutex_unlock(&otp_mutex);
- clk_disable_unprepare(otp_clk);
- return ret ? 0 : count;
-}
-
static int fsl_otp_probe(struct platform_device *pdev)
{
struct resource *res;
@@ -244,9 +190,8 @@ static int fsl_otp_probe(struct platform_device *pdev)
for (i = 0; i < num; i++) {
sysfs_attr_init(&otp_kattr[i].attr);
otp_kattr[i].attr.name = desc[i];
- otp_kattr[i].attr.mode = 0600;
+ otp_kattr[i].attr.mode = 0400;
otp_kattr[i].show = fsl_otp_show;
- otp_kattr[i].store = fsl_otp_store;
attrs[i] = &otp_kattr[i].attr;
}
otp_attr_group->attrs = attrs;
--
1.8.3.1
More information about the meta-freescale
mailing list