Skip to contentSkip to conversation

hw/arm/aspeed: Unlock SCU when running kernel

PATCH Superseded Joel Stanley 2 participants 3 messages Nov 8, 2017 – Nov 13, 2017 Arm/Aspeed machine support

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Joel Stanley

author maintainer
#0 lore raw

PATCH 1/1 hw/arm/aspeed: Unlock SCU when running kernel

The ASPEED hardware contains a lock register for the SCU that disables any writes to the SCU when it is locked. The machine comes up with the lock enabled, but on all known hardware u-boot will unlock it and leave it unlocked when loading the kernel.

This means the kernel expects the SCU to be unlocked. When booting from an emulated ROM the normal u-boot unlock path is executed. Things don't go well when booting using the -kernel command line, as u-boot does not run first.

Change behaviour so that when a kernel is passed to the machine, set the reset value of the SCU to be unlocked.

---
 hw/arm/aspeed.c               | 10 ++++++++++
 hw/arm/aspeed_soc.c           |  2 ++
 hw/misc/aspeed_scu.c          |  2 ++
 hw/misc/aspeed_sdmc.c         |  1 -
 include/hw/misc/aspeed_scu.h  |  1 +
 include/hw/misc/aspeed_sdmc.h |  2 ++
 6 files changed, 17 insertions(+), 1 deletion(-)
