summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2022-10-17 09:09:55 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2022-10-27 11:13:29 +0200
commit1c33083a1542db3ea596481781170123f0d0510f (patch)
tree343fb3b2c38f2567604c6b2da06e6f342af207e6
parent21dda946e7aa86246bf7ca22fb1a1609407c4bb9 (diff)
downloadbarebox-1c33083a1542db3ea596481781170123f0d0510f.tar.gz
barebox-1c33083a1542db3ea596481781170123f0d0510f.tar.xz
restart: add reset -w for warm bootrom reset
We currently support reboot mode communication with BootROMs of the i.MX6Q/DL, i.MX8MM and STM32MP15x. For each of these, the user must take care to use the correct reset as the highest priority reset often clears the non-volatile register mapped by the syscon holding the reboot mode. As we only have one BootROM, we can improve usability by adding a global flag that describes whether a restart handler is suitable for use after a bootrom reboot mode write. Add a flag bit describing this and allow populating it from the device tree as well as from drivers. Existing i.MX/STM32 drivers will be moved onto this in follow-up commits. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20221017071000.1458292-4-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--Documentation/boards/imx.rst2
-rw-r--r--Documentation/devicetree/bindings/power/restart.rst5
-rw-r--r--Documentation/user/reboot-mode.rst7
-rw-r--r--commands/reset.c16
-rw-r--r--common/restart.c17
-rw-r--r--include/restart.h5
6 files changed, 39 insertions, 13 deletions
diff --git a/Documentation/boards/imx.rst b/Documentation/boards/imx.rst
index 4ce9d9808c..6c16923340 100644
--- a/Documentation/boards/imx.rst
+++ b/Documentation/boards/imx.rst
@@ -105,7 +105,7 @@ that BootROM should select after a warm reset::
mode-serial = <0x10 0x40000000>;
};
- barebox@FSL i.MX8MM EVK board:/ gpr.reboot_mode.next=serial reset -r imxwd-warm
+ barebox@FSL i.MX8MM EVK board:/ gpr.reboot_mode.next=serial reset -w
This will cause barebox to fall into serial download mode on an i.MX8MM.
diff --git a/Documentation/devicetree/bindings/power/restart.rst b/Documentation/devicetree/bindings/power/restart.rst
index 8c866f6e0d..42b87f7e9c 100644
--- a/Documentation/devicetree/bindings/power/restart.rst
+++ b/Documentation/devicetree/bindings/power/restart.rst
@@ -8,3 +8,8 @@ Optional properties:
- ``restart-priority`` : Overrides the priority set by the driver. Normally,
the device with the biggest reach should reset the system.
See :ref:`_system_reset` for more information.
+
+- ``barebox,restart-warm-bootrom`` : Restart will not cause loss to non-volatile
+ registers sampled by the bootrom at startup. This is a necessary precondition
+ for working :ref:`reboot_mode` communication between barebox and the SoC's
+ BootROM.
diff --git a/Documentation/user/reboot-mode.rst b/Documentation/user/reboot-mode.rst
index 83d4136b85..1929a67e0b 100644
--- a/Documentation/user/reboot-mode.rst
+++ b/Documentation/user/reboot-mode.rst
@@ -47,7 +47,9 @@ Reboot mode providers have priorities. The provider with the highest
priority has its parameters aliased as ``$global.system.reboot_mode.prev``
and ``$global.system.reboot_mode.next``. After executing the init scripts,
barebox startup will ``source /env/bmode/${global.system.reboot_mode.prev}``
-if available.
+if available. Example usage::
+
+ gpr.reboot_mode=serial reset -w
Reset
=====
@@ -60,6 +62,9 @@ If such reboot mode storage is used, users must take care to use the correct
reset provider. In barebox, multiple reset providers may co-exist. The
``reset`` command allows listing and choosing a specific reboot mode.
+For communication with the SoC's BootROM, a warm reset can be triggered
+with ``reset -w`` if a suitable reset handler has been registered.
+
Disambiguation
==============
diff --git a/commands/reset.c b/commands/reset.c
index fe54e2f9b4..88e677afab 100644
--- a/commands/reset.c
+++ b/commands/reset.c
@@ -12,12 +12,12 @@
static int cmd_reset(int argc, char *argv[])
{
struct restart_handler *rst;
- int opt, shutdown_flag;
+ int opt, shutdown_flag, flags = 0;
const char *name = NULL;
shutdown_flag = 1;
- while ((opt = getopt(argc, argv, "flr:")) > 0) {
+ while ((opt = getopt(argc, argv, "flwr:")) > 0) {
switch (opt) {
case 'f':
shutdown_flag = 0;
@@ -25,6 +25,9 @@ static int cmd_reset(int argc, char *argv[])
case 'l':
restart_handlers_print();
return 0;
+ case 'w':
+ flags |= RESTART_FLAG_WARM_BOOTROM;
+ break;
case 'r':
name = optarg;
break;
@@ -33,9 +36,9 @@ static int cmd_reset(int argc, char *argv[])
}
}
- rst = restart_handler_get_by_name(name);
- if (!rst && name) {
- printf("reset '%s' does not exist\n", name);
+ rst = restart_handler_get_by_name(name, flags);
+ if (!rst && (name || flags)) {
+ printf("No matching restart handler found\n");
return COMMAND_ERROR;
}
@@ -57,13 +60,14 @@ BAREBOX_CMD_HELP_START(reset)
BAREBOX_CMD_HELP_TEXT("Options:")
BAREBOX_CMD_HELP_OPT("-f", "force RESET, don't call shutdown")
BAREBOX_CMD_HELP_OPT("-l", "list reset handlers")
+BAREBOX_CMD_HELP_OPT("-w", "only consider warm BootROM reboot-mode-preserving resets")
BAREBOX_CMD_HELP_OPT("-r RESET", "use reset handler named RESET")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(reset)
.cmd = cmd_reset,
BAREBOX_CMD_DESC("perform RESET of the CPU")
- BAREBOX_CMD_OPTS("[-flr]")
+ BAREBOX_CMD_OPTS("[-flrw]")
BAREBOX_CMD_GROUP(CMD_GRP_BOOT)
BAREBOX_CMD_HELP(cmd_reset_help)
BAREBOX_CMD_COMPLETE(empty_complete)
diff --git a/common/restart.c b/common/restart.c
index 9e988838bc..0294b36ecc 100644
--- a/common/restart.c
+++ b/common/restart.c
@@ -30,6 +30,9 @@ int restart_handler_register(struct restart_handler *rst)
if (rst->of_node) {
of_property_read_u32(rst->of_node, "restart-priority",
&rst->priority);
+ if (of_property_read_bool(rst->of_node,
+ "barebox,restart-warm-bootrom"))
+ rst->flags |= RESTART_FLAG_WARM_BOOTROM;
}
list_add_tail(&rst->list, &restart_handler_list);
@@ -73,7 +76,7 @@ int restart_handler_register_fn(const char *name,
/**
* restart_handler_get_by_name() - reset the whole system
*/
-struct restart_handler *restart_handler_get_by_name(const char *name)
+struct restart_handler *restart_handler_get_by_name(const char *name, int flags)
{
struct restart_handler *rst = NULL, *tmp;
unsigned int priority = 0;
@@ -81,6 +84,8 @@ struct restart_handler *restart_handler_get_by_name(const char *name)
list_for_each_entry(tmp, &restart_handler_list, list) {
if (name && tmp->name && strcmp(name, tmp->name))
continue;
+ if (flags && (tmp->flags & flags) != flags)
+ continue;
if (tmp->priority > priority) {
priority = tmp->priority;
rst = tmp;
@@ -97,7 +102,7 @@ void __noreturn restart_machine(void)
{
struct restart_handler *rst;
- rst = restart_handler_get_by_name(NULL);
+ rst = restart_handler_get_by_name(NULL, 0);
if (rst) {
pr_debug("%s: using restart handler %s\n", __func__, rst->name);
console_flush();
@@ -114,6 +119,10 @@ void restart_handlers_print(void)
{
struct restart_handler *tmp;
- list_for_each_entry(tmp, &restart_handler_list, list)
- printf("%-20s %6d\n", tmp->name, tmp->priority);
+ list_for_each_entry(tmp, &restart_handler_list, list) {
+ printf("%-20s %6d ", tmp->name, tmp->priority);
+ if (tmp->flags & RESTART_FLAG_WARM_BOOTROM)
+ putchar('W');
+ putchar('\n');
+ }
}
diff --git a/include/restart.h b/include/restart.h
index 330b50a53a..15f30bb7ad 100644
--- a/include/restart.h
+++ b/include/restart.h
@@ -4,18 +4,21 @@
#include <linux/compiler.h>
#include <linux/types.h>
+#include <linux/bitops.h>
struct device_node;
void restart_handlers_print(void);
void __noreturn restart_machine(void);
-struct restart_handler *restart_handler_get_by_name(const char *name);
+struct restart_handler *restart_handler_get_by_name(const char *name, int flags);
struct device_node;
struct restart_handler {
void (*restart)(struct restart_handler *);
int priority;
+#define RESTART_FLAG_WARM_BOOTROM BIT(0)
+ int flags;
struct device_node *of_node;
const char *name;
struct list_head list;