Initial support for One-Time Programmable Memory (OTP) in BCM2835
Subsystems (3)
PATCH 1/3 hw/nvram: Add BCM2835 OTP device
In reply to Rayhan FaizelThe OTP device registers are currently stubbed. For now, the device houses the OTP rows which will be accessed directly by other peripherals.
--- hw/nvram/bcm2835_otp.c | 187 +++++++++++++++++++++++++++++++++ hw/nvram/meson.build | 1 + include/hw/nvram/bcm2835_otp.h | 43 ++++++++ 3 files changed, 231 insertions(+) create mode 100644 hw/nvram/bcm2835_otp.c create mode 100644 include/hw/nvram/bcm2835_otp.h
hw/nvram/bcm2835_otp.c new file +187 -0
@@ -0,0 +1,187 @@ +/* +* BCM2835 One-Time Programmable (OTP) Memory +* +* The OTP implementation is mostly a stub except for the OTP rows +* which are accessed directly by other peripherals such as the mailbox. +* +* The OTP registers are unimplemented due to lack of documentation. +* +* Copyright (c) 2024 Rayhan Faizel <[email protected]> +* +* SPDX-License-Identifier: MIT +*/ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "hw/nvram/bcm2835_otp.h" +#include "migration/vmstate.h" + +/* OTP rows are 1-indexed */ +uint32_t bcm2835_otp_read_row (BCM2835OTPState *s,unsigned int row) +{ +assert (row <=66 && row >=1 ); + +return s->otp_rows[row -1 ]; +} + +void bcm2835_otp_write_row (BCM2835OTPState *s,unsigned int row, +uint32_t value) +{ +assert (row <=66 && row >=1 ); + +/* Real OTP rows work as e-fuses */ + s->otp_rows[row -1 ] |= value; +} + +static uint64_t bcm2835_otp_read (void *opaque,hwaddr addr,unsigned size) +{ +switch (addr) { +case BCM2835_OTP_BOOTMODE_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_BOOTMODE_REG\n" ); +break ; +case BCM2835_OTP_CONFIG_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_CONFIG_REG\n" ); +break ; +case BCM2835_OTP_CTRL_LO_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_CTRL_LO_REG\n" ); +break ; +case BCM2835_OTP_CTRL_HI_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_CTRL_HI_REG\n" ); +break ; +case BCM2835_OTP_STATUS_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_STATUS_REG\n" ); +break ; +case BCM2835_OTP_BITSEL_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_BITSEL_REG\n" ); +break ; +case BCM2835_OTP_DATA_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_DATA_REG\n" ); +break ; +case BCM2835_OTP_ADDR_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_ADDR_REG\n" ); +break ; +case BCM2835_OTP_WRITE_DATA_READ_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_WRITE_DATA_READ_REG\n" ); +break ; +case BCM2835_OTP_INIT_STATUS_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_INIT_STATUS_REG\n" ); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Bad offset 0x%" HWADDR_PRIx"\n" , __func__, addr); + } + +return 0 ; +} + +static void bcm2835_otp_write (void *opaque,hwaddr addr, +uint64_t value,unsigned int size) +{ +switch (addr) { +case BCM2835_OTP_BOOTMODE_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_BOOTMODE_REG\n" ); +break ; +case BCM2835_OTP_CONFIG_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_CONFIG_REG\n" ); +break ; +case BCM2835_OTP_CTRL_LO_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_CTRL_LO_REG\n" ); +break ; +case BCM2835_OTP_CTRL_HI_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_CTRL_HI_REG\n" ); +break ; +case BCM2835_OTP_STATUS_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_STATUS_REG\n" ); +break ; +case BCM2835_OTP_BITSEL_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_BITSEL_REG\n" ); +break ; +case BCM2835_OTP_DATA_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_DATA_REG\n" ); +break ; +case BCM2835_OTP_ADDR_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_ADDR_REG\n" ); +break ; +case BCM2835_OTP_WRITE_DATA_READ_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_WRITE_DATA_READ_REG\n" ); +break ; +case BCM2835_OTP_INIT_STATUS_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_INIT_STATUS_REG\n" ); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Bad offset 0x%" HWADDR_PRIx"\n" , __func__, addr); + } +} + +static const MemoryRegionOps bcm2835_otp_ops = { + .read = bcm2835_otp_read, + .write = bcm2835_otp_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + }, +}; + +static void bcm2835_otp_realize (DeviceState *dev,Error **errp) +{ +BCM2835OTPState *s =BCM2835_OTP (dev); +memory_region_init_io (&s->iomem,OBJECT (dev), &bcm2835_otp_ops, s, +TYPE_BCM2835_OTP ,0x28 ); +sysbus_init_mmio (SYS_BUS_DEVICE (dev), &s->iomem); + +memset (s->otp_rows,0x00 ,sizeof (s->otp_rows)); +} + +static const VMStateDescription vmstate_bcm2835_otp = { + .name =TYPE_BCM2835_OTP , + .version_id =1 , + .minimum_version_id =1 , + .fields = (const VMStateField []) { +VMSTATE_UINT32_ARRAY (otp_rows, BCM2835OTPState,66 ), +VMSTATE_END_OF_LIST () + } +}; + +static void bcm2835_otp_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = bcm2835_otp_realize; + dc->vmsd = &vmstate_bcm2835_otp; +} + +static const TypeInfo bcm2835_otp_info = { + .name =TYPE_BCM2835_OTP , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (BCM2835OTPState), + .class_init = bcm2835_otp_class_init, +}; + +static void bcm2835_otp_register_types (void ) +{ +type_register_static (&bcm2835_otp_info); +} + +type_init (bcm2835_otp_register_types)
hw/nvram/meson.build +1 -0
@@ -1,5 +1,6 @@ system_ss.add(files('fw_cfg-interface.c')) system_ss.add(files('fw_cfg.c')) +system_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_otp.c')) system_ss.add(when: 'CONFIG_CHRP_NVRAM', if_true: files('chrp_nvram.c')) system_ss.add(when: 'CONFIG_DS1225Y', if_true: files('ds1225y.c')) system_ss.add(when: 'CONFIG_NMC93XX_EEPROM', if_true: files('eeprom93xx.c'))
include/hw/nvram/bcm2835_otp.h new file +43 -0
43 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 2/3 hw/arm: Connect OTP device to BCM2835
In reply to Rayhan Faizel--- hw/arm/bcm2835_peripherals.c | 13 ++++++++++++- include/hw/arm/bcm2835_peripherals.h | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-)
hw/arm/bcm2835_peripherals.c +12 -1
@@ -116,6 +116,10 @@ static void raspi_peripherals_base_init(Object *obj)object_property_add_const_link (OBJECT (&s->fb),"dma-mr" ,OBJECT (&s->gpu_bus_mr)); +/* OTP */ +object_initialize_child (obj,"bcm2835-otp" , &s->otp, +TYPE_BCM2835_OTP ); +/* Property channel */ object_initialize_child (obj,"property" , &s->property,TYPE_BCM2835_PROPERTY );
@@ -374,6 +378,14 @@ void bcm_soc_peripherals_common_realize(DeviceState *dev, Error **errp)sysbus_connect_irq (SYS_BUS_DEVICE (&s->fb),0 ,qdev_get_gpio_in (DEVICE (&s->mboxes),MBOX_CHAN_FB )); +/* OTP */ +if (!sysbus_realize (SYS_BUS_DEVICE (&s->otp), errp)) { +return ; + } + +memory_region_add_subregion (&s->peri_mr,OTP_OFFSET , +sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->otp),0 )); +/* Property channel */ if (!sysbus_realize (SYS_BUS_DEVICE (&s->property), errp)) {return ;
@@ -500,7 +512,6 @@ void bcm_soc_peripherals_common_realize(DeviceState *dev, Error **errp)create_unimp (s, &s->i2s,"bcm2835-i2s" ,I2S_OFFSET ,0x100 );create_unimp (s, &s->smi,"bcm2835-smi" ,SMI_OFFSET ,0x100 );create_unimp (s, &s->bscsl,"bcm2835-spis" ,BSC_SL_OFFSET ,0x100 ); -create_unimp (s, &s->otp,"bcm2835-otp" ,OTP_OFFSET ,0x80 );create_unimp (s, &s->dbus,"bcm2835-dbus" ,DBUS_OFFSET ,0x8000 );create_unimp (s, &s->ave0,"bcm2835-ave0" ,AVE0_OFFSET ,0x8000 );create_unimp (s, &s->v3d,"bcm2835-v3d" ,V3D_OFFSET ,0x1000 );
include/hw/arm/bcm2835_peripherals.h +2 -1
@@ -33,6 +33,7 @@#include "hw/usb/hcd-dwc2.h" #include "hw/ssi/bcm2835_spi.h" #include "hw/i2c/bcm2835_i2c.h" +#include "hw/nvram/bcm2835_otp.h" #include "hw/misc/unimp.h" #include "qom/object.h"
@@ -71,7 +72,7 @@ struct BCMSocPeripheralBaseState {BCM2835SPIState spi[1 ];BCM2835I2CState i2c[3 ];OrIRQState orgated_i2c_irq; -UnimplementedDeviceState otp; +BCM2835OTPState otp;UnimplementedDeviceState dbus;UnimplementedDeviceState ave0;UnimplementedDeviceState v3d;
Signature · 1 line
2.34.1
PATCH 3/3 hw/misc: Implement mailbox properties for customer OTP and device specific private keys
In reply to Rayhan FaizelFour mailbox properties are implemented as follows:
1. Customer OTP: GET_CUSTOMER_OTP and SET_CUSTOMER_OTP
2. Device-specific private key: GET_PRIVATE_KEY and SET_PRIVATE_KEY.
The customer OTP is located in the rows 36-43. The device-specific private key is located in the rows 56-63.
The customer OTP can be locked with the magic numbers 0xffffffff 0xaffe0000 when running the SET_CUSTOMER_OTP mailbox command.
P.S I am not sure if the magic lock combo applies to the private key as well.
--- hw/arm/bcm2835_peripherals.c | 2 + hw/misc/bcm2835_property.c | 71 ++++++++++++++++++++++++++++ include/hw/arm/raspberrypi-fw-defs.h | 2 + include/hw/misc/bcm2835_property.h | 2 + 4 files changed, 77 insertions(+)
hw/arm/bcm2835_peripherals.c +2 -0
@@ -132,6 +132,8 @@ static void raspi_peripherals_base_init(Object *obj) OBJECT(&s->fb));object_property_add_const_link (OBJECT (&s->property),"dma-mr" ,OBJECT (&s->gpu_bus_mr)); +object_property_add_const_link (OBJECT (&s->property),"otp" , +OBJECT (&s->otp));/* Extended Mass Media Controller */ object_initialize_child (obj,"sdhci" , &s->sdhci,TYPE_SYSBUS_SDHCI );
hw/misc/bcm2835_property.c +71 -0
89 lines not on this page · raw message
include/hw/arm/raspberrypi-fw-defs.h +2 -0
@@ -56,6 +56,7 @@ enum rpi_firmware_property_tag {RPI_FWREQ_GET_THROTTLED =0x00030046 ,RPI_FWREQ_GET_CLOCK_MEASURED =0x00030047 ,RPI_FWREQ_NOTIFY_REBOOT =0x00030048 , +RPI_FWREQ_GET_PRIVATE_KEY =0x00030081 ,RPI_FWREQ_SET_CLOCK_STATE =0x00038001 ,RPI_FWREQ_SET_CLOCK_RATE =0x00038002 , RPI_FWREQ_SET_VOLTAGE = 0x00038003,
@@ -73,6 +74,7 @@ enum rpi_firmware_property_tag {RPI_FWREQ_SET_PERIPH_REG =0x00038045 ,RPI_FWREQ_GET_POE_HAT_VAL =0x00030049 ,RPI_FWREQ_SET_POE_HAT_VAL =0x00038049 , +RPI_FWREQ_SET_PRIVATE_KEY =0x00038081 ,RPI_FWREQ_SET_POE_HAT_VAL_OLD =0x00030050 ,RPI_FWREQ_NOTIFY_XHCI_RESET =0x00030058 , RPI_FWREQ_GET_REBOOT_FLAGS = 0x00030064,
include/hw/misc/bcm2835_property.h +2 -0
@@ -11,6 +11,7 @@#include "hw/sysbus.h" #include "net/net.h" #include "hw/display/bcm2835_fb.h" +#include "hw/nvram/bcm2835_otp.h" #include "qom/object.h" #define TYPE_BCM2835_PROPERTY "bcm2835-property"
@@ -26,6 +27,7 @@ struct BCM2835PropertyState {MemoryRegion iomem;qemu_irq mbox_irq;BCM2835FBState *fbdev; +BCM2835OTPState *otp;MACAddr macaddr;uint32_t board_rev;
Signature · 1 line
2.34.1
cover Initial support for One-Time Programmable Memory (OTP) in BCM2835
All BCM2835 boards have on-board OTP memory with 66 32-bit rows. Usually, its contents are accessible via mailbox commands.
Rayhan Faizel (3):
hw/nvram: Add BCM2835 OTP device
hw/arm: Connect OTP device to BCM2835
hw/misc: Implement mailbox properties for customer OTP and device
specific private keys
hw/arm/bcm2835_peripherals.c | 15 ++- hw/misc/bcm2835_property.c | 71 ++++++++++ hw/nvram/bcm2835_otp.c | 187 +++++++++++++++++++++++++++ hw/nvram/meson.build | 1 + include/hw/arm/bcm2835_peripherals.h | 3 +- include/hw/arm/raspberrypi-fw-defs.h | 2 + include/hw/misc/bcm2835_property.h | 2 + include/hw/nvram/bcm2835_otp.h | 43 ++++++ 8 files changed, 322 insertions(+), 2 deletions(-) create mode 100644 hw/nvram/bcm2835_otp.c create mode 100644 include/hw/nvram/bcm2835_otp.h
Signature · 1 line
2.34.1
Re: [PATCH 1/3] hw/nvram: Add BCM2835 OTP device
In reply to Rayhan FaizelHi Rayhan,
Quoted 58 lines · Rayhan Faizel
The OTP device registers are currently stubbed. For now, the device houses the OTP rows which will be accessed directly by other peripherals.
Signed-off-by Rayhan Faizel <[email protected]>--- hw/nvram/bcm2835_otp.c | 187 +++++++++++++++++++++++++++++++++ hw/nvram/meson.build | 1 + include/hw/nvram/bcm2835_otp.h | 43 ++++++++ 3 files changed, 231 insertions(+)create mode 100644
hw/nvram/bcm2835_otp.ccreate mode 100644include/hw/nvram/bcm2835_otp.hhw/nvram/bcm2835_otp.c new file +45
-0+static void bcm2835_otp_write (void *opaque,hwaddr addr, +uint64_t value,unsigned int size) +{ +switch (addr) { +case BCM2835_OTP_BOOTMODE_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_BOOTMODE_REG\n" ); +break ; +case BCM2835_OTP_CONFIG_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_CONFIG_REG\n" ); +break ; +case BCM2835_OTP_CTRL_LO_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_CTRL_LO_REG\n" ); +break ; +case BCM2835_OTP_CTRL_HI_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_CTRL_HI_REG\n" ); +break ; +case BCM2835_OTP_STATUS_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_STATUS_REG\n" ); +break ; +case BCM2835_OTP_BITSEL_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_BITSEL_REG\n" ); +break ; +case BCM2835_OTP_DATA_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_DATA_REG\n" ); +break ; +case BCM2835_OTP_ADDR_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_ADDR_REG\n" ); +break ; +case BCM2835_OTP_WRITE_DATA_READ_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_WRITE_DATA_READ_REG\n" ); +break ; +case BCM2835_OTP_INIT_STATUS_REG : +qemu_log_mask (LOG_UNIMP , +"bcm2835_otp: BCM2835_OTP_INIT_STATUS_REG\n" ); +break ; +default :
hw/nvram/bcm2835_otp.c line 141
Quoted 10 lines
hw/nvram/bcm2835_otp.c new file +10
-0+qemu_log_mask (LOG_GUEST_ERROR , +"%s: Bad offset 0x%" HWADDR_PRIx"\n" , __func__, addr); + } +} + +static const MemoryRegionOps bcm2835_otp_ops = { + .read = bcm2835_otp_read, + .write = bcm2835_otp_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .valid = {
s/valid/impl/ here, this is your implementation. It isn't illegal to access these registers with a non 32-bit size.
Quoted 17 lines
include/hw/nvram/bcm2835_otp.h new file +15
-0+ .min_access_size = 4, + .max_access_size = 4, + }, +}; +/* https://elinux.org/BCM2835_registers#OTP */ +#define BCM2835_OTP_BOOTMODE_REG 0x00 +#define BCM2835_OTP_CONFIG_REG 0x04 +#define BCM2835_OTP_CTRL_LO_REG 0x08 +#define BCM2835_OTP_CTRL_HI_REG 0x0c +#define BCM2835_OTP_STATUS_REG 0x10 +#define BCM2835_OTP_BITSEL_REG 0x14 +#define BCM2835_OTP_DATA_REG 0x18 +#define BCM2835_OTP_ADDR_REG 0x1c +#define BCM2835_OTP_WRITE_DATA_READ_REG 0x20 +#define BCM2835_OTP_INIT_STATUS_REG 0x24
Re: [PATCH 2/3] hw/arm: Connect OTP device to BCM2835
In reply to Rayhan FaizelHi Rayhan,
hw/arm/bcm2835_peripherals.c void bcm_soc_peripherals_common_realize(DeviceState *dev, Error **errp) · line 503
Quoted 12 lines · Rayhan Faizel
Signed-off-by Rayhan Faizel <[email protected]>--- hw/arm/bcm2835_peripherals.c | 13 ++++++++++++- include/hw/arm/bcm2835_peripherals.h | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-)hw/arm/bcm2835_peripherals.c +0
-1@@ -500,7 +512,6 @@ void bcm_soc_peripherals_common_realize(DeviceState *dev, Error **errp)create_unimp (s, &s->i2s,"bcm2835-i2s" ,I2S_OFFSET ,0x100 );create_unimp (s, &s->smi,"bcm2835-smi" ,SMI_OFFSET ,0x100 );create_unimp (s, &s->bscsl,"bcm2835-spis" ,BSC_SL_OFFSET ,0x100 ); -create_unimp (s, &s->otp,"bcm2835-otp" ,OTP_OFFSET ,0x80 );
Maybe worth noting in the description, before we were covering a range of 0x80 and now 0x28, so a range of 0x58 I/O ends in RAM. Maybe better keep a region of 0x80 in the previous patch?
Flatview diff:
(qemu) info mtree -f
FlatView #0
AS "memory", root: system
Root memory region: system
0000000000000000-000000003f002fff (prio 0, ram): ram
...
- 000000003f20f000-000000003f20f07f (prio -1000, i/o): bcm2835-otp
- 000000003f20f080-000000003f211fff (prio 0, ram): ram @000000003f20f080
+ 000000003f20f000-000000003f20f027 (prio 0, i/o): bcm2835-otp
+ 000000003f20f028-000000003f211fff (prio 0, ram): ram @000000003f20f028
FlatView #3
Root memory region: bcm2835-gpu
0000000000000000-000000003fffffff (prio 0, ram): ram 0000000040000000-000000007e002fff (prio 0, ram): ram
...
- 000000007e20f000-000000007e20f07f (prio -1000, i/o): bcm2835-otp
- 000000007e20f080-000000007e211fff (prio 0, ram): ram @000000003e20f080
+ 000000007e20f000-000000007e20f027 (prio 0, i/o): bcm2835-otp
+ 000000007e20f028-000000007e211fff (prio 0, ram): ram @000000003e20f028
Quoted 3 lines
hw/arm/bcm2835_peripherals.c +0
-0create_unimp (s, &s->dbus,"bcm2835-dbus" ,DBUS_OFFSET ,0x8000 );create_unimp (s, &s->ave0,"bcm2835-ave0" ,AVE0_OFFSET ,0x8000 );create_unimp (s, &s->v3d,"bcm2835-v3d" ,V3D_OFFSET ,0x1000 );
Re: [PATCH 1/3] hw/nvram: Add BCM2835 OTP device
In reply to Rayhan FaizelQuoted 18 lines · Rayhan Faizel
The OTP device registers are currently stubbed. For now, the device houses the OTP rows which will be accessed directly by other peripherals.
Signed-off-by Rayhan Faizel <[email protected]>--- hw/nvram/bcm2835_otp.c | 187 +++++++++++++++++++++++++++++++++ hw/nvram/meson.build | 1 + include/hw/nvram/bcm2835_otp.h | 43 ++++++++ 3 files changed, 231 insertions(+)create mode 100644
hw/nvram/bcm2835_otp.ccreate mode 100644include/hw/nvram/bcm2835_otp.hhw/nvram/bcm2835_otp.c new file +5
-0+/* OTP rows are 1-indexed */ +uint32_t bcm2835_otp_read_row (BCM2835OTPState *s,unsigned int row) +{ +assert (row <=66 && row >=1 ); +
hw/nvram/bcm2835_otp.c line 33
Quoted 10 lines
hw/nvram/bcm2835_otp.c new file +10
-0+return s->otp_rows[row -1 ]; +} + +void bcm2835_otp_write_row (BCM2835OTPState *s,unsigned int row, +uint32_t value) +{ +assert (row <=66 && row >=1 ); + +/* Real OTP rows work as e-fuses */ + s->otp_rows[row -1 ] |= value;
Maybe name get/set instead of read/write?
Quoted 1 line
+}
Re: [PATCH 3/3] hw/misc: Implement mailbox properties for customer OTP and device specific private keys
In reply to Rayhan FaizelQuoted 7 lines · Rayhan Faizel
Four mailbox properties are implemented as follows:
1. Customer OTP:GET_CUSTOMER_OTPandSET_CUSTOMER_OTP
2. Device-specific private key:GET_PRIVATE_KEYandSET_PRIVATE_KEY.The customer OTP is located in the rows 36-43. The device-specific private key is located in the rows 56-63.
Better to define these instead of using magic values in the code, i.e.:
#define OTP_PRIVATE_KEY_OFFSET 56 #define OTP_PRIVATE_KEY_LENGTH 8
Quoted 40 lines
The customer OTP can be locked with the magic numbers
0xffffffff0xaffe0000when running theSET_CUSTOMER_OTPmailbox command.
P.SI am not sure if the magic lock combo applies to the private key as well.Signed-off-by Rayhan Faizel <[email protected]>--- hw/arm/bcm2835_peripherals.c | 2 + hw/misc/bcm2835_property.c | 71 ++++++++++++++++++++++++++++ include/hw/arm/raspberrypi-fw-defs.h | 2 + include/hw/misc/bcm2835_property.h | 2 + 4 files changed, 77 insertions(+)hw/misc/bcm2835_property.c +26
-0+/* Device-specific private key */ + +case RPI_FWREQ_GET_PRIVATE_KEY : + start_num =ldl_le_phys (&s->dma_as, value +12 ); + number =ldl_le_phys (&s->dma_as, value +16 ); + + resplen =8 +4 * number; + +for (n = start_num; n < start_num + number && n <8 ; n++) { +stl_le_phys (&s->dma_as, + value +20 + ((n - start_num) <<2 ), +bcm2835_otp_read_row (s->otp,56 + n)); + } +break ; +case RPI_FWREQ_SET_PRIVATE_KEY : + start_num =ldl_le_phys (&s->dma_as, value +12 ); + number =ldl_le_phys (&s->dma_as, value +16 ); + + resplen =4 ; + +for (n = start_num; n < start_num + number && n <8 ; n++) { + otp_row =ldl_le_phys (&s->dma_as, + value +20 + ((n - start_num) <<2 )); +bcm2835_otp_write_row (s->otp,56 + n, otp_row); + } +break ;