Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | # |
Thomas Gleixner | 96ae6ea | 2007-10-11 11:16:45 +0200 | [diff] [blame] | 2 | # arch/x86/boot/Makefile |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | # |
| 4 | # This file is subject to the terms and conditions of the GNU General Public |
| 5 | # License. See the file "COPYING" in the main directory of this archive |
| 6 | # for more details. |
| 7 | # |
| 8 | # Copyright (C) 1994 by Linus Torvalds |
H. Peter Anvin | 5e47c47 | 2009-03-11 10:55:33 -0700 | [diff] [blame] | 9 | # Changed by many, many contributors over the years. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | # |
| 11 | |
Marco Elver | 40d0411 | 2019-11-14 19:03:03 +0100 | [diff] [blame] | 12 | # Sanitizer runtimes are unavailable and cannot be linked for early boot code. |
Josh Poimboeuf | c0dd671686 | 2016-02-28 22:22:34 -0600 | [diff] [blame] | 13 | KASAN_SANITIZE := n |
Marco Elver | 40d0411 | 2019-11-14 19:03:03 +0100 | [diff] [blame] | 14 | KCSAN_SANITIZE := n |
Josh Poimboeuf | c0dd671686 | 2016-02-28 22:22:34 -0600 | [diff] [blame] | 15 | OBJECT_FILES_NON_STANDARD := y |
Andrey Konovalov | c63f06d | 2015-11-05 18:51:09 -0800 | [diff] [blame] | 16 | |
Dmitry Vyukov | 5c9a875 | 2016-03-22 14:27:30 -0700 | [diff] [blame] | 17 | # Kernel does not boot with kcov instrumentation here. |
| 18 | # One of the problems observed was insertion of __sanitizer_cov_trace_pc() |
| 19 | # callback into middle of per-cpu data enabling code. Thus the callback observed |
| 20 | # inconsistent state and crashed. We are interested mostly in syscall coverage, |
| 21 | # so boot code is not interesting anyway. |
| 22 | KCOV_INSTRUMENT := n |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | # If you want to preset the SVGA mode, uncomment the next line and |
| 25 | # set SVGA_MODE to whatever number you want. |
| 26 | # Set it to -DSVGA_MODE=NORMAL_VGA if you just want the EGA/VGA mode. |
| 27 | # The number is the same as you would ordinarily press at bootup. |
| 28 | |
H. Peter Anvin | 5e47c47 | 2009-03-11 10:55:33 -0700 | [diff] [blame] | 29 | SVGA_MODE := -DSVGA_MODE=NORMAL_VGA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
H. Peter Anvin | 5e47c47 | 2009-03-11 10:55:33 -0700 | [diff] [blame] | 31 | targets := vmlinux.bin setup.bin setup.elf bzImage |
H. Peter Anvin (Intel) | f279b49 | 2021-05-10 01:28:40 -0700 | [diff] [blame] | 32 | targets += fdimage fdimage144 fdimage288 image.iso hdimage |
H. Peter Anvin | f0be6c6 | 2008-02-04 16:48:00 +0100 | [diff] [blame] | 33 | subdir- := compressed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Kees Cook | dd78b97 | 2013-10-10 17:18:13 -0700 | [diff] [blame] | 35 | setup-y += a20.o bioscall.o cmdline.o copy.o cpu.o cpuflags.o cpucheck.o |
Paolo Pisati | 9491630 | 2015-07-20 18:23:50 +0200 | [diff] [blame] | 36 | setup-y += early_serial_console.o edd.o header.o main.o memory.o |
Yinghai Lu | f4ed287 | 2010-08-02 02:17:31 -0700 | [diff] [blame] | 37 | setup-y += pm.o pmjump.o printf.o regs.o string.o tty.o video.o |
| 38 | setup-y += video-mode.o version.o |
Andi Kleen | a6b68076 | 2008-01-30 13:32:49 +0100 | [diff] [blame] | 39 | setup-$(CONFIG_X86_APM_BOOT) += apm.o |
H. Peter Anvin | 4fd0696 | 2007-07-11 12:18:56 -0700 | [diff] [blame] | 40 | |
| 41 | # The link order of the video-*.o modules can matter. In particular, |
| 42 | # video-vga.o *must* be listed first, followed by video-vesa.o. |
| 43 | # Hardware-specific drivers should follow in the order they should be |
| 44 | # probed, and video-bios.o should typically be last. |
| 45 | setup-y += video-vga.o |
| 46 | setup-y += video-vesa.o |
| 47 | setup-y += video-bios.o |
H. Peter Anvin | 30c8264 | 2007-10-15 17:13:22 -0700 | [diff] [blame] | 48 | |
Sam Ravnborg | 3fbc541 | 2007-07-17 22:27:22 +0200 | [diff] [blame] | 49 | targets += $(setup-y) |
Masahiro Yamada | 5f2fb52f | 2020-02-02 01:49:24 +0900 | [diff] [blame] | 50 | hostprogs := tools/build |
| 51 | hostprogs += mkcpustr |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Matt Fleming | b6eea87 | 2012-10-12 11:19:59 +0100 | [diff] [blame] | 53 | HOST_EXTRACFLAGS += -I$(srctree)/tools/include \ |
| 54 | -include include/generated/autoconf.h \ |
H. Peter Anvin | 446e1c8 | 2012-03-22 11:08:18 -0700 | [diff] [blame] | 55 | -D__EXPORTED_HEADERS__ |
| 56 | |
Josh Triplett | 9def39be | 2013-10-30 08:09:45 -0700 | [diff] [blame] | 57 | ifdef CONFIG_X86_FEATURE_NAMES |
H. Peter Anvin | f0be6c6 | 2008-02-04 16:48:00 +0100 | [diff] [blame] | 58 | $(obj)/cpu.o: $(obj)/cpustr.h |
| 59 | |
| 60 | quiet_cmd_cpustr = CPUSTR $@ |
| 61 | cmd_cpustr = $(obj)/mkcpustr > $@ |
H. Peter Anvin | f0be6c6 | 2008-02-04 16:48:00 +0100 | [diff] [blame] | 62 | $(obj)/cpustr.h: $(obj)/mkcpustr FORCE |
| 63 | $(call if_changed,cpustr) |
Josh Triplett | 9def39be | 2013-10-30 08:09:45 -0700 | [diff] [blame] | 64 | endif |
Masahiro Yamada | e3c7c10 | 2020-02-15 15:32:41 +0900 | [diff] [blame] | 65 | targets += cpustr.h |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | # --------------------------------------------------------------------------- |
| 68 | |
Paul Bolle | 0acba3f | 2016-11-03 10:47:48 +0100 | [diff] [blame] | 69 | KBUILD_CFLAGS := $(REALMODE_CFLAGS) -D_SETUP |
Sam Ravnborg | 222d394 | 2007-10-15 21:59:31 +0200 | [diff] [blame] | 70 | KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ |
Bruce Ashfield | 9e2276f | 2019-09-26 10:32:26 +0100 | [diff] [blame] | 71 | KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) |
Arvind Sankar | 003602ad5 | 2020-02-24 18:21:28 -0500 | [diff] [blame] | 72 | KBUILD_CFLAGS += -fno-asynchronous-unwind-tables |
Peter Oberparleiter | 7bf99fb | 2009-06-17 16:28:09 -0700 | [diff] [blame] | 73 | GCOV_PROFILE := n |
Andrey Ryabinin | c6d3085 | 2016-01-20 15:00:55 -0800 | [diff] [blame] | 74 | UBSAN_SANITIZE := n |
H. Peter Anvin | 4fd0696 | 2007-07-11 12:18:56 -0700 | [diff] [blame] | 75 | |
H. Peter Anvin | 5e47c47 | 2009-03-11 10:55:33 -0700 | [diff] [blame] | 76 | $(obj)/bzImage: asflags-y := $(SVGA_MODE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | quiet_cmd_image = BUILD $@ |
Arnd Bergmann | d460131 | 2017-07-19 14:53:03 +0200 | [diff] [blame] | 79 | silent_redirect_image = >/dev/null |
Kees Cook | 809373e2 | 2013-09-06 11:15:32 -0700 | [diff] [blame] | 80 | cmd_image = $(obj)/tools/build $(obj)/setup.bin $(obj)/vmlinux.bin \ |
Arnd Bergmann | d460131 | 2017-07-19 14:53:03 +0200 | [diff] [blame] | 81 | $(obj)/zoffset.h $@ $($(quiet)redirect_image) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
H. Peter Anvin | 5e47c47 | 2009-03-11 10:55:33 -0700 | [diff] [blame] | 83 | $(obj)/bzImage: $(obj)/setup.bin $(obj)/vmlinux.bin $(obj)/tools/build FORCE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | $(call if_changed,image) |
Arnd Bergmann | d460131 | 2017-07-19 14:53:03 +0200 | [diff] [blame] | 85 | @$(kecho) 'Kernel: $@ is ready' ' (#'`cat .version`')' |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Ian Campbell | 1622ac2 | 2008-02-04 16:47:56 +0100 | [diff] [blame] | 87 | OBJCOPYFLAGS_vmlinux.bin := -O binary -R .note -R .comment -S |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | $(obj)/vmlinux.bin: $(obj)/compressed/vmlinux FORCE |
| 89 | $(call if_changed,objcopy) |
| 90 | |
H. Peter Anvin | 4fd0696 | 2007-07-11 12:18:56 -0700 | [diff] [blame] | 91 | SETUP_OBJS = $(addprefix $(obj)/,$(setup-y)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Ard Biesheuvel | 97aa276 | 2020-02-12 12:18:17 +0100 | [diff] [blame] | 93 | sed-zoffset := -e 's/^\([0-9a-fA-F]*\) [a-zA-Z] \(startup_32\|startup_64\|efi32_stub_entry\|efi64_stub_entry\|efi_pe_entry\|efi32_pe_entry\|input_data\|kernel_info\|_end\|_ehead\|_text\|z_.*\)$$/\#define ZO_\2 0x\1/p' |
H. Peter Anvin | 77d1a49 | 2009-05-11 14:21:12 -0700 | [diff] [blame] | 94 | |
| 95 | quiet_cmd_zoffset = ZOFFSET $@ |
| 96 | cmd_zoffset = $(NM) $< | sed -n $(sed-zoffset) > $@ |
| 97 | |
| 98 | targets += zoffset.h |
| 99 | $(obj)/zoffset.h: $(obj)/compressed/vmlinux FORCE |
| 100 | $(call if_changed,zoffset) |
| 101 | |
Ian Campbell | 099e137 | 2008-02-13 20:54:58 +0000 | [diff] [blame] | 102 | |
Arnd Bergmann | 58ab5e0 | 2016-06-15 17:45:46 +0200 | [diff] [blame] | 103 | AFLAGS_header.o += -I$(objtree)/$(obj) |
Yinghai Lu | 67b6662 | 2016-04-28 17:09:06 -0700 | [diff] [blame] | 104 | $(obj)/header.o: $(obj)/zoffset.h |
Ian Campbell | 099e137 | 2008-02-13 20:54:58 +0000 | [diff] [blame] | 105 | |
Nick Desaulniers | b6c05de | 2022-08-10 15:24:41 -0700 | [diff] [blame] | 106 | LDFLAGS_setup.elf := -m elf_i386 -z noexecstack -T |
H. Peter Anvin | 4fd0696 | 2007-07-11 12:18:56 -0700 | [diff] [blame] | 107 | $(obj)/setup.elf: $(src)/setup.ld $(SETUP_OBJS) FORCE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | $(call if_changed,ld) |
| 109 | |
H. Peter Anvin | 4fd0696 | 2007-07-11 12:18:56 -0700 | [diff] [blame] | 110 | OBJCOPYFLAGS_setup.bin := -O binary |
H. Peter Anvin | 4fd0696 | 2007-07-11 12:18:56 -0700 | [diff] [blame] | 111 | $(obj)/setup.bin: $(obj)/setup.elf FORCE |
| 112 | $(call if_changed,objcopy) |
| 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | $(obj)/compressed/vmlinux: FORCE |
Paul Bolle | d960c9c | 2008-10-04 21:18:51 +0200 | [diff] [blame] | 115 | $(Q)$(MAKE) $(build)=$(obj)/compressed $@ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
H. Peter Anvin | f9c5107 | 2009-03-12 12:50:33 -0700 | [diff] [blame] | 117 | # Set this if you want to pass append arguments to the |
H. Peter Anvin (Intel) | f279b49 | 2021-05-10 01:28:40 -0700 | [diff] [blame] | 118 | # bzdisk/fdimage/hdimage/isoimage kernel |
H. Peter Anvin | f0be6c6 | 2008-02-04 16:48:00 +0100 | [diff] [blame] | 119 | FDARGS = |
H. Peter Anvin (Intel) | f279b49 | 2021-05-10 01:28:40 -0700 | [diff] [blame] | 120 | # Set this if you want one or more initrds included in the image |
H. Peter Anvin | 841b8a4 | 2006-03-26 01:36:59 -0800 | [diff] [blame] | 121 | FDINITRD = |
| 122 | |
H. Peter Anvin (Intel) | f279b49 | 2021-05-10 01:28:40 -0700 | [diff] [blame] | 123 | imgdeps = $(obj)/bzImage $(obj)/mtools.conf $(src)/genimage.sh |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
| 125 | $(obj)/mtools.conf: $(src)/mtools.conf.in |
| 126 | sed -e 's|@OBJ@|$(obj)|g' < $< > $@ |
| 127 | |
H. Peter Anvin (Intel) | f279b49 | 2021-05-10 01:28:40 -0700 | [diff] [blame] | 128 | targets += mtools.conf |
Changbin Du | 4366d57 | 2017-11-06 11:32:56 +0800 | [diff] [blame] | 129 | |
H. Peter Anvin (Intel) | f279b49 | 2021-05-10 01:28:40 -0700 | [diff] [blame] | 130 | # genimage.sh requires bash, but it also has a bunch of other |
| 131 | # external dependencies. |
| 132 | quiet_cmd_genimage = GENIMAGE $3 |
| 133 | cmd_genimage = $(BASH) $(srctree)/$(src)/genimage.sh $2 $3 $(obj)/bzImage \ |
| 134 | $(obj)/mtools.conf '$(FDARGS)' $(FDINITRD) |
| 135 | |
Masahiro Yamada | 0815512 | 2021-07-29 23:00:23 +0900 | [diff] [blame] | 136 | PHONY += bzdisk fdimage fdimage144 fdimage288 hdimage isoimage |
Masahiro Yamada | 675a59b7 | 2020-02-15 15:38:52 +0900 | [diff] [blame] | 137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | # This requires write access to /dev/fd0 |
H. Peter Anvin (Intel) | f279b49 | 2021-05-10 01:28:40 -0700 | [diff] [blame] | 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) |
Changbin Du | 4366d57 | 2017-11-06 11:32:56 +0800 | [diff] [blame] | 142 | $(call cmd,genimage,bzdisk,/dev/fd0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
H. Peter Anvin (Intel) | f279b49 | 2021-05-10 01:28:40 -0700 | [diff] [blame] | 144 | fdimage fdimage144: $(imgdeps) |
Changbin Du | 4366d57 | 2017-11-06 11:32:56 +0800 | [diff] [blame] | 145 | $(call cmd,genimage,fdimage144,$(obj)/fdimage) |
| 146 | @$(kecho) 'Kernel: $(obj)/fdimage is ready' |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
H. Peter Anvin (Intel) | f279b49 | 2021-05-10 01:28:40 -0700 | [diff] [blame] | 148 | fdimage288: $(imgdeps) |
Changbin Du | 4366d57 | 2017-11-06 11:32:56 +0800 | [diff] [blame] | 149 | $(call cmd,genimage,fdimage288,$(obj)/fdimage) |
| 150 | @$(kecho) 'Kernel: $(obj)/fdimage is ready' |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
H. Peter Anvin (Intel) | f279b49 | 2021-05-10 01:28:40 -0700 | [diff] [blame] | 152 | hdimage: $(imgdeps) |
| 153 | $(call cmd,genimage,hdimage,$(obj)/hdimage) |
| 154 | @$(kecho) 'Kernel: $(obj)/hdimage is ready' |
| 155 | |
| 156 | isoimage: $(imgdeps) |
Changbin Du | 4366d57 | 2017-11-06 11:32:56 +0800 | [diff] [blame] | 157 | $(call cmd,genimage,isoimage,$(obj)/image.iso) |
| 158 | @$(kecho) 'Kernel: $(obj)/image.iso is ready' |