images: rename CONFIG_TARGET_ROOTFS_FSPART to CONFIG_TARGET_ROOTFS_PARTSIZE
[oweals/openwrt.git] / target / linux / x86 / image / Makefile
1
2 # Copyright (C) 2006-2010 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 GRUB_TERMINALS =
13 GRUB_SERIAL_CONFIG =
14 GRUB_TERMINAL_CONFIG =
15 GRUB_CONSOLE_CMDLINE =
16
17 ifneq ($(CONFIG_X86_GRUB_CONSOLE),)
18   GRUB_CONSOLE_CMDLINE += console=tty0
19   GRUB_TERMINALS += console
20 endif
21
22 ifneq ($(CONFIG_X86_GRUB_SERIAL),)
23   GRUB_CONSOLE_CMDLINE += console=$(call qstrip,$(CONFIG_X86_GRUB_SERIAL)),$(CONFIG_X86_GRUB_BAUDRATE)n8
24   GRUB_SERIAL_CONFIG := serial --unit=0 --speed=$(CONFIG_X86_GRUB_BAUDRATE) --word=8 --parity=no --stop=1
25   GRUB_TERMINALS += serial
26 endif
27
28 ifneq ($(GRUB_TERMINALS),)
29   GRUB_TERMINAL_CONFIG := terminal --timeout=2 $(GRUB_TERMINALS)
30 endif
31
32
33 ifneq ($(CONFIG_X86_GRUB_IMAGES),)
34  ifneq ($(HOST_OS),Darwin)
35
36   BOOTOPTS:=$(call qstrip,$(CONFIG_X86_GRUB_BOOTOPTS))
37   ROOTPART:=$(call qstrip,$(CONFIG_X86_GRUB_ROOTPART))
38
39   define Image/cmdline/ext2
40     root=$(ROOTPART) rootfstype=ext2 rootwait
41   endef
42   
43   define Image/cmdline/jffs2-64k
44     block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
45   endef
46
47   define Image/cmdline/jffs2-128k
48     block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
49   endef
50
51   define Image/cmdline/squashfs
52     block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootwait
53   endef
54
55   define Image/Build/grub
56         # left here because the image builder doesnt need these
57         $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub
58         $(CP) \
59                 $(KDIR)/stage1 \
60                 $(KDIR)/stage2 \
61                 $(KDIR)/e2fs_stage1_5 \
62                 $(KDIR)/root.grub/boot/grub/
63         $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
64         sed \
65                 -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
66                 -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
67                 -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
68                 ./menu.lst > $(KDIR)/root.grub/boot/grub/menu.lst
69         PADDING="$(CONFIG_X86_GRUB_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_x86.sh \
70                 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
71                 $(CONFIG_X86_GRUB_KERNELPART) $(KDIR)/root.grub \
72                 $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1)
73         $(call Image/Build/grub/$(1))
74   endef
75
76   define Image/Prepare/grub
77         # for the image builder
78         $(CP) \
79                 $(STAGING_DIR)/usr/lib/grub/i386-openwrt/stage1 \
80                 $(STAGING_DIR)/usr/lib/grub/i386-openwrt/stage2 \
81                 $(STAGING_DIR)/usr/lib/grub/i386-openwrt/stage2_eltorito \
82                 $(STAGING_DIR)/usr/lib/grub/i386-openwrt/e2fs_stage1_5 \
83                 $(KDIR)/
84   endef
85
86  else
87
88   define Image/Build/grub
89         PADDING="$(CONFIG_X86_GRUB_IMAGES_PAD)" PATH="$(TARGET_PATH)" NOGRUB=1 ./gen_image_x86.sh 
90                 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
91                 $(CONFIG_X86_GRUB_KERNELPART) "" \
92                 $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1)
93   endef
94
95  endif
96 endif
97
98 ROOTDELAY=10
99
100 ifneq ($(CONFIG_OLPC_BOOTSCRIPT_IMAGES),)
101
102   ROOTPART:=$(call qstrip,$(CONFIG_OLPC_BOOTSCRIPT_ROOTPART))
103
104   define Image/cmdline/ext2
105     root=$(ROOTPART) rootfstype=ext2 rootwait
106   endef
107
108   define Image/cmdline/jffs2-64k
109     block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
110   endef
111
112   define Image/cmdline/jffs2-128k
113     block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
114   endef
115
116   define Image/cmdline/squashfs
117     block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootdelay=$(ROOTDELAY)
118   endef
119
120   define Image/Build/bootscript
121         # left here because the image builder doesnt need these
122         $(INSTALL_DIR) $(KDIR)/root.bootscript/boot
123         $(CP) $(KDIR)/bzImage $(KDIR)/root.bootscript/boot/vmlinuz
124         sed -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1))) $(BOOTOPTS)#g' \
125                 ./olpc.fth > $(KDIR)/root.bootscript/boot/olpc.fth
126         PADDING="$(CONFIG_OLPC_BOOTSCRIPT_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_olpc.sh \
127                 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
128                 $(CONFIG_OLPC_BOOTSCRIPT_KERNELPART) $(KDIR)/root.bootscript \
129                 $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1)
130   endef
131
132 endif
133
134 define Image/Build/squashfs
135         $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
136 endef
137
138 define Image/Build/iso 
139         $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub
140         $(CP) \
141                 $(KDIR)/stage2_eltorito \
142                 $(KDIR)/root.grub/boot/grub/ 
143         sed \
144                 -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
145                 -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
146                 -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
147                 -e 's#(hd0,0)#(cd)#g' \
148                 ./menu.lst > $(KDIR)/root.grub/boot/grub/menu.lst
149         $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz 
150         mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table \
151                 -o $(KDIR)/root.iso $(KDIR)/root.grub 
152 endef 
153
154 ifneq ($(CONFIG_X86_VDI_IMAGES),)
155   define Image/Build/vdi
156     # left here because the image builder doesnt need these
157     ifeq ($(1),ext2)
158                 rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi || true
159                 VBoxManage convertfromraw -format VDI \
160                         $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
161                         $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
162                 # XXX: VBoxManage insists on setting perms to 0600
163                 chmod 0644 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
164     endif
165   endef
166 endif
167
168 ifneq ($(CONFIG_X86_VMDK_IMAGES),)
169   define Image/Build/vmdk
170     # left here because the image builder doesnt need these
171     ifeq ($(1),ext2)
172                 rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true
173                 qemu-img convert -f raw -O vmdk \
174                         $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
175                         $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk
176     endif
177   endef
178 endif
179
180 define Image/BuildKernel
181         $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
182 endef
183
184 define Image/Prepare
185         $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
186         $(call Image/Prepare/bootscript)
187         $(call Image/Prepare/grub)
188 endef
189
190 define Image/Build
191         $(call Image/Build/$(1))
192         $(call Image/Build/bootscript,$(1))
193   ifneq ($(1),iso)
194         $(call Image/Build/grub,$(1))
195         $(call Image/Build/vdi,$(1))
196         $(call Image/Build/vmdk,$(1))
197   endif
198         $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
199         $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
200   ifeq ($(1),ext2)
201         gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
202         gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
203   endif
204 endef
205
206 $(eval $(call BuildImage))
207
208 ifneq ($(CONFIG_X86_VDI_IMAGES),)
209   $(eval $(call RequireCommand,VBoxManage, \
210         You need VBoxManage to generate VirtualBox images. \
211   ))
212 endif
213
214 ifneq ($(CONFIG_X86_VMDK_IMAGES),)
215   $(eval $(call RequireCommand,qemu-img, \
216         You need qemu-img to generate VMware images. \
217   ))
218 endif