2 # Copyright (C) 2006-2013 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_64_$(subtarget)))),)
22 GRUB2_MODULES += at_keyboard
23 GRUB2_MODULES_ISO += at_keyboard
26 ifneq ($(CONFIG_GRUB_CONSOLE),)
27 GRUB_CONSOLE_CMDLINE += console=tty0
28 GRUB_TERMINALS += console
31 GRUB_SERIAL:=$(call qstrip,$(CONFIG_GRUB_SERIAL))
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
36 GRUB_TERMINALS += serial
39 ifneq ($(GRUB_TERMINALS),)
40 GRUB_TERMINAL_CONFIG := terminal_input $(GRUB_TERMINALS); terminal_output $(GRUB_TERMINALS)
43 ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME))
45 GRUB_TIMEOUT:=$(call qstrip,$(CONFIG_GRUB_TIMEOUT))
47 ifneq ($(CONFIG_GRUB_IMAGES),)
49 BOOTOPTS:=$(call qstrip,$(CONFIG_GRUB_BOOTOPTS))
51 define Image/cmdline/ext4
52 root=$(ROOTPART) rootfstype=ext4 rootwait
55 define Image/cmdline/jffs2-64k
56 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
59 define Image/cmdline/jffs2-128k
60 block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
63 define Image/cmdline/squashfs
64 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootwait
67 define Image/Build/grub2
68 # left here because the image builder doesnt need these
69 $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
70 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
72 -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
73 -o $(KDIR)/grub2/core.img \
77 $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/grub2/
78 echo '(hd0) $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img' > $(KDIR)/grub2/device.map
80 -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
81 -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
82 -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
83 -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
84 ./grub.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
85 PADDING="$(CONFIG_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_generic.sh \
86 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
87 $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.grub \
88 $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1) \
91 --device-map="$(KDIR)/grub2/device.map" \
94 "$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img"
95 $(call Image/Build/grub/$(1))
101 define Image/Build/squashfs
102 $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
105 define Image/Build/iso
106 $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
107 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
109 -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
110 -o $(KDIR)/grub2/eltorito.img \
112 -c ./grub-early.cfg \
115 $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \
116 $(KDIR)/grub2/eltorito.img \
117 > $(KDIR)/root.grub/boot/grub/eltorito.img
119 -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
120 -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
121 -e 's#@CMDLINE@#root=/dev/sr0 rootfstype=iso9660 rootwait $(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
122 -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
123 ./grub-iso.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
124 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
125 mkisofs -R -b boot/grub/eltorito.img -no-emul-boot -boot-info-table \
126 -o $(KDIR)/root.iso $(KDIR)/root.grub $(TARGET_DIR)
129 ifneq ($(CONFIG_VDI_IMAGES),)
130 define Image/Build/vdi
131 # left here because the image builder doesnt need these
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
143 ifneq ($(CONFIG_VMDK_IMAGES),)
144 define Image/Build/vmdk
145 # left here because the image builder doesnt need these
147 rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true
148 qemu-img convert -f raw -O vmdk \
149 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
150 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk
155 define Image/Build/gzip
156 gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
157 gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
160 ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
161 define Image/Build/gzip/ext4
162 $(call Image/Build/gzip,ext4)
164 ifneq ($(CONFIG_TARGET_IMAGES_PAD),)
165 define Image/Build/gzip/squashfs
166 $(call Image/Build/gzip,squashfs)
168 define Image/Build/gzip/jffs2-64k
169 $(call Image/Build/gzip,jffs2-64k)
171 define Image/Build/gzip/jffs2-128k
172 $(call Image/Build/gzip,jffs2-128k)
177 define Image/BuildKernel
178 $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
182 $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
183 $(call Image/Prepare/bootscript)
184 $(call Image/Prepare/grub2)
187 define Image/Build/Initramfs
188 $(CP) $(KDIR)/bzImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-ramfs.bzImage
192 $(call Image/Build/$(1))
193 $(call Image/Build/bootscript,$(1))
195 $(call Image/Build/grub2,$(1))
196 $(call Image/Build/vdi,$(1))
197 $(call Image/Build/vmdk,$(1))
198 $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
200 $(CP) $(KDIR)/root.iso $(BIN_DIR)/$(IMG_PREFIX).iso
202 $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
203 $(call Image/Build/gzip/$(1))
204 $(call Image/Build/Profile/$(PROFILE),$(1))
205 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
206 $(call Image/Build/Initramfs)
210 $(eval $(call BuildImage))