From aa4aae4460f85693ac3f831cf240748181032bff Mon Sep 17 00:00:00 2001 From: William Manley Date: Thu, 16 Jul 2020 15:23:25 +0100 Subject: [PATCH 1/2] syslinux: Also check for extlinux.conf The NVidia Jetson NX comes with u-boot installed in syslinux compatible mode. It reads from `/boot/extlinux/extlinux.conf` to know what to boot. In my setup I set `/boot/extlinux/extlinux.conf` to be a symlink pointing at `../loader/syslinux.cfg` to take advantage of the ostree syslinux support. This commit improves compatibility by also checking for `extlinux.conf` in addition to `syslinux.cfg` when trying to locate the existing configuration. --- src/libostree/ostree-bootloader-syslinux.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/libostree/ostree-bootloader-syslinux.c b/src/libostree/ostree-bootloader-syslinux.c index 0055896bd9..54ed8203c0 100644 --- a/src/libostree/ostree-bootloader-syslinux.c +++ b/src/libostree/ostree-bootloader-syslinux.c @@ -26,6 +26,7 @@ #include static const char syslinux_config_path[] = "boot/syslinux/syslinux.cfg"; +static const char extlinux_config_path[] = "boot/extlinux/extlinux.conf"; struct _OstreeBootloaderSyslinux { @@ -51,6 +52,13 @@ _ostree_bootloader_syslinux_query (OstreeBootloader *bootloader, if (!glnx_fstatat_allow_noent (self->sysroot->sysroot_fd, syslinux_config_path, &stbuf, AT_SYMLINK_NOFOLLOW, error)) return FALSE; + if (errno == 0) + { + *out_is_active = TRUE; + return TRUE; + } + if (!glnx_fstatat_allow_noent (self->sysroot->sysroot_fd, extlinux_config_path, &stbuf, AT_SYMLINK_NOFOLLOW, error)) + return FALSE; *out_is_active = (errno == 0); return TRUE; } @@ -124,7 +132,19 @@ _ostree_bootloader_syslinux_write_config (OstreeBootloader *bootloader, glnx_file_get_contents_utf8_at (self->sysroot->sysroot_fd, syslinux_config_path, NULL, cancellable, error); if (!config_contents) - return FALSE; + { + if (errno != ENOENT) + return FALSE; + else + { + g_clear_error (error); + config_contents = + glnx_file_get_contents_utf8_at (self->sysroot->sysroot_fd, extlinux_config_path, NULL, + cancellable, error); + if (!config_contents) + return FALSE; + } + } g_auto(GStrv) lines = g_strsplit (config_contents, "\n", -1); g_autoptr(GPtrArray) new_lines = g_ptr_array_new_with_free_func (g_free); From 2e3ba998e0b8b54564200a5fbb158e67cf2ef3f2 Mon Sep 17 00:00:00 2001 From: William Manley Date: Thu, 16 Jul 2020 16:00:11 +0100 Subject: [PATCH 2/2] syslinux: Improve compatibility with u-boot extlinux.conf The NVidia Jetson NX comes with u-boot installed in syslinux compatible mode. It reads from `/boot/extlinux/extlinux.conf` to know what to boot. It's quite picky about what format it will accept. It crashes if `MENU LABEL` is missing or `KERNEL` is present rather than `LINUX`. This commit improves compatibility by conforming to what u-boot accepts. In theory it shouldn't affect real syslinux systems because the documentation says: > ### LINUX > > You can use this, instead of using KERNEL file to boot a linux kernel > image. although I don't have a real syslinux system to test it on. --- src/libostree/ostree-bootloader-syslinux.c | 10 ++++++++-- tests/bootloader-entries-crosscheck.py | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libostree/ostree-bootloader-syslinux.c b/src/libostree/ostree-bootloader-syslinux.c index 54ed8203c0..d7d9c7fc3b 100644 --- a/src/libostree/ostree-bootloader-syslinux.c +++ b/src/libostree/ostree-bootloader-syslinux.c @@ -92,12 +92,13 @@ append_config_from_loader_entries (OstreeBootloaderSyslinux *self, if (regenerate_default && i == 0) g_ptr_array_add (new_lines, g_strdup_printf ("DEFAULT %s", val)); - g_ptr_array_add (new_lines, g_strdup_printf ("LABEL %s", val)); + g_ptr_array_add (new_lines, g_strdup_printf ("\nLABEL %s", val)); + g_ptr_array_add (new_lines, g_strdup_printf ("\tMENU LABEL %s", val)); val = ostree_bootconfig_parser_get (config, "linux"); if (!val) return glnx_throw (error, "No \"linux\" key in bootloader config"); - g_ptr_array_add (new_lines, g_strdup_printf ("\tKERNEL /boot%s", val)); + g_ptr_array_add (new_lines, g_strdup_printf ("\tLINUX /boot%s", val)); val = ostree_bootconfig_parser_get (config, "initrd"); if (val) @@ -207,6 +208,11 @@ _ostree_bootloader_syslinux_write_config (OstreeBootloader *bootloader, g_free (kernel_arg); kernel_arg = g_strdup (line + strlen ("\tKERNEL ")); } + else if (parsing_label && g_str_has_prefix (line, "\tLINUX ")) + { + g_free (kernel_arg); + kernel_arg = g_strdup (line + strlen ("\tLINUX ")); + } else if (!parsing_label && (g_str_has_prefix (line, "DEFAULT "))) { diff --git a/tests/bootloader-entries-crosscheck.py b/tests/bootloader-entries-crosscheck.py index b5a0206644..52effd476a 100755 --- a/tests/bootloader-entries-crosscheck.py +++ b/tests/bootloader-entries-crosscheck.py @@ -88,6 +88,8 @@ def validate_syslinux(sysroot): syslinux_entry['title'] = v elif k == 'KERNEL': syslinux_entry['linux'] = v + elif k == 'LINUX': + syslinux_entry['linux'] = v elif k == 'INITRD': syslinux_entry['initrd'] = v elif k == 'APPEND':