x86: remove the arbitrary limitation of vmware/virtualbox images to ext4, select...
[openwrt/svn-archive/archive.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,5 root=/dev/mtdblock0 rootfstype=jffs2 rootwait
57 endef
58
59 define Image/cmdline/jffs2-128k
60 block2mtd.block2mtd=$(ROOTPART),131072,rootfs,5 root=/dev/mtdblock0 rootfstype=jffs2 rootwait
61 endef
62
63 define Image/cmdline/squashfs
64 block2mtd.block2mtd=$(ROOTPART),65536,rootfs,5 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 rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi || true
164 qemu-img convert -f raw -O vdi \
165 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
166 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
167 # XXX: VBoxManage insists on setting perms to 0600
168 chmod 0644 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
169 endef
170 endif
171
172 ifneq ($(CONFIG_VMDK_IMAGES),)
173 define Image/Build/vmdk
174 rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true
175 qemu-img convert -f raw -O vmdk \
176 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
177 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk
178 endef
179 endif
180
181 define Image/Build/gzip
182 gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
183 gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
184 endef
185
186 ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
187 define Image/Build/gzip/ext4
188 $(call Image/Build/gzip,ext4)
189 endef
190 ifneq ($(CONFIG_TARGET_IMAGES_PAD),)
191 define Image/Build/gzip/squashfs
192 $(call Image/Build/gzip,squashfs)
193 endef
194 define Image/Build/gzip/jffs2-64k
195 $(call Image/Build/gzip,jffs2-64k)
196 endef
197 define Image/Build/gzip/jffs2-128k
198 $(call Image/Build/gzip,jffs2-128k)
199 endef
200 endif
201 endif
202
203 define Image/BuildKernel
204 $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
205 ifneq ($(CONFIG_X86_ETHERBOOT_IMAGES),)
206 rm -f $(BIN_DIR)/$(IMG_PREFIX)-etherboot
207 $(STAGING_DIR_HOST)/bin/mkelfImage \
208 --append=$(CONFIG_X86_ETHERBOOT_BOOTOPTS) \
209 $(KDIR)/bzImage \
210 $(BIN_DIR)/$(IMG_PREFIX)-etherboot
211 endif
212 endef
213
214 define Image/Build/Profile/ar525w
215 cp $(KDIR)/bzImage $(KDIR)/bzImage.tmp
216 $(SCRIPT_DIR)/pad_image $(1) $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) 32
217 $(STAGING_DIR_HOST)/bin/airlink -b 1 $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) \
218 $(BIN_DIR)/$(IMG_PREFIX)-$(1)-ar525w.img
219 $(STAGING_DIR_HOST)/bin/airlink -e -b 1 $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) \
220 $(BIN_DIR)/$(IMG_PREFIX)-$(1)-ar525w-web.img
221 endef
222
223 define Image/Build/Profile/sitecom
224 cp $(KDIR)/bzImage $(KDIR)/bzImage.tmp
225 #32k config data + 20 bytes header + 2 bytes checksum after kernel image
226 $(SCRIPT_DIR)/pad_image $(1) $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) 32790
227 $(TOPDIR)/target/linux/rdc/image/mkimg_sitecom.pl $(KDIR)/bzImage.tmp > $(KDIR)/tmp.img
228 cat $(KDIR)/root.$(1) >> $(KDIR)/tmp.img
229 cp $(KDIR)/tmp.img $(BIN_DIR)/$(IMG_PREFIX)-$(1)-sitecom.img
230 rm $(KDIR)/tmp.img $(KDIR)/bzImage.tmp
231 endef
232
233 define Image/Build/Profile/bifferboard
234 $(TOPDIR)/target/linux/rdc/image/mkimg_bifferboard.py $(KDIR)/bzImage $(KDIR)/root.$(1) \
235 $(BIN_DIR)/$(IMG_PREFIX)-$(1)-bifferboard.img
236 endef
237
238 define Image/Prepare
239 $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
240 $(call Image/Prepare/bootscript)
241 $(call Image/Prepare/grub2)
242 endef
243
244 define Image/Build/Initramfs
245 $(CP) $(KDIR)/bzImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-ramfs.bzImage
246 endef
247
248 define Image/Build
249 $(call Image/Build/$(1))
250 $(call Image/Build/bootscript,$(1))
251 ifneq ($(1),iso)
252 $(call Image/Build/grub2,$(1))
253 $(call Image/Build/vdi,$(1))
254 $(call Image/Build/vmdk,$(1))
255 $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
256 else
257 $(CP) $(KDIR)/root.iso $(BIN_DIR)/$(IMG_PREFIX).iso
258 endif
259 $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
260 $(call Image/Build/gzip/$(1))
261 $(call Image/Build/Profile/$(PROFILE),$(1))
262 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
263 $(call Image/Build/Initramfs)
264 endif
265 endef
266
267 $(eval $(call BuildImage))