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
=
18 GRUB_ROOT
= hd0
,msdos1
20 USE_ATKBD
= generic
64
22 ifneq ($(strip $(foreach subtarget
,$(USE_ATKBD
),$(CONFIG_TARGET_x86_
$(subtarget
)))),)
23 GRUB2_MODULES
+= at_keyboard
24 GRUB2_MODULES_ISO
+= at_keyboard
27 ifneq ($(CONFIG_GRUB_CONSOLE
),)
28 GRUB_CONSOLE_CMDLINE
+= console
=tty0
29 GRUB_TERMINALS
+= console
32 GRUB_SERIAL
:=$(call qstrip
,$(CONFIG_GRUB_SERIAL
))
34 ifneq ($(GRUB_SERIAL
),)
35 GRUB_CONSOLE_CMDLINE
+= console
=$(GRUB_SERIAL
),$(CONFIG_GRUB_BAUDRATE
)n8
36 GRUB_SERIAL_CONFIG
:= serial
--unit
=0 --speed
=$(CONFIG_GRUB_BAUDRATE
) --word=8 --parity
=no
--stop
=1 --rtscts
=off
37 GRUB_TERMINALS
+= serial
40 ifneq ($(GRUB_TERMINALS
),)
41 GRUB_TERMINAL_CONFIG
:= terminal_input
$(GRUB_TERMINALS
); terminal_output
$(GRUB_TERMINALS
)
44 SIGNATURE
:=$(shell perl
-e
'printf("%08x", rand(0xFFFFFFFF))')
45 ROOTPART
:=$(call qstrip
,$(CONFIG_TARGET_ROOTFS_PARTNAME
))
46 ROOTPART
:=$(if
$(ROOTPART
),$(ROOTPART
),PARTUUID
=$(SIGNATURE
)-02)
48 GRUB_TIMEOUT
:=$(call qstrip
,$(CONFIG_GRUB_TIMEOUT
))
50 ifneq ($(CONFIG_TARGET_x86_xen_domu
),)
51 GRUB_ROOT
= xen
/xvda
,msdos1
54 ifneq ($(CONFIG_GRUB_IMAGES
),)
56 BOOTOPTS
:=$(call qstrip
,$(CONFIG_GRUB_BOOTOPTS
))
58 define Image
/cmdline
/ext4
59 root
=$(ROOTPART
) rootfstype
=ext4 rootwait
62 define Image
/cmdline
/squashfs
63 root
=$(ROOTPART
) rootfstype
=squashfs rootwait
66 define Image
/Build
/grub2
67 # left here because the image builder doesnt need these
68 $(INSTALL_DIR
) $(KDIR
)/root.grub
/boot
/grub
$(KDIR
)/grub2
69 $(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 -e
's#@ROOT@#$(GRUB_ROOT)#g' \
85 .
/grub.cfg
> $(KDIR
)/root.grub
/boot
/grub
/grub.cfg
86 PADDING
="$(CONFIG_TARGET_IMAGES_PAD)" SIGNATURE
="$(SIGNATURE)" PATH
="$(TARGET_PATH)" .
/gen_image_generic.sh \
87 $(BIN_DIR
)/$(IMG_PREFIX
)-combined-
$(1).img \
88 $(CONFIG_TARGET_KERNEL_PARTSIZE
) $(KDIR
)/root.grub \
89 $(CONFIG_TARGET_ROOTFS_PARTSIZE
) $(KDIR
)/root.
$(1) \
92 --device-map
="$(KDIR)/grub2/device.map" \
95 "$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img"
96 $(call Image
/Build
/grub
/$(1))
102 define Image
/Build
/squashfs
103 dd if
=/dev
/zero bs
=128k count
=1 >> $(KDIR
)/root.squashfs
106 define Image
/Build
/iso
107 $(INSTALL_DIR
) $(KDIR
)/root.grub
/boot
/grub
$(KDIR
)/grub2
108 $(CP
) $(KDIR
)/bzImage
$(KDIR
)/root.grub
/boot
/vmlinuz
111 -d
$(STAGING_DIR_HOST
)/lib
/grub
/i386-pc \
112 -o
$(KDIR
)/grub2
/eltorito.img \
114 -c .
/grub-early.cfg \
117 $(STAGING_DIR_HOST
)/lib
/grub
/i386-pc
/cdboot.img \
118 $(KDIR
)/grub2
/eltorito.img \
119 > $(KDIR
)/root.grub
/boot
/grub
/eltorito.img
121 -e
's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
122 -e
's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
123 -e
's#@CMDLINE@#root=/dev/sr0 rootfstype=iso9660 rootwait $(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
124 -e
's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
125 .
/grub-iso.cfg
> $(KDIR
)/root.grub
/boot
/grub
/grub.cfg
126 $(CP
) $(KDIR
)/bzImage
$(KDIR
)/root.grub
/boot
/vmlinuz
127 mkisofs
-R
-b boot
/grub
/eltorito.img
-no-emul-boot
-boot-info-table \
128 -o
$(KDIR
)/root.iso
$(KDIR
)/root.grub
$(TARGET_DIR
)
131 ifneq ($(CONFIG_VDI_IMAGES
),)
132 define Image
/Build
/vdi
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
142 ifneq ($(CONFIG_VMDK_IMAGES
),)
143 define Image
/Build
/vmdk
144 rm $(BIN_DIR
)/$(IMG_PREFIX
)-combined-
$(1).vmdk || true
145 qemu-img convert
-f raw
-O vmdk \
146 $(BIN_DIR
)/$(IMG_PREFIX
)-combined-
$(1).img \
147 $(BIN_DIR
)/$(IMG_PREFIX
)-combined-
$(1).vmdk
151 define Image
/Build
/gzip
152 gzip
-f9n
$(BIN_DIR
)/$(IMG_PREFIX
)-combined-
$(1).img
153 gzip
-f9n
$(BIN_DIR
)/$(IMG_PREFIX
)-rootfs-
$(1).img
156 ifneq ($(CONFIG_TARGET_IMAGES_GZIP
),)
157 define Image
/Build
/gzip
/ext4
158 $(call Image
/Build
/gzip
,ext4
)
160 ifneq ($(CONFIG_TARGET_IMAGES_PAD
),)
161 define Image
/Build
/gzip
/squashfs
162 $(call Image
/Build
/gzip
,squashfs
)
167 define Image
/BuildKernel
168 $(CP
) $(KDIR
)/bzImage
$(BIN_DIR
)/$(IMG_PREFIX
)-vmlinuz
172 $(call Image
/Prepare
/grub2
)
175 define Image
/Build
/Initramfs
176 $(CP
) $(KDIR
)/bzImage-initramfs
$(BIN_DIR
)/$(IMG_PREFIX
)-ramfs.bzImage
180 $(call Image
/Build
/$(1))
182 $(call Image
/Build
/grub2
,$(1))
183 $(call Image
/Build
/vdi
,$(1))
184 $(call Image
/Build
/vmdk
,$(1))
185 $(CP
) $(KDIR
)/root.
$(1) $(BIN_DIR
)/$(IMG_PREFIX
)-rootfs-
$(1).img
187 $(CP
) $(KDIR
)/root.iso
$(BIN_DIR
)/$(IMG_PREFIX
).iso
189 $(CP
) $(KDIR
)/bzImage
$(BIN_DIR
)/$(IMG_PREFIX
)-vmlinuz
190 $(call Image
/Build
/gzip
/$(1))
191 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS
),y
)
192 $(call Image
/Build
/Initramfs
)
196 $(eval
$(call BuildImage
))