summaryrefslogtreecommitdiffstats
path: root/common
Commit message (Collapse)AuthorAgeFilesLines
* usbgadget: autostart: don't print error on repeated nv.usbgadget.autostart=1Ahmad Fatoum2020-11-241-2/+8
| | | | | | | | | | | | | | | | | | | | | | nvvar_add results in two calls to dev_set_param: - once when the existing global variable is found and set - once more when setting the nv variable This results in an annoying but ultimately harmless message on startup: ERROR: USB multi gadget already registered ERROR: failed to create nv variable usbgadget.autostart: Device or resource busy Avoid this by ignoring usbgadget.autostart=1 after it succeeded once. This issue should only affect $global.usbgadget.autostart, because all other global variables are "simple" meaning that they have no setters triggered. Fixes: 5a5c5178e7dc ("usbgadget: autostart: support delayed usbgadget.autostart=1") Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common/Makefile: Fix dependencySascha Hauer2020-11-131-1/+1
| | | | | | | | | pbl object files have been renamed from pbl-*.o to *.pbl.o. Fix another place which hasn't been renamed. Fixes: ff047395b9 ("kbuild: rename pbl object pbl-*.o to *.pbl.o") Reported-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* nv: fix use-after-free when clearing from shellAhmad Fatoum2020-11-131-8/+4
| | | | | | | | | | | | | | | | | When we use hush to set the same nv.var twice to the empty string: $ nv.user= $ nv.user= nv_set is called twice with a NULL val argument leading to a double free and accompanied memory corruption. Reorder the code, so p->value is freed just once. Fixes: fa4c41ba60af ("nvvar: when setting a nvvar to NULL just free the content") Cc: Holger Assmann <has@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* uimage: disable zero page when loading to SDRAM at address 0x0Michael Tretter2020-10-221-2/+19
| | | | | | | | | | | | | | | | If the SDRAM is mapped to address 0x0 and an image should be loaded to to the SDRAM without offset, Barebox would normally trap the access as a null pointer. However, since Linux kernel commit cfa7ede20f13 ("arm64: set TEXT_OFFSET to 0x0 in preparation for removing it entirely") no offset is the default for arm64. Therefore, copying the image to 0x0 of the SDRAM is necessary. Disable the zero page trap for copying an image to address 0x0. Signed-off-by: Michael Tretter <m.tretter@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/reboot-mode' into masterSascha Hauer2020-10-143-3/+24
|\
| * Merge branch 'for-next/magicvar-unique-id' into for-next/reboot-modeSascha Hauer2020-10-0712-67/+52
| |\
| * | defaultenv: provide defaults for generic reboot modesAhmad Fatoum2020-09-292-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * | usbgadget: autostart: support delayed usbgadget.autostart=1Ahmad Fatoum2020-09-291-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | So far, global.usbgadget.autostart=1 from the shell was without effect, because the variable is only evaluated once at postenvironment_initcall. Use the new globalvar_add_bool() to allow acting on the variable being true at any time. This is necessary for scripts that want to enable the usbgadget autostart functionality selectively without themselves hardcoding the particularities of what is exported. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | Merge branch 'for-next/percent_pe' into masterSascha Hauer2020-10-143-6/+3
|\ \ \
| * | | treewide: replace strerror(-PTR_ERR(errno)) with %pe format specifierAhmad Fatoum2020-09-291-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using %pe instead of PTR_ERR has the benefit of being less verbose and less error-prone (no negation necessary) while potentially reducing code size. Make use of it. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | vsprintf: retire strerrorp in favor of %peAhmad Fatoum2020-09-292-4/+2
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | strerrorp() is only used along with printf. We now have a format specifier for printing error pointers directly, so use that and remove strerrorp. 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-144-4/+6
|\ \ \
| * | | 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>
| * | | common: debug_ll: remove reference to undefined Kconfig optionAhmad Fatoum2020-10-011-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The code was copied from the kernel, but we don't support the imx6sl. Drop the left-over. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | Kallsyms: Cleanup whitespacesSascha Hauer2020-09-281-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 96028fb099 ("Kallsyms: Also resolve global variables") introduced some whitespaces where should have been tabs. Fix this. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | common: misc: support strerror(err) for all err <= MAX_ERRNOAhmad Fatoum2020-09-281-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We have a _LAST_ERRNO of 3 decimal digits. strerror(_LAST_ERRNO) is ok, but it's still possible that some code passes a non-error code int, which will overflow the static buffer. Play it safe and bump up the buffer size to at least 11 characters. This is enough to represent all integers, with only 7 characters more static storage. This way strerror(some_int_passed_by_mistake) will not invoke UB. Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | | Merge branch 'for-next/magicvar-unique-id' into masterSascha Hauer2020-10-1412-70/+54
|\ \ \ \ | | |_|/ | |/| |
| * | | magicvar: Replace BAREBOX_MAGICVAR_NAMED with BAREBOX_MAGICVARSascha Hauer2020-10-0212-67/+52
| | |/ | |/| | | | | | | | | | | | | | | | | | | 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/clang-analyzer' into masterSascha Hauer2020-10-143-3/+3
|\ \ \
| * | | blspec: fix dead assignmentAhmad Fatoum2020-10-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | cdev is assigned for each loop iteration and consumed inside. The initial value is never read, so drop it. Reported-by: clang-analyzer-10 Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | common: memsize: eliminate dead storeAhmad Fatoum2020-10-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The assignment to val at this location serves no purpose, drop it to reduce clutter. Reported-by: clang-analyzer-10 Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | globalvar: fix uninitialized read of variable when no nvvars existAhmad Fatoum2020-10-021-1/+1
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | When there are no nvvars, the function returns an uninitialized ret, return 0 in this case instead. Reported-by: clang-analyzer-10 Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | Merge branch 'for-next/buildsystem-version' into masterSascha Hauer2020-10-144-0/+16
|\ \ \ | |/ / |/| |
| * | imd: add buildsystem version to metadataSteffen Trumtrar2020-09-282-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | To have information about the exact state of a barebox binary from userspace, add the buildsystem version to the IMD. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | common: globalvar: add variable for buildsystem_version_stringSteffen Trumtrar2020-09-281-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | Now that the buildsystem version is available, make it accessible as a global variable for runtime usage. If the buildsystem version is not present (i.e. empty), don't add the variable at all. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | common: print buildsystem version in barebox bannerSteffen Trumtrar2020-09-251-0/+6
| |/ | | | | | | | | | | | | | | | | When the barebox banner is enabled and printed during startup, also show information about the buildsystem version: the exact state of the barebox binary and its config. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* / lib: kasan: migrate Kconfig option to Debugging menuAhmad Fatoum2020-09-291-0/+1
|/ | | | | | | | UBSAN and ASAN as well as other debugging aids are all in the Debugging menu. Relocate KASAN to be there as well. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/protonic' into masterSascha Hauer2020-09-251-0/+18
|\
| * common: console_common: add of_console_get_by_alias() helperOleksij Rempel2020-08-241-0/+18
| | | | | | | | | | | | | | Add helper function to get console device by devicetree alias Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | Merge branch 'for-next/net' into masterSascha Hauer2020-09-2510-35/+572
|\ \
| * | workqueues: Add support for delayed workSascha Hauer2020-09-141-0/+3
| | | | | | | | | | | | | | | | | | | | | Sometimes it's necessary to do some work after a delay. Add support for this case. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | fs: Warn when filesystem operations are called from a pollerSascha Hauer2020-08-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Filesystem operations possibly call into arbitrary devices, so shouldn't be used from a poller. This patch sprinkles some WARN_ONCE() when this happens. One exception is when the file which is accessed is on ramfs which doesn't have any dependencies to devices. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | fastboot net: implement fastboot over UDPEdmund Henniges2020-08-191-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This implements the UDP variant of the fastboot protocol. The only way to start the service for now is to compile with CONFIG_FASTBOOT_NET_ON_BOOT. The service will bind to the network interface that provides the IPv4 gateway. Sending an OKAY packet before performing a restart is necessary since contrary to USB the host will not notice when a UDP server disappears. Signed-off-by: Edmund Henniges <eh@emlix.com> Signed-off-by: Daniel Glöckner <dg@emlix.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | fastboot: init list head in commonSascha Hauer2020-08-191-0/+2
| | | | | | | | | | | | | | | | | | | | | The list of variables can be initialized in common code, no need to do the in the different implementations. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | fastboot: Add fastboot_abort()Sascha Hauer2020-08-191-0/+12
| | | | | | | | | | | | | | | | | | Add fastboot_abort() to allow aborting the current session. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | fastboot: Warn when cb_download is called with file still openSascha Hauer2020-08-191-0/+6
| | | | | | | | | | | | | | | | | | | | | Warn when we are about to open a new download file without having closed the old one. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | fastboot: rename usbgadget.fastboot_* variables to fastboot.*Daniel Glöckner2020-08-192-18/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There is nothing USB-specific in the defined usbgadget.fastboot_* variables. Rename them to be usable also for the UDP fastboot transport. The usbgadget.fastboot_function variable is used to define the files and devices accessible with the erase and flash commands. Since "function" is a term from the USB specification and the Fastboot specification uses the term "partition", we rename that variable to "fastboot.partitions". Signed-off-by: Daniel Glöckner <dg@emlix.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | globalvar: Add helper for deprecated variable namesSascha Hauer2020-08-191-2/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When globalvars are renamed across releases it's not nice when variables in the persistent environment loose their meaning. This adds a helper function which adds an alias for the old names. When the persistent variables still use the old names then their values are automatically written to variables with the new names. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | ratp: Switch to workqueuesSascha Hauer2020-08-131-14/+43
| | | | | | | | | | | | | | | | | | | | | This switches running barebox commands in ratp to a context where it's safe to do so: In a work queue. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | Add workqueuesSascha Hauer2020-08-136-0/+109
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * | Introduce slicesSascha Hauer2020-08-132-0/+304
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | slices, the barebox idea of locking barebox has pollers which execute code in the background whenever one of the delay functions (udelay, mdelay, ...) or is_timeout() are called. This introduces resource problems when some device triggers a poller by calling a delay function and then the poller code calls into the same device again. As an example consider a I2C GPIO expander which drives a LED which shall be used as a heartbeat LED: poller -> LED on/off -> GPIO high/low -> I2C transfer The I2C controller has a timeout loop using is_timeout() and thus can trigger a poller run. With this the following can happen during an unrelated I2C transfer: I2C transfer -> is_timeout() -> poller -> LED on/off -> GPIO high/low -> I2C transfer We end up with issuing an I2C transfer during another I2C transfer and things go downhill. Due to the lack of interrupts we can't do real locking in barebox. We use a mechanism called slices instead. A slice describes a resource to which other slices can be attached. Whenever a slice is needed it must be acquired. Acquiring a slice never fails, it just increases the acquired counter of the slice and its dependent slices. when a slice shall be used inside a poller it must first be tested if the slice is already in use. If it is, we can't do the operation on the slice now and must return and hope that we have more luck in the next poller call. slices can be attached other slices as dependencies. In the example above LED driver would add a dependency to the GPIO controller and the GPIO driver would add a dependency to the I2C bus: GPIO driver probe: slice_add(&gpio->slice, i2c_device_slice(i2cdev)); LED driver probe: slice_add(&led->slice, gpio_slice(gpio)); The GPIO code would call slice_acquire(&gpio->slice) before doing any operation on the GPIO chip providing this GPIO, likewise the I2C core would call slice_acquire(&i2cbus->slice) before doing an operation on this I2C bus. The heartbeat poller code would call slice_acquired(led_slice(led)) and only continue when the slice is not acquired. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | Merge branch 'for-next/mmc' into masterSascha Hauer2020-09-253-7/+11
|\ \ \
| * | | fastboot: only unset image, not loadaddrRouven Czerwinski2020-09-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In case the board needs to setup the load address of the kernel, don't overwrite the variable, instead only override the image. Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | blspec: fix bootm_data initializationRouven Czerwinski2020-09-151-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Remove initialization of the verbose struct member, it will be overwritten by the call to bootm_data_init_defaults(). Also remove members which are initialized in the call. Verbose should be enabled if either the argument or variable is set, so || both. Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | blspec: only reset variable locations, not pathsRouven Czerwinski2020-09-151-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Configuration of the loadaddresses for image oftree and initrd can not be done inside the bootloader spec yet, so using bootloader spec should not override settings from the environment. Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | globalvar: add globalvar_set functionRouven Czerwinski2020-09-151-0/+5
| | |/ | |/| | | | | | | | | | | | | | | | | | | Instead of overwriting the whole hierarchy beneath a globalvar, the globalvar_set function only sets the specific globalvar. Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | | Merge branch 'for-next/misc' into masterSascha Hauer2020-09-257-13/+78
|\ \ \
| * | | globalvar: allow running actions on set with globalvar_add_bool()Ahmad Fatoum2020-09-181-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | globalvar_add_simple_bool() and the other family of globalvars don't allow running a callback when the variable is set. This is a useful thing to have however for things like global.usbgadget.autostart=1. Provide a globalvar_add_bool() that accommodates this. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | commands: setenv: allow use with hush shellAhmad Fatoum2020-09-182-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | setenv was so far restricted to the simple shell, because with hush, users could just do dev.var=VAL for setting variables in the environment. The hush syntax doesn't allow for setting all kinds of environment variables though, e.g. 5c00a000.tamp@5c00a000:reboot-mode.of.param can't be set with hush, because of the special characters. It could still be read by using the ${variable} syntax though. Allow setting these variables by making the setenv command generally available. The default is chosen to be 'y', because the command is deemed small and useful enough to have it there by default. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
| * | | commands: reset: allow specifying reset by nameAhmad Fatoum2020-09-151-2/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | So far, we were fine by using the highest priority restart handler whenever more than one was available. There are reasons to want to configure this however: - When communicating with BootROM, e.g. to force boot from recovery mode: The reset chosen must not cause the reboot mode stored to volatile memory to vanish - When testing (undocumented) reset behavior, e.g. to analyze how the EFI reset behaves Extend the reset command to support this. When no extra command line option is supplied, the old behavior is maintained. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>