x86: switch image generation to new code
[openwrt/staging/wigyori.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="$(CONFIG_TARGET_IMAGES_PAD)" 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 define Build/vdi
96 qemu-img convert -f raw -O vdi $@ $@.new
97 @mv $@.new $@
98 endef
99
100 define Build/vmdk
101 qemu-img convert -f raw -O vmdk $@ $@.new
102 @mv $@.new $@
103 endef
104
105 DEVICE_VARS += GRUB2_VARIANT
106 define Device/Default
107 ARTIFACT/image.iso := grub-config iso | iso
108 IMAGES := combined.img.gz
109 IMAGE/combined.img.gz := append-rootfs | pad-extra 128k | grub-config pc | combined | grub-install | gzip
110 IMAGE/combined.vdi := append-rootfs | pad-extra 128k | grub-config pc | combined | grub-install | vdi
111 IMAGE/combined.vmdk := append-rootfs | pad-extra 128k | grub-config pc | combined | grub-install | vmdk
112 KERNEL := kernel-bin
113 KERNEL_INSTALL := 1
114 KERNEL_NAME := bzImage
115 ifeq ($(CONFIG_ISO_IMAGES),y)
116 ARTIFACTS := image.iso
117 endif
118 ifeq ($(CONFIG_VDI_IMAGES),y)
119 IMAGES += combined.vdi
120 endif
121 ifeq ($(CONFIG_VMDK_IMAGES),y)
122 IMAGES += combined.vmdk
123 endif
124 endef
125
126 $(eval $(call Image/gzip-ext4-padded-squashfs))
127
128 ifeq ($(SUBTARGET),64)
129 include 64.mk
130 endif
131
132 ifeq ($(SUBTARGET),generic)
133 include generic.mk
134 endif
135
136 ifeq ($(SUBTARGET),legacy)
137 include legacy.mk
138 endif
139
140 $(eval $(call BuildImage))
141