Author: shlevy
Date: Sun Mar 18 17:14:52 2012
New Revision: 33235
URL: https://nixos.org/websvn/nix/?rev=33235&sc=1
Log:
Add a kernel patch for the efi boot stub to read a config file when booted
without arguments, and base removable media booting off of that patch
The patch is currently being discussed on LKML and hopefully will be included
in mainline in some form in the future. Note that booting from the livecd has
to do a lot of work before anything is output to the console, so if the drive
is still busy don't assume the boot has hanged
Added:
nixpkgs/trunk/pkgs/os-specific/linux/kernel/efi-bootstub-config-3.3.patch
Deleted:
nixos/trunk/modules/installer/efi-boot-stub/nixos-boot-pkg.nix
Modified:
nixos/trunk/modules/installer/cd-dvd/iso-image.nix
nixos/trunk/modules/installer/efi-boot-stub/efi-boot-stub-builder.sh
nixos/trunk/modules/installer/efi-boot-stub/efi-boot-stub.nix
nixpkgs/trunk/pkgs/os-specific/linux/kernel/patches.nix
nixpkgs/trunk/pkgs/top-level/all-packages.nix
Modified: nixos/trunk/modules/installer/cd-dvd/iso-image.nix
==============================================================================
--- nixos/trunk/modules/installer/cd-dvd/iso-image.nix Sun Mar 18 14:03:42
2012 (r33234)
+++ nixos/trunk/modules/installer/cd-dvd/iso-image.nix Sun Mar 18 17:14:52
2012 (r33235)
@@ -129,15 +129,11 @@
${pkgs.mtools}/bin/mmd -i "$out" efi/boot
${pkgs.mtools}/bin/mmd -i "$out" efi/nixos
${pkgs.mtools}/bin/mcopy -v -i "$out" \
- ${config.boot.kernelPackages.kernel + "/bzImage"} ::efi/nixos/bzImage
+ ${config.boot.kernelPackages.kernel + "/bzImage"}
::efi/boot/boot${targetArch}.efi
${pkgs.mtools}/bin/mcopy -v -i "$out" \
${config.system.build.initialRamdisk + "/initrd"} ::efi/nixos/initrd
- echo "\\efi\\nixos\\bzImage initrd=\\efi\\nixos\\initrd
init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams}"
| iconv -f utf-8 -t UCS-2 > boot-params
- ${pkgs.mtools}/bin/mcopy -v -i "$out" boot-params ::efi/nixos/boot-params
- ${pkgs.mtools}/bin/mcopy -v -i "$out" \
- ${import ../efi-boot-stub/nixos-boot-pkg.nix {
- inherit (pkgs) edk2 stdenv fetchhg;
- }}/*/NixosBoot.efi ::efi/boot/boot${targetArch}.efi
+ echo "initrd=\\efi\\nixos\\initrd
init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams}"
> boot-params
+ ${pkgs.mtools}/bin/mcopy -v -i "$out" boot-params ::efi/boot/linux.conf
'';
targetArch = if pkgs.stdenv.isi686 then
Modified: nixos/trunk/modules/installer/efi-boot-stub/efi-boot-stub-builder.sh
==============================================================================
--- nixos/trunk/modules/installer/efi-boot-stub/efi-boot-stub-builder.sh
Sun Mar 18 14:03:42 2012 (r33234)
+++ nixos/trunk/modules/installer/efi-boot-stub/efi-boot-stub-builder.sh
Sun Mar 18 17:14:52 2012 (r33235)
@@ -78,10 +78,8 @@
if test -n "@installRemovableMediaImage@"; then
mkdir -pv "@efiSysMountPoint@"/efi/boot
- cp "@removableMediaImage@" \
- "@efiSysMountPoint@"/efi/boot/boot"@targetArch@".efi
- iconv -f utf-8 -t UCS-2 < $startup >
"@efiSysMountPoint@"/efi/nixos/boot-params
- filesCopied["@efiSysMountPoint@"/efi/nixos/boot-params]=1
+ cp $kernel "@efiSysMountPoint@"/efi/boot/boot"@targetArch@".efi
+ sed 's|.*@[email protected] ||' $startup >
"@efiSysMountPoint@"/efi/boot/linux.conf
fi
if test -n "@installStartupNsh@"; then
sed 's|.*@[email protected]|@[email protected]|' < $startup >
"@efiSysMountPoint@/startup.nsh"
Modified: nixos/trunk/modules/installer/efi-boot-stub/efi-boot-stub.nix
==============================================================================
--- nixos/trunk/modules/installer/efi-boot-stub/efi-boot-stub.nix Sun Mar
18 14:03:42 2012 (r33234)
+++ nixos/trunk/modules/installer/efi-boot-stub/efi-boot-stub.nix Sun Mar
18 17:14:52 2012 (r33235)
@@ -80,24 +80,20 @@
###### implementation
let
- efiBootStubBuilder = pkgs.substituteAll ({
+ efiBootStubBuilder = pkgs.substituteAll {
src = ./efi-boot-stub-builder.sh;
isExecutable = true;
inherit (pkgs) bash;
path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep pkgs.glibc] ++
(pkgs.stdenv.lib.optionals config.boot.loader.efiBootStub.runEfibootmgr
[pkgs.efibootmgr pkgs.module_init_tools]);
inherit (config.boot.loader.efiBootStub) efiSysMountPoint runEfibootmgr
installStartupNsh efiDisk efiPartition installRemovableMediaImage;
kernelFile = platform.kernelTarget;
- } // pkgs.stdenv.lib.optionalAttrs
config.boot.loader.efiBootStub.installRemovableMediaImage rec {
- removableMediaImage = ''${import ./nixos-boot-pkg.nix {
- inherit (pkgs) edk2 stdenv fetchhg;
- }}/${targetArch}/NixosBoot.efi'';
targetArch = if pkgs.stdenv.isi686 then
"IA32"
else if pkgs.stdenv.isx86_64 then
"X64"
else
throw "Unsupported architecture";
- });
+ };
# Temporary check, for nixos to cope both with nixpkgs stdenv-updates and
trunk
platform = pkgs.stdenv.platform;
Added: nixpkgs/trunk/pkgs/os-specific/linux/kernel/efi-bootstub-config-3.3.patch
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ nixpkgs/trunk/pkgs/os-specific/linux/kernel/efi-bootstub-config-3.3.patch
Sun Mar 18 17:14:52 2012 (r33235)
@@ -0,0 +1,226 @@
+From 2c12b0f49831d2d96b6bdcef931794178312c288 Mon Sep 17 00:00:00 2001
+From: Shea Levy <[email protected]>
+Date: Sun, 18 Mar 2012 16:17:04 +0100
+Subject: [PATCH 1/1] x86, efi: EFI boot stub config file support
+
+When booting via the EFI boot stub, search for a file named 'linux.conf' in
+the same directory as the bzImage and read the kernel command line from it
+when no load options are passed.
+
+The file search should only be triggered when the bzImage is loaded from the
+firmware's boot process. When loaded via an EFI shell, the load options always
+contain at least one character, even if no parameters were passed at the
+prompt.
+
+Signed-off-by: Shea Levy <[email protected]>
+---
+ arch/x86/boot/compressed/eboot.c | 146 ++++++++++++++++++++++++++++++++++++--
+ arch/x86/boot/compressed/eboot.h | 2 +
+ 2 files changed, 143 insertions(+), 5 deletions(-)
+
+diff --git a/arch/x86/boot/compressed/eboot.c
b/arch/x86/boot/compressed/eboot.c
+index fec216f..672ecfe 100644
+--- a/arch/x86/boot/compressed/eboot.c
++++ b/arch/x86/boot/compressed/eboot.c
+@@ -486,14 +486,14 @@ struct initrd {
+ * kernel image.
+ */
+ static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
+- struct setup_header *hdr)
++ struct setup_header *hdr,
++ efi_file_handle_t *fh)
+ {
+ struct initrd *initrds;
+ unsigned long initrd_addr;
+ efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID;
+ u64 initrd_total;
+ efi_file_io_interface_t *io;
+- efi_file_handle_t *fh;
+ efi_status_t status;
+ int nr_initrds;
+ char *str;
+@@ -568,7 +568,7 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t
*image,
+ *p = '\0';
+
+ /* Only open the volume once. */
+- if (!i) {
++ if (!fh) {
+ efi_boot_services_t *boottime;
+
+ boottime = sys_table->boottime;
+@@ -712,6 +712,7 @@ static efi_status_t make_boot_params(struct boot_params
*boot_params,
+ u16 *s2;
+ u8 *s1;
+ int i;
++ efi_file_handle_t *fh = NULL;
+
+ hdr->type_of_loader = 0x21;
+
+@@ -743,14 +744,149 @@ static efi_status_t make_boot_params(struct boot_params
*boot_params,
+
+ *s1 = '\0';
+ }
+- }
++ } else {
++ efi_char16_t config_file_name[
++ sizeof CONFIG_FILE_NAME * sizeof(efi_char16_t)];
++ u16 *file_path = (u16 *)image->file_path;
++ efi_char16_t config_path[256], *config_path_position;
++ efi_boot_services_t *boottime;
++ efi_file_info_t *info;
++ unsigned long info_sz = 0;
++ u64 file_sz;
++ efi_guid_t info_guid = EFI_FILE_INFO_ID;
++ efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID;
++ efi_file_io_interface_t *io;
++ efi_file_handle_t *h;
++
++ boottime = sys_table->boottime;
++
++ config_path_position = config_path;
++
++ for (i = 0; i < sizeof CONFIG_FILE_NAME; i++)
++ config_file_name[i] = CONFIG_FILE_NAME[i];
++
++ while (*file_path == 0x404) {
++ u16 node_size = *(file_path + 1)/sizeof *file_path;
++
++ if (config_path_position - config_path) {
++ if (*(file_path + 2) == '\\' &&
++ *(file_path - 2) == '\\') {
++ config_path_position--;
++ } else if (*(file_path + 2) != '\\' &&
++ *(file_path - 2) != '\\') {
++ *config_path_position++ = '\\';
++ }
++ }
++
++ if ((config_path_position - config_path) + node_size - 3
++ + sizeof config_file_name
++ / sizeof *config_file_name
++ > sizeof config_path
++ / sizeof *config_path)
++ goto end;
++
++ memcpy((void *)config_path_position, file_path + 2,
++ (node_size - 3) * sizeof *config_path);
+
++ config_path_position += node_size - 3;
++ file_path += node_size;
++ }
++
++ while (*config_path_position != '\\' && config_path_position !=
++ config_path)
++ config_path_position--;
++
++ *config_path_position = '\\';
++
++ memcpy((void *)(config_path_position + 1),
++ config_file_name,
++ sizeof config_file_name);
++
++ status = efi_call_phys3(boottime->handle_protocol,
++ image->device_handle, &fs_proto, &io);
++
++ if (status != EFI_SUCCESS)
++ goto end;
++
++ status = efi_call_phys2(io->open_volume, io, &fh);
++
++ if (status != EFI_SUCCESS) {
++ fh = NULL;
++ goto end;
++ }
++
++ status = efi_call_phys5(fh->open,
++ fh,
++ &h,
++ config_path,
++ EFI_FILE_MODE_READ, (u64)0);
++
++ if (status != EFI_SUCCESS)
++ goto end;
++
++ status = efi_call_phys4(h->get_info, h, &info_guid,
++ &info_sz, NULL);
++
++ if (status != EFI_BUFFER_TOO_SMALL)
++ goto close_config_file;
++
++ while (status == EFI_BUFFER_TOO_SMALL) {
++ status = efi_call_phys3(boottime->allocate_pool,
++ EFI_LOADER_DATA, info_sz, &info);
++
++ if (status != EFI_SUCCESS)
++ goto close_config_file;
++
++ status = efi_call_phys4(h->get_info, h, &info_guid,
++ &info_sz, info);
++
++ if (status == EFI_BUFFER_TOO_SMALL)
++ efi_call_phys1(boottime->free_pool, info);
++ }
++
++ if (status != EFI_SUCCESS)
++ goto free_config_file_info;
++
++ file_sz = info->file_size;
++
++ if (file_sz > hdr->cmdline_size)
++ file_sz = hdr->cmdline_size;
++
++ options_size = file_sz + 1;
++
++ status = low_alloc(options_size, 1, &cmdline);
++
++ if (status != EFI_SUCCESS)
++ goto free_config_file_info;
++
++ status = efi_call_phys3(h->read, h, &file_sz, cmdline);
++
++ if (status != EFI_SUCCESS)
++ goto free_config_file_cmdline;
++
++ *((u8 *)cmdline + file_sz) = 0;
++
++ goto free_config_file_info;
++free_config_file_cmdline:
++ low_free(options_size, cmdline);
++ cmdline = 0;
++ options_size = 0;
++free_config_file_info:
++ efi_call_phys1(boottime->free_pool, info);
++close_config_file:
++ efi_call_phys1(h->close, h);
++ }
++end:
+ hdr->cmd_line_ptr = cmdline;
+
+ hdr->ramdisk_image = 0;
+ hdr->ramdisk_size = 0;
+
+- status = handle_ramdisks(image, hdr);
++ status = handle_ramdisks(image, hdr, fh);
++
++ if (fh)
++ efi_call_phys1(fh->close, fh);
++
+ if (status != EFI_SUCCESS)
+ goto free_cmdline;
+
+diff --git a/arch/x86/boot/compressed/eboot.h
b/arch/x86/boot/compressed/eboot.h
+index 3925166..186b4c6 100644
+--- a/arch/x86/boot/compressed/eboot.h
++++ b/arch/x86/boot/compressed/eboot.h
+@@ -20,6 +20,8 @@
+ #define PIXEL_BLT_ONLY 3
+ #define PIXEL_FORMAT_MAX 4
+
++#define CONFIG_FILE_NAME "linux.conf"
++
+ struct efi_pixel_bitmask {
+ u32 red_mask;
+ u32 green_mask;
+--
+1.7.9.4
+
Modified: nixpkgs/trunk/pkgs/os-specific/linux/kernel/patches.nix
==============================================================================
--- nixpkgs/trunk/pkgs/os-specific/linux/kernel/patches.nix Sun Mar 18
14:03:42 2012 (r33234)
+++ nixpkgs/trunk/pkgs/os-specific/linux/kernel/patches.nix Sun Mar 18
17:14:52 2012 (r33235)
@@ -334,6 +334,11 @@
patch = ./sheevaplug_modules-2.6.35.patch;
};
+ efi_bootstub_config_3_3 =
+ { name = "efi-config-3.3";
+ patch = ./efi-bootstub-config-3.3.patch;
+ };
+
mips_restart_2_6_36 =
{ name = "mips_restart_2_6_36";
patch = ./mips_restart.patch;
Modified: nixpkgs/trunk/pkgs/top-level/all-packages.nix
==============================================================================
--- nixpkgs/trunk/pkgs/top-level/all-packages.nix Sun Mar 18 14:03:42
2012 (r33234)
+++ nixpkgs/trunk/pkgs/top-level/all-packages.nix Sun Mar 18 17:14:52
2012 (r33235)
@@ -5638,6 +5638,7 @@
[ #kernelPatches.fbcondecor_2_6_38
kernelPatches.sec_perm_2_6_24
kernelPatches.aufs3_3
+ kernelPatches.efi_bootstub_config_3_3
#kernelPatches.mips_restart_2_6_36
];
};
_______________________________________________
nix-commits mailing list
[email protected]
http://lists.science.uu.nl/mailman/listinfo/nix-commits