SRAM reboot mode driver
cover SRAM reboot mode driver
This patchset extends on Andy Yan's reboot mode driver work from here: https://lkml.org/lkml/2016/1/12/315
It adds reboot mode/reason support for devices that use an SRAM location to communicate with the bootloader.
Doing this via an SRAM subnode was a suggestion from Arnd, but I worry this implementation isn't yet ideal, since I spent quite a bit of time futzing with getting the sram dts entry to work properly. So I suspect there will be a number of suggestions for improvements.
Again, this series dependson Andy's patch set above, but also was developed & tested against the 4.1 based hikey tree, so at least the hikey dts patch won't apply. I'm mostly sending this out for just a rough initial review of the dts and conceptual usage of sram subnodes.
Also, it was pointed out that the hikey dts entry for this really should be added by the UEFI firmware, since alternative bootloaders may be used which do not support this feature. So the hikey dts patch isn't likely to ever go upstream, but its a useful illustration for how other devices might use this driver.
John Stultz (3):
dt-bindings: power: reset: Add document for sram-reboot-mode driver
power: reset: Add sram-reboot-mode driver
dts: hikey: Add hikey support for sram-reboot-mode
.../bindings/power/reset/sram-reboot-mode.txt | 47 +++++++++++++++ arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts | 36 ++++++++++++ arch/arm64/configs/hikey_defconfig | 3 + drivers/power/reset/Kconfig | 9 +++ drivers/power/reset/Makefile | 1 + drivers/power/reset/sram-reboot-mode.c | 66 ++++++++++++++++++++++ 6 files changed, 162 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/reset/sram-reboot-mode.txt create mode 100644 drivers/power/reset/sram-reboot-mode.c
Signature · 1 line
1.9.1
RFC PATCH 1/3 dt-bindings: power: reset: Add document for sram-reboot-mode driver
Add device tree binding document for reboot-mode driver
--- .../bindings/power/reset/sram-reboot-mode.txt | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/reset/sram-reboot-mode.txt
Documentation/devicetree/bindings/power/reset/sram-reboot-mode.txt new file +47 -0
@@ -0,0 +1,47 @@ +SRAM reboot mode driver + +This driver get reboot mode magic value form reboot-mode driver +and stores it in a SRAM address. Then the bootloader +can read it and take different action according to the magic +value stored. + +This DT node should be represented as a sub-node of a "mmio-sram", "simple-bus" +node. + +Required properties: +- compatible: should be "sram-reboot-mode" +- reg: offset from the sram range where to store the magic value(in bytes) + +The rest of the properties should follow the generic reboot-mode discription +found in reboot-mode.txt + +Example: + + sram@5f01000 { + compatible = "mmio-sram", "simple-bus"; + reg = <0x0 0x05f01000 0x0 0x00001000>; + ranges = <0x0 0x0 0x05f01000 0x00001000>; + + #address-cells = <1>; + #size-cells = <1>; + + reboot-mode@0 { + compatible = "sram-reboot-mode"; + reg = <0x0 0x4>; + + none { + linux,mode = "none"; + loader,magic = <0x77665501>; + }; + + bootloader { + linux,mode = "bootloader"; + loader,magic = <0x77665500>; + }; + + recovery { + linux,mode = "recovery"; + loader,magic = <0x77665502>; + }; + }; + };
Signature · 1 line
1.9.1
Re: [RFC][PATCH 1/3] dt-bindings: power: reset: Add document for sram-reboot-mode driver
Hi John:
Welcome.
One nit.
Quoted 1 line · John Stultz
Add device tree binding document for reboot-mode driver
Maybe you want to use "sram-reboot-mode" instead of "reboot-mode" here.
Quoted 73 lines
Cc Andy Yan <[email protected]>Cc Rob Herring <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Thierry Reding <[email protected]>Cc Heiko Stübner <[email protected]>Cc Caesar Wang <[email protected]>Cc Kees Cook <[email protected]>Cc Guodong Xu <[email protected]>Cc Haojian Zhuang <[email protected]>Cc Vishal Bhoj <[email protected]>Cc Bjorn Andersson <[email protected]>Cc Android Kernel Team <[email protected]>Signed-off-by John Stultz <[email protected]>--- .../bindings/power/reset/sram-reboot-mode.txt | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+)create mode 100644
Documentation/devicetree/bindings/power/reset/sram-reboot-mode.txtDocumentation/devicetree/bindings/power/reset/sram-reboot-mode.txt new file +47
-0@@ -0,0 +1,47 @@ +SRAM reboot mode driver + +This driver get reboot mode magic value form reboot-mode driver +and stores it in a SRAM address. Then the bootloader +can read it and take different action according to the magic +value stored. + +This DT node should be represented as a sub-node of a "mmio-sram", "simple-bus" +node. + +Required properties: +- compatible: should be "sram-reboot-mode" +- reg: offset from the sram range where to store the magic value(in bytes) + +The rest of the properties should follow the generic reboot-mode discription +found in reboot-mode.txt + +Example: + + sram@5f01000 { + compatible = "mmio-sram", "simple-bus"; + reg = <0x0 0x05f01000 0x0 0x00001000>; + ranges = <0x0 0x0 0x05f01000 0x00001000>; + + #address-cells = <1>; + #size-cells = <1>; + + reboot-mode@0 { + compatible = "sram-reboot-mode"; + reg = <0x0 0x4>; + + none { + linux,mode = "none"; + loader,magic = <0x77665501>; + }; + + bootloader { + linux,mode = "bootloader"; + loader,magic = <0x77665500>; + }; + + recovery { + linux,mode = "recovery"; + loader,magic = <0x77665502>; + }; + }; + };
RFC PATCH 2/3 power: reset: Add sram-reboot-mode driver
In reply to John StultzAdd sram-reboot-mode driver, which enables reboot modes to be specified from sram subnodes.
--- drivers/power/reset/Kconfig | 9 +++++ drivers/power/reset/Makefile | 1 + drivers/power/reset/sram-reboot-mode.c | 66 ++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 drivers/power/reset/sram-reboot-mode.c
drivers/power/reset/Kconfig +9 -0
@@ -182,5 +182,14 @@ config SYSCON_REBOOT_MODE register, then the bootloader can read it to take different action according to the mode. +config SRAM_REBOOT_MODE + bool "Generic SRAM reboot mode driver" + select REBOOT_MODE + help + Say y here will enable reboot mode driver. This will + get reboot mode arguments and store it in an SRAM + address, then the bootloader can read it to take different + action according to the mode. + endif
drivers/power/reset/Makefile +1 -0
@@ -21,4 +21,5 @@ obj-$(CONFIG_POWER_RESET_SYSCON_POWEROFF) += syscon-poweroff.o obj-$(CONFIG_POWER_RESET_RMOBILE) += rmobile-reset.o obj-$(CONFIG_REBOOT_MODE) += reboot-mode.o obj-$(CONFIG_SYSCON_REBOOT_MODE) += syscon-reboot-mode.o +obj-$(CONFIG_SRAM_REBOOT_MODE) += sram-reboot-mode.o
drivers/power/reset/sram-reboot-mode.c new file +66 -0
66 lines not on this page · raw message
Signature · 1 line
1.9.1
RFC PATCH 3/3 dts: hikey: Add hikey support for sram-reboot-mode
In reply to John StultzAdd support to hikey dts and defconfig for the
sram-reboot-mode driver.
The dts entries added here should really be generated by the UEFI firmware, and not be static in the dts, since one may be using different firmware on HiKey. But this patch provides an example of how the sram-reboot-mode entry would otherwise look.
--- arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts | 36 ++++++++++++++++++++++++++ arch/arm64/configs/hikey_defconfig | 3 +++ 2 files changed, 39 insertions(+)
arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts +36 -0
@@ -52,6 +52,11 @@ <0x0 0x0740f000 0x0 0x00001000>; /* MCU firmware section */ }; + reboot-reason@05f01000 { + no-map; + reg = <0x0 0x05f01000 0x0 0x00001000>; + }; + mbox-buf@06dff000 { no-map; reg = <0x0 0x06dff000 0x0 0x00001000>; /* Mailbox message buf */
@@ -71,6 +76,37 @@ ftrace-size = <0x0 0x00020000>; }; + + /* This entry should really be provided by the UEFI firmware */ + sram@5f01000 { + compatible = "mmio-sram", "simple-bus"; + reg = <0x0 0x05f01000 0x0 0x00001000>; + ranges = <0x0 0x0 0x05f01000 0x00001000>; + + #address-cells = <1>; + #size-cells = <1>; + + reboot-mode@0 { + compatible = "sram-reboot-mode"; + reg = <0x0 0x4>; + + none { + linux,mode = "none"; + loader,magic = <0x77665501>; + }; + + bootloader { + linux,mode = "bootloader"; + loader,magic = <0x77665500>; + }; + + recovery { + linux,mode = "recovery"; + loader,magic = <0x77665502>; + }; + }; + }; + smb { uart0: uart@f8015000 { /* console */ status = "ok";
arch/arm64/configs/hikey_defconfig +3 -0
@@ -201,6 +201,7 @@ CONFIG_BLK_DEV_LOOP=y CONFIG_BLK_DEV_RAM=y CONFIG_BLK_DEV_RAM_SIZE=16384 CONFIG_VIRTIO_BLK=y +CONFIG_SRAM=y CONFIG_TI_ST=y CONFIG_ST_HCI=y # CONFIG_SCSI_PROC_FS is not set
@@ -266,6 +267,8 @@ CONFIG_SPI_PL022=y CONFIG_GPIO_SYSFS=y CONFIG_GPIO_XGENE=y CONFIG_POWER_RESET_SYSCON=y +CONFIG_SYSCON_REBOOT_MODE=y +CONFIG_SRAM_REBOOT_MODE=y CONFIG_THERMAL=y CONFIG_THERMAL_WRITABLE_TRIPS=y CONFIG_THERMAL_DEFAULT_GOV_POWER_ALLOCATOR=y
Signature · 1 line
1.9.1
Rob Herring
maintainerRe: [RFC][PATCH 3/3] dts: hikey: Add hikey support for sram-reboot-mode
Quoted 33 lines · John Stultz
Add support to hikey dts and defconfig for the
sram-reboot-mode driver.The dts entries added here should really be generated by the UEFI firmware, and not be static in the dts, since one may be using different firmware on HiKey. But this patch provides an example of how the sram-reboot-mode entry would otherwise look.
Cc Andy Yan <[email protected]>Cc Rob Herring <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Thierry Reding <[email protected]>Cc Heiko Stübner <[email protected]>Cc Caesar Wang <[email protected]>Cc Kees Cook <[email protected]>Cc Guodong Xu <[email protected]>Cc Haojian Zhuang <[email protected]>Cc Vishal Bhoj <[email protected]>Cc Bjorn Andersson <[email protected]>Cc Android Kernel Team <[email protected]>Signed-off-by John Stultz <[email protected]>--- arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts | 36 ++++++++++++++++++++++++++ arch/arm64/configs/hikey_defconfig | 3 +++ 2 files changed, 39 insertions(+)arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts +0
-0
arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts line 59
Quoted 8 lines
arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts +5
-0@@ -52,6 +52,11 @@ <0x0 0x0740f000 0x0 0x00001000>; /* MCU firmware section */ }; + reboot-reason@05f01000 { + no-map; + reg = <0x0 0x05f01000 0x0 0x00001000>; + }; +
This hunk should be dropped. These regions are for main memory.
arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts line 82
Quoted 11 lines
arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts +4
-0mbox-buf@06dff000 { no-map; reg = <0x0 0x06dff000 0x0 0x00001000>; /* Mailbox message buf */@@ -71,6 +76,37 @@ ftrace-size = <0x0 0x00020000>; }; + + /* This entry should really be provided by the UEFI firmware */ + sram@5f01000 { + compatible = "mmio-sram", "simple-bus";
The suggestion to put "simple-bus" here was really just for debugging. Really, the mmio-sram driver should call of_platform_default_populate to probe it's children.
Quoted 54 lines
arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts +27
-0+ reg = <0x0 0x05f01000 0x0 0x00001000>; + ranges = <0x0 0x0 0x05f01000 0x00001000>; + + #address-cells = <1>; + #size-cells = <1>; + + reboot-mode@0 { + compatible = "sram-reboot-mode"; + reg = <0x0 0x4>; + + none { + linux,mode = "none"; + loader,magic = <0x77665501>; + }; + + bootloader { + linux,mode = "bootloader"; + loader,magic = <0x77665500>; + }; + + recovery { + linux,mode = "recovery"; + loader,magic = <0x77665502>; + }; + }; + }; + smb { uart0: uart@f8015000 { /* console */ status = "ok";arch/arm64/configs/hikey_defconfig +3
-1@@ -201,6 +201,7 @@ CONFIG_BLK_DEV_LOOP=y CONFIG_BLK_DEV_RAM=y CONFIG_BLK_DEV_RAM_SIZE=16384 CONFIG_VIRTIO_BLK=y +CONFIG_SRAM=y CONFIG_TI_ST=y CONFIG_ST_HCI=y # CONFIG_SCSI_PROC_FS is not set@@ -266,6 +267,8 @@ CONFIG_SPI_PL022=y CONFIG_GPIO_SYSFS=y CONFIG_GPIO_XGENE=y CONFIG_POWER_RESET_SYSCON=y +CONFIG_SYSCON_REBOOT_MODE=y +CONFIG_SRAM_REBOOT_MODE=y CONFIG_THERMAL=y CONFIG_THERMAL_WRITABLE_TRIPS=y CONFIG_THERMAL_DEFAULT_GOV_POWER_ALLOCATOR=y --1.9.1
Hi John,
Quoted 11 lines · John Stultz
This patchset extends on Andy Yan's reboot mode driver work from here: https://lkml.org/lkml/2016/1/12/315
It adds reboot mode/reason support for devices that use an SRAM location to communicate with the bootloader.
Doing this via an SRAM subnode was a suggestion from Arnd, but I worry this implementation isn't yet ideal, since I spent quite a bit of time futzing with getting the sram dts entry to work properly. So I suspect there will be a number of suggestions for improvements.
sorry, I missed that discussion, what are the problems you've encountered?
Probably SRAM driver is ready to serve your purposes?
I believe I'm screwing up some HiSilicon specifics, but here is a rough draft, which you may find helpful:
1. Add SRAM node with defined reboot-reason area:
---8<---
(quoted diff) +0 -0
b/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts
index 8185251..c35f5ed 100644
arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts +14 -0
@@ -31,6 +31,20 @@ device_type = "memory"; reg = <0x0 0x0 0x0 0x40000000>; }; + + sram@5f01000 { + compatible = "mmio-sram"; + reg = <0x0 0x05f01000 0x0 0x00001000>; + ranges = <0x0 0x0 0x05f01000 0x00001000>; + + #address-cells = <1>; + #size-cells = <1>; + + reboot-reason: reboot-reason { + reg = <0x0 0x4>; + pool; + }; + }; }; &uart2 {
---8<---
2. Reference reboot-reason node from reboot mode driver's node, probably you need to add an optional property (here "reason-storage") to its binding:
---8<---
reboot-mode {
compatible = "syscon-reboot-mode";
[snip]
reason-storage = <&reboot-reason>;
}---8<---
3. In reboot-mode driver read or write to that SRAM partition:
---8<---
storage = of_gen_pool_get(reboot_mode_np, "reason-storage", 0);
if (!storage)
goto no_storage;
size = gen_pool_size(storage);
base = gen_pool_alloc(storage, pool_size);
if (!base)
return -EINVAL;
writel(0x77665501, base);
gen_pool_free(storage, base, size);no_storage:
return 0;
---8<---
There is one noticeable benefit of this approach - you don't need to write another driver and you don't need to add another DT binding.
With best wishes,
Vladimir
Quoted 42 lines
Again, this series dependson Andy's patch set above, but also was developed & tested against the 4.1 based hikey tree, so at least the hikey dts patch won't apply. I'm mostly sending this out for just a rough initial review of the dts and conceptual usage of sram subnodes.
Also, it was pointed out that the hikey dts entry for this really should be added by the UEFI firmware, since alternative bootloaders may be used which do not support this feature. So the hikey dts patch isn't likely to ever go upstream, but its a useful illustration for how other devices might use this driver.
Cc Andy Yan <[email protected]>Cc Rob Herring <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Thierry Reding <[email protected]>Cc Heiko Stübner <[email protected]>Cc Caesar Wang <[email protected]>Cc Kees Cook <[email protected]>Cc Guodong Xu <[email protected]>Cc Haojian Zhuang <[email protected]>Cc Vishal Bhoj <[email protected]>Cc Bjorn Andersson <[email protected]>Cc Android Kernel Team <[email protected]>John Stultz (3):
dt-bindings: power: reset: Add document for sram-reboot-mode driver
power: reset: Add sram-reboot-mode driver
dts: hikey: Add hikey support for sram-reboot-mode.../bindings/power/reset/sram-reboot-mode.txt | 47 +++++++++++++++ arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts | 36 ++++++++++++ arch/arm64/configs/hikey_defconfig | 3 + drivers/power/reset/Kconfig | 9 +++ drivers/power/reset/Makefile | 1 + drivers/power/reset/sram-reboot-mode.c | 66 ++++++++++++++++++++++ 6 files changed, 162 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/reset/sram-reboot-mode.txt create mode 100644 drivers/power/reset/sram-reboot-mode.c