WIP: rework image builder code for x86
[openwrt/staging/lynxis.git] / target / linux / x86 / image / Makefile
1 #
2 # Copyright (C) 2006-2012 OpenWrt.org
3 # Copyright (C) 2019 Alexander Couzens <lynxis@fe80.eu>
4 #
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
7 #
8 include $(TOPDIR)/rules.mk
9 include $(INCLUDE_DIR)/image.mk
10
11 export PATH=$(TARGET_PATH):/sbin
12
13 GRUB2_MODULES = biosdisk boot chain configfile ext2 linux ls part_msdos reboot serial test vga
14 GRUB2_MODULES_ISO = biosdisk boot chain configfile iso9660 linux ls part_msdos reboot serial test vga
15 GRUB_TERMINALS =
16 GRUB_SERIAL_CONFIG =
17 GRUB_TERMINAL_CONFIG =
18 GRUB_CONSOLE_CMDLINE =
19
20 USE_ATKBD = generic 64
21
22 ifneq ($(strip $(foreach subtarget,$(USE_ATKBD),$(CONFIG_TARGET_x86_$(subtarget)))),)
23 GRUB2_MODULES += at_keyboard
24 GRUB2_MODULES_ISO += at_keyboard
25 endif
26
27 ifneq ($(CONFIG_GRUB_CONSOLE),)
28 GRUB_CONSOLE_CMDLINE += console=tty0
29 GRUB_TERMINALS += console
30 endif
31
32 GRUB_SERIAL:=$(call qstrip,$(CONFIG_GRUB_SERIAL))
33
34 ifneq ($(GRUB_SERIAL),)
35 GRUB_CONSOLE_CMDLINE += console=$(GRUB_SERIAL),$(CONFIG_GRUB_BAUDRATE)n8$(if $(CONFIG_GRUB_FLOWCONTROL),r,)
36 GRUB_SERIAL_CONFIG := serial --unit=0 --speed=$(CONFIG_GRUB_BAUDRATE) --word=8 --parity=no --stop=1 --rtscts=$(if $(CONFIG_GRUB_FLOWCONTROL),on,off)
37 GRUB_TERMINALS += serial
38 endif
39
40 ifneq ($(GRUB_TERMINALS),)
41 GRUB_TERMINAL_CONFIG := terminal_input $(GRUB_TERMINALS); terminal_output $(GRUB_TERMINALS)
42 endif
43
44 SIGNATURE:=$(shell perl -e 'printf("%08x", rand(0xFFFFFFFF))')
45 ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME))
46 ROOTPART:=$(if $(ROOTPART),$(ROOTPART),PARTUUID=$(SIGNATURE)-02)
47
48 GRUB_TIMEOUT:=$(call qstrip,$(CONFIG_GRUB_TIMEOUT))
49 GRUB_TITLE:=$(call qstrip,$(CONFIG_GRUB_TITLE))
50
51 # Convert a raw image into a $1 type image.
52 # E.g. | qemu-image vdi
53 define Build/qemu-image
54 qemu-img convert -f raw -O $1 \
55 $@ \
56 $@.new
57 mv $@.new $@
58 endef
59
60 define Build/grubpc
61 -rm -rf "$@.grubpc" "$@.root.grub"
62 $(INSTALL_DIR) $@.root.grub/boot/grub $@.grubpc
63 $(CP) $(IMAGE_KERNEL) $@.root.grub/boot/vmlinuz
64 grub-mkimage \
65 -p /boot/grub \
66 -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
67 -o $@.grubpc/core.img \
68 -O i386-pc \
69 -c ./grub-early.cfg \
70 $(GRUB2_MODULES)
71 $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $@.grubpc/
72 echo '(hd0) $@' > $@.grubpc/device.map
73 sed \
74 -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
75 -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
76 -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(FILESYSTEM)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
77 -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
78 -e 's#@TITLE@#$(GRUB_TITLE)#g' \
79 ./grub.cfg > $@.root.grub/boot/grub/grub.cfg
80 -$(CP) $(STAGING_DIR_ROOT)/boot/. $@.root.grub/boot/
81 PADDING="1" SIGNATURE="$(SIGNATURE)" PATH="$(TARGET_PATH)" $(SCRIPT_DIR)/gen_image_generic.sh \
82 $@ \
83 $(CONFIG_TARGET_KERNEL_PARTSIZE) $@.root.grub \
84 $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(IMAGE_ROOTFS) \
85 256
86 grub-bios-setup \
87 --device-map="$@.grubpc/device.map" \
88 -d "$@.grubpc" \
89 -r "hd0,msdos1" \
90 "$@"
91 rm -rf "$@.grubpc" "$@.root.grub"
92 endef
93
94 ifneq ($(CONFIG_GRUB_IMAGES),)
95 BOOTOPTS:=$(call qstrip,$(CONFIG_GRUB_BOOTOPTS))
96
97 define Image/cmdline/ext4
98 root=$(ROOTPART) rootfstype=ext4 rootwait
99 endef
100
101 define Image/cmdline/squashfs
102 root=$(ROOTPART) rootfstype=squashfs rootwait
103 endef
104 endif
105
106 define Build/grubiso
107 -rm -rf "$@.root.grub/boot/grub" "$@.grubiso"
108 $(INSTALL_DIR) $@.root.grub/boot/grub $@.grubiso
109 $(CP) $(IMAGE_KERNEL) $@.root.grub/boot/vmlinuz
110 grub-mkimage \
111 -p /boot/grub \
112 -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
113 -o $@.grub2/eltorito.img \
114 -O i386-pc \
115 -c ./grub-early.cfg \
116 $(GRUB2_MODULES_ISO)
117 cat \
118 $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \
119 $@.grub2/eltorito.img \
120 > $@.root.grub/boot/grub/eltorito.img
121 sed \
122 -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
123 -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
124 -e 's#@CMDLINE@#root=/dev/sr0 rootfstype=iso9660 rootwait $(strip $(call Image/cmdline/$(FILESYSTEM)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
125 -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
126 -e 's#@TITLE@#$(GRUB_TITLE)#g' \
127 ./grub-iso.cfg > $@.root.grub/boot/grub/grub.cfg
128 -$(CP) $(STAGING_DIR_ROOT)/boot/. $@.root.grub/boot/
129 mkisofs -R -b boot/grub/eltorito.img -no-emul-boot -boot-info-table \
130 -o $@ $@.root.grub $(TARGET_DIR)
131 rm -rf "$@.root.grub/boot/grub" "$@.grubiso"
132 endef
133
134 define Device/generic
135 PROFILES := Default
136 DEVICE_TITLE := Generic (ext4/squashfs)
137 KERNEL := kernel-bin
138 IMAGES := vdi.gz vmdk.gz raw.img.gz
139 IMAGE/vdi.gz := grubpc | qemu-image vdi | gzip
140 IMAGE/vmdk.gz := grubpc | qemu-image vmdk | gzip
141 IMAGE/raw.img.gz := grubpc | gzip
142 FILESYSTEMS := squashfs ext4
143 endef
144
145 TARGET_DEVICES += generic
146
147 define Device/generic-iso
148 PROFILES := Default
149 DEVICE_TITLE := Generic (iso)
150 KERNEL := kernel-bin
151 IMAGES := iso.gz
152 IMAGE/iso.gz := grubiso | append-metadata | gzip
153 FILESYSTEMS := iso
154 endef
155
156 TARGET_DEVICES += generic-iso
157
158 ifeq ($(SUBTARGET),geode)
159
160 define Device/geos
161 DEVICE_TITLE := Geos
162 KERNEL := kernel-bin
163 IMAGES := iso.gz
164 IMAGE/iso.gz := grubiso | append-metadata | gzip
165 FILESYSTEMS := iso
166 DEVICE_PACKAGES := soloscli linux-atm br2684ctl ppp-mod-pppoa pppdump pppstats \
167 hwclock flashrom tc kmod-pppoa kmod-8139cp kmod-mppe \
168 kmod-usb-ohci-pci kmod-hwmon-lm90
169 endef
170 TARGET_DEVICES += geos
171
172 endif
173
174 $(eval $(call BuildImage))