c0c5c8323ac900b61cf3d6d634a60fe97e20c56b
[openwrt/openwrt.git] / target / linux / x86 / image / Makefile
1 #
2 # Copyright (C) 2006-2020 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7 include $(TOPDIR)/rules.mk
8 include $(INCLUDE_DIR)/image.mk
9
10 GRUB2_VARIANT =
11 GRUB_TERMINALS =
12 GRUB_SERIAL_CONFIG =
13 GRUB_TERMINAL_CONFIG =
14 GRUB_CONSOLE_CMDLINE =
15
16 ifneq ($(strip $(foreach subtarget,$(USE_ATKBD),$(CONFIG_TARGET_x86_$(subtarget)))),)
17 GRUB2_VARIANT := generic
18 else
19 GRUB2_VARIANT := legacy
20 endif
21
22 ifneq ($(CONFIG_GRUB_CONSOLE),)
23 GRUB_CONSOLE_CMDLINE += console=tty0
24 GRUB_TERMINALS += console
25 endif
26
27 GRUB_SERIAL:=$(call qstrip,$(CONFIG_GRUB_SERIAL))
28
29 ifneq ($(GRUB_SERIAL),)
30 GRUB_CONSOLE_CMDLINE += console=$(GRUB_SERIAL),$(CONFIG_GRUB_BAUDRATE)n8$(if $(CONFIG_GRUB_FLOWCONTROL),r,)
31 GRUB_SERIAL_CONFIG := serial --unit=0 --speed=$(CONFIG_GRUB_BAUDRATE) --word=8 --parity=no --stop=1 --rtscts=$(if $(CONFIG_GRUB_FLOWCONTROL),on,off)
32 GRUB_TERMINALS += serial
33 endif
34
35 ifneq ($(GRUB_TERMINALS),)
36 GRUB_TERMINAL_CONFIG := terminal_input $(GRUB_TERMINALS); terminal_output $(GRUB_TERMINALS)
37 endif
38
39 ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME))
40 ROOTPART:=$(if $(ROOTPART),$(ROOTPART),PARTUUID=$(IMG_PART_SIGNATURE)-02)
41
42 GRUB_TIMEOUT:=$(call qstrip,$(CONFIG_GRUB_TIMEOUT))
43 GRUB_TITLE:=$(call qstrip,$(CONFIG_GRUB_TITLE))
44
45 BOOTOPTS:=$(call qstrip,$(CONFIG_GRUB_BOOTOPTS))
46
47 define Build/combined
48 $(CP) $(KDIR)/$(KERNEL_NAME) $@.boot/boot/vmlinuz
49 -$(CP) $(STAGING_DIR_ROOT)/boot/. $@.boot/boot/
50 PADDING="1" SIGNATURE="$(IMG_PART_SIGNATURE)" $(SCRIPT_DIR)/gen_image_generic.sh \
51 $@ \
52 $(CONFIG_TARGET_KERNEL_PARTSIZE) $@.boot \
53 $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(IMAGE_ROOTFS) \
54 256
55 endef
56
57 define Build/grub-config
58 rm -fR $@.boot
59 $(INSTALL_DIR) $@.boot/boot/grub
60 sed \
61 -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
62 -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
63 -e 's#@ROOTPART@#root=$(ROOTPART) rootwait#g' \
64 -e 's#@CMDLINE@#$(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE)#g' \
65 -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
66 -e 's#@TITLE@#$(GRUB_TITLE)#g' \
67 ./grub-$(1).cfg > $@.boot/boot/grub/grub.cfg
68 endef
69
70 define Build/grub-install
71 rm -fR $@.grub2
72 $(INSTALL_DIR) $@.grub2
73 $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img \
74 $(STAGING_DIR_HOST)/lib/grub/grub2-$(GRUB2_VARIANT)/core.img \
75 $@.grub2/
76 echo '(hd0) $@' > $@.grub2/device.map
77 $(STAGING_DIR_HOST)/bin/grub-bios-setup \
78 -m "$@.grub2/device.map" \
79 -d "$@.grub2" \
80 -r "hd0,msdos1" \
81 $@
82 endef
83
84 define Build/iso
85 $(CP) $(KDIR)/$(KERNEL_NAME) $@.boot/boot/vmlinuz
86 cat \
87 $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \
88 $(STAGING_DIR_HOST)/lib/grub/grub2-iso/eltorito.img \
89 > $@.boot/boot/grub/eltorito.img
90 -$(CP) $(STAGING_DIR_ROOT)/boot/. $@.boot/boot/
91 mkisofs -R -b boot/grub/eltorito.img -no-emul-boot -boot-info-table \
92 -o $@ $@.boot $(TARGET_DIR)
93 endef
94
95 DEVICE_VARS += GRUB2_VARIANT
96 define Device/Default
97 ARTIFACT/image.iso := grub-config iso | iso
98 IMAGE/combined.img := grub-config pc | combined | grub-install
99 IMAGE/combined.img.gz := grub-config pc | combined | grub-install | gzip
100 IMAGE/combined.vdi := grub-config pc | combined | grub-install | qemu-image vdi
101 IMAGE/combined.vmdk := grub-config pc | combined | grub-install | qemu-image vmdk
102 IMAGE/rootfs.img := append-rootfs
103 IMAGE/rootfs.img.gz := append-rootfs | gzip
104 ifeq ($(CONFIG_TARGET_IMAGES_GZIP),y)
105 IMAGES := combined.img.gz rootfs.img.gz
106 else
107 IMAGES := combined.img rootfs.img
108 endif
109 KERNEL := kernel-bin
110 KERNEL_INSTALL := 1
111 KERNEL_NAME := bzImage
112 ifeq ($(CONFIG_ISO_IMAGES),y)
113 ARTIFACTS := image.iso
114 endif
115 ifeq ($(CONFIG_VDI_IMAGES),y)
116 IMAGES += combined.vdi
117 endif
118 ifeq ($(CONFIG_VMDK_IMAGES),y)
119 IMAGES += combined.vmdk
120 endif
121 endef
122
123 $(eval $(call Image/gzip-ext4-padded-squashfs))
124
125 ifeq ($(SUBTARGET),64)
126 include 64.mk
127 endif
128
129 ifeq ($(SUBTARGET),generic)
130 include generic.mk
131 endif
132
133 ifeq ($(SUBTARGET),geode)
134 include geode.mk
135 endif
136
137 ifeq ($(SUBTARGET),legacy)
138 include legacy.mk
139 endif
140
141 $(eval $(call BuildImage))
142