From f8b5b93b8871a1fc3bbcea92cab7a13d2f02e1bb Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Tue, 20 Feb 2018 09:18:17 -0500 Subject: [PATCH] linux_riscv: Add patches for initrd support --- pkgs/os-specific/linux/kernel/patches.nix | 10 ++++ .../linux/kernel/riscv-initrd-free.patch | 21 ++++++++ .../linux/kernel/riscv-initrd.patch | 48 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 8 +++- 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 pkgs/os-specific/linux/kernel/riscv-initrd-free.patch create mode 100644 pkgs/os-specific/linux/kernel/riscv-initrd.patch diff --git a/pkgs/os-specific/linux/kernel/patches.nix b/pkgs/os-specific/linux/kernel/patches.nix index 39af0a679361..e0494c6c535b 100644 --- a/pkgs/os-specific/linux/kernel/patches.nix +++ b/pkgs/os-specific/linux/kernel/patches.nix @@ -88,4 +88,14 @@ rec { patch = ./riscv-install.patch; }; + riscv_initrd = { + name = "riscv-initrd"; + patch = ./riscv-initrd.patch; + }; + + riscv_initrd_free = { + name = "riscv-initrd-free"; + patch = ./riscv-initrd-free.patch; + }; + } diff --git a/pkgs/os-specific/linux/kernel/riscv-initrd-free.patch b/pkgs/os-specific/linux/kernel/riscv-initrd-free.patch new file mode 100644 index 000000000000..680448385246 --- /dev/null +++ b/pkgs/os-specific/linux/kernel/riscv-initrd-free.patch @@ -0,0 +1,21 @@ +commit b1fbec8b74ace263ce1371e6bcfdd1dd71b52070 +Author: Shea Levy +Date: Tue Feb 20 08:48:12 2018 -0500 + + riscv: Implement free_initrd_mem. + + v2: Remove incorrect page alignment. + + Signed-off-by: Shea Levy + +diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c +index c77df8142be2..1b6daa5184e0 100644 +--- a/arch/riscv/mm/init.c ++++ b/arch/riscv/mm/init.c +@@ -66,5 +66,6 @@ void free_initmem(void) + #ifdef CONFIG_BLK_DEV_INITRD + void free_initrd_mem(unsigned long start, unsigned long end) + { ++ free_reserved_area((void *)start, (void *)end, -1, "initrd"); + } + #endif /* CONFIG_BLK_DEV_INITRD */ diff --git a/pkgs/os-specific/linux/kernel/riscv-initrd.patch b/pkgs/os-specific/linux/kernel/riscv-initrd.patch new file mode 100644 index 000000000000..2313e7645843 --- /dev/null +++ b/pkgs/os-specific/linux/kernel/riscv-initrd.patch @@ -0,0 +1,48 @@ +commit 1e5f6473492f41355289d022003a049ebf8995fa +Author: Shea Levy +Date: Tue Feb 20 07:52:14 2018 -0500 + + riscv: Respect the initrd found in the dt, if any. + + Signed-off-by: Shea Levy + +diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c +index 41d34008faf6..c4ebc907af34 100644 +--- a/arch/riscv/kernel/setup.c ++++ b/arch/riscv/kernel/setup.c +@@ -88,15 +88,20 @@ static void __init setup_initrd(void) + extern unsigned long __initramfs_size; + unsigned long size; + ++ if (initrd_start) ++ goto found; ++ + if (__initramfs_size > 0) { + initrd_start = (unsigned long)(&__initramfs_start); + initrd_end = initrd_start + __initramfs_size; + } + ++ initrd_below_start_ok = 1; + if (initrd_start >= initrd_end) { + printk(KERN_INFO "initrd not found or empty"); + goto disable; + } ++found: + if (__pa(initrd_end) > PFN_PHYS(max_low_pfn)) { + printk(KERN_ERR "initrd extends beyond end of memory"); + goto disable; +@@ -104,13 +109,13 @@ static void __init setup_initrd(void) + + size = initrd_end - initrd_start; + memblock_reserve(__pa(initrd_start), size); +- initrd_below_start_ok = 1; + + printk(KERN_INFO "Initial ramdisk at: 0x%p (%lu bytes)\n", + (void *)(initrd_start), size); + return; + disable: + pr_cont(" - disabling initrd\n"); ++ initrd_below_start_ok = 0; + initrd_start = 0; + initrd_end = 0; + } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 24676f237f0d..ffc8abcdf236 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -13118,7 +13118,13 @@ with pkgs; kernelPatches = [ kernelPatches.bridge_stp_helper kernelPatches.modinst_arg_list_too_long - ] ++ lib.optionals hostPlatform.isRiscV [ kernelPatches.riscv_modules kernelPatches.riscv_irq_busy kernelPatches.riscv_install ]; + ] ++ lib.optionals hostPlatform.isRiscV [ + kernelPatches.riscv_modules + kernelPatches.riscv_irq_busy + kernelPatches.riscv_install + kernelPatches.riscv_initrd + kernelPatches.riscv_initrd_free + ]; }; linux_samus_4_12 = callPackage ../os-specific/linux/kernel/linux-samus-4.12.nix {