Skip to content

Commit f279b49

Browse files
H. Peter Anvin (Intel)ingomolnar
authored andcommitted
x86/boot: Modernize genimage script; hdimage+EFI support
The image generation scripts in arch/x86/boot are pretty out of date, except for the isoimage target. Update and clean up the genimage.sh script, and make it support an arbitrary number of initramfs files in the image. Add a "hdimage" target, which can be booted by either BIOS or EFI (if the kernel is compiled with the EFI stub.) For EFI to be able to pass the command line to the kernel, we need the EFI shell, but the firmware builtin EFI shell, if it even exists, is pretty much always the last resort boot option, so search for OVMF or EDK2 and explicitly include a copy of the EFI shell. To make this all work, use bash features in the script. Furthermore, this version of the script makes use of some mtools features, especially mpartition, that might not exist in very old version of mtools, but given all the other dependencies on this script this doesn't seem such a big deal. Finally, put a volume label ("LINUX_BOOT") on all generated images. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20210510082840.628372-1-hpa@zytor.com
1 parent 6efb943 commit f279b49

5 files changed

Lines changed: 252 additions & 104 deletions

File tree

arch/x86/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ drivers-$(CONFIG_FB) += arch/x86/video/
256256

257257
boot := arch/x86/boot
258258

259-
BOOT_TARGETS = bzdisk fdimage fdimage144 fdimage288 isoimage
259+
BOOT_TARGETS = bzdisk fdimage fdimage144 fdimage288 hdimage isoimage
260260

261261
PHONY += bzImage $(BOOT_TARGETS)
262262

@@ -314,8 +314,9 @@ define archhelp
314314
echo ' fdimage - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)'
315315
echo ' fdimage144 - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)'
316316
echo ' fdimage288 - Create 2.8MB boot floppy image (arch/x86/boot/fdimage)'
317+
echo ' hdimage - Create a BIOS/EFI hard disk image (arch/x86/boot/hdimage)'
317318
echo ' isoimage - Create a boot CD-ROM image (arch/x86/boot/image.iso)'
318-
echo ' bzdisk/fdimage*/isoimage also accept:'
319+
echo ' bzdisk/fdimage*/hdimage/isoimage also accept:'
319320
echo ' FDARGS="..." arguments for the booted kernel'
320321
echo ' FDINITRD=file initrd for the booted kernel'
321322
echo ''

arch/x86/boot/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ setup.elf
1111
fdimage
1212
mtools.conf
1313
image.iso
14+
hdimage

arch/x86/boot/Makefile

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ KCOV_INSTRUMENT := n
2929
SVGA_MODE := -DSVGA_MODE=NORMAL_VGA
3030

3131
targets := vmlinux.bin setup.bin setup.elf bzImage
32-
targets += fdimage fdimage144 fdimage288 image.iso mtools.conf
32+
targets += fdimage fdimage144 fdimage288 image.iso hdimage
3333
subdir- := compressed
3434

3535
setup-y += a20.o bioscall.o cmdline.o copy.o cpu.o cpuflags.o cpucheck.o
@@ -115,47 +115,49 @@ $(obj)/compressed/vmlinux: FORCE
115115
$(Q)$(MAKE) $(build)=$(obj)/compressed $@
116116

117117
# Set this if you want to pass append arguments to the
118-
# bzdisk/fdimage/isoimage kernel
118+
# bzdisk/fdimage/hdimage/isoimage kernel
119119
FDARGS =
120-
# Set this if you want an initrd included with the
121-
# bzdisk/fdimage/isoimage kernel
120+
# Set this if you want one or more initrds included in the image
122121
FDINITRD =
123122

124-
image_cmdline = default linux $(FDARGS) $(if $(FDINITRD),initrd=initrd.img,)
123+
imgdeps = $(obj)/bzImage $(obj)/mtools.conf $(src)/genimage.sh
125124

126125
$(obj)/mtools.conf: $(src)/mtools.conf.in
127126
sed -e 's|@OBJ@|$(obj)|g' < $< > $@
128127

128+
targets += mtools.conf
129+
130+
# genimage.sh requires bash, but it also has a bunch of other
131+
# external dependencies.
129132
quiet_cmd_genimage = GENIMAGE $3
130-
cmd_genimage = sh $(srctree)/$(src)/genimage.sh $2 $3 $(obj)/bzImage \
131-
$(obj)/mtools.conf '$(image_cmdline)' $(FDINITRD)
133+
cmd_genimage = $(BASH) $(srctree)/$(src)/genimage.sh $2 $3 $(obj)/bzImage \
134+
$(obj)/mtools.conf '$(FDARGS)' $(FDINITRD)
132135

133-
PHONY += bzdisk fdimage fdimage144 fdimage288 isoimage bzlilo install
136+
PHONY += bzdisk fdimage fdimage144 fdimage288 hdimage isoimage install
134137

135138
# This requires write access to /dev/fd0
136-
bzdisk: $(obj)/bzImage $(obj)/mtools.conf
139+
# All images require syslinux to be installed; hdimage also requires
140+
# EDK2/OVMF if the kernel is compiled with the EFI stub.
141+
bzdisk: $(imgdeps)
137142
$(call cmd,genimage,bzdisk,/dev/fd0)
138143

139-
# These require being root or having syslinux 2.02 or higher installed
140-
fdimage fdimage144: $(obj)/bzImage $(obj)/mtools.conf
144+
fdimage fdimage144: $(imgdeps)
141145
$(call cmd,genimage,fdimage144,$(obj)/fdimage)
142146
@$(kecho) 'Kernel: $(obj)/fdimage is ready'
143147

144-
fdimage288: $(obj)/bzImage $(obj)/mtools.conf
148+
fdimage288: $(imgdeps)
145149
$(call cmd,genimage,fdimage288,$(obj)/fdimage)
146150
@$(kecho) 'Kernel: $(obj)/fdimage is ready'
147151

148-
isoimage: $(obj)/bzImage
152+
hdimage: $(imgdeps)
153+
$(call cmd,genimage,hdimage,$(obj)/hdimage)
154+
@$(kecho) 'Kernel: $(obj)/hdimage is ready'
155+
156+
isoimage: $(imgdeps)
149157
$(call cmd,genimage,isoimage,$(obj)/image.iso)
150158
@$(kecho) 'Kernel: $(obj)/image.iso is ready'
151159

152-
bzlilo:
153-
if [ -f $(INSTALL_PATH)/vmlinuz ]; then mv $(INSTALL_PATH)/vmlinuz $(INSTALL_PATH)/vmlinuz.old; fi
154-
if [ -f $(INSTALL_PATH)/System.map ]; then mv $(INSTALL_PATH)/System.map $(INSTALL_PATH)/System.old; fi
155-
cat $(obj)/bzImage > $(INSTALL_PATH)/vmlinuz
156-
cp System.map $(INSTALL_PATH)/
157-
if [ -x /sbin/lilo ]; then /sbin/lilo; else /etc/lilo/install; fi
158-
159160
install:
160-
sh $(srctree)/$(src)/install.sh $(KERNELRELEASE) $(obj)/bzImage \
161+
$(CONFIG_SHELL) $(srctree)/$(src)/install.sh \
162+
$(KERNELRELEASE) $(obj)/bzImage \
161163
System.map "$(INSTALL_PATH)"

0 commit comments

Comments
 (0)