x86: drop the use of block2mtd, use ext4/f2fs as overlay filesystem
[openwrt/openwrt.git] / target / linux / x86 / image / Makefile
1 #
2 # Copyright (C) 2006-2012 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 64
20
21 ifneq ($(strip $(foreach subtarget,$(USE_ATKBD),$(CONFIG_TARGET_x86_$(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 --rtscts=off
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 SIGNATURE:=$(shell perl -e 'printf("%08x", rand(0xFFFFFFFF))')
44 ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME))
45 ROOTPART:=$(if $(ROOTPART),$(ROOTPART),PARTUUID=$(SIGNATURE)-02)
46
47 GRUB_TIMEOUT:=$(call qstrip,$(CONFIG_GRUB_TIMEOUT))
48
49 ifneq ($(CONFIG_GRUB_IMAGES),)
50
51 BOOTOPTS:=$(call qstrip,$(CONFIG_GRUB_BOOTOPTS))
52
53 define Image/cmdline/ext4
54 root=$(ROOTPART) rootfstype=ext4 rootwait
55 endef
56
57 define Image/cmdline/squashfs
58 root=$(ROOTPART) rootfstype=squashfs rootwait
59 endef
60
61 define Image/Build/grub2
62 # left here because the image builder doesnt need these
63 $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
64 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
65 grub-mkimage \
66 -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
67 -o $(KDIR)/grub2/core.img \
68 -O i386-pc \
69 -c ./grub-early.cfg \
70 $(GRUB2_MODULES)
71 $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/grub2/
72 echo '(hd0) $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img' > $(KDIR)/grub2/device.map
73 sed \
74 -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
75 -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
76 -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
77 -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
78 ./grub.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
79 PADDING="$(CONFIG_TARGET_IMAGES_PAD)" SIGNATURE="$(SIGNATURE)" PATH="$(TARGET_PATH)" ./gen_image_generic.sh \
80 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
81 $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.grub \
82 $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1) \
83 256
84 grub-bios-setup \
85 --device-map="$(KDIR)/grub2/device.map" \
86 -d "$(KDIR)/grub2" \
87 -r "hd0,msdos1" \
88 "$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img"
89 $(call Image/Build/grub/$(1))
90 endef
91 endif
92
93 ROOTDELAY=10
94
95 define Image/Build/squashfs
96 dd if=/dev/zero bs=128k count=1 >> $(KDIR)/root.squashfs
97 endef
98
99 define Image/Build/iso
100 $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
101 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
102 grub-mkimage \
103 -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
104 -o $(KDIR)/grub2/eltorito.img \
105 -O i386-pc \
106 -c ./grub-early.cfg \
107 $(GRUB2_MODULES_ISO)
108 cat \
109 $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \
110 $(KDIR)/grub2/eltorito.img \
111 > $(KDIR)/root.grub/boot/grub/eltorito.img
112 sed \
113 -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
114 -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
115 -e 's#@CMDLINE@#root=/dev/sr0 rootfstype=iso9660 rootwait $(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
116 -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
117 ./grub-iso.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
118 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
119 mkisofs -R -b boot/grub/eltorito.img -no-emul-boot -boot-info-table \
120 -o $(KDIR)/root.iso $(KDIR)/root.grub $(TARGET_DIR)
121 endef
122
123 ifneq ($(CONFIG_VDI_IMAGES),)
124 define Image/Build/vdi
125 rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi || true
126 qemu-img convert -f raw -O vdi \
127 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
128 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
129 # XXX: VBoxManage insists on setting perms to 0600
130 chmod 0644 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
131 endef
132 endif
133
134 ifneq ($(CONFIG_VMDK_IMAGES),)
135 define Image/Build/vmdk
136 rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true
137 qemu-img convert -f raw -O vmdk \
138 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
139 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk
140 endef
141 endif
142
143 define Image/Build/gzip
144 gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
145 gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
146 endef
147
148 ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
149 define Image/Build/gzip/ext4
150 $(call Image/Build/gzip,ext4)
151 endef
152 ifneq ($(CONFIG_TARGET_IMAGES_PAD),)
153 define Image/Build/gzip/squashfs
154 $(call Image/Build/gzip,squashfs)
155 endef
156 endif
157 endif
158
159 define Image/BuildKernel
160 $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
161 endef
162
163 define Image/Prepare
164 $(call Image/Prepare/grub2)
165 endef
166
167 define Image/Build/Initramfs
168 $(CP) $(KDIR)/bzImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-ramfs.bzImage
169 endef
170
171 define Image/Build
172 $(call Image/Build/$(1))
173 ifneq ($(1),iso)
174 $(call Image/Build/grub2,$(1))
175 $(call Image/Build/vdi,$(1))
176 $(call Image/Build/vmdk,$(1))
177 $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
178 else
179 $(CP) $(KDIR)/root.iso $(BIN_DIR)/$(IMG_PREFIX).iso
180 endif
181 $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
182 $(call Image/Build/gzip/$(1))
183 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
184 $(call Image/Build/Initramfs)
185 endif
186 endef
187
188 $(eval $(call BuildImage))