Add reboot mode support
v2 cover Add reboot mode support
Description
-----------
Add support for reboot-mode configuration using GPIOs and RTC SRAM as back-end.
Testing
-------
Tested on a Zynq based board where device tree was configured to contain the reboot-mode configuration:
&amba {
status = "okay";
reboot-mode-gpio {
compatible = "reboot-mode-gpio";
gpios = <&gpio0 47 GPIO_ACTIVE_LOW>;
mode-test = <0x1>;
};
reboot-mode-rtc {
compatible = "reboot-mode-rtc";
rtc = <&rtc_0>;
reg = <0x14 4>;
mode-test = <0x21969147>;
};
};In addition to this and not part of this patchset is a change to board.c where GPIO or RTC SRAM backed is selected dynamically at runtime.
1. Test that the reboot mode configured in user-space is read in U-Boot and environment configured: PASS
Userspace ~ # reboot test
....
[ 177.335936] reboot: Restarting system with command 'test'
U-Boot SPL 2019.01 (Mar 29 2019 - 10:44:22 +0000)
...
U-Boot> print reboot-mode
reboot-mode=test
2. Reset the system using the reset command and stop in U-Boot.
3. Verify that reboot-mode env variable is not configured anymore: PASS
U-Boot> print reboot-mode
## Error: "reboot-mode" not defined
4. Toggle the GPIO configured for test mode to active and reset the system with command reset.
5. Stop in U-Boot and check that reboot-mode env variable is configured:PASS
U-Boot> print reboot-mode
reboot-mode=test
Changes since v1:
----------------
- rebased
Nandor Han (3):
reboot-mode: add support for reboot mode control
reboot-mode: read the boot mode from GPIOs status
reboot-mode: read the boot mode from RTC memory
.../reboot-mode/reboot-mode-gpio.txt | 20 +++ .../reboot-mode/reboot-mode-rtc.txt | 22 +++ drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/reboot-mode/Kconfig | 36 +++++ drivers/reboot-mode/Makefile | 9 ++ drivers/reboot-mode/reboot-mode-gpio.c | 125 +++++++++++++++++ drivers/reboot-mode/reboot-mode-rtc.c | 132 ++++++++++++++++++ drivers/reboot-mode/reboot-mode-uclass.c | 132 ++++++++++++++++++ include/dm/uclass-id.h | 1 + include/reboot-mode/reboot-mode-gpio.h | 32 +++++ include/reboot-mode/reboot-mode-rtc.h | 16 +++ include/reboot-mode/reboot-mode.h | 56 ++++++++ 13 files changed, 584 insertions(+) create mode 100644 doc/device-tree-bindings/reboot-mode/reboot-mode-gpio.txt create mode 100644 doc/device-tree-bindings/reboot-mode/reboot-mode-rtc.txt create mode 100644 drivers/reboot-mode/Kconfig create mode 100644 drivers/reboot-mode/Makefile create mode 100644 drivers/reboot-mode/reboot-mode-gpio.c create mode 100644 drivers/reboot-mode/reboot-mode-rtc.c create mode 100644 drivers/reboot-mode/reboot-mode-uclass.c create mode 100644 include/reboot-mode/reboot-mode-gpio.h create mode 100644 include/reboot-mode/reboot-mode-rtc.h create mode 100644 include/reboot-mode/reboot-mode.h
Signature · 1 line
2.24.1
PATCH v2 1/3 reboot-mode: add support for reboot mode control
A new driver uclass is created to handle the reboot mode control.
The new uclass driver is updating an environment variable with the configured reboot mode. The mode is extracted from a map provided at initialization time. The map contains a list of modes and associated ids.
--- drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/reboot-mode/Kconfig | 18 ++++ drivers/reboot-mode/Makefile | 7 ++ drivers/reboot-mode/reboot-mode-uclass.c | 132 +++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/reboot-mode/reboot-mode.h | 56 ++++++++++ 7 files changed, 217 insertions(+) create mode 100644 drivers/reboot-mode/Kconfig create mode 100644 drivers/reboot-mode/Makefile create mode 100644 drivers/reboot-mode/reboot-mode-uclass.c create mode 100644 include/reboot-mode/reboot-mode.h
drivers/Kconfig +2 -0
@@ -86,6 +86,8 @@ source "drivers/qe/Kconfig" source "drivers/ram/Kconfig" +source "drivers/reboot-mode/Kconfig" + source "drivers/remoteproc/Kconfig" source "drivers/reset/Kconfig"
drivers/Makefile +1 -0
@@ -91,6 +91,7 @@ obj-y += dfu/ obj-$(CONFIG_PCH) += pch/ obj-y += phy/allwinner/ obj-y += phy/marvell/ +obj-$(CONFIG_DM_REBOOT_MODE) += reboot-mode/ obj-y += rtc/ obj-y += scsi/ obj-y += sound/
drivers/reboot-mode/Kconfig new file +18 -0
@@ -0,0 +1,18 @@ +# +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (c), Vaisala Oyj +# + +menu "Reboot Mode Support" + +config DM_REBOOT_MODE + bool "Enable reboot mode using Driver Model" + depends on DM + default n + help + Enable support for reboot mode control. This will allow users to + adjust the boot process based on reboot mode parameter + passed to U-Boot. + +endmenu
drivers/reboot-mode/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (c), Vaisala Oyj +# + +obj-$(CONFIG_DM_REBOOT_MODE) += reboot-mode-uclass.o
drivers/reboot-mode/reboot-mode-uclass.c new file +132 -0
132 lines not on this page · raw message
include/dm/uclass-id.h +1 -0
@@ -87,6 +87,7 @@ enum uclass_id {UCLASS_PWM ,/* Pulse-width modulator */ UCLASS_PWRSEQ ,/* Power sequence device */ UCLASS_RAM ,/* RAM controller */ +UCLASS_REBOOT_MODE ,/* Reboot mode */ UCLASS_REGULATOR ,/* Regulator device */ UCLASS_REMOTEPROC ,/* Remote Processor device */ UCLASS_RESET, /* Reset controller device */
include/reboot-mode/reboot-mode.h new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH v2 2/3 reboot-mode: read the boot mode from GPIOs status
In reply to Nandor HanA use case for controlling the boot mode is when the user wants to control the device boot by pushing a button without needing to go in user-space.
Add a new backed for reboot mode where GPIOs are used to control the reboot-mode. The driver is able to scan a predefined list of GPIOs and return the magic value. Having the modes associated with the magic value generated based on the GPIO values, allows the reboot mode uclass to select the proper mode.
--- .../reboot-mode/reboot-mode-gpio.txt | 20 +++ drivers/reboot-mode/Kconfig | 9 ++ drivers/reboot-mode/Makefile | 1 + drivers/reboot-mode/reboot-mode-gpio.c | 125 ++++++++++++++++++ include/reboot-mode/reboot-mode-gpio.h | 32 +++++ 5 files changed, 187 insertions(+) create mode 100644 doc/device-tree-bindings/reboot-mode/reboot-mode-gpio.txt create mode 100644 drivers/reboot-mode/reboot-mode-gpio.c create mode 100644 include/reboot-mode/reboot-mode-gpio.h
doc/device-tree-bindings/reboot-mode/reboot-mode-gpio.txt new file +20 -0
@@ -0,0 +1,20 @@ +GPIO Reboot Mode Configuration + +Required Properties: +- compatible: must be "reboot-mode-gpio". +- gpios: list of gpios that are used to calculate the reboot-mode magic value. + Every gpio represents a bit in the magic value in the same order + as defined in device tree. +- modes: list of properties that define the modes and associated unique ids. + +Optional Properties: +- u-boot,env-variable: used to save the reboot mode (default: reboot-mode). + +Example: + reboot-mode { + compatible = "reboot-mode-gpio"; + gpios = <&gpio1 2 GPIO_ACTIVE_LOW>, <&gpio2 6 GPIO_ACTIVE_HIGH>; + u-boot,env-variable = "bootstatus"; + mode-test = <0x00000001>; + mode-download = <0x00000002>; + };
drivers/reboot-mode/Kconfig +9 -0
@@ -15,4 +15,13 @@ config DM_REBOOT_MODE adjust the boot process based on reboot mode parameter passed to U-Boot. +config DM_REBOOT_MODE_GPIO + bool "Use GPIOs as reboot mode backend" + depends on DM_REBOOT_MODE + default n + help + Use GPIOs to control the reboot mode. This will allow users to boot + a device in a specific mode by using a GPIO that can be controlled + outside U-Boot. + endmenu
drivers/reboot-mode/Makefile +1 -0
@@ -5,3 +5,4 @@ # obj-$(CONFIG_DM_REBOOT_MODE) += reboot-mode-uclass.o +obj-$(CONFIG_DM_REBOOT_MODE_GPIO) += reboot-mode-gpio.o
drivers/reboot-mode/reboot-mode-gpio.c new file +125 -0
125 lines not on this page · raw message
include/reboot-mode/reboot-mode-gpio.h new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (c) Vaisala Oyj. +*/ + +#ifndef REBOOT_MODE_REBOOT_MODE_GPIO_H_ +#define REBOOT_MODE_REBOOT_MODE_GPIO_H_ + +#include <asm/gpio.h> + +/* +* In case of initializing the driver statically (using U_BOOT_DEVICE macro), +* we can use this struct to declare the pins used. +*/ + +#if !CONFIG_IS_ENABLED (OF_CONTROL ) +struct reboot_mode_gpio_config { +int gpio_dev_offset; +int gpio_offset; +int flags; +}; +#endif + +struct reboot_mode_gpio_platdata { +struct gpio_desc *gpio_desc; +#if !CONFIG_IS_ENABLED (OF_CONTROL ) +struct reboot_mode_gpio_config *gpios_config; +#endif +int gpio_count; +}; + +#endif /* REBOOT_MODE_REBOOT_MODE_GPIO_H_ */
Signature · 1 line
2.24.1
PATCH v2 3/3 reboot-mode: read the boot mode from RTC memory
In reply to Nandor HanRTC devices could provide battery-backed memory that can be used for storing the reboot mode magic value.
Add a new reboot-mode back-end that uses RTC to store the reboot-mode magic value. The driver also supports both endianness modes.
--- .../reboot-mode/reboot-mode-rtc.txt | 22 +++ drivers/reboot-mode/Kconfig | 9 ++ drivers/reboot-mode/Makefile | 1 + drivers/reboot-mode/reboot-mode-rtc.c | 132 ++++++++++++++++++ include/reboot-mode/reboot-mode-rtc.h | 16 +++ 5 files changed, 180 insertions(+) create mode 100644 doc/device-tree-bindings/reboot-mode/reboot-mode-rtc.txt create mode 100644 drivers/reboot-mode/reboot-mode-rtc.c create mode 100644 include/reboot-mode/reboot-mode-rtc.h
doc/device-tree-bindings/reboot-mode/reboot-mode-rtc.txt new file +22 -0
@@ -0,0 +1,22 @@ +RTC Reboot Mode Configuration + +Required Properties: +- compatible: must be "reboot-mode-rtc". +- rtc: reference to the rtc device used. +- reg: start register and the number of bytes used. Maximum 4 bytes supported. +- modes: list of properties that define the modes and associated unique ids. + +Optional Properties: +- u-boot,env-variable: used to save the reboot mode (default: reboot-mode). +- big-endian: if the magic value is stored in big-endian. (default: false). + +Example: + reboot-mode-rtc { + compatible = "reboot-mode-rtc"; + rtc = <&rtc_0>; + reg = <0x14 4>; + u-boot,env-variable = "bootstatus"; + big-endian; + modes-test = <0x21969147>; + modes-download = <0x51939147>; + };
drivers/reboot-mode/Kconfig +9 -0
@@ -24,4 +24,13 @@ config DM_REBOOT_MODE_GPIO a device in a specific mode by using a GPIO that can be controlled outside U-Boot. +config DM_REBOOT_MODE_RTC + bool "Use RTC as reboot mode backend" + depends on DM_REBOOT_MODE + default n + help + Use RTC non volatile memory to control the reboot mode. This will allow users to boot + a device in a specific mode by using a register(s) that can be controlled + outside U-Boot (e.g. Kernel). + endmenu
drivers/reboot-mode/Makefile +1 -0
@@ -6,3 +6,4 @@ obj-$(CONFIG_DM_REBOOT_MODE) += reboot-mode-uclass.o obj-$(CONFIG_DM_REBOOT_MODE_GPIO) += reboot-mode-gpio.o +obj-$(CONFIG_DM_REBOOT_MODE_RTC) += reboot-mode-rtc.o
drivers/reboot-mode/reboot-mode-rtc.c new file +132 -0
132 lines not on this page · raw message
include/reboot-mode/reboot-mode-rtc.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (c), Vaisala Oyj +*/ + +#ifndef REBOOT_MODE_REBOOT_MODE_RTC_H_ +#define REBOOT_MODE_REBOOT_MODE_RTC_H_ + +struct reboot_mode_rtc_platdata { +struct udevice *rtc; +bool is_big_endian; +int addr; +size_t size; +}; + +#endif /* REBOOT_MODE_REBOOT_MODE_RTC_H_ */
Signature · 1 line
2.24.1
v2 cover Add reboot mode support
In reply to Nandor HanQuoted 5 lines · Nandor Han
Description
-----------
Add support for reboot-mode configuration using GPIOs and RTC SRAM as back-end.
Ping. Any comments about this? Can this be applied?
Regards,
Nandor
v2 cover Add reboot mode support
Quoted 8 lines · Nandor Han
Quoted 5 lines · Nandor Han
Description
-----------
Add support for reboot-mode configuration using GPIOs and RTC SRAM as back-end.Ping. Any comments about this? Can this be applied?
Sorry for the delay. Can you please update this to include some documentation and tests?
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200930/6456c0f4/attachment.sig>
v3 cover Add reboot mode support
Description
-----------
Add support for reboot-mode configuration using GPIOs and RTC SRAM as back-end.
Testing
-------
Tested on a Zynq based board where device tree was configured to contain the reboot-mode configuration:
&amba {
status = "okay";
reboot-mode-gpio {
compatible = "reboot-mode-gpio";
gpios = <&gpio0 47 GPIO_ACTIVE_LOW>;
mode-test = <0x1>;
};
reboot-mode-rtc {
compatible = "reboot-mode-rtc";
rtc = <&rtc_0>;
reg = <0x14 4>;
mode-test = <0x21969147>;
};
};In addition to this and not part of this patchset is a change to board.c where GPIO or RTC SRAM backed is selected dynamically at runtime.
1. Test that the reboot mode configured in user-space is read in U-Boot and environment configured: PASS
Userspace ~ # reboot test
....
[ 177.335936] reboot: Restarting system with command 'test'
U-Boot SPL 2019.01 (Mar 29 2019 - 10:44:22 +0000)
...
U-Boot> print reboot-mode
reboot-mode=test
2. Reset the system using the reset command and stop in U-Boot.
3. Verify that reboot-mode env variable is not configured anymore: PASS
U-Boot> print reboot-mode
## Error: "reboot-mode" not defined
4. Toggle the GPIO configured for test mode to active and reset the system with command reset.
5. Stop in U-Boot and check that reboot-mode env variable is configured:PASS
U-Boot> print reboot-mode
reboot-mode=test
6. Verify that unit-tests are successful: PASS
``` localhost /u-boot-latest (wip-reboot-mode)> ./test/py/test.py --bd sandbox --build -k ut_dm_reboot_mode -v ... test/py/tests/test_ut.py::test_ut[ut_dm_reboot_mode_gpio] PASSED [ 50%] test/py/tests/test_ut.py::test_ut[ut_dm_reboot_mode_rtc] PASSED [100%] ========================================================== 2 passed, 759 deselected in 0.40 seconds ========================================================== ```
Changes since v1:
----------------
- rebased
Changes since v2:
----------------
- unit-tests added
Nandor Han (3):
reboot-mode: add support for reboot mode control
reboot-mode: read the boot mode from GPIOs status
reboot-mode: read the boot mode from RTC memory
arch/sandbox/dts/test.dts | 18 +++ configs/sandbox_defconfig | 3 + .../reboot-mode/reboot-mode-gpio.txt | 20 +++ .../reboot-mode/reboot-mode-rtc.txt | 22 +++ drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/reboot-mode/Kconfig | 36 +++++ drivers/reboot-mode/Makefile | 9 ++ drivers/reboot-mode/reboot-mode-gpio.c | 128 +++++++++++++++++ drivers/reboot-mode/reboot-mode-rtc.c | 127 +++++++++++++++++ drivers/reboot-mode/reboot-mode-uclass.c | 134 ++++++++++++++++++ include/dm/uclass-id.h | 1 + include/reboot-mode/reboot-mode-gpio.h | 32 +++++ include/reboot-mode/reboot-mode-rtc.h | 16 +++ include/reboot-mode/reboot-mode.h | 56 ++++++++ test/dm/Makefile | 1 + test/dm/reboot-mode.c | 71 ++++++++++ 17 files changed, 677 insertions(+) create mode 100644 doc/device-tree-bindings/reboot-mode/reboot-mode-gpio.txt create mode 100644 doc/device-tree-bindings/reboot-mode/reboot-mode-rtc.txt create mode 100644 drivers/reboot-mode/Kconfig create mode 100644 drivers/reboot-mode/Makefile create mode 100644 drivers/reboot-mode/reboot-mode-gpio.c create mode 100644 drivers/reboot-mode/reboot-mode-rtc.c create mode 100644 drivers/reboot-mode/reboot-mode-uclass.c create mode 100644 include/reboot-mode/reboot-mode-gpio.h create mode 100644 include/reboot-mode/reboot-mode-rtc.h create mode 100644 include/reboot-mode/reboot-mode.h create mode 100644 test/dm/reboot-mode.c
Signature · 1 line
2.26.3
PATCH v3 1/3 reboot-mode: add support for reboot mode control
In reply to Tom RiniA new driver uclass is created to handle the reboot mode control.
The new uclass driver is updating an environment variable with the configured reboot mode. The mode is extracted from a map provided at initialization time. The map contains a list of modes and associated ids.
--- drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/reboot-mode/Kconfig | 18 +++ drivers/reboot-mode/Makefile | 7 ++ drivers/reboot-mode/reboot-mode-uclass.c | 134 +++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/reboot-mode/reboot-mode.h | 56 ++++++++++ 7 files changed, 219 insertions(+) create mode 100644 drivers/reboot-mode/Kconfig create mode 100644 drivers/reboot-mode/Makefile create mode 100644 drivers/reboot-mode/reboot-mode-uclass.c create mode 100644 include/reboot-mode/reboot-mode.h
drivers/Kconfig +2 -0
@@ -92,6 +92,8 @@ source "drivers/qe/Kconfig" source "drivers/ram/Kconfig" +source "drivers/reboot-mode/Kconfig" + source "drivers/remoteproc/Kconfig" source "drivers/reset/Kconfig"
drivers/Makefile +1 -0
@@ -94,6 +94,7 @@ obj-y += dfu/ obj-$(CONFIG_PCH) += pch/ obj-y += phy/allwinner/ obj-y += phy/marvell/ +obj-$(CONFIG_DM_REBOOT_MODE) += reboot-mode/ obj-y += phy/rockchip/ obj-y += rtc/ obj-y += scsi/
drivers/reboot-mode/Kconfig new file +18 -0
@@ -0,0 +1,18 @@ +# +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (c), Vaisala Oyj +# + +menu "Reboot Mode Support" + +config DM_REBOOT_MODE + bool "Enable reboot mode using Driver Model" + depends on DM + default n + help + Enable support for reboot mode control. This will allow users to + adjust the boot process based on reboot mode parameter + passed to U-Boot. + +endmenu
drivers/reboot-mode/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (c), Vaisala Oyj +# + +obj-$(CONFIG_DM_REBOOT_MODE) += reboot-mode-uclass.o
drivers/reboot-mode/reboot-mode-uclass.c new file +134 -0
134 lines not on this page · raw message
include/dm/uclass-id.h +1 -0
@@ -90,6 +90,7 @@ enum uclass_id {UCLASS_PWM ,/* Pulse-width modulator */ UCLASS_PWRSEQ ,/* Power sequence device */ UCLASS_RAM ,/* RAM controller */ +UCLASS_REBOOT_MODE ,/* Reboot mode */ UCLASS_REGULATOR ,/* Regulator device */ UCLASS_REMOTEPROC ,/* Remote Processor device */ UCLASS_RESET, /* Reset controller device */
include/reboot-mode/reboot-mode.h new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.26.3
PATCH v3 2/3 reboot-mode: read the boot mode from GPIOs status
In reply to Tom RiniA use case for controlling the boot mode is when the user wants to control the device boot by pushing a button without needing to go in user-space.
Add a new backed for reboot mode where GPIOs are used to control the reboot-mode. The driver is able to scan a predefined list of GPIOs and return the magic value. Having the modes associated with the magic value generated based on the GPIO values, allows the reboot mode uclass to select the proper mode.
--- arch/sandbox/dts/test.dts | 8 ++ configs/sandbox_defconfig | 2 + .../reboot-mode/reboot-mode-gpio.txt | 20 +++ drivers/reboot-mode/Kconfig | 9 ++ drivers/reboot-mode/Makefile | 1 + drivers/reboot-mode/reboot-mode-gpio.c | 128 ++++++++++++++++++ include/reboot-mode/reboot-mode-gpio.h | 32 +++++ test/dm/Makefile | 1 + test/dm/reboot-mode.c | 42 ++++++ 9 files changed, 243 insertions(+) create mode 100644 doc/device-tree-bindings/reboot-mode/reboot-mode-gpio.txt create mode 100644 drivers/reboot-mode/reboot-mode-gpio.c create mode 100644 include/reboot-mode/reboot-mode-gpio.h create mode 100644 test/dm/reboot-mode.c
arch/sandbox/dts/test.dts +8 -0
@@ -48,6 +48,14 @@ osd0 = "/osd"; }; + reboot-mode0 { + compatible = "reboot-mode-gpio"; + gpios = <&gpio_c 0 GPIO_ACTIVE_HIGH>, <&gpio_c 1 GPIO_ACTIVE_HIGH>; + u-boot,env-variable = "bootstatus"; + mode-test = <0x01>; + mode-download = <0x03>; + }; + audio: audio-codec { compatible = "sandbox,audio-codec"; #sound-dai-cells = <1>;
configs/sandbox_defconfig +2 -0
@@ -274,3 +274,5 @@ CONFIG_TEST_FDTDEC=y CONFIG_UNIT_TEST=y CONFIG_UT_TIME=y CONFIG_UT_DM=y +CONFIG_DM_REBOOT_MODE=y +CONFIG_DM_REBOOT_MODE_GPIO=y
doc/device-tree-bindings/reboot-mode/reboot-mode-gpio.txt new file +20 -0
@@ -0,0 +1,20 @@ +GPIO Reboot Mode Configuration + +Required Properties: +- compatible: must be "reboot-mode-gpio". +- gpios: list of gpios that are used to calculate the reboot-mode magic value. + Every gpio represents a bit in the magic value in the same order + as defined in device tree. +- modes: list of properties that define the modes and associated unique ids. + +Optional Properties: +- u-boot,env-variable: used to save the reboot mode (default: reboot-mode). + +Example: + reboot-mode { + compatible = "reboot-mode-gpio"; + gpios = <&gpio1 2 GPIO_ACTIVE_LOW>, <&gpio2 6 GPIO_ACTIVE_HIGH>; + u-boot,env-variable = "bootstatus"; + mode-test = <0x00000001>; + mode-download = <0x00000002>; + };
drivers/reboot-mode/Kconfig +9 -0
@@ -15,4 +15,13 @@ config DM_REBOOT_MODE adjust the boot process based on reboot mode parameter passed to U-Boot. +config DM_REBOOT_MODE_GPIO + bool "Use GPIOs as reboot mode backend" + depends on DM_REBOOT_MODE + default n + help + Use GPIOs to control the reboot mode. This will allow users to boot + a device in a specific mode by using a GPIO that can be controlled + outside U-Boot. + endmenu
drivers/reboot-mode/Makefile +1 -0
@@ -5,3 +5,4 @@ # obj-$(CONFIG_DM_REBOOT_MODE) += reboot-mode-uclass.o +obj-$(CONFIG_DM_REBOOT_MODE_GPIO) += reboot-mode-gpio.o
drivers/reboot-mode/reboot-mode-gpio.c new file +128 -0
128 lines not on this page · raw message
include/reboot-mode/reboot-mode-gpio.h new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (c) Vaisala Oyj. +*/ + +#ifndef REBOOT_MODE_REBOOT_MODE_GPIO_H_ +#define REBOOT_MODE_REBOOT_MODE_GPIO_H_ + +#include <asm/gpio.h> + +/* +* In case of initializing the driver statically (using U_BOOT_DEVICE macro), +* we can use this struct to declare the pins used. +*/ + +#if !CONFIG_IS_ENABLED (OF_CONTROL ) +struct reboot_mode_gpio_config { +int gpio_dev_offset; +int gpio_offset; +int flags; +}; +#endif + +struct reboot_mode_gpio_platdata { +struct gpio_desc *gpio_desc; +#if !CONFIG_IS_ENABLED (OF_CONTROL ) +struct reboot_mode_gpio_config *gpios_config; +#endif +int gpio_count; +}; + +#endif /* REBOOT_MODE_REBOOT_MODE_GPIO_H_ */
test/dm/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-$(CONFIG_BLK) += blk.o obj-$(CONFIG_BOARD) += board.o obj-$(CONFIG_BUTTON) += button.o obj-$(CONFIG_DM_BOOTCOUNT) += bootcount.o +obj-$(CONFIG_DM_REBOOT_MODE) += reboot-mode.o obj-$(CONFIG_CLK) += clk.o clk_ccf.o obj-$(CONFIG_DEVRES) += devres.o obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi_host.o
test/dm/reboot-mode.c new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.26.3
PATCH v3 3/3 reboot-mode: read the boot mode from RTC memory
In reply to Tom RiniRTC devices could provide battery-backed memory that can be used for storing the reboot mode magic value.
Add a new reboot-mode back-end that uses RTC to store the reboot-mode magic value. The driver also supports both endianness modes.
--- arch/sandbox/dts/test.dts | 10 ++ configs/sandbox_defconfig | 1 + .../reboot-mode/reboot-mode-rtc.txt | 22 +++ drivers/reboot-mode/Kconfig | 9 ++ drivers/reboot-mode/Makefile | 1 + drivers/reboot-mode/reboot-mode-rtc.c | 127 ++++++++++++++++++ include/reboot-mode/reboot-mode-rtc.h | 16 +++ test/dm/reboot-mode.c | 29 ++++ 8 files changed, 215 insertions(+) create mode 100644 doc/device-tree-bindings/reboot-mode/reboot-mode-rtc.txt create mode 100644 drivers/reboot-mode/reboot-mode-rtc.c create mode 100644 include/reboot-mode/reboot-mode-rtc.h
arch/sandbox/dts/test.dts +10 -0
@@ -56,6 +56,16 @@ mode-download = <0x03>; }; + reboot_mode1: reboot-mode at 14 { + compatible = "reboot-mode-rtc"; + rtc = <&rtc_0>; + reg = <0x30 4>; + u-boot,env-variable = "bootstatus"; + big-endian; + mode-test = <0x21969147>; + mode-download = <0x51939147>; + }; + audio: audio-codec { compatible = "sandbox,audio-codec"; #sound-dai-cells = <1>;
configs/sandbox_defconfig +1 -0
@@ -276,3 +276,4 @@ CONFIG_UT_TIME=y CONFIG_UT_DM=y CONFIG_DM_REBOOT_MODE=y CONFIG_DM_REBOOT_MODE_GPIO=y +CONFIG_DM_REBOOT_MODE_RTC=y
doc/device-tree-bindings/reboot-mode/reboot-mode-rtc.txt new file +22 -0
@@ -0,0 +1,22 @@ +RTC Reboot Mode Configuration + +Required Properties: +- compatible: must be "reboot-mode-rtc". +- rtc: reference to the rtc device used. +- reg: start register and the number of bytes used. Maximum 4 bytes supported. +- modes: list of properties that define the modes and associated unique ids. + +Optional Properties: +- u-boot,env-variable: used to save the reboot mode (default: reboot-mode). +- big-endian: if the magic value is stored in big-endian. (default: false). + +Example: + reboot-mode-rtc { + compatible = "reboot-mode-rtc"; + rtc = <&rtc_0>; + reg = <0x14 4>; + u-boot,env-variable = "bootstatus"; + big-endian; + modes-test = <0x21969147>; + modes-download = <0x51939147>; + };
drivers/reboot-mode/Kconfig +9 -0
@@ -24,4 +24,13 @@ config DM_REBOOT_MODE_GPIO a device in a specific mode by using a GPIO that can be controlled outside U-Boot. +config DM_REBOOT_MODE_RTC + bool "Use RTC as reboot mode backend" + depends on DM_REBOOT_MODE + default n + help + Use RTC non volatile memory to control the reboot mode. This will allow users to boot + a device in a specific mode by using a register(s) that can be controlled + outside U-Boot (e.g. Kernel). + endmenu
drivers/reboot-mode/Makefile +1 -0
@@ -6,3 +6,4 @@ obj-$(CONFIG_DM_REBOOT_MODE) += reboot-mode-uclass.o obj-$(CONFIG_DM_REBOOT_MODE_GPIO) += reboot-mode-gpio.o +obj-$(CONFIG_DM_REBOOT_MODE_RTC) += reboot-mode-rtc.o
drivers/reboot-mode/reboot-mode-rtc.c new file +127 -0
127 lines not on this page · raw message
include/reboot-mode/reboot-mode-rtc.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (c), Vaisala Oyj +*/ + +#ifndef REBOOT_MODE_REBOOT_MODE_RTC_H_ +#define REBOOT_MODE_REBOOT_MODE_RTC_H_ + +struct reboot_mode_rtc_platdata { +struct udevice *rtc; +bool is_big_endian; +int addr; +size_t size; +}; + +#endif /* REBOOT_MODE_REBOOT_MODE_RTC_H_ */
test/dm/reboot-mode.c +29 -0
@@ -9,10 +9,13 @@#include <env.h> #include <log.h> #include <asm/gpio.h> +#include <asm/rtc.h> #include <asm/test.h> #include <dm/test.h> #include <test/test.h> #include <test/ut.h> +#include <rtc.h> +#include <linux/byteorder/generic.h> static int dm_test_reboot_mode_gpio (struct unit_test_state *uts) {
@@ -40,3 +43,29 @@ static int dm_test_reboot_mode_gpio(struct unit_test_state *uts)DM_TEST (dm_test_reboot_mode_gpio,UT_TESTF_PROBE_TEST |UT_TESTF_SCAN_FDT |UT_TESTF_FLAT_TREE ); + +static int dm_test_reboot_mode_rtc (struct unit_test_state *uts) +{ +struct udevice *rtc_dev; +struct udevice *rm_dev; +u32 read_val; +u32 test_magic_val =cpu_to_be32 (0x21969147 ); + +uclass_get_device_by_name (UCLASS_RTC ,"rtc at 43" , + &rtc_dev); +dm_rtc_write (rtc_dev,REG_AUX0 , (u8 *)&test_magic_val,4 ); + +ut_assertok (uclass_get_device_by_name (UCLASS_REBOOT_MODE , +"reboot-mode at 14" , &rm_dev)); +ut_assertok (dm_reboot_mode_update (rm_dev)); + +ut_asserteq_str ("test" ,env_get ("bootstatus" )); + +dm_rtc_read (rtc_dev,REG_AUX0 , (u8 *)&read_val,4 ); +ut_asserteq (read_val,0 ); + +return 0 ; +} + +DM_TEST (dm_test_reboot_mode_rtc, +UT_TESTF_PROBE_TEST |UT_TESTF_SCAN_FDT |UT_TESTF_FLAT_TREE );
Signature · 1 line
2.26.3