2 # Copyright (C) 2006-2012 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
7 include $(TOPDIR)/rules.mk
8 include $(INCLUDE_DIR)/image.mk
10 export PATH=$(TARGET_PATH):/sbin
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
16 GRUB_TERMINAL_CONFIG =
17 GRUB_CONSOLE_CMDLINE =
19 USE_ATKBD = generic kvm_guest
21 ifneq ($(strip $(foreach subtarget,$(USE_ATKBD),$(CONFIG_TARGET_x86_$(subtarget)))),)
22 GRUB2_MODULES += at_keyboard
23 GRUB2_MODULES_ISO += at_keyboard
26 ifneq ($(CONFIG_X86_GRUB_CONSOLE),)
27 GRUB_CONSOLE_CMDLINE += console=tty0
28 GRUB_TERMINALS += console
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
37 ifneq ($(GRUB_TERMINALS),)
38 GRUB_TERMINAL_CONFIG := terminal_input $(GRUB_TERMINALS); terminal_output $(GRUB_TERMINALS)
41 ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME))
43 GRUB_TIMEOUT:=$(call qstrip,$(CONFIG_X86_GRUB_TIMEOUT))
45 ifneq ($(CONFIG_X86_GRUB_IMAGES),)
47 BOOTOPTS:=$(call qstrip,$(CONFIG_X86_GRUB_BOOTOPTS))
49 define Image/cmdline/ext4
50 root=$(ROOTPART) rootfstype=ext4 rootwait
53 define Image/cmdline/jffs2-64k
54 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
57 define Image/cmdline/jffs2-128k
58 block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
61 define Image/cmdline/squashfs
62 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootwait
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
70 -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
71 -o $(KDIR)/grub2/core.img \
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
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) \
89 --device-map="$(KDIR)/grub2/device.map" \
92 "$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img"
93 $(call Image/Build/grub/$(1))
99 ifneq ($(CONFIG_OLPC_BOOTSCRIPT_IMAGES),)
101 define Image/cmdline/ext4
102 root=$(ROOTPART) rootfstype=ext4 rootwait
105 define Image/cmdline/jffs2-64k
106 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
109 define Image/cmdline/jffs2-128k
110 block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
113 define Image/cmdline/squashfs
114 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootdelay=$(ROOTDELAY)
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)
131 define Image/Build/squashfs
132 $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
135 define Image/Build/iso
136 $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
137 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
139 -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
140 -o $(KDIR)/grub2/eltorito.img \
142 -c ./grub-early.cfg \
145 $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \
146 $(KDIR)/grub2/eltorito.img \
147 > $(KDIR)/root.grub/boot/grub/eltorito.img
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)
159 ifneq ($(CONFIG_X86_VDI_IMAGES),)
160 define Image/Build/vdi
161 # left here because the image builder doesnt need these
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
173 ifneq ($(CONFIG_X86_VMDK_IMAGES),)
174 define Image/Build/vmdk
175 # left here because the image builder doesnt need these
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
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
190 ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
191 define Image/Build/gzip/ext4
192 $(call Image/Build/gzip,ext4)
194 ifneq ($(CONFIG_TARGET_IMAGES_PAD),)
195 define Image/Build/gzip/squashfs
196 $(call Image/Build/gzip,squashfs)
198 define Image/Build/gzip/jffs2-64k
199 $(call Image/Build/gzip,jffs2-64k)
201 define Image/Build/gzip/jffs2-128k
202 $(call Image/Build/gzip,jffs2-128k)
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) \
214 $(BIN_DIR)/$(IMG_PREFIX)-etherboot
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
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
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
243 $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
244 $(call Image/Prepare/bootscript)
245 $(call Image/Prepare/grub2)
248 define Image/Build/Initramfs
249 $(CP) $(KDIR)/bzImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-ramfs.bzImage
253 $(call Image/Build/$(1))
254 $(call Image/Build/bootscript,$(1))
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
261 $(CP) $(KDIR)/root.iso $(BIN_DIR)/$(IMG_PREFIX).iso
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)
271 $(eval $(call BuildImage))