diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2020-09-28 16:45:09 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-09-29 10:25:02 +0200 |
commit | 071eecf8c040782515512777b02573c79a3e9899 (patch) | |
tree | 7705ce2c9ae0fb4696ac10281ed2b8c15165ada5 | |
parent | b28bcba8662cf0e60d35ef30c8d284f320fc9b1c (diff) | |
download | barebox-071eecf8c040782515512777b02573c79a3e9899.tar.gz barebox-071eecf8c040782515512777b02573c79a3e9899.tar.xz |
defaultenv: provide defaults for generic reboot modes
While reboot mode magic identifiers can be very board specific, we can
settle on common names to allow some generic reboot mode handling:
- loader -> drop to bootloader shell on next boot
- bootloader -> enable fastboot on next boot
- recovery -> display barebox boot menu
Boot modes loader and bootloader are admittedly a bit ambiguous, but
this nomenclature was chosen, because it's already in use on Android and
Rockchip systems.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | Documentation/user/defaultenv-2.rst | 18 | ||||
-rw-r--r-- | common/Kconfig | 5 | ||||
-rw-r--r-- | common/startup.c | 16 | ||||
-rw-r--r-- | defaultenv/Makefile | 1 | ||||
-rw-r--r-- | defaultenv/defaultenv-2-reboot-mode/bmode/bootloader | 3 | ||||
-rwxr-xr-x | defaultenv/defaultenv-2-reboot-mode/bmode/loader | 2 | ||||
-rw-r--r-- | defaultenv/defaultenv-2-reboot-mode/bmode/recovery | 2 | ||||
-rw-r--r-- | defaultenv/defaultenv.c | 2 |
8 files changed, 45 insertions, 4 deletions
diff --git a/Documentation/user/defaultenv-2.rst b/Documentation/user/defaultenv-2.rst index a79ae83d56..da766e4edc 100644 --- a/Documentation/user/defaultenv-2.rst +++ b/Documentation/user/defaultenv-2.rst @@ -19,10 +19,11 @@ All new boards should use defaultenv-2 exclusively. The default environment is composed from different directories during compilation:: - defaultenv/defaultenv-2-base -> base files - defaultenv/defaultenv-2-dfu -> overlay for DFU - defaultenv/defaultenv-2-menu -> overlay for menus - arch/$ARCH/boards/<board>/env -> board specific overlay + defaultenv/defaultenv-2-base -> base files + defaultenv/defaultenv-2-dfu -> overlay for DFU + defaultenv/defaultenv-2-reboot-mode -> overlay for reboot modes + defaultenv/defaultenv-2-menu -> overlay for menus + arch/$ARCH/boards/<board>/env -> board specific overlay The content of the above directories is applied one after another. If the same file exists in a later overlay, it will overwrite the preceding one. @@ -37,6 +38,7 @@ and their respective included directories in ``defaultenv/Makefile``: bbenv-$(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW) += defaultenv-2-base bbenv-$(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_MENU) += defaultenv-2-menu bbenv-$(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_DFU) += defaultenv-2-dfu + bbenv-$(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_REBOOT_MODE) += defaultenv-2-reboot-mode bbenv-$(CONFIG_DEFAULT_ENVIRONMENT_GENERIC) += defaultenv-1 /env/bin/init @@ -138,3 +140,11 @@ there will be a file ``eth0`` with a content like this: # put code to discover eth0 (i.e. 'usb') to /env/network/eth0-discover exit 0 + +/env/bmode/ +----------- + +This contains the files to be sourced when barebox detects that the OS +had requested a specific reboot mode (via e.g. ``reboot bootloader`` +under Linux). After the ``/env/init`` scripts were executed, barebox will +``source /env/bmode/${global.system.reboot_mode.prev}`` if available. diff --git a/common/Kconfig b/common/Kconfig index 1a5bb53182..9419977276 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -906,6 +906,11 @@ config DEFAULT_ENVIRONMENT_GENERIC_NEW_DFU depends on USB_GADGET_DFU default y +config DEFAULT_ENVIRONMENT_GENERIC_NEW_REBOOT_MODE + bool "Generic reboot-mode handlers in the environment" + depends on DEFAULT_ENVIRONMENT_GENERIC_NEW + depends on REBOOT_MODE + config DEFAULT_ENVIRONMENT_PATH string depends on DEFAULT_ENVIRONMENT diff --git a/common/startup.c b/common/startup.c index ea7ce6b8da..f3e5765d5d 100644 --- a/common/startup.c +++ b/common/startup.c @@ -38,6 +38,7 @@ #include <linux/stat.h> #include <envfs.h> #include <magicvar.h> +#include <linux/reboot-mode.h> #include <asm/sections.h> #include <uncompress.h> #include <globalvar.h> @@ -310,6 +311,7 @@ static int run_init(void) DIR *dir; struct dirent *d; const char *initdir = "/env/init"; + const char *bmode; bool env_bin_init_exists; enum autoboot_state autoboot; struct stat s; @@ -350,6 +352,20 @@ static int run_init(void) closedir(dir); } + /* source matching script in /env/bmode/ */ + bmode = reboot_mode_get(); + if (bmode) { + char *scr, *path; + + scr = xasprintf("source /env/bmode/%s", bmode); + path = &scr[strlen("source ")]; + if (stat(path, &s) == 0) { + pr_info("Invoking '%s'...\n", path); + run_command(scr); + } + free(scr); + } + autoboot = do_autoboot_countdown(); console_ctrlc_allow(); diff --git a/defaultenv/Makefile b/defaultenv/Makefile index e030355a40..91293567c0 100644 --- a/defaultenv/Makefile +++ b/defaultenv/Makefile @@ -1,6 +1,7 @@ bbenv-$(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW) += defaultenv-2-base bbenv-$(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_MENU) += defaultenv-2-menu bbenv-$(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_DFU) += defaultenv-2-dfu +bbenv-$(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_REBOOT_MODE) += defaultenv-2-reboot-mode bbenv-$(CONFIG_DEFAULT_ENVIRONMENT_GENERIC) += defaultenv-1 obj-$(CONFIG_DEFAULT_ENVIRONMENT) += defaultenv.o extra-y += barebox_default_env barebox_default_env.h barebox_default_env$(DEFAULT_COMPRESSION_SUFFIX) barebox_zero_env diff --git a/defaultenv/defaultenv-2-reboot-mode/bmode/bootloader b/defaultenv/defaultenv-2-reboot-mode/bmode/bootloader new file mode 100644 index 0000000000..50a7a0f633 --- /dev/null +++ b/defaultenv/defaultenv-2-reboot-mode/bmode/bootloader @@ -0,0 +1,3 @@ +# Mode to re-flash partitions +global.autoboot_timeout=30 +global.usbgadget.autostart=1 diff --git a/defaultenv/defaultenv-2-reboot-mode/bmode/loader b/defaultenv/defaultenv-2-reboot-mode/bmode/loader new file mode 100755 index 0000000000..45647dec29 --- /dev/null +++ b/defaultenv/defaultenv-2-reboot-mode/bmode/loader @@ -0,0 +1,2 @@ +# Development mode +global.autoboot=abort diff --git a/defaultenv/defaultenv-2-reboot-mode/bmode/recovery b/defaultenv/defaultenv-2-reboot-mode/bmode/recovery new file mode 100644 index 0000000000..0496ba3b0d --- /dev/null +++ b/defaultenv/defaultenv-2-reboot-mode/bmode/recovery @@ -0,0 +1,2 @@ +# Interactive mode for recovery +global.autoboot=menu diff --git a/defaultenv/defaultenv.c b/defaultenv/defaultenv.c index b773030fe8..d69446c893 100644 --- a/defaultenv/defaultenv.c +++ b/defaultenv/defaultenv.c @@ -45,6 +45,8 @@ static void defaultenv_add_base(void) defaultenv_append_directory(defaultenv_2_menu); if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_DFU)) defaultenv_append_directory(defaultenv_2_dfu); + if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_REBOOT_MODE)) + defaultenv_append_directory(defaultenv_2_reboot_mode); if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC)) defaultenv_append_directory(defaultenv_1); } |