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