028612a12eacb9d1e4f8d7e5f0754d025c43edc6
[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 = at_keyboard biosdisk boot chain configfile ext2 linux ls part_msdos reboot serial vga
13 GRUB2_MODULES_ISO = at_keyboard 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 ifneq ($(CONFIG_X86_GRUB_CONSOLE),)
20 GRUB_CONSOLE_CMDLINE += console=tty0
21 GRUB_TERMINALS += console
22 endif
23
24 ifneq ($(CONFIG_X86_GRUB_SERIAL),)
25 GRUB_CONSOLE_CMDLINE += console=$(call qstrip,$(CONFIG_X86_GRUB_SERIAL)),$(CONFIG_X86_GRUB_BAUDRATE)n8
26 GRUB_SERIAL_CONFIG := serial --unit=0 --speed=$(CONFIG_X86_GRUB_BAUDRATE) --word=8 --parity=no --stop=1
27 GRUB_TERMINALS += serial
28 endif
29
30 ifneq ($(GRUB_TERMINALS),)
31 GRUB_TERMINAL_CONFIG := terminal_input $(GRUB_TERMINALS); terminal_output $(GRUB_TERMINALS)
32 endif
33
34 ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME))
35
36 GRUB_TIMEOUT:=$(call qstrip,$(CONFIG_X86_GRUB_TIMEOUT))
37
38 ifneq ($(CONFIG_X86_GRUB_IMAGES),)
39
40 BOOTOPTS:=$(call qstrip,$(CONFIG_X86_GRUB_BOOTOPTS))
41
42 define Image/cmdline/ext4
43 root=$(ROOTPART) rootfstype=ext4 rootwait
44 endef
45
46 define Image/cmdline/jffs2-64k
47 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
48 endef
49
50 define Image/cmdline/jffs2-128k
51 block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
52 endef
53
54 define Image/cmdline/squashfs
55 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootwait
56 endef
57
58 define Image/Build/grub2
59 # left here because the image builder doesnt need these
60 $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
61 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
62 grub-mkimage \
63 -o $(KDIR)/grub2/core.img \
64 -O i386-pc \
65 -c ./grub-early.cfg \
66 $(GRUB2_MODULES)
67 $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/grub2/
68 echo '(hd0) $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img' > $(KDIR)/grub2/device.map
69 sed \
70 -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
71 -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
72 -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
73 -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
74 ./grub.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
75 PADDING="$(CONFIG_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_generic.sh \
76 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
77 $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.grub \
78 $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1) \
79 256
80 grub-bios-setup \
81 --device-map="$(KDIR)/grub2/device.map" \
82 -d "$(KDIR)/grub2" \
83 -r "hd0,msdos1" \
84 "$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img"
85 $(call Image/Build/grub/$(1))
86 endef
87 endif
88
89 ROOTDELAY=10
90
91 ifneq ($(CONFIG_OLPC_BOOTSCRIPT_IMAGES),)
92
93 define Image/cmdline/ext4
94 root=$(ROOTPART) rootfstype=ext4 rootwait
95 endef
96
97 define Image/cmdline/jffs2-64k
98 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
99 endef
100
101 define Image/cmdline/jffs2-128k
102 block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
103 endef
104
105 define Image/cmdline/squashfs
106 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootdelay=$(ROOTDELAY)
107 endef
108
109 define Image/Build/bootscript
110 # left here because the image builder doesnt need these
111 $(INSTALL_DIR) $(KDIR)/root.bootscript/boot
112 $(CP) $(KDIR)/bzImage $(KDIR)/root.bootscript/boot/vmlinuz
113 sed -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1))) $(BOOTOPTS)#g' \
114 ./olpc.fth > $(KDIR)/root.bootscript/boot/olpc.fth
115 PADDING="$(CONFIG_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_olpc.sh \
116 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
117 $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.bootscript \
118 $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1)
119 endef
120
121 endif
122
123 define Image/Build/squashfs
124 $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
125 endef
126
127 define Image/Build/iso
128 $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
129 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
130 grub-mkimage \
131 -o $(KDIR)/grub2/eltorito.img \
132 -O i386-pc \
133 -c ./grub-early.cfg \
134 $(GRUB2_MODULES_ISO)
135 cat \
136 $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \
137 $(KDIR)/grub2/eltorito.img \
138 > $(KDIR)/root.grub/boot/grub/eltorito.img
139 sed \
140 -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
141 -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
142 -e 's#@CMDLINE@#root=/dev/sr0 rootfstype=iso9660 rootwait $(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
143 -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
144 ./grub-iso.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
145 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
146 mkisofs -R -b boot/grub/eltorito.img -no-emul-boot -boot-info-table \
147 -o $(KDIR)/root.iso $(KDIR)/root.grub $(TARGET_DIR)
148 endef
149
150 ifneq ($(CONFIG_X86_VDI_IMAGES),)
151 define Image/Build/vdi
152 # left here because the image builder doesnt need these
153 ifeq ($(1),ext4)
154 rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi || true
155 qemu-img convert -f raw -O vdi \
156 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
157 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
158 # XXX: VBoxManage insists on setting perms to 0600
159 chmod 0644 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
160 endif
161 endef
162 endif
163
164 ifneq ($(CONFIG_X86_VMDK_IMAGES),)
165 define Image/Build/vmdk
166 # left here because the image builder doesnt need these
167 ifeq ($(1),ext4)
168 rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true
169 qemu-img convert -f raw -O vmdk \
170 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
171 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk
172 endif
173 endef
174 endif
175
176 define Image/Build/gzip
177 gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
178 gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
179 endef
180
181 ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
182 define Image/Build/gzip/ext4
183 $(call Image/Build/gzip,ext4)
184 endef
185 ifneq ($(CONFIG_TARGET_IMAGES_PAD),)
186 define Image/Build/gzip/squashfs
187 $(call Image/Build/gzip,squashfs)
188 endef
189 define Image/Build/gzip/jffs2-64k
190 $(call Image/Build/gzip,jffs2-64k)
191 endef
192 define Image/Build/gzip/jffs2-128k
193 $(call Image/Build/gzip,jffs2-128k)
194 endef
195 endif
196 endif
197
198 define Image/BuildKernel
199 $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
200 ifneq ($(CONFIG_X86_ETHERBOOT_IMAGES),)
201 rm -f $(BIN_DIR)/$(IMG_PREFIX)-etherboot
202 $(STAGING_DIR_HOST)/bin/mkelfImage \
203 --append=$(CONFIG_X86_ETHERBOOT_BOOTOPTS) \
204 $(KDIR)/bzImage \
205 $(BIN_DIR)/$(IMG_PREFIX)-etherboot
206 endif
207 endef
208
209 define Image/Prepare
210 $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
211 $(call Image/Prepare/bootscript)
212 $(call Image/Prepare/grub2)
213 endef
214
215 define Image/Build
216 $(call Image/Build/$(1))
217 $(call Image/Build/bootscript,$(1))
218 ifneq ($(1),iso)
219 $(call Image/Build/grub2,$(1))
220 $(call Image/Build/vdi,$(1))
221 $(call Image/Build/vmdk,$(1))
222 endif
223 $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
224 $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
225 $(call Image/Build/gzip/$(1))
226 endef
227
228 $(eval $(call BuildImage))