ffda5c1578cd4f7d1e2de9ef48af4b729d492c4b
[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 --rtscts=off
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 SIGNATURE:=$(shell dd if=/dev/urandom bs=4 count=1 2>/dev/null | hexdump -v -e '"%08x"')
44 ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME))
45 ROOTPART:=$(if $(ROOTPART),$(ROOTPART),PARTUUID=$(SIGNATURE)-02)
46
47 GRUB_TIMEOUT:=$(call qstrip,$(CONFIG_GRUB_TIMEOUT))
48
49 ifneq ($(CONFIG_GRUB_IMAGES),)
50
51 BOOTOPTS:=$(call qstrip,$(CONFIG_GRUB_BOOTOPTS))
52
53 define Image/cmdline/ext4
54 root=$(ROOTPART) rootfstype=ext4 rootwait
55 endef
56
57 define Image/cmdline/jffs2-64k
58 block2mtd.block2mtd=$(ROOTPART),65536,rootfs,5 root=/dev/mtdblock0 rootfstype=jffs2 rootwait
59 endef
60
61 define Image/cmdline/jffs2-128k
62 block2mtd.block2mtd=$(ROOTPART),131072,rootfs,5 root=/dev/mtdblock0 rootfstype=jffs2 rootwait
63 endef
64
65 define Image/cmdline/squashfs
66 block2mtd.block2mtd=$(ROOTPART),65536,rootfs,5 root=/dev/mtdblock0 rootfstype=squashfs rootwait
67 endef
68
69 define Image/Build/grub2
70 # left here because the image builder doesnt need these
71 $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
72 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
73 grub-mkimage \
74 -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
75 -o $(KDIR)/grub2/core.img \
76 -O i386-pc \
77 -c ./grub-early.cfg \
78 $(GRUB2_MODULES)
79 $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/grub2/
80 echo '(hd0) $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img' > $(KDIR)/grub2/device.map
81 sed \
82 -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
83 -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
84 -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
85 -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
86 ./grub.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
87 PADDING="$(CONFIG_TARGET_IMAGES_PAD)" SIGNATURE="$(SIGNATURE)" PATH="$(TARGET_PATH)" ./gen_image_generic.sh \
88 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
89 $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.grub \
90 $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1) \
91 256
92 grub-bios-setup \
93 --device-map="$(KDIR)/grub2/device.map" \
94 -d "$(KDIR)/grub2" \
95 -r "hd0,msdos1" \
96 "$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img"
97 $(call Image/Build/grub/$(1))
98 endef
99 endif
100
101 ROOTDELAY=10
102
103 define Image/Build/squashfs
104 $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
105 endef
106
107 define Image/Build/iso
108 $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
109 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
110 grub-mkimage \
111 -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
112 -o $(KDIR)/grub2/eltorito.img \
113 -O i386-pc \
114 -c ./grub-early.cfg \
115 $(GRUB2_MODULES_ISO)
116 cat \
117 $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \
118 $(KDIR)/grub2/eltorito.img \
119 > $(KDIR)/root.grub/boot/grub/eltorito.img
120 sed \
121 -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
122 -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
123 -e 's#@CMDLINE@#root=/dev/sr0 rootfstype=iso9660 rootwait $(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
124 -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
125 ./grub-iso.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
126 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
127 mkisofs -R -b boot/grub/eltorito.img -no-emul-boot -boot-info-table \
128 -o $(KDIR)/root.iso $(KDIR)/root.grub $(TARGET_DIR)
129 endef
130
131 ifneq ($(CONFIG_VDI_IMAGES),)
132 define Image/Build/vdi
133 rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi || true
134 qemu-img convert -f raw -O vdi \
135 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
136 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
137 # XXX: VBoxManage insists on setting perms to 0600
138 chmod 0644 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
139 endef
140 endif
141
142 ifneq ($(CONFIG_VMDK_IMAGES),)
143 define Image/Build/vmdk
144 rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true
145 qemu-img convert -f raw -O vmdk \
146 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
147 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk
148 endef
149 endif
150
151 define Image/Build/gzip
152 gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
153 gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
154 endef
155
156 ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
157 define Image/Build/gzip/ext4
158 $(call Image/Build/gzip,ext4)
159 endef
160 ifneq ($(CONFIG_TARGET_IMAGES_PAD),)
161 define Image/Build/gzip/squashfs
162 $(call Image/Build/gzip,squashfs)
163 endef
164 define Image/Build/gzip/jffs2-64k
165 $(call Image/Build/gzip,jffs2-64k)
166 endef
167 define Image/Build/gzip/jffs2-128k
168 $(call Image/Build/gzip,jffs2-128k)
169 endef
170 endif
171 endif
172
173 define Image/BuildKernel
174 $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
175 ifneq ($(CONFIG_X86_ETHERBOOT_IMAGES),)
176 rm -f $(BIN_DIR)/$(IMG_PREFIX)-etherboot
177 $(STAGING_DIR_HOST)/bin/mkelfImage \
178 --append=$(CONFIG_X86_ETHERBOOT_BOOTOPTS) \
179 $(KDIR)/bzImage \
180 $(BIN_DIR)/$(IMG_PREFIX)-etherboot
181 endif
182 endef
183
184 define Image/Build/Profile/ar525w
185 cp $(KDIR)/bzImage $(KDIR)/bzImage.tmp
186 $(SCRIPT_DIR)/pad_image $(1) $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) 32
187 $(STAGING_DIR_HOST)/bin/airlink -b 1 $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) \
188 $(BIN_DIR)/$(IMG_PREFIX)-$(1)-ar525w.img
189 $(STAGING_DIR_HOST)/bin/airlink -e -b 1 $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) \
190 $(BIN_DIR)/$(IMG_PREFIX)-$(1)-ar525w-web.img
191 endef
192
193 define Image/Build/Profile/sitecom
194 cp $(KDIR)/bzImage $(KDIR)/bzImage.tmp
195 #32k config data + 20 bytes header + 2 bytes checksum after kernel image
196 $(SCRIPT_DIR)/pad_image $(1) $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) 32790
197 $(TOPDIR)/target/linux/rdc/image/mkimg_sitecom.pl $(KDIR)/bzImage.tmp > $(KDIR)/tmp.img
198 cat $(KDIR)/root.$(1) >> $(KDIR)/tmp.img
199 cp $(KDIR)/tmp.img $(BIN_DIR)/$(IMG_PREFIX)-$(1)-sitecom.img
200 rm $(KDIR)/tmp.img $(KDIR)/bzImage.tmp
201 endef
202
203 define Image/Build/Profile/bifferboard
204 $(TOPDIR)/target/linux/rdc/image/mkimg_bifferboard.py $(KDIR)/bzImage $(KDIR)/root.$(1) \
205 $(BIN_DIR)/$(IMG_PREFIX)-$(1)-bifferboard.img
206 endef
207
208 define Image/Prepare
209 $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
210 $(call Image/Prepare/grub2)
211 endef
212
213 define Image/Build/Initramfs
214 $(CP) $(KDIR)/bzImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-ramfs.bzImage
215 endef
216
217 define Image/Build
218 $(call Image/Build/$(1))
219 ifneq ($(1),iso)
220 $(call Image/Build/grub2,$(1))
221 $(call Image/Build/vdi,$(1))
222 $(call Image/Build/vmdk,$(1))
223 $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
224 else
225 $(CP) $(KDIR)/root.iso $(BIN_DIR)/$(IMG_PREFIX).iso
226 endif
227 $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
228 $(call Image/Build/gzip/$(1))
229 $(call Image/Build/Profile/$(PROFILE),$(1))
230 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
231 $(call Image/Build/Initramfs)
232 endif
233 endef
234
235 $(eval $(call BuildImage))