summaryrefslogtreecommitdiffstats
path: root/init
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2019-05-13 20:18:24 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-05-14 12:47:47 -0400
commit7c184ecd262fe64fe8cf4e099e0f7cefe88d88b2 (patch)
treeca950aa20bf44390628608298e6b0a964536f43e /init
parent23091e287355440fb680868c23bcada594d3f399 (diff)
initramfs: factor out a helper to populate the initrd image
This will allow for cleaner code sharing in the caller. Link: http://lkml.kernel.org/r/20190213174621.29297-5-hch@lst.de Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Mike Rapoport <rppt@linux.ibm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> [arm64] Cc: Geert Uytterhoeven <geert@linux-m68k.org> [m68k] Cc: Steven Price <steven.price@arm.com> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Guan Xuetao <gxt@pku.edu.cn> Cc: Russell King <linux@armlinux.org.uk> Cc: Will Deacon <will.deacon@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'init')
-rw-r--r--init/initramfs.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/init/initramfs.c b/init/initramfs.c
index 5fda9557a134..e3de626dbd98 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -597,6 +597,28 @@ static void __init clean_rootfs(void)
597} 597}
598#endif 598#endif
599 599
600#ifdef CONFIG_BLK_DEV_RAM
601static void populate_initrd_image(char *err)
602{
603 ssize_t written;
604 int fd;
605
606 unpack_to_rootfs(__initramfs_start, __initramfs_size);
607
608 printk(KERN_INFO "rootfs image is not initramfs (%s); looks like an initrd\n",
609 err);
610 fd = ksys_open("/initrd.image", O_WRONLY | O_CREAT, 0700);
611 if (fd < 0)
612 return;
613
614 written = xwrite(fd, (char *)initrd_start, initrd_end - initrd_start);
615 if (written != initrd_end - initrd_start)
616 pr_err("/initrd.image: incomplete write (%zd != %ld)\n",
617 written, initrd_end - initrd_start);
618 ksys_close(fd);
619}
620#endif /* CONFIG_BLK_DEV_RAM */
621
600static int __init populate_rootfs(void) 622static int __init populate_rootfs(void)
601{ 623{
602 /* Load the built in initramfs */ 624 /* Load the built in initramfs */
@@ -606,7 +628,6 @@ static int __init populate_rootfs(void)
606 /* If available load the bootloader supplied initrd */ 628 /* If available load the bootloader supplied initrd */
607 if (initrd_start && !IS_ENABLED(CONFIG_INITRAMFS_FORCE)) { 629 if (initrd_start && !IS_ENABLED(CONFIG_INITRAMFS_FORCE)) {
608#ifdef CONFIG_BLK_DEV_RAM 630#ifdef CONFIG_BLK_DEV_RAM
609 int fd;
610 printk(KERN_INFO "Trying to unpack rootfs image as initramfs...\n"); 631 printk(KERN_INFO "Trying to unpack rootfs image as initramfs...\n");
611 err = unpack_to_rootfs((char *)initrd_start, 632 err = unpack_to_rootfs((char *)initrd_start,
612 initrd_end - initrd_start); 633 initrd_end - initrd_start);
@@ -614,22 +635,7 @@ static int __init populate_rootfs(void)
614 goto done; 635 goto done;
615 636
616 clean_rootfs(); 637 clean_rootfs();
617 unpack_to_rootfs(__initramfs_start, __initramfs_size); 638 populate_initrd_image(err);
618
619 printk(KERN_INFO "rootfs image is not initramfs (%s)"
620 "; looks like an initrd\n", err);
621 fd = ksys_open("/initrd.image",
622 O_WRONLY|O_CREAT, 0700);
623 if (fd >= 0) {
624 ssize_t written = xwrite(fd, (char *)initrd_start,
625 initrd_end - initrd_start);
626
627 if (written != initrd_end - initrd_start)
628 pr_err("/initrd.image: incomplete write (%zd != %ld)\n",
629 written, initrd_end - initrd_start);
630
631 ksys_close(fd);
632 }
633 done: 639 done:
634 /* empty statement */; 640 /* empty statement */;
635#else 641#else