2 # Copyright (C) 2006-2010 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
14 GRUB_TERMINAL_CONFIG =
15 GRUB_CONSOLE_CMDLINE =
17 ifneq ($(CONFIG_X86_GRUB_CONSOLE),)
18 GRUB_CONSOLE_CMDLINE += console=tty0
19 GRUB_TERMINALS += console
22 ifneq ($(CONFIG_X86_GRUB_SERIAL),)
23 GRUB_CONSOLE_CMDLINE += console=$(call qstrip,$(CONFIG_X86_GRUB_SERIAL)),$(CONFIG_X86_GRUB_BAUDRATE)n8
24 GRUB_SERIAL_CONFIG := serial --unit=0 --speed=$(CONFIG_X86_GRUB_BAUDRATE) --word=8 --parity=no --stop=1
25 GRUB_TERMINALS += serial
28 ifneq ($(GRUB_TERMINALS),)
29 GRUB_TERMINAL_CONFIG := terminal --timeout=2 $(GRUB_TERMINALS)
33 ifneq ($(CONFIG_X86_GRUB_IMAGES),)
34 ifneq ($(HOST_OS),Darwin)
36 BOOTOPTS:=$(call qstrip,$(CONFIG_X86_GRUB_BOOTOPTS))
37 ROOTPART:=$(call qstrip,$(CONFIG_X86_GRUB_ROOTPART))
39 define Image/cmdline/ext2
40 root=$(ROOTPART) rootfstype=ext2 rootwait
43 define Image/cmdline/jffs2-64k
44 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
47 define Image/cmdline/jffs2-128k
48 block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
51 define Image/cmdline/squashfs
52 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootwait
55 define Image/Build/grub
56 # left here because the image builder doesnt need these
57 $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub
61 $(KDIR)/e2fs_stage1_5 \
62 $(KDIR)/root.grub/boot/grub/
63 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
65 -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
66 -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
67 -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
68 ./menu.lst > $(KDIR)/root.grub/boot/grub/menu.lst
69 PADDING="$(CONFIG_X86_GRUB_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_x86.sh \
70 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
71 $(CONFIG_X86_GRUB_KERNELPART) $(KDIR)/root.grub \
72 $(CONFIG_TARGET_ROOTFS_FSPART) $(KDIR)/root.$(1)
73 $(call Image/Build/grub/$(1))
76 define Image/Prepare/grub
77 # for the image builder
79 $(STAGING_DIR)/usr/lib/grub/i386-openwrt/stage1 \
80 $(STAGING_DIR)/usr/lib/grub/i386-openwrt/stage2 \
81 $(STAGING_DIR)/usr/lib/grub/i386-openwrt/stage2_eltorito \
82 $(STAGING_DIR)/usr/lib/grub/i386-openwrt/e2fs_stage1_5 \
88 define Image/Build/grub
89 PADDING="$(CONFIG_X86_GRUB_IMAGES_PAD)" PATH="$(TARGET_PATH)" NOGRUB=1 ./gen_image_x86.sh
90 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
91 $(CONFIG_X86_GRUB_KERNELPART) "" \
92 $(CONFIG_TARGET_ROOTFS_FSPART) $(KDIR)/root.$(1)
100 ifneq ($(CONFIG_OLPC_BOOTSCRIPT_IMAGES),)
102 ROOTPART:=$(call qstrip,$(CONFIG_OLPC_BOOTSCRIPT_ROOTPART))
104 define Image/cmdline/ext2
105 root=$(ROOTPART) rootfstype=ext2 rootwait
108 define Image/cmdline/jffs2-64k
109 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
112 define Image/cmdline/jffs2-128k
113 block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
116 define Image/cmdline/squashfs
117 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootdelay=$(ROOTDELAY)
120 define Image/Build/bootscript
121 # left here because the image builder doesnt need these
122 $(INSTALL_DIR) $(KDIR)/root.bootscript/boot
123 $(CP) $(KDIR)/bzImage $(KDIR)/root.bootscript/boot/vmlinuz
124 sed -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1))) $(BOOTOPTS)#g' \
125 ./olpc.fth > $(KDIR)/root.bootscript/boot/olpc.fth
126 PADDING="$(CONFIG_OLPC_BOOTSCRIPT_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_olpc.sh \
127 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
128 $(CONFIG_OLPC_BOOTSCRIPT_KERNELPART) $(KDIR)/root.bootscript \
129 $(CONFIG_TARGET_ROOTFS_FSPART) $(KDIR)/root.$(1)
134 define Image/Build/squashfs
135 $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
138 define Image/Build/iso
139 $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub
141 $(KDIR)/stage2_eltorito \
142 $(KDIR)/root.grub/boot/grub/
144 -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
145 -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
146 -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
147 -e 's#(hd0,0)#(cd)#g' \
148 ./menu.lst > $(KDIR)/root.grub/boot/grub/menu.lst
149 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
150 mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table \
151 -o $(KDIR)/root.iso $(KDIR)/root.grub
154 ifneq ($(CONFIG_X86_VDI_IMAGES),)
155 define Image/Build/vdi
156 # left here because the image builder doesnt need these
158 rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi || true
159 VBoxManage convertfromraw -format VDI \
160 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
161 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
162 # XXX: VBoxManage insists on setting perms to 0600
163 chmod 0644 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
168 ifneq ($(CONFIG_X86_VMDK_IMAGES),)
169 define Image/Build/vmdk
170 # left here because the image builder doesnt need these
172 rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true
173 qemu-img convert -f raw -O vmdk \
174 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
175 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk
180 define Image/BuildKernel
181 $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
185 $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
186 $(call Image/Prepare/bootscript)
187 $(call Image/Prepare/grub)
191 $(call Image/Build/$(1))
192 $(call Image/Build/bootscript,$(1))
194 $(call Image/Build/grub,$(1))
195 $(call Image/Build/vdi,$(1))
196 $(call Image/Build/vmdk,$(1))
198 $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
199 $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
201 gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
202 gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
206 $(eval $(call BuildImage))
208 ifneq ($(CONFIG_X86_VDI_IMAGES),)
209 $(eval $(call RequireCommand,VBoxManage, \
210 You need VBoxManage to generate VirtualBox images. \
214 ifneq ($(CONFIG_X86_VMDK_IMAGES),)
215 $(eval $(call RequireCommand,qemu-img, \
216 You need qemu-img to generate VMware images. \