hw/arm/aspeed.c +10 -0
index ab895ad490af..179ee66624b9 100644
@@ -36,6 +36,7 @@ typedef struct AspeedBoardState {
 typedef struct AspeedBoardConfig {
     const char *soc_name;
     uint32_t hw_strap1;
+    uint32_t hw_prot_key;
     const char *fmc_model;
     const char *spi_model;
     uint32_t num_cs;
@@ -186,6 +187,15 @@ static void aspeed_board_init(MachineState *machine,
                             &error_abort);
     object_property_set_int(OBJECT(&bmc->soc), cfg->num_cs, "num-cs",
                             &error_abort);
+    if (machine->kernel_filename) {
+        /*
+         * When booting with a -kernel command line there is no u-boot
+         * that runs to unlock the SCU. In this case set the default to
+         * be unlocked as the kernel expects
+         */
+        object_property_set_int(OBJECT(&bmc->soc), PROT_KEY_UNLOCK,
+                                "hw-prot-key", &error_abort);
+    }
     object_property_set_bool(OBJECT(&bmc->soc), true, "realized",
                              &error_abort);
 
hw/arm/aspeed_soc.c +2 -0
index 5aa3d2ddd9cd..c83b7e207b86 100644
@@ -154,6 +154,8 @@ static void aspeed_soc_init(Object *obj)
                               "hw-strap1", &error_abort);
     object_property_add_alias(obj, "hw-strap2", OBJECT(&s->scu),
                               "hw-strap2", &error_abort);
+    object_property_add_alias(obj, "hw-prot-key", OBJECT(&s->scu),
+                              "hw-prot-key", &error_abort);
 
     object_initialize(&s->fmc, sizeof(s->fmc), sc->info->fmc_typename);
     object_property_add_child(obj, "fmc", OBJECT(&s->fmc), NULL);
hw/misc/aspeed_scu.c +2 -0
index 95022d3607ad..c71e77729581 100644
@@ -246,6 +246,7 @@ static void aspeed_scu_reset(DeviceState *dev)
     s->regs[SILICON_REV] = s->silicon_rev;
     s->regs[HW_STRAP1] = s->hw_strap1;
     s->regs[HW_STRAP2] = s->hw_strap2;
+    s->regs[PROT_KEY] = s->hw_prot_key;
 }
 
 static uint32_t aspeed_silicon_revs[] = {
@@ -299,6 +300,7 @@ static Property aspeed_scu_properties[] = {
     DEFINE_PROP_UINT32("silicon-rev", AspeedSCUState, silicon_rev, 0),
     DEFINE_PROP_UINT32("hw-strap1", AspeedSCUState, hw_strap1, 0),
     DEFINE_PROP_UINT32("hw-strap2", AspeedSCUState, hw_strap2, 0),
+    DEFINE_PROP_UINT32("hw-prot-key", AspeedSCUState, hw_prot_key, 0),
     DEFINE_PROP_END_OF_LIST(),
 };
 
hw/misc/aspeed_sdmc.c +0 -1
index f0b3053fae36..35dc803604f8 100644
@@ -18,7 +18,6 @@
 
 /* Protection Key Register */
 #define R_PROT            (0x00 / 4)
-#define   PROT_KEY_UNLOCK     0xFC600309
 
 /* Configuration Register */
 #define R_CONF            (0x04 / 4)
include/hw/misc/aspeed_scu.h +1 -0
index bd4ac013f997..f5da54e27105 100644
@@ -29,6 +29,7 @@ typedef struct AspeedSCUState {
     uint32_t silicon_rev;
     uint32_t hw_strap1;
     uint32_t hw_strap2;
+    uint32_t hw_prot_key;
 } AspeedSCUState;
 
 #define AST2400_A0_SILICON_REV   0x02000303U
include/hw/misc/aspeed_sdmc.h +2 -0
index 551c8afdf4be..a1b3232c5ef3 100644
@@ -16,6 +16,8 @@
 
 #define ASPEED_SDMC_NR_REGS (0x8 >> 2)
 
+#define PROT_KEY_UNLOCK 0xFC600309
+
 typedef struct AspeedSDMCState {
     /*< private >*/
     SysBusDevice parent_obj;
Signature · 1 line
2.14.1
#1 lore raw
Quoted 89 lines · Joel Stanley

The ASPEED hardware contains a lock register for the SCU that disables any writes to the SCU when it is locked. The machine comes up with the lock enabled, but on all known hardware u-boot will unlock it and leave it unlocked when loading the kernel.

This means the kernel expects the SCU to be unlocked. When booting from an emulated ROM the normal u-boot unlock path is executed. Things don't go well when booting using the -kernel command line, as u-boot does not run first.

Change behaviour so that when a kernel is passed to the machine, set the reset value of the SCU to be unlocked.

---
 hw/arm/aspeed.c               | 10 ++++++++++
 hw/arm/aspeed_soc.c           |  2 ++
 hw/misc/aspeed_scu.c          |  2 ++
 hw/misc/aspeed_sdmc.c         |  1 -
 include/hw/misc/aspeed_scu.h  |  1 +
 include/hw/misc/aspeed_sdmc.h |  2 ++
 6 files changed, 17 insertions(+), 1 deletion(-)
hw/arm/aspeed.c +10 -0
index ab895ad490af..179ee66624b9 100644
@@ -36,6 +36,7 @@ typedef struct AspeedBoardState {
 typedef struct AspeedBoardConfig {
     const char *soc_name;
     uint32_t hw_strap1;
+    uint32_t hw_prot_key;
     const char *fmc_model;
     const char *spi_model;
     uint32_t num_cs;
@@ -186,6 +187,15 @@ static void aspeed_board_init(MachineState *machine,
                             &error_abort);
     object_property_set_int(OBJECT(&bmc->soc), cfg->num_cs, "num-cs",
                             &error_abort);
+    if (machine->kernel_filename) {
+        /*
+         * When booting with a -kernel command line there is no u-boot
+         * that runs to unlock the SCU. In this case set the default to
+         * be unlocked as the kernel expects
+         */
+        object_property_set_int(OBJECT(&bmc->soc), PROT_KEY_UNLOCK,
+                                "hw-prot-key", &error_abort);
+    }
     object_property_set_bool(OBJECT(&bmc->soc), true, "realized",
                              &error_abort);
 
hw/arm/aspeed_soc.c +2 -0
index 5aa3d2ddd9cd..c83b7e207b86 100644
@@ -154,6 +154,8 @@ static void aspeed_soc_init(Object *obj)
                               "hw-strap1", &error_abort);
     object_property_add_alias(obj, "hw-strap2", OBJECT(&s->scu),
                               "hw-strap2", &error_abort);
+    object_property_add_alias(obj, "hw-prot-key", OBJECT(&s->scu),
+                              "hw-prot-key", &error_abort);
 
     object_initialize(&s->fmc, sizeof(s->fmc), sc->info->fmc_typename);
     object_property_add_child(obj, "fmc", OBJECT(&s->fmc), NULL);
hw/misc/aspeed_scu.c +2 -0
index 95022d3607ad..c71e77729581 100644
@@ -246,6 +246,7 @@ static void aspeed_scu_reset(DeviceState *dev)
     s->regs[SILICON_REV] = s->silicon_rev;
     s->regs[HW_STRAP1] = s->hw_strap1;
     s->regs[HW_STRAP2] = s->hw_strap2;
+    s->regs[PROT_KEY] = s->hw_prot_key;
 }
 
 static uint32_t aspeed_silicon_revs[] = {
@@ -299,6 +300,7 @@ static Property aspeed_scu_properties[] = {
     DEFINE_PROP_UINT32("silicon-rev", AspeedSCUState, silicon_rev, 0),
     DEFINE_PROP_UINT32("hw-strap1", AspeedSCUState, hw_strap1, 0),
     DEFINE_PROP_UINT32("hw-strap2", AspeedSCUState, hw_strap2, 0),
+    DEFINE_PROP_UINT32("hw-prot-key", AspeedSCUState, hw_prot_key, 0),
     DEFINE_PROP_END_OF_LIST(),
 };
 
hw/misc/aspeed_sdmc.c +0 -0
index f0b3053fae36..35dc803604f8 100644

hw/misc/aspeed_sdmc.c line 21

Quoted 4 lines
hw/misc/aspeed_sdmc.c +0 -1
@@ -18,7 +18,6 @@
 
 /* Protection Key Register */
 #define R_PROT            (0x00 / 4)
-#define   PROT_KEY_UNLOCK     0xFC600309

why are you using the memory controller magic value ?

Quoted 19 lines
hw/misc/aspeed_sdmc.c +0 -0
 /* Configuration Register */
 #define R_CONF            (0x04 / 4)
include/hw/misc/aspeed_scu.h +1 -0
index bd4ac013f997..f5da54e27105 100644
@@ -29,6 +29,7 @@ typedef struct AspeedSCUState {
     uint32_t silicon_rev;
     uint32_t hw_strap1;
     uint32_t hw_strap2;
+    uint32_t hw_prot_key;
 } AspeedSCUState;
 
 #define AST2400_A0_SILICON_REV   0x02000303U
include/hw/misc/aspeed_sdmc.h +0 -0
index 551c8afdf4be..a1b3232c5ef3 100644

include/hw/misc/aspeed_sdmc.h line 19

Quoted 4 lines
include/hw/misc/aspeed_sdmc.h +1 -0
@@ -16,6 +16,8 @@
 
 #define ASPEED_SDMC_NR_REGS (0x8 >> 2)
 
+#define PROT_KEY_UNLOCK 0xFC600309

Ditto. Should we be using the one from SCU ?

Now that we are externalizing this value, adding a prefix would be preferable : ASPEED_SCU_ ?

Otherwise, it looks ok to me.

Cheers,

C.

Quoted 5 lines
include/hw/misc/aspeed_sdmc.h +1 -0
+
 typedef struct AspeedSDMCState {
     /*< private >*/
     SysBusDevice parent_obj;
author maintainer
#2 lore raw
Quoted 11 lines · Cédric Le Goater

hw/misc/aspeed_sdmc.c line 21

Quoted 7 lines · Joel Stanley
hw/misc/aspeed_sdmc.c +0 -1
@@ -18,7 +18,6 @@
 
 /* Protection Key Register */
 #define R_PROT            (0x00 / 4)
-#define   PROT_KEY_UNLOCK     0xFC600309

why are you using the memory controller magic value ?

Oh. My bad. I think both ctags and myself became confused :)

Quoted 4 lines
Quoted 4 lines
include/hw/misc/aspeed_sdmc.h +0 -0
@@ -16,6 +16,8 @@
 
Quoted 8 lines

include/hw/misc/aspeed_sdmc.h line 19

Quoted 3 lines
include/hw/misc/aspeed_sdmc.h +1 -0
 #define ASPEED_SDMC_NR_REGS (0x8 >> 2)
 
+#define PROT_KEY_UNLOCK 0xFC600309

Ditto. Should we be using the one from SCU ?

Now that we are externalizing this value, adding a prefix would be preferable : ASPEED_SCU_ ?

I will grab the correct value from the SCU and rename it ASPEED_SCU_PROT_KEY for v2.

Thanks for taking a look.

Cheers,

Joel