summaryrefslogtreecommitdiffstats
path: root/common/startup.c
Commit message (Collapse)AuthorAgeFilesLines
* test: add basic barebox self-test infrastructureAhmad Fatoum2021-06-091-0/+4
| | | | | | | | | | | | | | | | | | Self tests is code written to run within barebox to exercise functionality. They offer flexibility to test specific units of barebox instead of the program as a whole. Add a very simple infrastructure for registering and executing self-tests. This is based on the Linux kselftest modules. We don't utilize modules for this, however, because we only have module support on ARM, but we need a generic solution. Selftests can be enabled individually and even tested without shell support to allow tests to happen for size-restricted barebox images as well. Acked-by: Rouven Czerwinski <r.czerwinski@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210604084704.17410-8-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* startup: Execute init scripts in alphabetical orderSascha Hauer2021-01-211-12/+17
| | | | | | | | | | | Documentation states that init scripts are executed in order and this had been the case before 90df2a955e. This patch replaced the shell loop around /env/init/* with a plain readdir which is not sorted at all. Iterate over the files with glob() which guarantees sorted results. Reported-by: Marcel Hellwig <git@cookiesoft.de> Fixes: 90df2a955e ("defaultenv: Convert init script to C") Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* startup: export PATH variableSascha Hauer2021-01-141-0/+1
| | | | | | | | | | The PATH environment variable is set at the shell prompt, but it is not exported, so currently scripts can't execute other scripts in PATH anymore. PATH used to be exported in the init script, but this part was lost when converting the init script to C. Add it back. Fixes: 90df2a955e ("defaultenv: Convert init script to C") Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: replace license statements with SPDX-License-IdentifiersAhmad Fatoum2020-11-271-11/+1
| | | | | | | | | | | | | For all files in common/ that already have a license text: - Replace with appropriate SPDX-License-Identifier - Remove empty comment lines around replacement - remove comment completely if only thing remaining is name of file without description Reviewed-by: Roland Hieber <rhi@pengutronix.de> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/reboot-mode' into masterSascha Hauer2020-10-141-0/+16
|\
| * Merge branch 'for-next/magicvar-unique-id' into for-next/reboot-modeSascha Hauer2020-10-071-9/+6
| |\
| * | defaultenv: provide defaults for generic reboot modesAhmad Fatoum2020-09-291-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | | Merge branch 'for-next/misc' into masterSascha Hauer2020-10-141-0/+2
|\ \ \ | |_|/ |/| |
| * | shutdown: flush console on barebox shutdownLucas Stach2020-10-021-0/+2
| |/ | | | | | | | | | | | | | | | | | | | | Same as in the poweroff and restart path, we should make sure to properly drain the console devices when shutting down barebox. This fixes serial console corruption when the software running after barebox changes the peripheral configuration before all the characters have drained out of the FIFO. Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / magicvar: Replace BAREBOX_MAGICVAR_NAMED with BAREBOX_MAGICVARSascha Hauer2020-10-021-9/+6
|/ | | | | | | | BAREBOX_MAGICVAR now generates a unique identifier automatically, so we can convert users of BAREBOX_MAGICVAR_NAMED to the simpler BAREBOX_MAGICVAR macro. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/net' into masterSascha Hauer2020-09-251-0/+3
|\
| * Add workqueuesSascha Hauer2020-08-131-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some code wants to run arbitrary code in the background, examples are fastboot and ratp. Currently this is implemented in pollers. The problem with this is that pollers are executed whenever is_timeout() is called which may happen anywhere in the code. With this we can never tell which resources are currently in use when the poller is executed. This adds a work queue interface which is specifically designed to trigger doing work in a context where it's safe to run arbitrary commands. Code in pollers can attach work to a work queue which is at that time only queued up. A new slice, the command slice, is added which by default is acquired. It is only released at places where the shell waits for input. When during this time pollers are executed the queued up works are done before running the registered pollers. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Add constructor supportSascha Hauer2020-09-181-0/+15
|/ | | | | | | Call constructors (gcc-generated initcall-like functions) during barebox start. Constructors are e.g. used for kasan initialization. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* startup: Add missing newline to notice messageJules Maselbas2020-08-031-1/+1
| | | | | Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/watchdog'Sascha Hauer2020-07-271-0/+4
|\
| * startup: inhibit watchdogs on non-interactive autoboot abortAhmad Fatoum2020-06-231-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | nv.autoboot=abort has been added as development aid to have barebox stop at the shell prompt automatically. It makes sense to inhibit all watchdogs in this mode, so the user can later use the shell in peace. This also applies to fastboot aborting the shell prompt. If this happens, watchdog will be automatically inhibited as well. Behavior on user aborting the shell prompt via keypad or uart input remains unchanged for backwards-compatibility. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | startup: Fix do_autoboot_countdown() running multiple timesSascha Hauer2020-06-261-1/+4
| | | | | | | | | | | | | | | | | | | | The comment above do_autoboot_countdown() states: "This function can be called multiple times, it is executed only the first time.". Since 1973892533 ("startup: don't clobber original autoboot state") This is no longer the case. Bring back the old and documented behaviour. Fixes: 1973892533 ("startup: don't clobber original autoboot state") Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | startup: register autoboot vars in initcallSascha Hauer2020-06-261-12/+14
|/ | | | | | | | | globalvars should be registered early so that code modifying them also updates the backing store pointer. Move registering of global.autoboot_abort_key, global.autoboot_timeout and global.autoboot to an initcall. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common.h: move and rename lregion_overlap()Masahiro Yamada2020-05-051-2/+12
| | | | | | | | | | | | lregion_overlap() is only used by common/startup.c There is no need to define it in include/common.h While I was here, I also renamed it to region_overlap(), and got rid of the 'inline' keyword. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: remove references to CREDITSUwe Kleine-König2020-04-271-3/+0
| | | | | | | | The CREDITS file was removed from barebox in 2015 by commit 6570288f2d97 ("Remove the CREDITS file"). Remove references to it from several files. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* startup: add $global.autoboot to make behavior configurableAhmad Fatoum2020-04-271-2/+15
| | | | | | | | | | | | | | | | | | | | | | We already have a global_autoboot_state variable that controls barebox init behavior on startup: * ABORT abort and fall into shell * MENU display boot menu * BOOT boot immediately, only abortable via ctrl+c during init * COUNTDOWN regular boot after count down Exporting this as a device parameter allows us to support some different boot scenarios: * COUNTDOWN is the default * ABORT boot always while debugging * display MENU by default (e.g. for graphical boots) * BOOT while ignoring external code calling console_countdown_abort() Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* startup: don't clobber original autoboot stateAhmad Fatoum2020-04-271-4/+5
| | | | | | | | | | | | | do_autoboot_countdown changes autoboot state if the user presses m for menu or ctrl+c to abort during count down. This is an internal detail and doesn't need to be reflected in the state of the global variable. This will improve UX when exporting the variable in the follow-up commit, because on a regular boot it $autoboot will expand to countdown instead of abort/boot/menu dependent on prior user input. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* startup: rename AUTOBOOT_UNKNOWN to more descriptive AUTOBOOT_COUNTDOWNAhmad Fatoum2020-04-271-2/+2
| | | | | | | | | If we export the autoboot state variable for customization, having unknown as default is not so helpful. Rename it to what actually happens (abortable countdown). Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Add magicvar description for autoboot variablesSascha Hauer2020-04-271-0/+8
| | | | | | | global.autoboot_abort_key and global.autoboot_timeout lack a magicvar description. Add one. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Allow usage of default environment without environment file storageAlbert Schwarzkopf2019-12-111-7/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | Currently, the default environment is only used when the barebox environment on the persistent store is not valid or when ENVFS_FLAGS_FORCE_BUILT_IN is set in the super block. However, ENVFS_FLAGS_FORCE_BUILT_IN can be cleared and the environmnet variables in the persistent store will be used again. This may not be desirable. This patch allows building CONFIG_DEFAULT_ENVIRONMENT independent of CONFIG_ENV_HANDLING. This can be useful if you never want to load or write values from the persistent store and you only need to read environment variables from your default environment. If CONFIG_ENV_HANDLING is not set, a message will be printed to the user indicating that changes to non-volatile variables won't be persisted. Move envfs functions that are needed when CONFIG_DEFAULT_ENVIRONMENT and/or CONFIG_ENV_HANDLING is set to a new file common/envfs-core.c. Signed-off-by: Albert Schwarzkopf <a.schwarzkopf@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* startup: allow ctrl+c abort during boot sequenceAhmad Fatoum2019-08-301-2/+2
| | | | | | | | | | At the moment e.g. a wait for an ARP response during net boot can only aborted if the auto boot countdown was aborted. Otherwise ctrl+c is without effect. For better user experience allow code querying for ctrl+c to see it even if barebox had not dropped into a shell. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* startup: Fix typo in commentLadislav Michl2019-08-231-1/+1
| | | | | | Fixes: 35266d7e583f ("startup: Factor out the autoboot counter...") Signed-off-by: Ladislav Michl <ladis@linux-mips.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* startup: Register autoboot variables earlierLadislav Michl2019-08-231-7/+11
| | | | | | | | | | | Autoboot is controlled by autoboot_timeout and autoboot_abort_key variables which might be altered by init scripts, so we need to register them before those scripts are run. Otherwise they are set back to defaultenv values upon registration. Fixes: 35266d7e583f ("startup: Factor out the autoboot counter...") Signed-off-by: Ladislav Michl <ladis@linux-mips.org> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* startup: Factor out the autoboot counter to separate functionSascha Hauer2019-07-031-46/+88
| | | | | | | | | The autoboot countdown is part of the init function. This patch factors out this code to a separate function to allow boards to call it at a different time. Also boards can set the autoboot state manually in case they have its own idea how to interrupt the autoboot process. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* startup: Create boot related variables where they are usedSascha Hauer2019-07-031-10/+0
| | | | | | | global.boot.default, global.linux.bootargs.base and global.user are used in the boot code, so create them there. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* startup: Create global.linux.bootargs.dyn.* variables where they are neededSascha Hauer2019-07-031-6/+0
| | | | | | | | | global.linux.bootargs.dyn.* variables are exclusively used in boot scripts, so create them right before executing a script. This moves the corresponding code from the unrelated startup code to the place where the variables are used. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* startup: remove unused editcmd variableSascha Hauer2019-07-031-3/+0
| | | | | | Nobody uses global.editcmd, so remove it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* startup: execute /env/bin/init as part of the initial shellIan Abbott2019-06-131-4/+5
| | | | | | | | | | | | | | | Commit 90df2a955e3c ("defaultenv: Convert init script to C") unintentionally changed the way the legacy "/env/bin/init" script is run, so that it runs in a sub-shell context, effectively changing `run_command("source /env/bin/init");` to `run_command("/env/bin/init");`. Therefore, any changes to shell environment variables made by the script are undone when the script exits. This patch reverts back to the old behavior. Fixes: 90df2a955e3c ("defaultenv: Convert init script to C") Cc: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* startup: Do not overwrite global.linux.bootargs.consoleSascha Hauer2019-06-131-3/+0
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* defaultenv: Convert init script to CSascha Hauer2019-04-241-19/+169
| | | | | | | | | | | It's hard to get more complicated things right in hush. This commit converts the /env/bin/init script to C code. With this we get a better error handling and better control what is being done. If /env/bin/init exists in the environment then it is still executed instead of the corresponding C code. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* environment: bypass overlap check for mtd devicesSascha Hauer2018-10-121-0/+3
| | | | | | | | | | | | | | | | For mtd devices the overlap check does not work as expected for two reasons. First is that cdev->offset is 0 for mtd partitions, instead cdev->mtd->master_offset has to be used. That could be fixed easily. Second on NAND devices the environment is on the bb devices and not on the raw nand devices which means we would need something to get the mtd device from the bb device before doing the check. Both issues are fixable, but the check was mainly done to catch cases when an environment partition is created in the free space before the first MBR/GPT partition on SD/MMC devices, so leave out the mtd case for now. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* environment: Fix overlapping partitions error messageLadislav Michl2018-10-121-2/+2
| | | | | | | Signed-off-by: Ladislav Michl <ladis@linux-mips.org> Fixes: b234a6da331f ("environment: Do not use environment when overlapping with other partitions") Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* environment: Do not use environment when overlapping with other partitionsSascha Hauer2018-09-261-1/+51
| | | | | | | | | | | Environment partitions are usually specified with their hardcoded offset and size, either in the device tree or the board file. These partitions potentially overlap with other partitions read from the partition table. Overlapping partitions for sure have bad effects. Be more friendly to our users and warn them when such a situation occurs and stop using that partition for storing the environment. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Revert "startup: Load default environment earlier"Sascha Hauer2018-03-191-3/+3
| | | | | | | | | | | | | | | | Several boards use defaultenv_append_directory() to append a board specific envfs snippet during runtime. This only works when defaultenv_append_directory() is called before defaultenv_load() is exectuted. Since that was executed at the end of the start process every initcall level could be used to append a env directory. With this patch only initcall levels earlier than fsdevice_initcall work and most boards do not cope with this. Revert this patch until a better solution is found. Reported-by: Alexander Kurz <akurz@blala.de> This reverts commit 5b92cfceff38f3a6462a21cf6b69159ad0ae9744.
* Merge branch 'for-next/tftp-workaround'Sascha Hauer2018-02-081-0/+1
|\
| * startup: create /tmpSascha Hauer2018-01-231-0/+1
| | | | | | | | | | | | | | Some commands create temporary files in /. Create /tmp to offer these commands an appropriate place for storing temporary files. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | startup: Load default environment earlierSascha Hauer2018-02-061-3/+3
|/ | | | | | | | | | | Some files compiled into the default environment may be needed earlier in the boot process, so move loading of the default environment to fs_initcall. Only the default environment is loaded earlier, but not the overwriting with the persistent environment files, so when the files are used that early, only the compiled in version is available; it's not overwritable at that time. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* include: move shell prototypes to shell.hSascha Hauer2016-04-151-0/+1
| | | | | | We have a shell,h, so move shell specific prototypes there. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* fs: Add pstore filesystemMarkus Pargmann2015-12-101-0/+5
| | | | | | | | | | | | | | | | pstore is a persistent storage filesystem used for RAMOOPS. It is used to store console logs, panics, ftrace and other information in case of a crash/panic/oops/reboot. pstore is implemented for barebox as a read-only filesystem at the moment. It may be extended later on. The idea is to provide a way to extract essential data from the last running kernel. Most of the code is copied from the kernel. However this is only a lightweight implementation without real write support yet. Signed-off-by: Markus Pargmann <mpa@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* login: rework login mechanismSascha Hauer2015-08-281-5/+2
| | | | | | | | | | | | | | We used to have the login functionality in the /env/bin/init script. This is hard to review and it's too easy to break the login functionality with changes to this script. Move the places to ask for a password to C code where we have only a few places where we have to ask for a password. Mainly these are run_shell() and the menutree command. This patch introduces a login() function which will only return if the correct password has been entered. Following calls will return immediately without asking for a password again. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* exitcall: move board_shutdown to exitcall infrastructureHerve Codina2015-07-131-5/+0
| | | | | Signed-off-by: Herve Codina <Herve.CODINA@celad.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* exitcall: move arch_shutdown to exitcall infrastructureHerve Codina2015-07-131-3/+0
| | | | | Signed-off-by: Herve Codina <Herve.CODINA@celad.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* exitcall: move device_shutdown to exitcall infrastructureHerve Codina2015-07-131-1/+0
| | | | | Signed-off-by: Herve Codina <Herve.CODINA@celad.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* exitcall: Add exitcall infrastructureHerve Codina2015-07-131-0/+11
| | | | | | | | exitcall infrastructure is based on initcall infrastructure. It allows to have and use exit call hooks on barebox shutdown. Signed-off-by: Herve Codina <Herve.CODINA@celad.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* startup: introduce postenvironment_initcallSascha Hauer2015-05-151-10/+18
| | | | | | | | To allow init code that depends on the environment being loaded. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>