fad6d2d383306d3b07146e9400df9a4e32c45f28
[openwrt/staging/chunkeey.git] / target / linux / x86_64 / image / Makefile
1 #
2 # Copyright (C) 2006-2013 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7 include $(TOPDIR)/rules.mk
8 include $(INCLUDE_DIR)/image.mk
9
10 export PATH=$(TARGET_PATH):/sbin
11
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
14 GRUB_TERMINALS =
15 GRUB_SERIAL_CONFIG =
16 GRUB_TERMINAL_CONFIG =
17 GRUB_CONSOLE_CMDLINE =
18
19 USE_ATKBD = generic kvm_guest
20
21 ifneq ($(strip $(foreach subtarget,$(USE_ATKBD),$(CONFIG_TARGET_x86_64_$(subtarget)))),)
22 GRUB2_MODULES += at_keyboard
23 GRUB2_MODULES_ISO += at_keyboard
24 endif
25
26 ifneq ($(CONFIG_GRUB_CONSOLE),)
27 GRUB_CONSOLE_CMDLINE += console=tty0
28 GRUB_TERMINALS += console
29 endif
30
31 GRUB_SERIAL:=$(call qstrip,$(CONFIG_GRUB_SERIAL))
32
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
37 endif
38
39 ifneq ($(GRUB_TERMINALS),)
40 GRUB_TERMINAL_CONFIG := terminal_input $(GRUB_TERMINALS); terminal_output $(GRUB_TERMINALS)
41 endif
42
43 ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME))
44
45 GRUB_TIMEOUT:=$(call qstrip,$(CONFIG_GRUB_TIMEOUT))
46
47 ifneq ($(CONFIG_GRUB_IMAGES),)
48
49 BOOTOPTS:=$(call qstrip,$(CONFIG_GRUB_BOOTOPTS))
50
51 define Image/cmdline/ext4
52 root=$(ROOTPART) rootfstype=ext4 rootwait
53 endef
54
55 define Image/cmdline/jffs2-64k
56 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
57 endef
58
59 define Image/cmdline/jffs2-128k
60 block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
61 endef
62
63 define Image/cmdline/squashfs
64 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootwait
65 endef
66
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
71 grub-mkimage \
72 -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
73 -o $(KDIR)/grub2/core.img \
74 -O i386-pc \
75 -c ./grub-early.cfg \
76 $(GRUB2_MODULES)
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
79 sed \
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) \
89 256
90 grub-bios-setup \
91 --device-map="$(KDIR)/grub2/device.map" \
92 -d "$(KDIR)/grub2" \
93 -r "hd0,msdos1" \
94 "$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img"
95 $(call Image/Build/grub/$(1))
96 endef
97 endif
98
99 ROOTDELAY=10
100
101 define Image/Build/squashfs
102 $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
103 endef
104
105 define Image/Build/iso
106 $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
107 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
108 grub-mkimage \
109 -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
110 -o $(KDIR)/grub2/eltorito.img \
111 -O i386-pc \
112 -c ./grub-early.cfg \
113 $(GRUB2_MODULES_ISO)
114 cat \
115 $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \
116 $(KDIR)/grub2/eltorito.img \
117 > $(KDIR)/root.grub/boot/grub/eltorito.img
118 sed \
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)
127 endef
128
129 ifneq ($(CONFIG_VDI_IMAGES),)
130 define Image/Build/vdi
131 # left here because the image builder doesnt need these
132 ifeq ($(1),ext4)
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
139 endif
140 endef
141 endif
142
143 ifneq ($(CONFIG_VMDK_IMAGES),)
144 define Image/Build/vmdk
145 # left here because the image builder doesnt need these
146 ifeq ($(1),ext4)
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
151 endif
152 endef
153 endif
154
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
158 endef
159
160 ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
161 define Image/Build/gzip/ext4
162 $(call Image/Build/gzip,ext4)
163 endef
164 ifneq ($(CONFIG_TARGET_IMAGES_PAD),)
165 define Image/Build/gzip/squashfs
166 $(call Image/Build/gzip,squashfs)
167 endef
168 define Image/Build/gzip/jffs2-64k
169 $(call Image/Build/gzip,jffs2-64k)
170 endef
171 define Image/Build/gzip/jffs2-128k
172 $(call Image/Build/gzip,jffs2-128k)
173 endef
174 endif
175 endif
176
177 define Image/BuildKernel
178 $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
179 endef
180
181 define Image/Prepare
182 $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
183 $(call Image/Prepare/bootscript)
184 $(call Image/Prepare/grub2)
185 endef
186
187 define Image/Build/Initramfs
188 $(CP) $(KDIR)/bzImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-ramfs.bzImage
189 endef
190
191 define Image/Build
192 $(call Image/Build/$(1))
193 $(call Image/Build/bootscript,$(1))
194 ifneq ($(1),iso)
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
199 else
200 $(CP) $(KDIR)/root.iso $(BIN_DIR)/$(IMG_PREFIX).iso
201 endif
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)
207 endif
208 endef
209
210 $(eval $(call BuildImage))