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