Add support for extlinux.conf
PATCH 1/2 Add support for extlinux.conf
This adds support for the extlinux.conf configuration format, commonly used by Syslinux and many Linux distributions. The configuration file is typically located at /boot/extlinux/extlinux.conf or /extlinux/extlinux.conf and defines boot entries with kernel, initrd, device tree, and command line options.
The implementation integrates with the existing boot entry framework:
- The extlinux scanner discovers entries on mounted filesystems
- Default label is turned into a boot entry
- The "root=" parameter is automatically stripped from the append line
to allow barebox to inject the correct root device (via appendroot)
- Bootm is used to load and start the kernel
---
barebox@Diasom DS-RK3568-SOM-EVB:/ global.boot.default=mmc1.2
barebox@Diasom DS-RK3568-SOM-EVB:/ boot
ext4 ext40: EXT2 rev 1, inode_size 256, descriptor size 64
Booting entry 'extlinux: linux'
extlinux: Booting extlinux label 'linux'
Adding "root=/dev/mmcblk1p3" to Kernel commandline
Loading ARM aarch64 Linux/EFI image '/mnt/mmc1.2/boot/extlinux/../vmlinuz'
Loaded initrd from GZIP compressed /mnt/mmc1.2/boot/extlinux/../initrd.img to 0x000000000d390000-0x000000000fb48ca6
commandline: mem=0xef600000 root=/dev/mmcblk1p3 console=ttyS2,1500000n8 ro systemd.unit=setup.target quiet splash systemd.machine_id=181af2816b4c6b0aef77068e0ccc69ad Loaded kernel to 0x0a400000, devicetree at 0x000000000fb49000
--- common/Kconfig | 19 ++++ common/Makefile | 1 + common/extlinux.c | 271 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 291 insertions(+) create mode 100644 common/extlinux.c
common/Kconfig +19 -0
@@ -726,6 +726,25 @@ config BLSPEC on a device and it allows the Operating System to install / update kernels. +config EXTLINUX + bool + prompt "Support extlinux.conf" + depends on FLEXIBLE_BOOTARGS + depends on !SHELL_NONE + select BOOT + select BOOTM + select MMCBLKDEV_ROOTARG if MCI + help + Enable this to let barebox parse extlinux.conf configuration files, + commonly used by the Syslinux bootloader and many Linux distributions + (e.g., on SD cards or USB drives). + extlinux.conf is typically located at /boot/extlinux/extlinux.conf or + /extlinux/extlinux.conf. It defines boot entries with kernel, initrd, + device tree, and command line options. + This option allows barebox to discover and boot operating systems + that follow the extlinux configuration format, providing a simple + and portable way to manage multiple boot options. + config FLEXIBLE_BOOTARGS bool prompt "flexible Linux bootargs generation"
common/Makefile +1 -0
@@ -9,6 +9,7 @@ obj-y += clock.o pbl-$(CONFIG_PBL_CLOCKSOURCE) += clock.o obj-y += console_common.o obj-$(CONFIG_OFDEVICE) += deep-probe.o +obj-$(CONFIG_EXTLINUX) += extlinux.o obj-y += startup.o obj-y += misc.o obj-pbl-y += memsize.o
common/extlinux.c new file +271 -0
271 lines not on this page · raw message
Signature · 1 line
2.52.0
PATCH 2/2 Documentation: add extlinux.conf support description
--- Documentation/user/booting-linux.rst | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
Documentation/user/booting-linux.rst +38 -0
@@ -306,6 +306,44 @@ Additional notes about keys in the bootloader spec entries: different devices without having to specify a different ``root=`` option each time. +.. _extlinux_conf: + +extlinux.conf Support +^^^^^^^^^^^^^^^^^^^^^ + +In addition to the Boot Loader Specification, barebox also supports the +extlinux configuration format, commonly used by the Syslinux bootloader and +many Linux distributions. This format is often found on SD cards, USB drives, +or disk partitions prepared with tools like ``extlinux --install``. + +The configuration file is named ``extlinux.conf`` and can be located at: +* ``/boot/extlinux/extlinux.conf`` + +The file uses a simple key-value syntax with sections labeled by ``LABEL``. +A typical example looks like: + +.. code-block:: none + + DEFAULT linux + LABEL linux + KERNEL /boot/vmlinuz + INITRD /boot/initrd.img + FDT /boot/board.dtb + APPEND console=ttyS0,115200 root=PARTUUID=deadbeef-01 + +When booting an extlinux entry, barebox automatically strips any ``root=`` +parameter from the ``APPEND`` line and injects the correct ``root=`` based on +the boot device (similar to the ``linux-appendroot`` feature in blspec). This +makes the same root filesystem image usable across different storage media. + +To use extlinux support, enable ``CONFIG_EXTLINUX`` in your barebox +configuration. Entries are automatically discovered by the :ref:`command_boot` +command when scanning a device or mount point. For example: + +.. code-block:: sh + + boot mmc1.2 + .. _booting_linux_net: Network boot
Signature · 1 line
2.52.0
Re: [PATCH 2/2] Documentation: add extlinux.conf support description
Hi,
Quoted 1 line · Alexander Shiyan
Signed-off-by Alexander Shiyan <[email protected]>
Thanks for adding documentation.
I have been wanting to add bootloader spec support to openembedded-core to barebox can be used to boot Beaglebone black images generated by it, but with extlinux support in barebox that should work as well. I will surely give this a try in the future.
Could I motivate you to add a self test that exercises the parser?
Doesn't have to be anything extensive, see test/self/blspec.c for an example. It's basically adding a few configs into the barebox environment, calling bootentry_create_from_name() on the directory and then running some assertions.
Thanks,
Ahmad
Quoted 53 lines
--- Documentation/user/booting-linux.rst | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)Documentation/user/booting-linux.rst +38
-0@@ -306,6 +306,44 @@ Additional notes about keys in the bootloader spec entries: different devices without having to specify a different ``root=`` option each time. +.. _extlinux_conf: + +extlinux.conf Support +^^^^^^^^^^^^^^^^^^^^^ + +In addition to the Boot Loader Specification, barebox also supports the +extlinux configuration format, commonly used by the Syslinux bootloader and +many Linux distributions. This format is often found on SD cards, USB drives, +or disk partitions prepared with tools like ``extlinux --install``. + +The configuration file is named ``extlinux.conf`` and can be located at: +* ``/boot/extlinux/extlinux.conf`` + +The file uses a simple key-value syntax with sections labeled by ``LABEL``. +A typical example looks like: + +.. code-block:: none + + DEFAULT linux + LABEL linux + KERNEL /boot/vmlinuz + INITRD /boot/initrd.img + FDT /boot/board.dtb + APPEND console=ttyS0,115200 root=PARTUUID=deadbeef-01 + +When booting an extlinux entry, barebox automatically strips any ``root=`` +parameter from the ``APPEND`` line and injects the correct ``root=`` based on +the boot device (similar to the ``linux-appendroot`` feature in blspec). This +makes the same root filesystem image usable across different storage media. + +To use extlinux support, enable ``CONFIG_EXTLINUX`` in your barebox +configuration. Entries are automatically discovered by the :ref:`command_boot` +command when scanning a device or mount point. For example: + +.. code-block:: sh + + boot mmc1.2 + .. _booting_linux_net: Network boot
Signature · 4 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 |
Re: [PATCH 2/2] Documentation: add extlinux.conf support description
Hello Ahmad.
Quoted 10 lines · Alexander Shiyan
Quoted 1 line
Signed-off-by Alexander Shiyan <[email protected]>Thanks for adding documentation.
I have been wanting to add bootloader spec support to openembedded-core to barebox can be used to boot Beaglebone black images generated by it, but with extlinux support in barebox that should work as well. I will surely give this a try in the future.
Quoted 6 lines
Could I motivate you to add a self test that exercises the parser?
Doesn't have to be anything extensive, see
test/self/blspec.cfor an example. It's basically adding a few configs into the barebox environment, callingbootentry_create_from_name()on the directory and then running some assertions.
I think this can be done later, so as not to bloat the patch series...
Hi Alexander,
Thanks for your patch!
Quoted 111 lines · Alexander Shiyan
This adds support for the extlinux.conf configuration format, commonly used by Syslinux and many Linux distributions. The configuration file is typically located at
/boot/extlinux/extlinux.confor /extlinux/extlinux.conf and defines boot entries with kernel, initrd, device tree, and command line options.The implementation integrates with the existing boot entry framework:
- The extlinux scanner discovers entries on mounted filesystems
- Default label is turned into a boot entry
- The "root=" parameter is automatically stripped from the append line
to allow barebox to inject the correct root device (via appendroot)
- Bootm is used to load and start the kernel
---
barebox@Diasom DS-RK3568-SOM-EVB:/ global.boot.default=mmc1.2
barebox@Diasom DS-RK3568-SOM-EVB:/ boot
ext4 ext40: EXT2 rev 1,inode_size256, descriptor size 64
Booting entry 'extlinux: linux'
extlinux: Booting extlinux label 'linux'
Adding "root=/dev/mmcblk1p3" to Kernel commandline
Loading ARM aarch64 Linux/EFI image '/mnt/mmc1.2/boot/extlinux/../vmlinuz'
Loaded initrd from GZIP compressed/mnt/mmc1.2/boot/extlinux/../initrd.imgto 0x000000000d390000-0x000000000fb48ca6
commandline: mem=0xef600000 root=/dev/mmcblk1p3 console=ttyS2,1500000n8 ro systemd.unit=setup.target quiet splash systemd.machine_id=181af2816b4c6b0aef77068e0ccc69ad Loaded kernel to0x0a400000, devicetree at0x000000000fb49000Signed-off-by Alexander Shiyan <[email protected]>--- common/Kconfig | 19 ++++ common/Makefile | 1 + common/extlinux.c | 271 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 291 insertions(+) create mode 100644 common/extlinux.ccommon/Kconfig +19
-0@@ -726,6 +726,25 @@ config BLSPEC on a device and it allows the Operating System to install / update kernels. +config EXTLINUX + bool + prompt "Support extlinux.conf" + depends on FLEXIBLE_BOOTARGS + depends on !SHELL_NONE + select BOOT + select BOOTM + select MMCBLKDEV_ROOTARG if MCI + help + Enable this to let barebox parse extlinux.conf configuration files, + commonly used by the Syslinux bootloader and many Linux distributions + (e.g., on SD cards or USB drives). + extlinux.conf is typically located at /boot/extlinux/extlinux.conf or + /extlinux/extlinux.conf. It defines boot entries with kernel, initrd, + device tree, and command line options. + This option allows barebox to discover and boot operating systems + that follow the extlinux configuration format, providing a simple + and portable way to manage multiple boot options. + config FLEXIBLE_BOOTARGS bool prompt "flexible Linux bootargs generation"common/Makefile +1
-0@@ -9,6 +9,7 @@ obj-y += clock.o pbl-$(CONFIG_PBL_CLOCKSOURCE) += clock.o obj-y += console_common.o obj-$(CONFIG_OFDEVICE) += deep-probe.o +obj-$(CONFIG_EXTLINUX) += extlinux.o obj-y += startup.o obj-y += misc.o obj-pbl-y += memsize.ocommon/extlinux.c new file +31
-0@@ -0,0 +1,271 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* SPDX-FileCopyrightText: Alexander Shiyan <[email protected]> */ + +#define pr_fmt (fmt) "extlinux: " fmt + +#include <boot.h> +#include <bootm.h> +#include <bootscan.h> +#include <common.h> +#include <environment.h> +#include <fs.h> +#include <globalvar.h> +#include <libfile.h> +#include <libgen.h> +#include <malloc.h> +#include <string.h> + +struct extlinux_entry { +struct bootentry entry; +char *rootpath; +char *label; +char *kernel; +char *initrd; +char *fdtdir; +char *fdt; +char *append; +}; + +static int extlinux_boot (struct bootentry *be,int verbose,int dryrun) +{ + struct extlinux_entry *e =
common/extlinux.c line 41
Quoted 10 lines
common/extlinux.c new file +10
-0+ container_of(be, struct extlinux_entry, entry); +char *kernel_abs, *initrd_abs =NULL , *fdt_abs =NULL ; +struct bootm_data data = {}; +int ret; + +bootm_data_init_defaults (&data); + + data.dryrun =max_t (int, dryrun, data.dryrun); + data.verbose =max (verbose, data.verbose); + data.appendroot = true;
Not sure this is a good idea because of potential of clashing with extlinux appended command line options.
Quoted 12 lines
common/extlinux.c new file +12
-0+ + kernel_abs =basprintf ("%s/%s" , e->rootpath, e->kernel); + data.os_file = kernel_abs; + +if (e->initrd) { + initrd_abs =basprintf ("%s/%s" , e->rootpath, e->initrd); + data.initrd_file = initrd_abs; + } + +if (e->fdt) { +char *fdtdir = e->fdtdir ? : e->rootpath; +
common/extlinux.c line 63
Quoted 10 lines
common/extlinux.c new file +10
-0+ fdt_abs =basprintf ("%s/%s" , fdtdir, e->fdt); + data.oftree_file = fdt_abs; + } + +if (e->append) +globalvar_add_simple ("linux.bootargs.dyn.extlinux" , e->append); + +pr_info ("Booting extlinux label '%s'\n" , e->label); + + ret =bootm_boot (&data);
Please make use of new bootm_entry instead, so it can be used with devboot:
https://github.com/barebox/barebox/blob/next/Documentation/user/devboot.rst
Quoted 56 lines
common/extlinux.c new file +56
-0+if (ret) +pr_err ("bootm failed: %s\n" ,strerror (-ret)); + +free (kernel_abs); +free (initrd_abs); +free (fdt_abs); + +return ret; +} + +static void extlinux_entry_free (struct bootentry *be) +{ +struct extlinux_entry *e = + container_of(be, struct extlinux_entry, entry); + +free (e->rootpath); +free (e->label); +free (e->kernel); +free (e->initrd); +free (e->fdtdir); +free (e->fdt); +free (e->append); +free (e); +} + +static char *remove_param (const char *params,const char *param) +{ +char *result, *dst; +const char *src; + + result =xmalloc (strlen (params) +1 ); + + src = params; + dst = result; + +while (*src) { +if (!strncasecmp (src, param,strlen (param))) { +while (*src && *src !=' ' ) + src++; + + src =skip_spaces (src); + +continue ; + } + + *dst++ = *src++; + } + + *dst ='\0' ; + +return result; +} + +static struct extlinux_entry *parse_extlinux_conf (const char *abspath, +const char *rootpath) +{
common/extlinux.c line 129
Quoted 10 lines
common/extlinux.c new file +10
-0+char *buf, *bufptr, *line, *p, *default_label =NULL ; +struct extlinux_entry *entry =NULL ; + + bufptr =read_file (abspath,NULL ); +if (!bufptr) +return ERR_PTR (-errno); + +for (p = bufptr; *p; p++) +if (*p =='\r' ) + *p ='\n' ;
I think this can be dropped.
common/extlinux.c line 132
Quoted 3 lines
common/extlinux.c new file +3
-0+ + buf = bufptr; +while ((line =strsep (&buf,"\n" )) !=NULL ) {
And then you replace the set searched here with "\r\n"
common/extlinux.c line 139
Quoted 7 lines
common/extlinux.c new file +7
-0+char *key, *val; + + line =skip_spaces (line); + +if (*line =='#' || *line =='\0' ) +continue ; +
Nitpick: I think below can be simplified to:
common/extlinux.c line 148
Quoted 9 lines
common/extlinux.c new file +9
-0+ key = line; + val =strchr (line,' ' ); +if (!val) + val =strchr (line,'\t' ); +if (val) { + *val++ ='\0' ; + val =skip_spaces (val); + }else +continue ;
key = strsep(&line, ' \t');
val = strsep(&line, '\n');
val = isempty(val) ? NULL : skip_spaces(val);
common/extlinux.c line 158
Quoted 10 lines
common/extlinux.c new file +10
-0+ +if (!default_label) { +if (!strcasecmp (key,"DEFAULT" )) + default_label =xstrdup (val); + +continue ; + } + +if (!strcasecmp (key,"LABEL" )) { +if (!strcmp (val, default_label)) {
defaut_label might not have been set here?
You can use streq_ptr which includes NULL pointer checks.
common/extlinux.c line 163
Quoted 5 lines
common/extlinux.c new file +5
-0+ entry =xzalloc (sizeof (*entry)); + entry->label =xstrdup (val); + entry->rootpath =dirname (xstrdup (abspath)); + }else if (entry) +break ;
Kernel coding style is keeping the { braces } for an else when the if has some.
common/extlinux.c line 172
Quoted 9 lines
common/extlinux.c new file +9
-0+continue ; + } + +/* +* The same rootfs image may be launched from eMMC or SD card. +* Remove any hardcoded root= parameter from "append" to avoid +* conflicts, then let barebox automatically add the correct +* root= (via appendroot) based on the boot device. +*/
I understand the thought process, but this feels very invasive. What if the extlinux.conf files are on a different partition? I think that's not too uncommon for systems that have a ROM-code mandated FAT partition anyway.
At the very least, make this dependent on a parameter being set, maybe just global.bootm.appendroot?
common/extlinux.c line 185
Quoted 13 lines
common/extlinux.c new file +13
-0+if (entry) { +if (!strcasecmp (key,"KERNEL" )) + entry->kernel =xstrdup (val); +else if (!strcasecmp (key,"INITRD" )) + entry->initrd =xstrdup (val); +else if (!strcasecmp (key,"FDTDIR" )) + entry->fdtdir =xstrdup (val); +else if (!strcasecmp (key,"FDT" )) + entry->fdt =xstrdup (val); +else if (!strcasecmp (key,"APPEND" )) + entry->append =remove_param (val,"ROOT=" ); +else +pr_debug ("Unhandled key: %s\n" , key);
I would make this a pr_warn or at least a pr_info, so new users have an easier time knowing why something doesn't work.
Quoted 18 lines
common/extlinux.c new file +18
-0+ } + } + +free (default_label); +free (bufptr); + +if (!entry || !entry->kernel) { +if (entry) +extlinux_entry_free (&entry->entry); +return ERR_PTR (-EINVAL ); + } + +return entry; +} + +static int extlinux_scan_file (struct bootscanner *scanner, +struct bootentries *bootentries, +const char *configname)
common/extlinux.c line 213
Quoted 10 lines
common/extlinux.c new file +10
-0+{ +struct extlinux_entry *e; +const char *rootpath; + +if (!strends (configname,"extlinux.conf" )) +return 0 ; + + rootpath =get_mounted_path (configname); +if (IS_ERR (rootpath)) +return PTR_ERR (rootpath);
This means you don't support this file existing at a subdirectory of a mountpoint. That can be useful though if one is using ostree or if we include extlinux.conf files in the environment for testing.
Please add an intermediate __extlinux_scan_file that takes rootpath, see how blspec does it.
common/extlinux.c line 221
Quoted 8 lines
common/extlinux.c new file +8
-0+ + e =parse_extlinux_conf (configname, rootpath); +if (IS_ERR (e)) +return PTR_ERR (e); + + e->entry.boot = extlinux_boot; + e->entry.release = extlinux_entry_free; + e->entry.path =xstrdup (configname);
xstrdup_const
Quoted 9 lines
common/extlinux.c new file +9
-0+ e->entry.title =basprintf ("extlinux: %s" , e->label); + e->entry.description =basprintf ("extlinux entry \'%s\" on %s" , + e->label, rootpath); + e->entry.me.type =MENU_ENTRY_NORMAL ; + +bootentries_add_entry (bootentries, &e->entry); + +return 1 ; +}
common/extlinux.c line 240
Quoted 10 lines
common/extlinux.c new file +10
-0+ +static int extlinux_scan_directory (struct bootscanner *scanner, +struct bootentries *bootentries, +const char *rootpath) +{ +char *path; +struct stat s; +int ret; + + path =basprintf ("%s/boot/extlinux/extlinux.conf" , rootpath);
You mention both /boot/extlinux/extlinux and /extlinux/extlinux as directory, but you only check one of them here.
Should you not check the second one as well?
common/extlinux.c line 243
Quoted 2 lines
common/extlinux.c new file +2
-0+ ret =stat (path, &s); +if (!ret &&S_ISREG (s.st_mode))
A extlinux.conf _directory_ is silently skipped by this. Intentional?
common/extlinux.c line 244
Quoted 1 line
common/extlinux.c new file +1
-0+ ret =extlinux_scan_file (scanner, bootentries, path);
You should pass along rootpath here.
common/extlinux.c line 248
Quoted 4 lines
common/extlinux.c new file +4
-0+ +free (path); + +return ret <1 ? ret :1 ;
This can be simplified to return ret;
common/extlinux.c line 254
Quoted 6 lines
common/extlinux.c new file +6
-0+} + +static struct bootscanner extlinux_scanner = { + .name ="extlinux" , + .scan_file = extlinux_scan_file, + .scan_directory = extlinux_scan_directory,
This implements
boot -l /mnt/mmc0.1/boot/extlinux/extlinux.conf
boot -l /mnt/mmc0.1/
and leaves the rest to the core.
I think that's fine, but can you check if the following work:
boot -l mmc0
boot -l /dev/mmc0
boot -l mmc0.1
boot -l /dev/mmc0.1
common/extlinux.c line 264
Quoted 10 lines
common/extlinux.c new file +10
-0+}; + +static int extlinux_generate (struct bootentries *bootentries,const char *name) +{ +return bootentry_scan_generate (&extlinux_scanner, bootentries, name); +} + +static struct bootentry_provider extlinux_provider = { + .name ="extlinux" , + .generate = extlinux_generate,
You need to set a negative priority here, so existing bootloader spec support wins if both are available.
I think .priority = -25 is ok, so it's in-between blspec and efiboomgr.
common/extlinux.c line 271
Quoted 7 lines
common/extlinux.c new file +7
-0+}; + +static int extlinux_init (void ) +{ +return bootentry_register_provider (&extlinux_provider); +} +device_initcall (extlinux_init);
Thanks,
Ahmad
Signature · 4 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 |
Hello Ahmad.
Quoted 8 lines
Thanks for your patch!
Quoted 5 lines · Alexander Shiyan
This adds support for the extlinux.conf configuration format, commonly used by Syslinux and many Linux distributions. The configuration file is typically located at
/boot/extlinux/extlinux.confor /extlinux/extlinux.conf and defines boot entries with kernel, initrd, device tree, and command line options.
...
Quoted 8 lines
Quoted 8 lines
common/extlinux.c new file +8
-0+static int extlinux_boot (struct bootentry *be,int verbose,int dryrun) +{ +struct extlinux_entry *e = + container_of(be, struct extlinux_entry, entry); +char *kernel_abs, *initrd_abs =NULL , *fdt_abs =NULL ; +struct bootm_data data = {}; +int ret; +
Quoted 8 lines
common/extlinux.c line 41
Quoted 5 lines
common/extlinux.c new file +5
-0+bootm_data_init_defaults (&data); + + data.dryrun =max_t (int, dryrun, data.dryrun); + data.verbose =max (verbose, data.verbose); + data.appendroot = true;Not sure this is a good idea because of potential of clashing with extlinux appended command line options.
globalvar_add_bool("extlinux.fix_root", NULL); ?
...
Quoted 10 lines
common/extlinux.c line 63
Quoted 6 lines
common/extlinux.c new file +6
-0+if (e->append) +globalvar_add_simple ("linux.bootargs.dyn.extlinux" , e->append); + +pr_info ("Booting extlinux label '%s'\n" , e->label); + + ret =bootm_boot (&data);Please make use of new
bootm_entryinstead, so it can be used with devboot:https://github.com/barebox/barebox/blob/next/Documentation/user/devboot.rst
I haven't figured out how to do this yet...
...
Quoted 16 lines
common/extlinux.c line 129
Quoted 13 lines
common/extlinux.c new file +13
-0+static struct extlinux_entry *parse_extlinux_conf (const char *abspath, +const char *rootpath) +{ +char *buf, *bufptr, *line, *p, *default_label =NULL ; +struct extlinux_entry *entry =NULL ; + + bufptr =read_file (abspath,NULL ); +if (!bufptr) +return ERR_PTR (-errno); + +for (p = bufptr; *p; p++) +if (*p =='\r' ) + *p ='\n' ;I think this can be dropped.
Quoted 5 lines
common/extlinux.c line 132
Quoted 3 lines
common/extlinux.c new file +3
-0+ + buf = bufptr; +while ((line =strsep (&buf,"\n" )) !=NULL ) {And then you replace the set searched here with "\r\n"
The end of the line may be \n, \r, \n\r.
We are simply converting it to a uniform format.
Quoted 20 lines
common/extlinux.c line 139
Quoted 7 lines
common/extlinux.c new file +7
-0+char *key, *val; + + line =skip_spaces (line); + +if (*line =='#' || *line =='\0' ) +continue ; +Nitpick: I think below can be simplified to:
common/extlinux.c line 148
Quoted 9 lines
common/extlinux.c new file +9
-0+ key = line; + val =strchr (line,' ' ); +if (!val) + val =strchr (line,'\t' ); +if (val) { + *val++ ='\0' ; + val =skip_spaces (val); + }else +continue ;
Quoted 3 lines
key =
strsep(&line, ' \t');
val =strsep(&line, '\n');
val = isempty(val) ? NULL :skip_spaces(val);
strsep inserts a null byte in place of the separator; this will corrupt the buffer,
and consequently, we will not be able to find the val.
Quoted 4 lines
Quoted 4 lines
common/extlinux.c new file +4
-0+ +if (!default_label) { +if (!strcasecmp (key,"DEFAULT" )) + default_label =xstrdup (val);
Quoted 8 lines
common/extlinux.c line 158
Quoted 6 lines
common/extlinux.c new file +6
-0+ +continue ; + } + +if (!strcasecmp (key,"LABEL" )) { +if (!strcmp (val, default_label)) {
defaut_labelmight not have been set here?
No: if (!default_label) ... continue;
Hello,
Quoted 24 lines · Alexander Shiyan
Quoted 6 lines · Alexander Shiyan
Quoted 5 lines
This adds support for the extlinux.conf configuration format, commonly used by Syslinux and many Linux distributions. The configuration file is typically located at
/boot/extlinux/extlinux.confor /extlinux/extlinux.conf and defines boot entries with kernel, initrd, device tree, and command line options....
Quoted 8 lines
Quoted 8 lines
common/extlinux.c new file +8
-0+static int extlinux_boot (struct bootentry *be,int verbose,int dryrun) +{ +struct extlinux_entry *e = + container_of(be, struct extlinux_entry, entry); +char *kernel_abs, *initrd_abs =NULL , *fdt_abs =NULL ; +struct bootm_data data = {}; +int ret; +Quoted 8 lines
common/extlinux.c line 41
Quoted 5 lines
common/extlinux.c new file +5
-0+bootm_data_init_defaults (&data); + + data.dryrun =max_t (int, dryrun, data.dryrun); + data.verbose =max (verbose, data.verbose); + data.appendroot = true;Not sure this is a good idea because of potential of clashing with extlinux appended command line options.
Quoted 1 line
globalvar_add_bool("extlinux.fix_root", NULL); ?
global.extlinux.strip_root to remove root=
and bootm.appendroot to add barebox' own root?
@Sascha, any thoughts on this?
Quoted 11 lines
...
Quoted 9 lines
common/extlinux.c line 63
Quoted 6 lines
common/extlinux.c new file +6
-0+if (e->append) +globalvar_add_simple ("linux.bootargs.dyn.extlinux" , e->append); + +pr_info ("Booting extlinux label '%s'\n" , e->label); + + ret =bootm_boot (&data);Please make use of new
bootm_entryinstead, so it can be used with devboot:
Quoted 3 lines
I haven't figured out how to do this yet...
Just make sure it can be used by calling bootm_entry instead of bootm_boot.
Quoted 17 lines
...
Quoted 16 lines
common/extlinux.c line 129
Quoted 13 lines
common/extlinux.c new file +13
-0+static struct extlinux_entry *parse_extlinux_conf (const char *abspath, +const char *rootpath) +{ +char *buf, *bufptr, *line, *p, *default_label =NULL ; +struct extlinux_entry *entry =NULL ; + + bufptr =read_file (abspath,NULL ); +if (!bufptr) +return ERR_PTR (-errno); + +for (p = bufptr; *p; p++) +if (*p =='\r' ) + *p ='\n' ;I think this can be dropped.
Quoted 8 lines
Quoted 5 lines
common/extlinux.c line 132
Quoted 3 lines
common/extlinux.c new file +3
-0+ + buf = bufptr; +while ((line =strsep (&buf,"\n" )) !=NULL ) {And then you replace the set searched here with "\r\n"
The end of the line may be \n, \r, \n\r.
We are simply converting it to a uniform format.
strsep's second argument means split at any of these characters and not split at them in exactly that order.
Quoted 21 lines
Quoted 21 lines
common/extlinux.c line 139
Quoted 8 lines
common/extlinux.c new file +7
-0+char *key, *val; + + line =skip_spaces (line); + +if (*line =='#' || *line =='\0' ) +continue ; +Nitpick: I think below can be simplified to:
Quoted 9 lines
common/extlinux.c new file +9
-0+ key = line; + val =strchr (line,' ' ); +if (!val) + val =strchr (line,'\t' ); +if (val) { + *val++ ='\0' ; + val =skip_spaces (val); + }else +continue ;
Quoted 7 lines
Quoted 3 lines
key =
strsep(&line, ' \t');
val =strsep(&line, '\n');
val = isempty(val) ? NULL :skip_spaces(val);strsep inserts a null byte in place of the separator; this will corrupt the buffer,
and consequently, we will not be able to find the val.
char line[] = "DEFAULT test", *p = line;
char *key = strsep(&p, " \t");
char *val = strsep(&p, "\n");
printf("key<%s> value<%s>\n", key, val);
prints key<DEFAULT> value<test>.
Isn't that exactly what you need?
Quoted 3 lines
Quoted 1 line
defaut_labelmight not have been set here?No: if (!default_label) ... continue;
Ah ok.
Cheers,
Ahmad
Signature · 4 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 |
Quoted 27 lines · Ahmad Fatoum
Hello,
Quoted 24 lines · Alexander Shiyan
Quoted 6 lines · Alexander Shiyan
Quoted 5 lines
This adds support for the extlinux.conf configuration format, commonly used by Syslinux and many Linux distributions. The configuration file is typically located at
/boot/extlinux/extlinux.confor /extlinux/extlinux.conf and defines boot entries with kernel, initrd, device tree, and command line options....
Quoted 16 lines
common/extlinux.c line 41
Quoted 13 lines
common/extlinux.c new file +13
-0+static int extlinux_boot (struct bootentry *be,int verbose,int dryrun) +{ +struct extlinux_entry *e = + container_of(be, struct extlinux_entry, entry); +char *kernel_abs, *initrd_abs =NULL , *fdt_abs =NULL ; +struct bootm_data data = {}; +int ret; + +bootm_data_init_defaults (&data); + + data.dryrun =max_t (int, dryrun, data.dryrun); + data.verbose =max (verbose, data.verbose); + data.appendroot = true;Not sure this is a good idea because of potential of clashing with extlinux appended command line options.
Quoted 4 lines
Quoted 1 line
globalvar_add_bool("extlinux.fix_root", NULL); ?global.extlinux.strip_root to remove root=
and bootm.appendroot to add barebox' own root?
We already have the latter, so nothing to do here.
Shouldn't we by default remove the root= option once data->appendroot is set? Also in the bootspec case we do not want to end up with two root= options.
Sascha
Signature · 4 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 |
Hello, Sasha.
...
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 5 lines
Quoted 5 lines
This adds support for the extlinux.conf configuration format, commonly used by Syslinux and many Linux distributions. The configuration file is typically located at
/boot/extlinux/extlinux.confor /extlinux/extlinux.conf and defines boot entries with kernel, initrd, device tree, and command line options....
Quoted 8 lines
Quoted 8 lines
common/extlinux.c new file +8
-0+static int extlinux_boot (struct bootentry *be,int verbose,int dryrun) +{ +struct extlinux_entry *e = + container_of(be, struct extlinux_entry, entry); +char *kernel_abs, *initrd_abs =NULL , *fdt_abs =NULL ; +struct bootm_data data = {}; +int ret; +Quoted 8 lines
common/extlinux.c line 41
Quoted 5 lines
common/extlinux.c new file +5
-0+bootm_data_init_defaults (&data); + + data.dryrun =max_t (int, dryrun, data.dryrun); + data.verbose =max (verbose, data.verbose); + data.appendroot = true;Not sure this is a good idea because of potential of clashing with extlinux appended command line options.
globalvar_add_bool("extlinux.fix_root", NULL); ?
Quoted 8 lines
Quoted 2 lines
global.extlinux.strip_root to remove root=
and bootm.appendroot to add barebox' own root?We already have the latter, so nothing to do here.
Shouldn't we by default remove the root= option once
data->appendrootis set? Also in the bootspec case we do not want to end up with two root= options.
Is this method better?
I haven't tested it yet, but it goes something like this:
if (getenv_bool("bootm.appendroot", (int *)&data.appendroot)) data.appendroot = true;
if (e->append) {
/*
* The same rootfs image may be launched from eMMC or SD card.
* Remove any hardcoded root= parameter from "append" to avoid
* conflicts, then let barebox automatically add the correct
* root= (via appendroot) based on the boot device. */
if (data.appendroot) {
char *append = remove_param(e->append, "ROOT="); free(e->append);e->append = append;
}
globalvar_add_simple("linux.bootargs.dyn.extlinux", e->append); }
Hello Sascha,
Quoted 30 lines · Sascha Hauer
Quoted 29 lines · Ahmad Fatoum
Hello,
Quoted 25 lines · Alexander Shiyan
Quoted 6 lines · Alexander Shiyan
Quoted 5 lines
This adds support for the extlinux.conf configuration format, commonly used by Syslinux and many Linux distributions. The configuration file is typically located at
/boot/extlinux/extlinux.confor /extlinux/extlinux.conf and defines boot entries with kernel, initrd, device tree, and command line options....
Quoted 8 lines
Quoted 8 lines
common/extlinux.c new file +8
-0+static int extlinux_boot (struct bootentry *be,int verbose,int dryrun) +{ +struct extlinux_entry *e = + container_of(be, struct extlinux_entry, entry); +char *kernel_abs, *initrd_abs =NULL , *fdt_abs =NULL ; +struct bootm_data data = {}; +int ret; +Quoted 8 lines
common/extlinux.c line 41
Quoted 5 lines
common/extlinux.c new file +5
-0+bootm_data_init_defaults (&data); + + data.dryrun =max_t (int, dryrun, data.dryrun); + data.verbose =max (verbose, data.verbose); + data.appendroot = true;Not sure this is a good idea because of potential of clashing with extlinux appended command line options.
globalvar_add_bool("extlinux.fix_root", NULL); ?
Quoted 8 lines
Quoted 2 lines
global.extlinux.strip_root to remove root=
and bootm.appendroot to add barebox' own root?We already have the latter, so nothing to do here.
Shouldn't we by default remove the root= option once
data->appendrootis set? Also in the bootspec case we do not want to end up with two root= options.
I think we can't get this to work properly anyhow. Besides root= there are other options as well (e.g. rootfstype) that we won't be able to exhaustively remove. Add on top of that, that an initrd may decide for itself that another rootfs should be used anyway...
If a user knows for a given system that appending root= will work, they can do that, but I think it's useful for the cases where it doesn't work that there are two root='s, so the root appending is directly apparent.
We just need to ensure the appended root comes last, so it has precedence.
Cheers,
Ahmad
Quoted 3 lines
Sascha
Signature · 4 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 |