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
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)
32 ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME))
34 GRUB_TIMEOUT:=$(call qstrip,$(CONFIG_X86_GRUB_TIMEOUT))
36 ifneq ($(CONFIG_X86_GRUB_IMAGES),)
38 BOOTOPTS:=$(call qstrip,$(CONFIG_X86_GRUB_BOOTOPTS))
40 define Image/cmdline/ext4
41 root=$(ROOTPART) rootfstype=ext4 rootwait
44 define Image/cmdline/jffs2-64k
45 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
48 define Image/cmdline/jffs2-128k
49 block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
52 define Image/cmdline/squashfs
53 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootwait
56 define Image/Build/grub
57 # left here because the image builder doesnt need these
58 $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub
62 $(KDIR)/e2fs_stage1_5 \
63 $(KDIR)/root.grub/boot/grub/
64 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
66 -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
67 -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
68 -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
69 -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
70 ./menu.lst > $(KDIR)/root.grub/boot/grub/menu.lst
71 PADDING="$(CONFIG_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_x86.sh \
72 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
73 $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.grub \
74 $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1)
75 $(call Image/Build/grub/$(1))
78 define Image/Prepare/grub
79 # for the image builder
81 $(STAGING_DIR)/usr/lib/grub/i386-openwrt/stage1 \
82 $(STAGING_DIR)/usr/lib/grub/i386-openwrt/stage2 \
83 $(STAGING_DIR)/usr/lib/grub/i386-openwrt/stage2_eltorito \
84 $(STAGING_DIR)/usr/lib/grub/i386-openwrt/e2fs_stage1_5 \
92 ifneq ($(CONFIG_OLPC_BOOTSCRIPT_IMAGES),)
94 define Image/cmdline/ext4
95 root=$(ROOTPART) rootfstype=ext4 rootwait
98 define Image/cmdline/jffs2-64k
99 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
102 define Image/cmdline/jffs2-128k
103 block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
106 define Image/cmdline/squashfs
107 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootdelay=$(ROOTDELAY)
110 define Image/Build/bootscript
111 # left here because the image builder doesnt need these
112 $(INSTALL_DIR) $(KDIR)/root.bootscript/boot
113 $(CP) $(KDIR)/bzImage $(KDIR)/root.bootscript/boot/vmlinuz
114 sed -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1))) $(BOOTOPTS)#g' \
115 ./olpc.fth > $(KDIR)/root.bootscript/boot/olpc.fth
116 PADDING="$(CONFIG_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_olpc.sh \
117 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
118 $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.bootscript \
119 $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1)
124 define Image/Build/squashfs
125 $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
128 define Image/Build/iso
129 $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub
131 $(KDIR)/stage2_eltorito \
132 $(KDIR)/root.grub/boot/grub/
134 -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
135 -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
136 -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
137 -e 's#(hd0,0)#(cd)#g' \
138 ./menu.lst > $(KDIR)/root.grub/boot/grub/menu.lst
139 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
140 mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table \
141 -o $(KDIR)/root.iso $(KDIR)/root.grub
144 ifneq ($(CONFIG_X86_VDI_IMAGES),)
145 define Image/Build/vdi
146 # left here because the image builder doesnt need these
148 rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi || true
149 qemu-img convert -f raw -O vdi \
150 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
151 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
152 # XXX: VBoxManage insists on setting perms to 0600
153 chmod 0644 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
158 ifneq ($(CONFIG_X86_VMDK_IMAGES),)
159 define Image/Build/vmdk
160 # left here because the image builder doesnt need these
162 rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true
163 qemu-img convert -f raw -O vmdk \
164 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
165 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk
170 define Image/Build/gzip
171 gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
172 gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
175 ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
176 define Image/Build/gzip/ext4
177 $(call Image/Build/gzip,ext4)
179 define Image/Build/gzip/jffs2-64k
180 $(call Image/Build/gzip,jffs2-64k)
182 define Image/Build/gzip/jffs2-128k
183 $(call Image/Build/gzip,jffs2-128k)
187 define Image/BuildKernel
188 $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
189 ifneq ($(CONFIG_X86_ETHERBOOT_IMAGES),)
190 rm -f $(BIN_DIR)/$(IMG_PREFIX)-etherboot
191 $(STAGING_DIR_HOST)/bin/mkelfImage \
192 --append=$(CONFIG_X86_ETHERBOOT_BOOTOPTS) \
194 $(BIN_DIR)/$(IMG_PREFIX)-etherboot
199 $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
200 $(call Image/Prepare/bootscript)
201 $(call Image/Prepare/grub)
205 $(call Image/Build/$(1))
206 $(call Image/Build/bootscript,$(1))
208 $(call Image/Build/grub,$(1))
209 $(call Image/Build/vdi,$(1))
210 $(call Image/Build/vmdk,$(1))
212 $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
213 $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
214 $(call Image/Build/gzip/$(1))
217 $(eval $(call BuildImage))