Apply device tree overlays to kernel tree
Subsystems (8)
v2 cover Apply device tree overlays to kernel tree
With this series barebox gains the capability to apply device tree overlays to the kernel device tree before starting the kernel with it. Which overlays are applied can be controlled with a set of globavars, for details see the documentation patch in this series.
The particular usecase we have in mind with this series is that the rootfs has a bunch of device tree overlays in it which shall be applied based on bootloader knowledge. For example information of the exact board type might be stored in an EEPROM. Based on that information barebox can now pick the right overlays for that board from the rootfs. Interpreting the EEPROM content is board specific and not part of this series, for now the the globalvars must be set manually.
The previous series had the problem that each time a of_fix_tree() was executed all firmwares were reloaded. This is solved in this series. Instead of loading the firmware files directly when applying an overlay, they are collected to a list. Only when we are booting the Kernel we explicitly load the firmwares we have previously collected.
Changes since v1:
- Do not (re-)load firmware on each of_fix_tree()
- handle empty strings returned from strsep gracefully
- Drop -S option from of_overlay command instead of ignoring it
Sascha Hauer (17):
fdt: Check blob size during unflattening
firmware: make device_node argument non const
libbb: Add find_path function
firmware: consolidate ifdefs
firmware: Add search path
firmware: Fix device_node matching
firmware: recognize by reproducible name
blspec: Set firmware searchpath
overlay: only apply compatible trees
overlay: Add of_overlay_apply_file()
firmware: Load from global search path
blspec: Rework firmware load
of_overlay: apply overlays during booting
blspec: Apply overlays from rootfs
doc: devicetree: Refer to internal device tree also as live tree
Documentation: Add documentation for device tree overlays
of_firmware: Fix handling of firmware-name property
Documentation/user/devicetree.rst | 39 +++++- arch/arm/boards/qemu-virt/board.c | 4 +- arch/arm/boards/raspberry-pi/rpi-common.c | 2 +- arch/arm/boards/webasto-ccbv2/board.c | 2 +- arch/arm/lib32/bootm.c | 6 +- arch/arm/lib32/bootu.c | 5 +- arch/arm/lib32/bootz.c | 3 + arch/arm/lib64/armlinux.c | 4 + arch/kvx/lib/bootm.c | 6 + arch/mips/lib/bootm.c | 4 + arch/powerpc/lib/ppclinux.c | 4 + arch/riscv/lib/bootm.c | 5 + commands/of_diff.c | 2 +- commands/of_display_timings.c | 2 +- commands/of_dump.c | 4 +- commands/of_overlay.c | 34 +---- commands/oftree.c | 2 +- common/blspec.c | 102 ++++++--------- common/bootm.c | 4 +- common/efi/efi.c | 2 +- common/firmware.c | 59 ++++++++- common/image-fit.c | 2 +- common/oftree.c | 2 + common/state/backend_format_dtb.c | 2 +- drivers/firmware/altera_serial.c | 1 + drivers/firmware/socfpga.c | 2 + drivers/firmware/zynqmp-fpga.c | 2 + drivers/of/base.c | 2 +- drivers/of/fdt.c | 17 ++- drivers/of/of_firmware.c | 137 ++++++++++++------- drivers/of/overlay.c | 152 ++++++++++++++++++++++ include/firmware.h | 26 ++-- include/libbb.h | 4 +- include/of.h | 45 ++++++- lib/libbb.c | 58 ++++++--- 35 files changed, 552 insertions(+), 195 deletions(-)
Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 1/17 fdt: Check blob size during unflattening
of_unflatten_dtb() doesn't check the size of the device tree blob passed to it. Add a size argument end add checks for the size. Some callers have no idea of the buffer size themselves, INT_MAX is passed in these cases.
--- arch/arm/boards/qemu-virt/board.c | 4 ++-- arch/arm/boards/raspberry-pi/rpi-common.c | 2 +- arch/arm/boards/webasto-ccbv2/board.c | 2 +- arch/arm/lib32/bootm.c | 2 +- commands/of_diff.c | 2 +- commands/of_display_timings.c | 2 +- commands/of_dump.c | 4 ++-- commands/of_overlay.c | 5 +++-- commands/oftree.c | 2 +- common/blspec.c | 7 ++++--- common/bootm.c | 4 ++-- common/efi/efi.c | 2 +- common/image-fit.c | 2 +- common/state/backend_format_dtb.c | 2 +- drivers/of/base.c | 2 +- drivers/of/fdt.c | 17 ++++++++++++----- include/of.h | 4 ++-- 17 files changed, 37 insertions(+), 28 deletions(-)
arch/arm/boards/qemu-virt/board.c +2 -2
@@ -31,14 +31,14 @@ static int replace_dtb(void) {return 0 ; } - root =of_unflatten_dtb (fdt); + root =of_unflatten_dtb (fdt,INT_MAX );if (!of_device_is_compatible (root,"linux,dummy-virt" )) {of_delete_node (root);return 0 ; } - overlay =of_unflatten_dtb (__dtb_overlay_of_flash_start); + overlay =of_unflatten_dtb (__dtb_overlay_of_flash_start,INT_MAX );of_overlay_apply_tree (root, overlay);return barebox_register_of (root);
arch/arm/boards/raspberry-pi/rpi-common.c +1 -1
@@ -430,7 +430,7 @@ static int rpi_vc_fdt_bootargs(void *fdt)struct device_node *root =NULL , *node;const char *cmdline; - root =of_unflatten_dtb (fdt); + root =of_unflatten_dtb (fdt,INT_MAX );if (IS_ERR (root)) { ret =PTR_ERR (root); root =NULL ;
arch/arm/boards/webasto-ccbv2/board.c +1 -1
@@ -28,7 +28,7 @@ static int ccbv2_probe(struct device_d *dev)return 0 ; fdt = (void *)OPTEE_OVERLAY_LOCATION ; - overlay =of_unflatten_dtb (fdt); + overlay =of_unflatten_dtb (fdt,INT_MAX );if (IS_ERR (overlay))return PTR_ERR (overlay);
arch/arm/lib32/bootm.c +1 -1
@@ -421,7 +421,7 @@ static int do_bootz_linux_fdt(int fd, struct image_data *data, void **outfdt)if (IS_BUILTIN (CONFIG_OFTREE )) {struct device_node *root; - root =of_unflatten_dtb (oftree); + root =of_unflatten_dtb (oftree, header->totalsize);if (IS_ERR (root)) {pr_err ("unable to unflatten devicetree\n" ); goto err_free;
commands/of_diff.c +1 -1
@@ -44,7 +44,7 @@ static struct device_node *get_tree(const char *filename, struct device_node *roif (ret)return ERR_PTR (ret); - node =of_unflatten_dtb (fdt); + node =of_unflatten_dtb (fdt, size);free (fdt);
commands/of_display_timings.c +1 -1
@@ -83,7 +83,7 @@ static int do_of_display_timings(int argc, char *argv[])return -EINVAL ; } - root =of_unflatten_dtb (fdt); + root =of_unflatten_dtb (fdt, size);free (fdt);
commands/of_dump.c +2 -2
@@ -71,7 +71,7 @@ static int do_of_dump(int argc, char *argv[])return -errno; } - root =of_unflatten_dtb (fdt); + root =of_unflatten_dtb (fdt, size);free (fdt);
@@ -88,7 +88,7 @@ static int do_of_dump(int argc, char *argv[])/* create a copy of internal devicetree */ void *fdt; fdt =of_flatten_dtb (root); - root =of_unflatten_dtb (fdt); + root =of_unflatten_dtb (fdt,fdt_totalsize (fdt));free (fdt);
commands/of_overlay.c +3 -2
@@ -17,6 +17,7 @@ static int do_of_overlay(int argc, char *argv[])struct fdt_header *fdt;struct device_node *overlay;const char *search_path =NULL ; +size_t size;while ((opt =getopt (argc, argv,"S:" )) >0 ) {switch (opt) {
@@ -31,13 +32,13 @@ static int do_of_overlay(int argc, char *argv[])if (argc != optind +1 )return COMMAND_ERROR_USAGE ; - fdt =read_file (argv[optind],NULL ); + fdt =read_file (argv[optind], &size);if (!fdt) {printf ("cannot read %s\n" , argv[optind]);return 1 ; } - overlay =of_unflatten_dtb (fdt); + overlay =of_unflatten_dtb (fdt, size);free (fdt);if (IS_ERR (overlay))return PTR_ERR (overlay);
commands/oftree.c +1 -1
@@ -82,7 +82,7 @@ static int do_oftree(int argc, char *argv[])return 1 ; } - root =of_unflatten_dtb (fdt); + root =of_unflatten_dtb (fdt, size);free (fdt);
common/blspec.c +4 -3
@@ -40,17 +40,18 @@ static int blspec_apply_oftree_overlay(char *file, const char *abspath,struct device_node *overlay;char *path;char *firmware_path; +size_t size; path =basprintf ("%s/%s" , abspath, file); - fdt =read_file (path,NULL ); + fdt =read_file (path, &size);if (!fdt) {pr_warn ("unable to read \"%s\"\n" , path); ret = -EINVAL ; goto out; } - overlay =of_unflatten_dtb (fdt); + overlay =of_unflatten_dtb (fdt, size);free (fdt);if (IS_ERR (overlay)) { ret =PTR_ERR (overlay);
@@ -490,7 +491,7 @@ static bool entry_is_of_compatible(struct blspec_entry *entry) goto out; } - root =of_unflatten_dtb (fdt); + root =of_unflatten_dtb (fdt, size);if (IS_ERR (root)) { ret = false; root =NULL ;
common/bootm.c +2 -2
@@ -361,7 +361,7 @@ void *bootm_get_devicetree(struct image_data *data)if (ret)return ERR_PTR (ret); - data->of_root_node =of_unflatten_dtb (of_tree); + data->of_root_node =of_unflatten_dtb (of_tree, of_size); }else if (data->oftree_file) {size_t size;
@@ -389,7 +389,7 @@ void *bootm_get_devicetree(struct image_data *data)if (ret)return ERR_PTR (ret); - data->of_root_node =of_unflatten_dtb (oftree); + data->of_root_node =of_unflatten_dtb (oftree, size);free (oftree);
common/efi/efi.c +1 -1
@@ -437,7 +437,7 @@ static int efi_late_init(void)return -EINVAL ; } - root =of_unflatten_dtb (fdt); + root =of_unflatten_dtb (fdt, size);free (fdt);
common/image-fit.c +1 -1
@@ -754,7 +754,7 @@ static int fit_do_open(struct fit_handle *handle)const char *desc ="(no description)" ;struct device_node *root; - root =of_unflatten_dtb_const (handle->fit); + root =of_unflatten_dtb_const (handle->fit, handle->size);if (IS_ERR (root))return PTR_ERR (root);
common/state/backend_format_dtb.c +1 -1
@@ -59,7 +59,7 @@ static int state_backend_format_dtb_verify(struct state_backend_format *format, fdtb->root =NULL ; } - root =of_unflatten_dtb (buf); + root =of_unflatten_dtb (buf, dtb_len);if (IS_ERR (root)) {dev_err (fdtb->dev,"Failed to unflatten dtb from buffer with length %zd, %ld\n" , len,PTR_ERR (root));
drivers/of/base.c +1 -1
@@ -1720,7 +1720,7 @@ int barebox_register_fdt(const void *dtb)if (root_node)return -EBUSY ; - root =of_unflatten_dtb (dtb); + root =of_unflatten_dtb (dtb,INT_MAX );if (IS_ERR (root)) {pr_err ("Cannot unflatten dtb: %pe\n" , root);return PTR_ERR (root);
drivers/of/fdt.c +12 -5
@@ -114,7 +114,8 @@ static int of_unflatten_reservemap(struct device_node *root,* Parse a flat device tree binary blob and return a pointer to the * unflattened tree. */ -static struct device_node *__of_unflatten_dtb (const void *infdt,bool constprops) +static struct device_node *__of_unflatten_dtb (const void *infdt,int size, +bool constprops) {const void *nodep;/* property node pointer */ uint32_t tag;/* tag */
@@ -131,6 +132,9 @@ static struct device_node *__of_unflatten_dtb(const void *infdt, bool constpropsunsigned int maxlen;const struct fdt_header *fdt = infdt; +if (size <sizeof (struct fdt_header )) +return ERR_PTR (-EINVAL ); +if (fdt->magic !=cpu_to_fdt32 (FDT_MAGIC )) {pr_err ("bad magic: 0x%08x\n" ,fdt32_to_cpu (fdt->magic));return ERR_PTR (-EINVAL );
@@ -147,6 +151,9 @@ static struct device_node *__of_unflatten_dtb(const void *infdt, bool constprops f.off_dt_strings =fdt32_to_cpu (fdt->off_dt_strings); f.size_dt_strings =fdt32_to_cpu (fdt->size_dt_strings); +if (f.totalsize > size) +return ERR_PTR (-EINVAL ); +if (f.off_dt_struct + f.size_dt_struct > f.totalsize) {pr_err ("unflatten: dt size exceeds total size\n" );return ERR_PTR (-ESPIPE );
@@ -274,9 +281,9 @@ err:* Parse a flat device tree binary blob and return a pointer to the unflattened * tree. The tree must be freed after use with of_delete_node(). */ -struct device_node *of_unflatten_dtb (const void *infdt) +struct device_node *of_unflatten_dtb (const void *infdt,int size) { -return __of_unflatten_dtb (infdt, false); +return __of_unflatten_dtb (infdt, size, false); }/**
@@ -290,9 +297,9 @@ struct device_node *of_unflatten_dtb(const void *infdt)* whole lifetime of the returned tree. This is normally not what you want, so * use of_unflatten_dtb() instead. */ -struct device_node *of_unflatten_dtb_const (const void *infdt) +struct device_node *of_unflatten_dtb_const (const void *infdt,int size) { -return __of_unflatten_dtb (infdt, true); +return __of_unflatten_dtb (infdt, size, true); }struct fdt {
include/of.h +2 -2
@@ -109,8 +109,8 @@ void of_print_properties(struct device_node *node);void of_diff (struct device_node *a,struct device_node *b,int indent);int of_probe (void );int of_parse_dtb (struct fdt_header *fdt); -struct device_node *of_unflatten_dtb (const void *fdt); -struct device_node *of_unflatten_dtb_const (const void *infdt); +struct device_node *of_unflatten_dtb (const void *fdt,int size); +struct device_node *of_unflatten_dtb_const (const void *infdt,int size);struct cdev ;
Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 2/17 firmware: make device_node argument non const
In reply to Sascha Hauerfirmwaremgr_find_by_node() takes a const pointer to a device tree node. Most functions that take a device tree node take a non const pointer though, so we can't call them from there. It might be worth looking into making the pointers const for other functions, but we are not there yet. Make the pointer non const for now.
--- common/firmware.c | 2 +- include/firmware.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
common/firmware.c +1 -1
@@ -63,7 +63,7 @@ struct firmware_mgr *firmwaremgr_find(const char *id)* handler. This allows to retrieve the firmware handler with a phandle from * the device tree. */ -struct firmware_mgr *firmwaremgr_find_by_node (const struct device_node *np) +struct firmware_mgr *firmwaremgr_find_by_node (struct device_node *np) {struct firmware_mgr *mgr;
include/firmware.h +2 -2
@@ -28,9 +28,9 @@ int firmwaremgr_register(struct firmware_handler *);struct firmware_mgr *firmwaremgr_find (const char *);#ifdef CONFIG_FIRMWARE -struct firmware_mgr *firmwaremgr_find_by_node (const struct device_node *np); +struct firmware_mgr *firmwaremgr_find_by_node (struct device_node *np);#else -static inline struct firmware_mgr *firmwaremgr_find_by_node (const struct device_node *np) +static inline struct firmware_mgr *firmwaremgr_find_by_node (struct device_node *np) {return NULL ; }
Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 3/17 libbb: Add find_path function
In reply to Sascha Hauerlibbb contains a find_execable() function to find an executable in a colon separated path. The code can be reused by making the environment variable name and the is-executable test parameters. Do this and add a find_path()
--- include/libbb.h | 4 +++- lib/libbb.c | 58 ++++++++++++++++++++++++++++++++----------------- 2 files changed, 41 insertions(+), 21 deletions(-)
include/libbb.h +3 -1
@@ -8,8 +8,10 @@char *concat_path_file (const char *path,const char *filename);char *concat_subpath_file (const char *path,const char *f); -int execable_file (const char *name); +bool execable_file (const char *name);char *find_execable (const char *filename); +char *find_path (const char *path,const char *filename, +bool (*filter)(const char *));char *last_char_is (const char *s,int c);enum {
lib/libbb.c +38 -20
74 lines not on this page · raw message
Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 4/17 firmware: consolidate ifdefs
In reply to Sascha HauerInstead of having multiple #ifdef CONFIG_FIRMWARE in a single file move the code together inside a single #ifdef.
--- include/firmware.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
include/firmware.h +3 -6
@@ -29,24 +29,21 @@ int firmwaremgr_register(struct firmware_handler *);struct firmware_mgr *firmwaremgr_find (const char *);#ifdef CONFIG_FIRMWARE struct firmware_mgr *firmwaremgr_find_by_node (struct device_node *np); +int firmwaremgr_load_file (struct firmware_mgr *,const char *path);#else static inline struct firmware_mgr *firmwaremgr_find_by_node (struct device_node *np) {return NULL ; } -#endif -void firmwaremgr_list_handlers (void ); - -#ifdef CONFIG_FIRMWARE -int firmwaremgr_load_file (struct firmware_mgr *,const char *path); -#else static inline int firmwaremgr_load_file (struct firmware_mgr *mgr,const char *path) {return -ENOSYS ; }#endif +void firmwaremgr_list_handlers (void ); +#define get_builtin_firmware (name, start, size) \ { \ extern char _fw_##name##_start[]; \
Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 5/17 firmware: Add search path
In reply to Sascha HauerThis adds a colon separated search path for firmware files. When the firmware we are searching is not an absolute path then look in the search path first. This will be useful later when the bootloader spec implementation shall look for firmware files relative to the provided root.
--- common/firmware.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/firmware.h | 12 ++++++++++++ 2 files changed, 53 insertions(+)
common/firmware.c +41 -0
@@ -11,6 +11,8 @@#include <libbb.h> #include <libfile.h> #include <fs.h> +#include <globalvar.h> +#include <magicvar.h> #include <linux/list.h> #include <linux/stat.h> #include <linux/err.h>
@@ -208,6 +210,26 @@ out:return ret; } +static char *firmware_path; + +const char *firmware_get_searchpath (void ) +{ +return firmware_path; +} + +void firmware_set_searchpath (const char *path) +{ +free (firmware_path); + firmware_path =strdup (path); +} + +static bool file_exists (const char *filename) +{ +struct stat s; + +return !stat (filename, &s); +} +/* * firmware_load_file - load a firmware to a device */
@@ -216,6 +238,7 @@ int firmwaremgr_load_file(struct firmware_mgr *mgr, const char *firmware)char *dst;enum filetype type;int ret =0 ; +char *fw =NULL ;int firmwarefd =0 ;int devicefd =0 ;
@@ -229,6 +252,12 @@ int firmwaremgr_load_file(struct firmware_mgr *mgr, const char *firmware) dst =basprintf ("/dev/%s" , mgr->handler->id); +if (*firmware !='/' ) { + fw =find_path (firmware_path, firmware, file_exists); +if (fw) + firmware = fw; + } + firmwarefd =open (firmware,O_RDONLY );if (firmwarefd <0 ) { printf("could not open %s: %s\n", firmware,
@@ -254,6 +283,7 @@ int firmwaremgr_load_file(struct firmware_mgr *mgr, const char *firmware) out:free (dst); +free (fw);if (firmwarefd >0 )close (firmwarefd);
@@ -262,3 +292,14 @@ out:return ret; } + +static int firmware_init (void ) +{ + firmware_path =strdup ("/env/firmware" ); +globalvar_add_simple_string ("firmware.path" , &firmware_path); + +return 0 ; +} +device_initcall (firmware_init); + +BAREBOX_MAGICVAR (global.firmware.path,"Firmware search path" );
include/firmware.h +12 -0
@@ -30,6 +30,8 @@ struct firmware_mgr *firmwaremgr_find(const char *);#ifdef CONFIG_FIRMWARE struct firmware_mgr *firmwaremgr_find_by_node (struct device_node *np);int firmwaremgr_load_file (struct firmware_mgr *,const char *path); +const char *firmware_get_searchpath (void ); +void firmware_set_searchpath (const char *path);#else static inline struct firmware_mgr *firmwaremgr_find_by_node (struct device_node *np) {
@@ -40,6 +42,16 @@ static inline int firmwaremgr_load_file(struct firmware_mgr *mgr, const char *pa {return -ENOSYS ; } + +static inline const char *firmware_get_searchpath (void ) +{ +return NULL ; +} + +static inline void firmware_set_searchpath (const char *path) +{ +} +#endif void firmwaremgr_list_handlers (void );
Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 6/17 firmware: Fix device_node matching
In reply to Sascha Hauerfirmwaremgr_find_by_node() matches against the device node of the parent of the device associated to the handler. This is correct for the socfpga and zyncmp driver, but not for the altera_serial driver. Add a device_node argument to the handler which is set by the drivers to the correct device node and match against that.
--- common/firmware.c | 2 +- drivers/firmware/altera_serial.c | 1 + drivers/firmware/socfpga.c | 2 ++ drivers/firmware/zynqmp-fpga.c | 2 ++ include/firmware.h | 1 + 5 files changed, 7 insertions(+), 1 deletion(-)
common/firmware.c +1 -1
@@ -70,7 +70,7 @@ struct firmware_mgr *firmwaremgr_find_by_node(struct device_node *np)struct firmware_mgr *mgr;list_for_each_entry (mgr, &firmwaremgr_list, list) -if (mgr->handler->dev->parent->device_node == np) +if (mgr->handler->device_node == np)return mgr;return NULL ;
drivers/firmware/altera_serial.c +1 -0
@@ -371,6 +371,7 @@ static int altera_spi_probe(struct device_d *dev)if (model) fh->model =xstrdup (model); fh->dev = dev; + fh->device_node = dev->device_node; this->spi = (struct spi_device *)dev->type_data; this->data = data;
drivers/firmware/socfpga.c +2 -0
@@ -435,6 +435,8 @@ static int socfpga_fpgamgr_probe(struct device_d *dev) } fh->dev = &mgr->dev; + fh->device_node = dev->device_node; + ret =firmwaremgr_register (fh);if (ret !=0 ) {free (mgr);
drivers/firmware/zynqmp-fpga.c +2 -0
@@ -383,6 +383,8 @@ static int zynqmp_fpga_probe(struct device_d *dev) } fh->dev = &mgr->dev; + fh->device_node = dev->device_node; + ret =firmwaremgr_register (fh);if (ret !=0 ) {free (mgr);
include/firmware.h +1 -0
@@ -14,6 +14,7 @@ struct firmware_handler {char *model;/* description for this device */ struct device_d *dev;void *priv; +struct device_node *device_node;/* called once to prepare the firmware's programming cycle */ int (*open)(struct firmware_handler *);/* called multiple times to program the firmware with the given data */
Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 7/17 firmware: recognize by reproducible name
In reply to Sascha Hauerfirmwaremgr_find_by_node() matches the device node pointers to find the firmware manager associated to a node. This function is called by the of_overlay code when it finds a firmware-name property to find a firmware manager for this node. This works when the overlay is applied to the live tree, but not when it's applied to the tree we are going to load the kernel with. To overcome this limitation match by the nodes reproducible name instead of pointers.
--- common/firmware.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
common/firmware.c +14 -2
@@ -68,10 +68,22 @@ struct firmware_mgr *firmwaremgr_find(const char *id)struct firmware_mgr *firmwaremgr_find_by_node (struct device_node *np) {struct firmware_mgr *mgr; +char *na, *nb; -list_for_each_entry (mgr, &firmwaremgr_list, list) -if (mgr->handler->device_node == np) + na =of_get_reproducible_name (np); + +list_for_each_entry (mgr, &firmwaremgr_list, list) { + nb =of_get_reproducible_name (mgr->handler->device_node); +if (!strcmp (na, nb)) { +free (na); +free (nb);return mgr; + } + +free (nb); + } + +free (na);return NULL ; }
Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 8/17 blspec: Set firmware searchpath
In reply to Sascha HauerWhen bootloader spec triggers dt overlay loading then this might also trigger loading firmware. This firmware should be looked for relative to the filesystem providing the bootloader spec files, so add that to the firmware search path.
--- common/blspec.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
common/blspec.c +13 -0
@@ -122,6 +122,8 @@ static int blspec_boot(struct bootentry *be, int verbose, int dryrun)const char *abspath, *devicetree, *options, *initrd, *linuximage;const char *overlays;const char *appendroot; +const char *old_fws; +char *fws;struct bootm_data data = { .dryrun = dryrun, };
@@ -184,9 +186,20 @@ static int blspec_boot(struct bootentry *be, int verbose, int dryrun) (entry->cdev && entry->cdev->dev) ? dev_name(entry->cdev->dev) : "none"); + old_fws =firmware_get_searchpath (); +if (old_fws && *old_fws) + fws =basprintf ("%s/lib/firmware:%s" , abspath, old_fws); +else + fws =basprintf ("%s/lib/firmware" , abspath); +firmware_set_searchpath (fws); +free (fws); + ret =bootm_boot (&data);if (ret)pr_err ("Booting failed\n" ); + +firmware_set_searchpath (old_fws); + err_out:free ((char *)data.oftree_file);free ((char *)data.initrd_file);
Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 9/17 overlay: only apply compatible trees
In reply to Sascha HauerThis adds support for a global.of_overlay_compatible variable which is a space separated list of compatible strings. Device tree overlays not matching any won't be applied (unless the overlay doesn't have a compatible property at all).
--- drivers/of/overlay.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
drivers/of/overlay.c +46 -0
@@ -11,6 +11,9 @@#include <common.h> #include <of.h> #include <errno.h> +#include <globalvar.h> +#include <magicvar.h> +#include <string.h> static struct device_node *find_target (struct device_node *root,struct device_node *fragment)
@@ -160,6 +163,36 @@ static int of_overlay_apply_fragment(struct device_node *root,return of_overlay_apply (target, overlay); } +static char *of_overlay_compatible; + +static bool of_overlay_is_compatible (struct device_node *ovl) +{ +char *p, *n, *compatibles; +bool res = false; + +if (!of_overlay_compatible || !*of_overlay_compatible) +return true; +if (!of_find_property (ovl,"compatible" ,NULL )) +return true; + + p = compatibles =xstrdup (of_overlay_compatible); + +while ((n =strsep_unescaped (&p," " ))) { +if (!*n) +continue ; + +if (of_device_is_compatible (ovl, n)) { + res = true; +break ; + } + } + +free (compatibles); + +return res; +} + +/** * Apply the overlay on the passed devicetree root * @root: the devicetree onto which the overlay will be applied
@@ -172,6 +205,9 @@ int of_overlay_apply_tree(struct device_node *root,struct device_node *fragment;int err =0 ; +if (!of_overlay_is_compatible (overlay)) +return -ENODEV ; + resolved =of_resolve_phandles (root, overlay);if (!resolved)return -EINVAL ;
@@ -250,3 +286,13 @@ int of_register_overlay(struct device_node *overlay) {return of_register_fixup (of_overlay_fixup, overlay); } + +static int of_overlay_init (void ) +{ +globalvar_add_simple_string ("of_overlay_compatible" , &of_overlay_compatible); + +return 0 ; +} +device_initcall (of_overlay_init); + +BAREBOX_MAGICVAR (global.of_overlay_compatible,"space separated list of compatibles an overlay must match" );
Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 10/17 overlay: Add of_overlay_apply_file()
In reply to Sascha HauerA shortcut to of_overlay_apply_tree() which takes a filename rather than an unflattened device tree.
--- drivers/of/overlay.c | 35 +++++++++++++++++++++++++++++++++++ include/of.h | 7 +++++++ 2 files changed, 42 insertions(+)
drivers/of/overlay.c +35 -0
@@ -14,6 +14,8 @@#include <globalvar.h> #include <magicvar.h> #include <string.h> +#include <libfile.h> +#include <fs.h> static struct device_node *find_target (struct device_node *root,struct device_node *fragment)
@@ -227,6 +229,39 @@ int of_overlay_apply_tree(struct device_node *root,return err; } +int of_overlay_apply_file (struct device_node *root,const char *filename) +{ +void *fdt; +struct device_node *ovl; +size_t size; +int ret; + + ret =read_file_2 (filename, &size, &fdt,FILESIZE_MAX ); +if (ret) +return ret; + + ovl =of_unflatten_dtb (fdt, size); + +free (fdt); + +if (IS_ERR (ovl)) { +pr_err ("Failed to unflatten %s: %pe\n" , filename, ovl); +return PTR_ERR (ovl); + } + + ret =of_overlay_apply_tree (root, ovl); +if (ret == -ENODEV ) +pr_debug ("Not applied %s (not compatible)\n" , filename); +else if (ret) +pr_err ("Cannot apply %s: %s\n" , filename,strerror (-ret)); +else +pr_info ("Applied %s\n" , filename); + +of_delete_node (ovl); + +return ret; +} +static int of_overlay_fixup (struct device_node *root,void *data) {struct device_node *overlay = data;
include/of.h +7 -0
@@ -1026,6 +1026,7 @@ struct device_node *of_resolve_phandles(struct device_node *root, const struct device_node *overlay);int of_overlay_apply_tree (struct device_node *root,struct device_node *overlay); +int of_overlay_apply_file (struct device_node *root,const char *filename);int of_register_overlay (struct device_node *overlay); int of_process_overlay(struct device_node *root, struct device_node *overlay,
@@ -1047,6 +1048,12 @@ static inline int of_overlay_apply_tree(struct device_node *root,return -ENOSYS ; } +static inline int of_overlay_apply_file (struct device_node *root, +const char *filename) +{ +return -ENOSYS ; +} +static inline int of_register_overlay (struct device_node *overlay) {return -ENOSYS ;
Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 11/17 firmware: Load from global search path
In reply to Sascha HauerWe have a global firmware search path, so use it. This removes the path argument from of_firmware_load_overlay(). blspec already extends the global firmware search path, so the path is not needed there. The of_overlay command has an option for specifying the search path, this is removed here, the global search path has to be used instead.
--- commands/of_overlay.c | 31 ++++++------------------------- common/blspec.c | 11 +---------- drivers/of/of_firmware.c | 25 ++++--------------------- include/of.h | 4 ++-- 4 files changed, 13 insertions(+), 58 deletions(-)
commands/of_overlay.c +6 -25
@@ -13,23 +13,12 @@static int do_of_overlay (int argc,char *argv[]) { -int opt, ret; +int ret;struct fdt_header *fdt;struct device_node *overlay; -const char *search_path =NULL ;size_t size; -while ((opt =getopt (argc, argv,"S:" )) >0 ) { -switch (opt) { -case 'S' : - search_path = optarg; -break ; -default : -return COMMAND_ERROR_USAGE ; - } - } - -if (argc != optind +1 ) +if (argc !=2 )return COMMAND_ERROR_USAGE ; fdt =read_file (argv[optind], &size);
@@ -43,11 +32,9 @@ static int do_of_overlay(int argc, char *argv[])if (IS_ERR (overlay))return PTR_ERR (overlay); -if (search_path) { - ret =of_firmware_load_overlay (overlay, search_path); -if (ret) - goto err; - } + ret =of_firmware_load_overlay (overlay); +if (ret) + goto err; ret =of_register_overlay (overlay);if (ret) {
@@ -62,15 +49,9 @@ err:return ret; } -BAREBOX_CMD_HELP_START(of_overlay) -BAREBOX_CMD_HELP_TEXT("Options:") -BAREBOX_CMD_HELP_OPT("-S path", "load firmware using this search path") -BAREBOX_CMD_HELP_END -BAREBOX_CMD_START (of_overlay) .cmd = do_of_overlay, BAREBOX_CMD_DESC("register device tree overlay as fixup") - BAREBOX_CMD_OPTS("[-S path] FILE") + BAREBOX_CMD_OPTS("FILE")BAREBOX_CMD_GROUP (CMD_GRP_MISC) - BAREBOX_CMD_HELP(cmd_of_overlay_help)BAREBOX_CMD_END
common/blspec.c +1 -10
@@ -39,7 +39,6 @@ static int blspec_apply_oftree_overlay(char *file, const char *abspath,struct fdt_header *fdt;struct device_node *overlay;char *path; -char *firmware_path;size_t size; path =basprintf ("%s/%s" , abspath, file);
@@ -64,15 +63,7 @@ static int blspec_apply_oftree_overlay(char *file, const char *abspath, goto out; } -/* -* Unfortunately the device tree overlay contains only the filename of -* the firmware and relies on the firmware search paths to find the -* actual file. Use /lib/firmware in the Linux root directory and hope -* for the best. -*/ - firmware_path =basprintf ("%s/%s" , abspath,"/lib/firmware" ); - ret =of_firmware_load_overlay (overlay, firmware_path); -free (firmware_path); + ret =of_firmware_load_overlay (overlay);if (ret) {pr_warn ("failed to load firmware: skip overlay \"%s\"\n" , path);of_delete_node (overlay);
drivers/of/of_firmware.c +4 -21
@@ -6,10 +6,6 @@#include <firmware.h> #include <of.h> -struct overlay_info { -const char *firmware_path; -}; -static struct firmware_mgr *of_node_get_mgr (struct device_node *np) {struct device_node *mgr_node;
@@ -26,12 +22,9 @@ static struct firmware_mgr *of_node_get_mgr(struct device_node *np) }static int load_firmware (struct device_node *target, -struct device_node *fragment,void *data) +struct device_node *fragment,void *unused) { -struct overlay_info *info = data;const char *firmware_name; -const char *firmware_path = info->firmware_path; -char *firmware;int err;struct firmware_mgr *mgr;
@@ -50,22 +43,13 @@ static int load_firmware(struct device_node *target,if (!mgr)return -EINVAL ; - firmware =basprintf ("%s/%s" , firmware_path, firmware_name); -if (!firmware) -return -ENOMEM ; - - err =firmwaremgr_load_file (mgr, firmware); - -free (firmware); + err =firmwaremgr_load_file (mgr, firmware_name);return err; } -int of_firmware_load_overlay (struct device_node *overlay,const char *path) +int of_firmware_load_overlay (struct device_node *overlay) { -struct overlay_info info = { - .firmware_path = path, - };int err;struct device_node *root;struct device_node *resolved;
@@ -81,8 +65,7 @@ int of_firmware_load_overlay(struct device_node *overlay, const char *path)*/ ovl = resolved ? resolved : overlay; - err =of_process_overlay (root, ovl, - load_firmware, &info); + err =of_process_overlay (root, ovl, load_firmware,NULL );if (resolved)of_delete_node (resolved);
include/of.h +2 -2
@@ -1034,7 +1034,7 @@ int of_process_overlay(struct device_node *root, struct device_node *overlay, void *data), void *data); -int of_firmware_load_overlay (struct device_node *overlay,const char *path); +int of_firmware_load_overlay (struct device_node *overlay);#else static inline struct device_node *of_resolve_phandles (struct device_node *root,const struct device_node *overlay)
@@ -1068,7 +1068,7 @@ static inline int of_process_overlay(struct device_node *root,return -ENOSYS ; } -static inline int of_firmware_load_overlay (struct device_node *overlay,const char *path) +static inline int of_firmware_load_overlay (struct device_node *overlay) {return -ENOSYS ; }
Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 12/17 blspec: Rework firmware load
In reply to Sascha HauerApplying 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.
--- arch/arm/lib32/bootm.c | 4 ++ arch/arm/lib32/bootu.c | 5 +- arch/arm/lib32/bootz.c | 3 + arch/arm/lib64/armlinux.c | 4 ++ arch/kvx/lib/bootm.c | 6 ++ arch/mips/lib/bootm.c | 4 ++ arch/powerpc/lib/ppclinux.c | 4 ++ arch/riscv/lib/bootm.c | 5 ++ commands/of_overlay.c | 4 -- common/blspec.c | 73 ++++++------------------ common/oftree.c | 2 + drivers/of/of_firmware.c | 111 ++++++++++++++++++++++++++++-------- drivers/of/overlay.c | 5 ++ include/of.h | 17 +++++- 14 files changed, 162 insertions(+), 85 deletions(-)
arch/arm/lib32/bootm.c +4 -0
@@ -325,6 +325,10 @@ static int __do_bootm_linux(struct image_data *data, unsigned long free_mem,if (data->dryrun)return 0 ; + ret =of_overlay_load_firmware (); +if (ret) +return ret; +if (data->tee_res) tee = (void *)data->tee_res->start;else
arch/arm/lib32/bootu.c +4 -1
@@ -8,7 +8,7 @@static int do_bootu (int argc,char *argv[]) { -int fd; +int fd, ret;void *kernel =NULL ;void *oftree =NULL ;
@@ -25,6 +25,9 @@ static int do_bootu(int argc, char *argv[])#ifdef CONFIG_OFTREE oftree =of_get_fixed_tree (NULL );#endif + ret =of_overlay_load_firmware (); +if (ret) +return ret;start_linux (kernel,0 ,0 ,0 , oftree,ARM_STATE_SECURE ,NULL );
arch/arm/lib32/bootz.c +3 -0
@@ -111,6 +111,9 @@ static int do_bootz(int argc, char *argv[])#ifdef CONFIG_OFTREE oftree =of_get_fixed_tree (NULL );#endif + ret =of_overlay_load_firmware (); +if (ret) +return ret;start_linux (zimage, swap,0 ,0 , oftree,ARM_STATE_SECURE ,NULL );
arch/arm/lib64/armlinux.c +4 -0
@@ -16,6 +16,10 @@ static int do_bootm_linux(struct image_data *data)if (IS_ERR (fn))return PTR_ERR (fn); + ret =of_overlay_load_firmware (); +if (ret) +return ret; +shutdown_barebox ();fn (devicetree,0 ,0 ,0 );
arch/kvx/lib/bootm.c +6 -0
@@ -24,11 +24,17 @@ typedef void __noreturn (*boot_func_entry)(unsigned long, void *);static int do_boot_entry (struct image_data *data,boot_func_entry entry,void *fdt_load_addr) { +int ret; +printf ("starting elf (entry at %p)\n" , entry);if (data->dryrun)return 0 ; + ret =of_overlay_load_firmware (); +if (ret) +return ret; +shutdown_barebox ();/* Synchronize I-cache with D-cache */
arch/mips/lib/bootm.c +4 -0
@@ -65,6 +65,10 @@ static int do_bootm_elf(struct image_data *data)if (data->dryrun) goto bootm_free_fdt; + ret =of_overlay_load_firmware (); +if (ret) +return ret; +shutdown_barebox (); entry = (void *) (unsigned long ) data->os_address;
arch/powerpc/lib/ppclinux.c +4 -0
@@ -67,6 +67,10 @@ static int do_bootm_linux(struct image_data *data)if (data->dryrun)return 0 ; + ret =of_overlay_load_firmware (); +if (ret) +return ret; +/* Relocate the device tree if outside the initial * Linux mapped TLB. */
arch/riscv/lib/bootm.c +5 -0
@@ -8,11 +8,16 @@ static int do_bootm_linux(struct image_data *data) {void (*fn)(unsigned long a0,unsigned long dtb,unsigned long a2);phys_addr_t devicetree; +int ret; fn =booti_load_image (data, &devicetree);if (IS_ERR (fn))return PTR_ERR (fn); + ret =of_overlay_load_firmware (); +if (ret) +return ret; +shutdown_barebox ();fn (0 , devicetree,0 );
commands/of_overlay.c +0 -4
@@ -32,10 +32,6 @@ static int do_of_overlay(int argc, char *argv[])if (IS_ERR (overlay))return PTR_ERR (overlay); - ret =of_firmware_load_overlay (overlay); -if (ret) - goto err; - ret =of_register_overlay (overlay);if (ret) {printf ("cannot apply oftree overlay: %s\n" ,strerror (-ret));
common/blspec.c +19 -54
103 lines not on this page · raw message
common/oftree.c +2 -0
@@ -326,6 +326,8 @@ int of_fix_tree(struct device_node *node)struct of_fixup *of_fixup;int ret; +of_overlay_load_firmware_clear (); +list_for_each_entry (of_fixup, &of_fixup_list, list) { ret = of_fixup->fixup (node, of_fixup->context);if (ret)
drivers/of/of_firmware.c +87 -24
131 lines not on this page · raw message
drivers/of/overlay.c +5 -0
@@ -214,6 +214,10 @@ int of_overlay_apply_tree(struct device_node *root,if (!resolved)return -EINVAL ; + err =of_overlay_pre_load_firmware (root, resolved); +if (err) + goto out_err; +/* Copy symbols from resolved overlay to base device tree */ of_overlay_apply_symbols (root, resolved);
@@ -224,6 +228,7 @@ int of_overlay_apply_tree(struct device_node *root,pr_warn ("failed to apply %s\n" , fragment->name); } +out_err:of_delete_node (resolved);return err;
include/of.h +15 -2
@@ -1034,7 +1034,9 @@ int of_process_overlay(struct device_node *root, struct device_node *overlay, void *data), void *data); -int of_firmware_load_overlay (struct device_node *overlay); +int of_overlay_pre_load_firmware (struct device_node *root,struct device_node *overlay); +int of_overlay_load_firmware (void ); +void of_overlay_load_firmware_clear (void );#else static inline struct device_node *of_resolve_phandles (struct device_node *root,const struct device_node *overlay)
@@ -1068,10 +1070,21 @@ static inline int of_process_overlay(struct device_node *root,return -ENOSYS ; } -static inline int of_firmware_load_overlay (struct device_node *overlay) +static inline int of_overlay_pre_load_firmware (struct device_node *root, +struct device_node *overlay) {return -ENOSYS ; } + +static inline int of_overlay_load_firmware (void ) +{ +return 0 ; +} + +static inline void of_overlay_load_firmware_clear (void ) +{ +} +#endif #endif /* __OF_H */
Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 13/17 of_overlay: apply overlays during booting
In reply to Sascha HauerThis offers the possibility to load dt overlays on the kernel device tree during booting. Several globalvars control which device trees are used. global.of_overlay_dir specifies the directory where overlay files are expected. global.of_overlay_filepattern specifies file patterns which the overlay files must match. It is a colon separated list for multiple file patterns. The patterns may contain '*' and '?' wildcards. When this variable is empty then no overlays are applied. global.of_overlay_compatible is used to apply only compatible overlays. This is also a colon separated list which contains compatible strings. An overlay is only applied when it's compatible to one of the strings.
--- drivers/of/overlay.c | 66 ++++++++++++++++++++++++++++++++++++++++++++ include/of.h | 17 ++++++++++++ 2 files changed, 83 insertions(+)
drivers/of/overlay.c +66 -0
@@ -16,6 +16,7 @@#include <string.h> #include <libfile.h> #include <fs.h> +#include <glob.h> static struct device_node *find_target (struct device_node *root,struct device_node *fragment)
@@ -327,12 +328,77 @@ int of_register_overlay(struct device_node *overlay)return of_register_fixup (of_overlay_fixup, overlay); } +static char *of_overlay_filepattern; +static char *of_overlay_dir; + +const char *of_overlay_get_dir (void ) +{ +return of_overlay_dir; +} + +void of_overlay_set_dir (const char *path) +{ +free (of_overlay_dir); + of_overlay_dir =strdup (path); +} + +int of_overlay_apply_dir (struct device_node *root,const char *dir) +{ +char *p, *path, *n, *str; +int ret =0 , i; +glob_t g = {}; +int globflags =GLOB_NOCHECK ; + +if (!dir || !*dir) +return 0 ; + + p = path =strdup (of_overlay_filepattern); + +while ((n =strsep_unescaped (&p," " ))) { + str =basprintf ("%s/%s" , dir, n); +if (!str) { + ret = -ENOMEM ; + goto out; + } + + ret =glob (str, globflags,NULL , &g); + +free (str); + +if (ret) + goto out; + + globflags |=GLOB_APPEND ; + } + +for (i =0 ; i < g.gl_pathc; i++) +of_overlay_apply_file (root, g.gl_pathv[i]); + +out: +globfree (&g); + +free (path); + +return ret; +} + +static int of_overlay_global_fixup (struct device_node *root,void *data) +{ +return of_overlay_apply_dir (root, of_overlay_dir); +} +static int of_overlay_init (void ) {globalvar_add_simple_string ("of_overlay_compatible" , &of_overlay_compatible); +globalvar_add_simple_string ("of_overlay_filepattern" , &of_overlay_filepattern); +globalvar_add_simple_string ("of_overlay_dir" , &of_overlay_dir); + +of_register_fixup (of_overlay_global_fixup,NULL );return 0 ; }device_initcall (of_overlay_init);BAREBOX_MAGICVAR (global.of_overlay_compatible,"space separated list of compatibles an overlay must match" ); +BAREBOX_MAGICVAR (global.of_overlay_filepattern,"space separated list of filepatterns an overlay must match" ); +BAREBOX_MAGICVAR (global.of_overlay_dir,"Directory to look for dt overlays" );
include/of.h +17 -0
@@ -1037,6 +1037,9 @@ int of_process_overlay(struct device_node *root,int of_overlay_pre_load_firmware (struct device_node *root,struct device_node *overlay);int of_overlay_load_firmware (void );void of_overlay_load_firmware_clear (void ); +int of_overlay_apply_dir (struct device_node *root,const char *dir); +const char *of_overlay_get_dir (void ); +void of_overlay_set_dir (const char *path);#else static inline struct device_node *of_resolve_phandles (struct device_node *root,const struct device_node *overlay)
@@ -1085,6 +1088,20 @@ static inline void of_overlay_load_firmware_clear(void) { } +static inline int of_overlay_apply_dir (struct device_node *root,const char *dir) +{ +return 0 ; +} + +static inline const char *of_overlay_get_dir (void ) +{ +return NULL ; +} + +static inline void of_overlay_set_dir (const char *path) +{ +} +#endif #endif /* __OF_H */
Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 14/17 blspec: Apply overlays from rootfs
In reply to Sascha HauerThis sets the overlay search path to $BOOT/overlays during starting an bootloader spec entry with the effect that overlays from there can be applied.
--- common/blspec.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
common/blspec.c +8 -2
@@ -75,8 +75,8 @@ static int blspec_boot(struct bootentry *be, int verbose, int dryrun)const char *abspath, *devicetree, *options, *initrd, *linuximage;const char *overlays;const char *appendroot; -const char *old_fws; -char *fws; +const char *old_fws, *old_ovld; +char *fws, *ovld;struct bootm_data data = { .dryrun = dryrun, };
@@ -139,6 +139,11 @@ static int blspec_boot(struct bootentry *be, int verbose, int dryrun) (entry->cdev && entry->cdev->dev) ? dev_name(entry->cdev->dev) : "none"); + old_ovld =of_overlay_get_dir (); + ovld =basprintf ("%s/overlays" , abspath); +of_overlay_set_dir (ovld); +free (ovld); + old_fws =firmware_get_searchpath ();if (old_fws && *old_fws) fws =basprintf ("%s/lib/firmware:%s" , abspath, old_fws);
@@ -154,6 +159,7 @@ static int blspec_boot(struct bootentry *be, int verbose, int dryrun)if (overlays)of_unregister_fixup (blspec_overlay_fixup, entry); +of_overlay_set_dir (old_ovld);firmware_set_searchpath (old_fws); err_out:
Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 15/17 doc: devicetree: Refer to internal device tree also as live tree
In reply to Sascha Hauer--- Documentation/user/devicetree.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/user/devicetree.rst +1 -1
@@ -21,7 +21,7 @@ The internal devicetree ----------------------- The devicetree consulted by barebox plays a special role. It is referred to -as the "internal devicetree." The barebox devicetree commands work on this +as the "internal devicetree" or "live tree". The barebox devicetree commands work on this devicetree. The devicetree source (DTS) files are kept in sync with the kernel DTS files. As the FDT files are meant to be backward compatible, it should always be possible to start a kernel with the barebox internal devicetree. However, since the barebox
Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 16/17 Documentation: Add documentation for device tree overlays
In reply to Sascha HauerDocument the recently gained device tree overlay features.
--- Documentation/user/devicetree.rst | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
Documentation/user/devicetree.rst +37 -0
@@ -75,3 +75,40 @@ It is important to know that these commands normally work on the internal devicetree. If you want to modify the devicetree the kernel is started with see the -f options to of_property and of_node. This option will register the operation for later execution on the Kernel devicetree. + +Device tree overlays +-------------------- + +barebox has support for device tree overlays. barebox knows two different trees, +the live tree and the device tree the kernel is started with. Both can be applied +overlays to. + +Device tree overlays on the live tree +..................................... + +While the live tree can be patched by board code, barebox does not +detect any changes to the live tree. To let the overlays have any effect, board +code must make sure the live tree is patched before the devices are instanciated +from it. + +Device tree overlays on the kernel device tree +.............................................. + +Overlays can be applied to the kernel device tree before it is handed over to +the kernel. The behaviour is controlled by different variables: + +``global.of_overlay_dir`` + Overlays are read from this directory. barebox will try to apply all overlays + found here if not limited by one of the other variables below. When using + bootloader spec this variable will be temporarily overwritten with + ``$mountpoint/overlays`` where ``$mountpoint`` is the path where the filesystem + containing the bootloader spec entries are located. +``global.of_overlay_compatible`` + This is a space separated list of compatibles. Only overlays matching one of + these compatibles will be applied. When this list is empty then all overlays + will be applied. Overlays that don't have a compatible are considered being + always compatible. +``global.of_overlay_filepattern`` + This is a space separated list of file patterns. An overlay is only applied + when its filename matches one of the patterns. The patterns can contain + ``*`` and ``?`` as wildcards. When empty, all files are applied.
Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 16/17] Documentation: Add documentation for device tree overlays
Hi,
some bikeshedding incoming.
Quoted 28 lines · Sascha Hauer
Document the recently gained device tree overlay features.
Signed-off-by Sascha Hauer <[email protected]>--- Documentation/user/devicetree.rst | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)Documentation/user/devicetree.rst +13
-0@@ -75,3 +75,40 @@ It is important to know that these commands normally work on the internal devicetree. If you want to modify the devicetree the kernel is started with see the -f options to of_property and of_node. This option will register the operation for later execution on the Kernel devicetree. + +Device tree overlays +-------------------- + +barebox has support for device tree overlays. barebox knows two different trees, +the live tree and the device tree the kernel is started with. Both can be applied +overlays to. + +Device tree overlays on the live tree +..................................... + +While the live tree can be patched by board code, barebox does not +detect any changes to the live tree. To let the overlays have any effect, board
Documentation/user/devicetree.rst It is important to know that these commands normally work on the internal · line 100
Quoted 10 lines
Documentation/user/devicetree.rst +10
-0+code must make sure the live tree is patched before the devices are instanciated +from it. + +Device tree overlays on the kernel device tree +.............................................. + +Overlays can be applied to the kernel device tree before it is handed over to +the kernel. The behaviour is controlled by different variables: + +``global.of_overlay_dir``
Convention seems to be that attributes of the same thing are preceded by a `.', e.g.:
global.of.overlay.dir
global.of.overlay.compatible
global.of.overlay.filepattern
(I think the `.' between of and overlay is not a bad idea, as we may decide to have e.g.
global.of.compatible in future)
Documentation/user/devicetree.rst It is important to know that these commands normally work on the internal · line 105
Quoted 5 lines
Documentation/user/devicetree.rst +5
-0+ Overlays are read from this directory. barebox will try to apply all overlays + found here if not limited by one of the other variables below. When using + bootloader spec this variable will be temporarily overwritten with + ``$mountpoint/overlays`` where ``$mountpoint`` is the path where the filesystem + containing the bootloader spec entries are located.
Couldn't paths be interpreted relative to the $mountpoint? That way you can make overlays the default always and have the user override it if they prefer something else?
Documentation/user/devicetree.rst It is important to know that these commands normally work on the internal · line 110
Quoted 5 lines
Documentation/user/devicetree.rst +5
-0+``global.of_overlay_compatible`` + This is a space separated list of compatibles. Only overlays matching one of + these compatibles will be applied. When this list is empty then all overlays + will be applied. Overlays that don't have a compatible are considered being + always compatible.
Makes sense.
Documentation/user/devicetree.rst It is important to know that these commands normally work on the internal · line 114
Quoted 4 lines
Documentation/user/devicetree.rst +4
-0+``global.of_overlay_filepattern`` + This is a space separated list of file patterns. An overlay is only applied + when its filename matches one of the patterns. The patterns can contain + ``*`` and ``?`` as wildcards. When empty, all files are applied.
Similarly, we could have ``*`` as a default.
In future, I think we will want to have $global.of.overlay.filters. Board code can register filters that do more than look into compatibles and file patterns, e.g. compare a property with a value in EEPROM. If a user wants to make use of it, they can add the name of the filter into $global.of.overlay.filters. But this can be retrofitted: The variable will have filepattern and compatible filters as default, so no breakage.
Cheers,
Ahmad
Signature · 9 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 16/17] Documentation: Add documentation for device tree overlays
Quoted 4 lines · Ahmad Fatoum
Hi,
some bikeshedding incoming.
Well, while we're out here at the shed...
Quoted 5 lines
Convention seems to be that attributes of the same thing are preceded by a `.', e.g.:
global.of.overlay.dir
global.of.overlay.compatible
global.of.overlay.filepattern
This looks a lot more Barebox-like to me.
Quoted 2 lines
(I think the `.' between of and overlay is not a bad idea, as we may decide to have e.g.
global.of.compatible in future)
Are these only used when bootm is run? Aren't most magivars that work this way in the namespace "global.bootm"?
Quoted 7 lines
Documentation/user/devicetree.rst It is important to know that these commands normally work on the internal · line 110
Quoted 5 lines
+``global.of_overlay_compatible``
Documentation/user/devicetree.rst +4
-0+ This is a space separated list of compatibles. Only overlays matching one of + these compatibles will be applied. When this list is empty then all overlays + will be applied. Overlays that don't have a compatible are considered being + always compatible.Makes sense.
I've always thought the way Barebox's global.linux.bootargs.* variables worked was nice. It avoids different things that add arguments for different reasons from interacting with each other trying to write to a single variable.
There's a similar process with overlays. Some overlays are based on the board variant. Then an add-on board might bring in an overlay. Then another overlay from a second add-on board that is unrelated to the 1st. Then an overlay to configure something at boot time, like add an LED trigger at boot. It's so much easier to just set or unset a single variable, than to need to worry about appending or removing or modifying a string inside a space separated list.
Quoted 6 lines
Documentation/user/devicetree.rst It is important to know that these commands normally work on the internal · line 114
Quoted 4 lines
+``global.of_overlay_filepattern``
Documentation/user/devicetree.rst +3
-0+ This is a space separated list of file patterns. An overlay is only applied + when its filename matches one of the patterns. The patterns can contain + ``*`` and ``?`` as wildcards. When empty, all files are applied.Similarly, we could have ``*`` as a default.
If the default value is "*", and it's necessary to use a space separated list, then a script adding another pattern will use something like:
global.of_overlay_filepattern="${global.of_overlay_filepattern} new-overlay.dtb"
But that doesn't work if the variable doesn't start as empty. Using "global.of.filepatterns.*" as a set of variables would help.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 16/17] Documentation: Add documentation for device tree overlays
Quoted 35 lines · Trent Piepho
Quoted 4 lines · Ahmad Fatoum
Hi,
some bikeshedding incoming.
Well, while we're out here at the shed...
Quoted 5 lines
Convention seems to be that attributes of the same thing are preceded by a `.', e.g.:
global.of.overlay.dir
global.of.overlay.compatible
global.of.overlay.filepatternThis looks a lot more Barebox-like to me.
Quoted 2 lines
(I think the `.' between of and overlay is not a bad idea, as we may decide to have e.g.
global.of.compatible in future)Are these only used when bootm is run? Aren't most magivars that work this way in the namespace "global.bootm"?
Quoted 7 lines
Documentation/user/devicetree.rst It is important to know that these commands normally work on the internal · line 110
Quoted 5 lines
+``global.of_overlay_compatible``
Documentation/user/devicetree.rst +4
-0+ This is a space separated list of compatibles. Only overlays matching one of + these compatibles will be applied. When this list is empty then all overlays + will be applied. Overlays that don't have a compatible are considered being + always compatible.Makes sense.
I've always thought the way Barebox's global.linux.bootargs.* variables worked was nice. It avoids different things that add arguments for different reasons from interacting with each other trying to write to a single variable.
Quoted 7 lines
There's a similar process with overlays. Some overlays are based on the board variant. Then an add-on board might bring in an overlay. Then another overlay from a second add-on board that is unrelated to the 1st. Then an overlay to configure something at boot time, like add an LED trigger at boot. It's so much easier to just set or unset a single variable, than to need to worry about appending or removing or modifying a string inside a space separated list.
I see what you mean. I talked to Ahmad and I have now implemented a filter mechanism for overlays which can be extended when a board has the need to do so. I think the result is quite flexible and already quite complex. I am not against using global.linux.bootargs.* style multi variables for the filepatterns, but maybe we can leave that out for now until somebody has a concrete need for this.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 17/17 of_firmware: Fix handling of firmware-name property
In reply to Sascha HauerThe fpga-region binding states that the firmware-name property must be in the same node as the fpga-region compatible, so checking for this compatible when walking up the parents is wrong. Instead, only test for it in the target node. Also, when the current node is not a fpga-region we must return successfully.
--- drivers/of/of_firmware.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/of/of_firmware.c +6 -5
@@ -11,11 +11,9 @@ static struct firmware_mgr *of_node_get_mgr(struct device_node *np)struct device_node *mgr_node;do { -if (of_device_is_compatible (np,"fpga-region" )) { - mgr_node =of_parse_phandle (np,"fpga-mgr" ,0 ); -if (mgr_node) -return firmwaremgr_find_by_node (mgr_node); - } + mgr_node =of_parse_phandle (np,"fpga-mgr" ,0 ); +if (mgr_node) +return firmwaremgr_find_by_node (mgr_node); }while ((np =of_get_parent (np)) !=NULL );return NULL ;
@@ -48,6 +46,9 @@ static int load_firmware(struct device_node *target,if (!target)return -EINVAL ; +if (!of_device_is_compatible (target,"fpga-region" )) +return 0 ; + mgr =of_node_get_mgr (target);if (!mgr)return -EINVAL ;
Signature · 7 lines
2.29.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox