Skip to content

Commit 694cfd8

Browse files
rminnichsuryasaimadhu
authored andcommitted
x86/setup: Add an initrdmem= option to specify initrd physical address
Add the initrdmem option: initrdmem=ss[KMG],nn[KMG] which is used to specify the physical address of the initrd, almost always an address in FLASH. Also add code for x86 to use the existing phys_init_start and phys_init_size variables in the kernel. This is useful in cases where a kernel and an initrd is placed in FLASH, but there is no firmware file system structure in the FLASH. One such situation occurs when unused FLASH space on UEFI systems has been reclaimed by, e.g., taking it from the Management Engine. For example, on many systems, the ME is given half the FLASH part; not only is 2.75M of an 8M part unused; but 10.75M of a 16M part is unused. This space can be used to contain an initrd, but need to tell Linux where it is. This space is "raw": due to, e.g., UEFI limitations: it can not be added to UEFI firmware volumes without rebuilding UEFI from source or writing a UEFI device driver. It can be referenced only as a physical address and size. At the same time, if a kernel can be "netbooted" or loaded from GRUB or syslinux, the option of not using the physical address specification should be available. Then, it is easy to boot the kernel and provide an initrd; or boot the the kernel and let it use the initrd in FLASH. In practice, this has proven to be very helpful when integrating Linux into FLASH on x86. Hence, the most flexible and convenient path is to enable the initrdmem command line option in a way that it is the last choice tried. For example, on the DigitalLoggers Atomic Pi, an image into FLASH can be burnt in with a built-in command line which includes: initrdmem=0xff968000,0x200000 which specifies a location and size. [ bp: Massage commit message, make it passive. ] [[email protected]: coding style fixes] Signed-off-by: Ronald G. Minnich <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: H. Peter Anvin (Intel) <[email protected]> Link: http://lkml.kernel.org/r/CAP6exYLK11rhreX=6QPyDQmW7wPHsKNEFtXE47pjx41xS6O7-A@mail.gmail.com Link: https://lkml.kernel.org/r/20200426011021.1cskg0AGd%[email protected]
1 parent 6a8b55e commit 694cfd8

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,13 @@
17481748

17491749
initrd= [BOOT] Specify the location of the initial ramdisk
17501750

1751+
initrdmem= [KNL] Specify a physical address and size from which to
1752+
load the initrd. If an initrd is compiled in or
1753+
specified in the bootparams, it takes priority over this
1754+
setting.
1755+
Format: ss[KMG],nn[KMG]
1756+
Default is 0, 0
1757+
17511758
init_on_alloc= [MM] Fill newly allocated pages and heap objects with
17521759
zeroes.
17531760
Format: 0 | 1

arch/x86/kernel/setup.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ static u64 __init get_ramdisk_image(void)
237237

238238
ramdisk_image |= (u64)boot_params.ext_ramdisk_image << 32;
239239

240+
if (ramdisk_image == 0)
241+
ramdisk_image = phys_initrd_start;
242+
240243
return ramdisk_image;
241244
}
242245
static u64 __init get_ramdisk_size(void)
@@ -245,6 +248,9 @@ static u64 __init get_ramdisk_size(void)
245248

246249
ramdisk_size |= (u64)boot_params.ext_ramdisk_size << 32;
247250

251+
if (ramdisk_size == 0)
252+
ramdisk_size = phys_initrd_size;
253+
248254
return ramdisk_size;
249255
}
250256

init/do_mounts_initrd.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static int __init no_initrd(char *str)
2828

2929
__setup("noinitrd", no_initrd);
3030

31-
static int __init early_initrd(char *p)
31+
static int __init early_initrdmem(char *p)
3232
{
3333
phys_addr_t start;
3434
unsigned long size;
@@ -43,6 +43,17 @@ static int __init early_initrd(char *p)
4343
}
4444
return 0;
4545
}
46+
early_param("initrdmem", early_initrdmem);
47+
48+
/*
49+
* This is here as the initrd keyword has been in use since 11/2018
50+
* on ARM, PowerPC, and MIPS.
51+
* It should not be; it is reserved for bootloaders.
52+
*/
53+
static int __init early_initrd(char *p)
54+
{
55+
return early_initrdmem(p);
56+
}
4657
early_param("initrd", early_initrd);
4758

4859
static int init_linuxrc(struct subprocess_info *info, struct cred *new)

0 commit comments

Comments
 (0)