summaryrefslogtreecommitdiffstats
path: root/common/oftree.c
Commit message (Collapse)AuthorAgeFilesLines
* bootsource: add function to get device_node we booted fromSascha Hauer2024-02-201-6/+1
| | | | | | | | | | | We have a relation between the bootsource and the corresponding device_node. Add a function to get the device_node we booted from. This is already open coded in of_fixup_bootargs_bootsource(), use the newly created function for it. Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20240219145159.1962618-3-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: never fixup internal live treeSascha Hauer2023-08-031-9/+10
| | | | | | | | | | | | | | | | | | | | | Calling of_fix_tree() on the internal live tree has undesired side effects, so refrain from doing so. One of the side effects is that some parts of barebox store pointers to properties in the live tree which might become invalid when during of_fixup these properties are deleted or updated. The other is that it's unexpected that the live tree is modified after a dry run boot with the live tree. This changes of_get_fixed_tree() to always call of_fix_tree() on a copy of the device tree and not on the device tree itself. To emphasize this make the device tree argument to of_get_fixed_tree() const. Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230803085134.3912884-1-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/of-compat'Sascha Hauer2023-06-221-8/+2
|\
| * of: change superfluous of_fix_tree int return type to voidAhmad Fatoum2023-06-091-8/+2
| | | | | | | | | | | | | | | | | | | | | | | | of_fix_tree always returns 0, so propagating its return code and checking it serves no purpose. Let's just change it to void *. I considered having it return the first argument, but that could mislead users to think that the argument is not modified. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230608134040.2123869-2-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | of: override existing reg property in of_fixup_reserved_memoryAhmad Fatoum2023-06-091-2/+2
|/ | | | | | | | | | | | | of_new_property doesn't care for existing properties and would happily add a property that already exists leading Linux to trip over it when creating the VFS view into the device tree. Fix this by using of_set_property, which would delete an existing reg property first, before adding it anew. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230608143818.3147443-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* commands: add new of_fixup command to list and disable DT fixupsAhmad Fatoum2023-05-221-6/+8
| | | | | | | | | | | | | | barebox can already dry run fixups with of_diff - +, but there's no way to selectively disable a fixup to rule out it causing issues. For platforms supporting kallsyms, we can readily allow enabling and disabling fixups by name, so let's add a command that does just that to aid in debugging. Suggested-by: Daniel Brát <danek.brat@gmail.com> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230420203219.2255564-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename struct device_d to deviceSascha Hauer2023-01-101-1/+1
| | | | | | | | | | | | | The '_d' suffix was originally introduced in case we want to import Linux struct device as a separate struct into barebox. Over time it became clear that this won't happen, instead barebox struct device_d is basically the same as Linux struct device. Rename the struct name accordingly to make porting Linux code easier. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-3-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Rename device_d::device_node to device_d::of_nodeSascha Hauer2023-01-101-2/+2
| | | | | | | | | | | | | | | | | | | | Linux struct device has the member of_node for the device_node pointer. Rename this in barebox accordingly to minimize the necessary changes when porting Linux code. This was done with the semantic patch: @@ struct device_d E; @@ - E.device_node + E.of_node @@ struct device_d *E; @@ - E->device_node + E->of_node Plus some manual adjustments. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20221214123512.189688-2-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: refactor for of_fixup_reserved_memory() for clarityAhmad Fatoum2022-09-131-2/+4
| | | | | | | | | | | pp was never used and the ?: construct made the code needlessly terse. Use it and make the code a bit clearer. No functional change. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220905095557.596891-17-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: add new of_fixup_reserved_memory() helperAhmad Fatoum2022-08-161-0/+41
| | | | | | | | | | | | | | We are opencoding the reserved memory fixup in fs/pstore/ram.c and the sequence is generic enough that we could use it for other fixups as well, e.g. rmem, barebox as secure monitor or OP-TEE which is not configured to generate an overlay or fix up the device tree itself. Add a helper that can be directly registered and reads all the necessary information out of a struct resource. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220815114246.2275465-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: add generic of_prepend_machine_compatible()Oleksij Rempel2022-05-051-0/+36
| | | | | | | | Add generic function to extend/fixup machine compatible. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Link: https://lore.barebox.org/20220503091220.3871612-4-o.rempel@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: add $global.serial_number with device tree fixupAhmad Fatoum2022-05-051-0/+5
| | | | | | | | | | | This new variable can be set by boards from C code or from the environment to change the serial number fixed up into the kernel device tree. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Link: https://lore.barebox.org/20220503091220.3871612-2-o.rempel@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: rename of_find_node_by_name() to of_find_node_by_name_address()Sascha Hauer2022-03-081-2/+2
| | | | | | | | | | | | | of_find_node_by_name() has the same name as the corresponding kernel function but a different semantics. A node name is comprised of the nodes name and a unit address, separated with '@'. Linux of_find_node_by_name() matches only the name before the '@' whereas the barebox function compares the full name. As several callers depend on the barebox semantics we can't just change the semantics, so rename the barebox function to of_find_node_by_name_address(). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: add SPDX-License-Identifier for files without explicit licenseAhmad Fatoum2022-01-051-0/+2
| | | | | | | | | Record GPL-2.0-only as license for all files lacking an explicit license statement. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20220103120539.1730644-12-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/riscv'Sascha Hauer2021-07-181-1/+18
|\
| * RISC-V: S-Mode: propagate Hart IDAhmad Fatoum2021-06-241-1/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Unlike other architectures we support, Linux must apparently be booted on all cores by the bootloader. To achieve this, the bootloaders running on the multiple cores synchronize via IPIs. We will get there eventually, but for now, let's restrict barebox to boot Linux on a single core. S-Mode firmware is passed hart (core) id in a0. This is propagated via the thread pointer register, which is unused by GCC and made available as: - cpuinfo output when running in S-Mode - $global.hartid - a0 when booting via bootm - /chosen/boot-hartid fixup: will come in handy when we gain EFI loading support - single /cpus/*/reg: All other CPU nodes are deleted via fixup For M-Mode, we can query hart id via CSR. It's unknown whether erizo supports it and we don't yet have exception support to handle it not being available, so changes are only done for S-Mode for now. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210619045055.779-6-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | blspec: Rework firmware loadSascha Hauer2021-06-281-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Applying overlays in blspec currently works in two steps. First of_firmware_load_overlay() is called which doesn't load an overlay, but instead loads firmware when one is needed by the overlay. This is done on the live tree, because that was needed to find the firmware manager. The second step is to call of_register_overlay() to apply the overlay to the kernel device tree when the fixups are executed. Instead of using a separate step to load the firmware, load the firmware as part of the of_fixups. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20210624085223.14616-14-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | of: Add function to duplicate a device treeSascha Hauer2021-06-251-1/+1
|/ | | | | | | | | | | | | | This adds of_dup() to duplicate a device tree. Previously of_copy_node() was used for this, but of_copy_node() has issues with potentially duplicated phandle values when the new tree is inserted to an existing tree, that is when the parent argument of of_copy_node() is non NULL. All users of of_copy_node() with a NULL parent argument are converted to of_dup() which is safe to use leaving only the problematic users of of_copy_node(). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20210624085223.14616-3-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: introduce global.linux.bootargs_appendAhmad Fatoum2021-05-261-1/+21
| | | | | | | | | | | | | | | | | By default, barebox overwrites the bootargs in the oftree if it itself has any. Make this behavior configurable by adding a new global variable. The new global variable allows either appending barebox' bootargs to the original oftree bootargs (global.linux.bootargs_append=1) or overwriting the original oftree bootargs (global.linux.bootargs_append=0) as before. The default is to overwrite the original bootargs. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> [bst: dropped a new line removal, extend commit message] Signed-off-by: Bastian Krause <bst@pengutronix.de> Link: https://lore.barebox.org/20210414130044.6910-2-bst@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: fix up /chosen node even when there are no bootargsAhmad Fatoum2021-05-261-7/+13
| | | | | | | | | | | | | | | | Currently the /chosen fixups of "reset-source", "reset-source-instance", "reset-source-device" and "bootsource" do not happen if no bootargs are available. Fix that by moving the actual bootargs fixup to a dedicated function of_write_bootargs() and only return there early on empty bootargs, but still perform the /chosen fixups mentioned above. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> [bst: dropped new line deletions and modified string comparison, moved of_write_bootargs() call to original position, add commit message] Signed-off-by: Bastian Krause <bst@pengutronix.de> Link: https://lore.barebox.org/20210414130044.6910-1-bst@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: oftree: replace printf by pr_infoMarco Felsch2021-05-251-1/+1
| | | | | | | | | This allows us to control the output behaviour e.g. booting silently to improve boot time. Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.barebox.org/20210521163435.17365-5-m.felsch@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: Return copy of live tree as fixed treeSascha Hauer2021-03-231-4/+10
| | | | | | | | the of fixups modify the the tree passed to them. It is undesired that these modify the live tree, so when we are requested to return the fixed live tree then make a copy first. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* boot: introduce option to pass barebox-enabled watchdog to systemdAhmad Fatoum2020-11-301-0/+25
| | | | | | | | | | | | | | | | | Like Linux, barebox supports co-existence of multiple watchdog devices. On boot, barebox enables only the default watchdog, which is defined as the watchdog with highest non-zero priority. The kernel handles all watchdogs the same and defers to userspace, which watchdogs to service. It can be useful to have barebox tell the system, which watchdog it activated, so it can service the same. Having this feature behind a global variable adds 354 bytes to a LZO compressed THUMB2 barebox. Users can opt out by toggling the Kconfig option, which defaults to off. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: oftree: trim leading spaces from bootargsClement Leger2020-03-231-0/+4
| | | | | | | | | | | | | When barebox concatenates all dynamic bootargs string for linux, if they are empty, the resulting string might be composed of only spaces. Currently, there is no check for such string and it leads to overwriting bootargs in the device tree by an empty string. To avoid this behavior, use skip_spaces to trim leading spaces and then check if the string is empty. If so, simply returns and don't patch device tree bootargs. Signed-off-by: Clement Leger <cleger@kalray.eu> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* oftree: expose reset_source device in device treeUwe Kleine-König2019-09-091-0/+14
| | | | | Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* reset_source: use instance = -1 as defaultUwe Kleine-König2019-08-281-2/+3
| | | | | | | | | | | As with platform device id (does someone still remember?) 0 might be a valid id. So use -1 for "unknown" or "doesn't apply" instead of 0. Also don't pass the instance to the device tree if negative. (This ends up as 0xffffffff otherwise.) Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: oftree: Pass reset source and reset source instance to kernelAndrey Smirnov2018-05-181-0/+5
| | | | | | | | | | | | | | | | | | | Detecting reset reason is, in some cases, a destructive operation and in such cases it is impossible to obtain that information in the kernel without some help from barebox. Pass reset source and reset source instance to kernel to Linux to make it availible to Linux userspace. This info is placeed under /chosen/bootsource and it can be read under Linux in /sys/firmware/devicetree/base/chosen/reset-source. and /sys/firmware/devicetree/base/chosen/reset-source-instance. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: oftree: Pass bootsource and bootsource instance to kernelAndrey Smirnov2018-05-181-1/+27
| | | | | | | | | | | | Pass barebox-detected bootsource to Linux to make it availible to Linux userspace. That information is passed as full path to the node corresponding to the bootsource and is placed under /chosen/bootsource and it can be read under Linux in /sys/firmware/devicetree/base/chosen/bootsource Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: Pass barebox version to kernelSascha Hauer2018-03-221-0/+1
| | | | | | | | Pass the barebox version to Linux in case somebody is interested in it under Linux. We use put the version under /chosen/barebox-version and it can be read under Linux in /sys/firmware/devicetree/base/chosen/barebox-version. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: oftree: Add autoenable functionalityDaniel Schultz2017-11-071-0/+89
| | | | | | | | | | This patch adds an API to automatically enable either hardware components with existing device drivers or i2c clients. All functions take a device tree path to find the hardware and will fix up the node status in the kernel device tree, if it's accessible. Signed-off-by: Daniel Schultz <d.schultz@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* treewide: Use of_property_write_string() where appropriateSascha Hauer2017-03-301-1/+1
| | | | | | | Replace users which use of_set_property() to set a property to a string with of_property_write_string(). Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* common: oftree: Add function to register set status fixupTeresa Remmet2016-03-011-0/+36
| | | | | | | | Added a function to register a fixup to enable or disable device tree nodes. Signed-off-by: Teresa Remmet <t.remmet@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of_fix_tree: do not fail when fixup failsSascha Hauer2015-09-241-4/+2
| | | | | | | When a device tree fixup fails it is worth printing a warning, but we should not fail booting. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of_fix_tree: Print error messageSascha Hauer2015-09-081-1/+4
| | | | | | | | When a of_fixup handler fails add a meaningful error message so that the user gets a clue what might have gone wrong. Suggested-by: Enrico Joerns <ejo@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: add a function to remove an of_fixupUwe Kleine-König2015-05-181-0/+19
| | | | | | | | | This function is needed when a device that already registered a fixup in the probe routine fails later to probe completely. Without unregistering the fixup the function might later be called with invalid data. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: Add a context pointer to fixup functionsSascha Hauer2013-11-061-5/+7
| | | | | | | If drivers want to fixup their specific instance they need some context to know which instance they have to fixup. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: Use correct devicetree in of_print_cmdlineSascha Hauer2013-07-271-1/+1
| | | | | | | | of_print_cmdline() is passed a devicetree, so use this one instead of the internal devicetree. This fixes the cmdline printout when bootm on ARM is used with an external devicetree. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* OF: base: sync of_find_node_by_path with linux OF APISebastian Hesselbarth2013-06-201-1/+1
| | | | | | | | | | | | | Barebox of_find_node_by_path requires a node to be passed as start node to start searching. Linux OF API does not pass this node and no current user of it in barebox is passing anything else than the root node. Therefore, we rename current function to of_find_node_by_path_from and introduce a Linux OF API compatible of_find_node_by_path that always passes the current root_node. Also, all current users of that function are updated to reflect the API change. Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* bootm: print Kernel commandline in verbose modeSascha Hauer2013-05-311-0/+15
| | | | | | | Without devicetree support we print the Kernel commandline in verbose mode. Do the same with devicetree boot aswell. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: remove unused defineSascha Hauer2013-05-311-6/+0
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: remove unused libfdtSascha Hauer2013-03-061-175/+0
| | | | | | | Now that we are completely independent of libfdt remove the unused code. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* ARM bootm: Switch initrd support to unflattened treeSascha Hauer2013-03-061-66/+0
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: fixup unflattened devicetreeSascha Hauer2013-03-061-48/+22
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: Pass barebox internal format devicetree to of_get_fixed_treeSascha Hauer2013-03-061-10/+9
| | | | | | | With this every devicetree is first converted to the barebox internal format before it's converted back to dtb again. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: make flatten independent of libfdtSascha Hauer2013-03-061-1/+7
| | | | Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* Merge branch 'for-next/highbank'Sascha Hauer2013-03-041-0/+27
|\
| * of: add do_fixup_by_compatible with u32 and string versionJean-Christophe PLAGNIOL-VILLARD2013-03-031-0/+27
| | | | | | | | | | Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* | DeviceTree: add support for initrd in the DTVicente Bergas2013-02-121-0/+66
|/ | | | | | | Add the initrd start and end address to the DT, code comes from u-boot. Signed-off-by: Vicente Bergas <vicencb@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* oftree command: refactorSascha Hauer2013-01-191-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | This has several improvements for the oftree command: - loading a devicetree (-l) and actually probing (-p) it now is separated - the command now can dump the internal devicetree or a dtb given on the command line. - The -f option now actually frees the internal devicetree With this the usage pattern for this command is: oftree -l /env/oftree oftree -d -n /sound oftree -d /env/oftree oftree -f oftree -p oftree -l -p /env/oftree Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
* of: remove unused barebox_fdtSascha Hauer2013-01-191-2/+0
| | | | | | | | barebox_fdt should once become the pointer to the barebox internal devicetree. Since barebox has its own internal devicetree format this was never used. remove it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>