x86: remove legacy script/makefile code for rdc devices
[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 dd if=/dev/urandom bs=4 count=1 2>/dev/null | hexdump -v -e '"%08x"')
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/jffs2-64k
58 block2mtd.block2mtd=$(ROOTPART),65536,rootfs,5 root=/dev/mtdblock0 rootfstype=jffs2 rootwait
59 endef
60
61 define Image/cmdline/jffs2-128k
62 block2mtd.block2mtd=$(ROOTPART),131072,rootfs,5 root=/dev/mtdblock0 rootfstype=jffs2 rootwait
63 endef
64
65 define Image/cmdline/squashfs
66 block2mtd.block2mtd=$(ROOTPART),65536,rootfs,5 root=/dev/mtdblock0 rootfstype=squashfs rootwait
67 endef
68
69 define Image/Build/grub2
70 # left here because the image builder doesnt need these
71 $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
72 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
73 grub-mkimage \
74 -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
75 -o $(KDIR)/grub2/core.img \
76 -O i386-pc \
77 -c ./grub-early.cfg \
78 $(GRUB2_MODULES)
79 $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/grub2/
80 echo '(hd0) $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img' > $(KDIR)/grub2/device.map
81 sed \
82 -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
83 -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
84 -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
85 -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
86 ./grub.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
87 PADDING="$(CONFIG_TARGET_IMAGES_PAD)" SIGNATURE="$(SIGNATURE)" PATH="$(TARGET_PATH)" ./gen_image_generic.sh \
88 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
89 $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.grub \
90 $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1) \
91 256
92 grub-bios-setup \
93 --device-map="$(KDIR)/grub2/device.map" \
94 -d "$(KDIR)/grub2" \
95 -r "hd0,msdos1" \
96 "$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img"
97 $(call Image/Build/grub/$(1))
98 endef
99 endif
100
101 ROOTDELAY=10
102
103 define Image/Build/squashfs
104 $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
105 endef
106
107 define Image/Build/iso
108 $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
109 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
110 grub-mkimage \
111 -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
112 -o $(KDIR)/grub2/eltorito.img \
113 -O i386-pc \
114 -c ./grub-early.cfg \
115 $(GRUB2_MODULES_ISO)
116 cat \
117 $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \
118 $(KDIR)/grub2/eltorito.img \
119 > $(KDIR)/root.grub/boot/grub/eltorito.img
120 sed \
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)
129 endef
130
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
139 endef
140 endif
141
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
148 endef
149 endif
150
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
154 endef
155
156 ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
157 define Image/Build/gzip/ext4
158 $(call Image/Build/gzip,ext4)
159 endef
160 ifneq ($(CONFIG_TARGET_IMAGES_PAD),)
161 define Image/Build/gzip/squashfs
162 $(call Image/Build/gzip,squashfs)
163 endef
164 define Image/Build/gzip/jffs2-64k
165 $(call Image/Build/gzip,jffs2-64k)
166 endef
167 define Image/Build/gzip/jffs2-128k
168 $(call Image/Build/gzip,jffs2-128k)
169 endef
170 endif
171 endif
172
173 define Image/BuildKernel
174 $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
175 ifneq ($(CONFIG_X86_ETHERBOOT_IMAGES),)
176 rm -f $(BIN_DIR)/$(IMG_PREFIX)-etherboot
177 $(STAGING_DIR_HOST)/bin/mkelfImage \
178 --append=$(CONFIG_X86_ETHERBOOT_BOOTOPTS) \
179 $(KDIR)/bzImage \
180 $(BIN_DIR)/$(IMG_PREFIX)-etherboot
181 endif
182 endef
183
184 define Image/Prepare
185 $(call Image/Prepare/grub2)
186 endef
187
188 define Image/Build/Initramfs
189 $(CP) $(KDIR)/bzImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-ramfs.bzImage
190 endef
191
192 define Image/Build
193 $(call Image/Build/$(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))