move most of the x86 image generation options to the main file
[openwrt.git] / target / linux / x86 / image / Makefile
1
2 # Copyright (C) 2006-2012 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 export PATH=$(TARGET_PATH):/sbin
11
12 GRUB2_MODULES = biosdisk boot chain configfile ext2 linux ls part_msdos reboot serial vga
13 GRUB2_MODULES_ISO = biosdisk boot chain configfile iso9660 linux ls part_msdos reboot serial vga
14 GRUB_TERMINALS =
15 GRUB_SERIAL_CONFIG =
16 GRUB_TERMINAL_CONFIG =
17 GRUB_CONSOLE_CMDLINE =
18
19 USE_ATKBD = generic kvm_guest
20
21 ifneq ($(strip $(foreach subtarget,$(USE_ATKBD),$(CONFIG_TARGET_x86_$(subtarget)))),)
22   GRUB2_MODULES += at_keyboard
23   GRUB2_MODULES_ISO += at_keyboard
24 endif
25
26 ifneq ($(CONFIG_GRUB_CONSOLE),)
27   GRUB_CONSOLE_CMDLINE += console=tty0
28   GRUB_TERMINALS += console
29 endif
30
31 GRUB_SERIAL:=$(call qstrip,$(CONFIG_GRUB_SERIAL))
32
33 ifneq ($(GRUB_SERIAL),)
34   GRUB_CONSOLE_CMDLINE += console=$(GRUB_SERIAL),$(CONFIG_GRUB_BAUDRATE)n8
35   GRUB_SERIAL_CONFIG := serial --unit=0 --speed=$(CONFIG_GRUB_BAUDRATE) --word=8 --parity=no --stop=1
36   GRUB_TERMINALS += serial
37 endif
38
39 ifneq ($(GRUB_TERMINALS),)
40   GRUB_TERMINAL_CONFIG := terminal_input $(GRUB_TERMINALS); terminal_output $(GRUB_TERMINALS)
41 endif
42
43 ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME))
44
45 GRUB_TIMEOUT:=$(call qstrip,$(CONFIG_GRUB_TIMEOUT))
46
47 ifneq ($(CONFIG_GRUB_IMAGES),)
48
49   BOOTOPTS:=$(call qstrip,$(CONFIG_GRUB_BOOTOPTS))
50
51   define Image/cmdline/ext4
52     root=$(ROOTPART) rootfstype=ext4 rootwait
53   endef
54
55   define Image/cmdline/jffs2-64k
56     block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
57   endef
58
59   define Image/cmdline/jffs2-128k
60     block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
61   endef
62
63   define Image/cmdline/squashfs
64     block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootwait
65   endef
66
67   define Image/Build/grub2
68         # left here because the image builder doesnt need these
69         $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
70         $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
71         grub-mkimage \
72                 -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
73                 -o $(KDIR)/grub2/core.img \
74                 -O i386-pc \
75                 -c ./grub-early.cfg \
76                 $(GRUB2_MODULES)
77         $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/grub2/
78         echo '(hd0) $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img' > $(KDIR)/grub2/device.map
79         sed \
80                 -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
81                 -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
82                 -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
83                 -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
84                 ./grub.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
85         PADDING="$(CONFIG_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_generic.sh \
86                 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
87                 $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.grub \
88                 $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1) \
89                 256
90         grub-bios-setup \
91                 --device-map="$(KDIR)/grub2/device.map" \
92                 -d "$(KDIR)/grub2" \
93                 -r "hd0,msdos1" \
94                 "$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img"
95         $(call Image/Build/grub/$(1))
96   endef
97 endif
98
99 ROOTDELAY=10
100
101 ifneq ($(CONFIG_OLPC_BOOTSCRIPT_IMAGES),)
102
103   define Image/cmdline/ext4
104     root=$(ROOTPART) rootfstype=ext4 rootwait
105   endef
106
107   define Image/cmdline/jffs2-64k
108     block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
109   endef
110
111   define Image/cmdline/jffs2-128k
112     block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
113   endef
114
115   define Image/cmdline/squashfs
116     block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootdelay=$(ROOTDELAY)
117   endef
118
119   define Image/Build/bootscript
120         # left here because the image builder doesnt need these
121         $(INSTALL_DIR) $(KDIR)/root.bootscript/boot
122         $(CP) $(KDIR)/bzImage $(KDIR)/root.bootscript/boot/vmlinuz
123         sed -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1))) $(BOOTOPTS)#g' \
124                 ./olpc.fth > $(KDIR)/root.bootscript/boot/olpc.fth
125         PADDING="$(CONFIG_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_olpc.sh \
126                 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
127                 $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.bootscript \
128                 $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1)
129   endef
130
131 endif
132
133 define Image/Build/squashfs
134         $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
135 endef
136
137 define Image/Build/iso
138         $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
139         $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
140         grub-mkimage \
141                 -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
142                 -o $(KDIR)/grub2/eltorito.img \
143                 -O i386-pc \
144                 -c ./grub-early.cfg \
145                 $(GRUB2_MODULES_ISO)
146         cat \
147                 $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \
148                 $(KDIR)/grub2/eltorito.img \
149                 > $(KDIR)/root.grub/boot/grub/eltorito.img
150         sed \
151                 -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
152                 -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
153                 -e 's#@CMDLINE@#root=/dev/sr0 rootfstype=iso9660 rootwait $(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
154                 -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
155                 ./grub-iso.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
156         $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
157         mkisofs -R -b boot/grub/eltorito.img -no-emul-boot -boot-info-table \
158                 -o $(KDIR)/root.iso $(KDIR)/root.grub $(TARGET_DIR)
159 endef
160
161 ifneq ($(CONFIG_VDI_IMAGES),)
162   define Image/Build/vdi
163     # left here because the image builder doesnt need these
164     ifeq ($(1),ext4)
165                 rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi || true
166                 qemu-img convert -f raw -O vdi \
167                         $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
168                         $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
169                 # XXX: VBoxManage insists on setting perms to 0600
170                 chmod 0644 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
171     endif
172   endef
173 endif
174
175 ifneq ($(CONFIG_VMDK_IMAGES),)
176   define Image/Build/vmdk
177     # left here because the image builder doesnt need these
178     ifeq ($(1),ext4)
179                 rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true
180                 qemu-img convert -f raw -O vmdk \
181                         $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
182                         $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk
183     endif
184   endef
185 endif
186
187 define Image/Build/gzip
188         gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
189         gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
190 endef
191
192 ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
193   define Image/Build/gzip/ext4
194         $(call Image/Build/gzip,ext4)
195   endef
196   ifneq ($(CONFIG_TARGET_IMAGES_PAD),)
197     define Image/Build/gzip/squashfs
198         $(call Image/Build/gzip,squashfs)
199     endef
200     define Image/Build/gzip/jffs2-64k
201         $(call Image/Build/gzip,jffs2-64k)
202     endef
203     define Image/Build/gzip/jffs2-128k
204         $(call Image/Build/gzip,jffs2-128k)
205     endef
206   endif
207 endif
208
209 define Image/BuildKernel
210         $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
211   ifneq ($(CONFIG_X86_ETHERBOOT_IMAGES),)
212         rm -f $(BIN_DIR)/$(IMG_PREFIX)-etherboot
213         $(STAGING_DIR_HOST)/bin/mkelfImage \
214                 --append=$(CONFIG_X86_ETHERBOOT_BOOTOPTS) \
215                 $(KDIR)/bzImage \
216                 $(BIN_DIR)/$(IMG_PREFIX)-etherboot
217   endif
218 endef
219
220 define Image/Build/Profile/ar525w
221         cp $(KDIR)/bzImage $(KDIR)/bzImage.tmp
222         $(SCRIPT_DIR)/pad_image $(1) $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) 32
223         $(STAGING_DIR_HOST)/bin/airlink -b 1 $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) \
224                 $(BIN_DIR)/$(IMG_PREFIX)-$(1)-ar525w.img
225         $(STAGING_DIR_HOST)/bin/airlink -e -b 1 $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) \
226                 $(BIN_DIR)/$(IMG_PREFIX)-$(1)-ar525w-web.img
227 endef
228
229 define Image/Build/Profile/sitecom
230         cp $(KDIR)/bzImage $(KDIR)/bzImage.tmp
231         #32k config data + 20 bytes header + 2 bytes checksum after kernel image
232         $(SCRIPT_DIR)/pad_image $(1) $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) 32790
233         $(TOPDIR)/target/linux/rdc/image/mkimg_sitecom.pl $(KDIR)/bzImage.tmp > $(KDIR)/tmp.img
234         cat $(KDIR)/root.$(1) >> $(KDIR)/tmp.img
235         cp $(KDIR)/tmp.img $(BIN_DIR)/$(IMG_PREFIX)-$(1)-sitecom.img
236         rm $(KDIR)/tmp.img $(KDIR)/bzImage.tmp
237 endef
238
239 define Image/Build/Profile/bifferboard
240         $(TOPDIR)/target/linux/rdc/image/mkimg_bifferboard.py $(KDIR)/bzImage $(KDIR)/root.$(1) \
241                 $(BIN_DIR)/$(IMG_PREFIX)-$(1)-bifferboard.img
242 endef
243
244 define Image/Prepare
245         $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
246         $(call Image/Prepare/bootscript)
247         $(call Image/Prepare/grub2)
248 endef
249
250 define Image/Build/Initramfs
251         $(CP) $(KDIR)/bzImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-ramfs.bzImage
252 endef
253
254 define Image/Build
255         $(call Image/Build/$(1))
256         $(call Image/Build/bootscript,$(1))
257   ifneq ($(1),iso)
258         $(call Image/Build/grub2,$(1))
259         $(call Image/Build/vdi,$(1))
260         $(call Image/Build/vmdk,$(1))
261         $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
262   else
263         $(CP) $(KDIR)/root.iso $(BIN_DIR)/$(IMG_PREFIX).iso
264   endif
265         $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
266         $(call Image/Build/gzip/$(1))
267         $(call Image/Build/Profile/$(PROFILE),$(1))
268 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
269         $(call Image/Build/Initramfs)
270 endif
271 endef
272
273 $(eval $(call BuildImage))