make console port editable through menuconfig, gzip ext2 images, add suitable default...
[openwrt/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 CONSOLE=$(strip $(subst ",, $(CONFIG_X86_GRUB_CONSOLE)))
24
25
26 ifeq ($(CONFIG_X86_GRUB_IMAGES),y)
27 ifneq ($(HOST_OS),Darwin)
28 define Image/cmdline/squashfs
29 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootwait
30 endef
31
32 define Image/cmdline/jffs2-64k
33 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
34 endef
35
36 define Image/cmdline/jffs2-128k
37 block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
38 endef
39
40 define Image/cmdline/ext2
41 root=$(ROOTPART) rootfstype=ext2 rootwait
42 endef
43
44 define Image/Build/grub
45 # left here because the image builder doesnt need these
46 $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub
47 $(CP) \
48 $(KDIR)/*stage* \
49 $(KDIR)/root.grub/boot/grub/
50 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
51 sed \
52 -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1))) $(BOOTOPTS)#g' \
53 -e 's#@CONSOLE@#$(CONSOLE)#g' \
54 -e 's#@BAUDRATE@#$(CONFIG_X86_GRUB_BAUDRATE)#g' \
55 ./menu.lst > $(KDIR)/root.grub/boot/grub/menu.lst
56 PADDING="$(CONFIG_X86_GRUB_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_x86.sh $(BIN_DIR)/openwrt-$(BOARD)-$(1).image $(CONFIG_X86_GRUB_KERNELPART) $(KDIR)/root.grub $(CONFIG_TARGET_ROOTFS_FSPART) $(KDIR)/root.$(1)
57 $(call Image/Build/grub/$(1))
58 endef
59
60 define Image/Prepare/grub
61 # for the image builder
62 $(CP) \
63 $(STAGING_DIR_HOST)/usr/lib/grub/i386-*/stage1 \
64 $(STAGING_DIR_HOST)/usr/lib/grub/i386-*/stage2 \
65 $(STAGING_DIR_HOST)/usr/lib/grub/i386-*/e2fs_stage1_5 \
66 $(KDIR)/
67 endef
68 else
69 define Image/Build/grub
70 PADDING="$(CONFIG_X86_GRUB_IMAGES_PAD)" PATH="$(TARGET_PATH)" NOGRUB=1 ./gen_image_x86.sh $(BIN_DIR)/openwrt-$(BOARD)-$(1).image $(CONFIG_X86_GRUB_KERNELPART) "" $(CONFIG_TARGET_ROOTFS_FSPART) $(KDIR)/root.$(1)
71 endef
72 endif
73 endif
74
75 ifeq ($(CONFIG_X86_VDI_IMAGES),y)
76 define Image/Build/vdi
77 # left here because the image builder doesnt need these
78 ifeq ($(1),ext2)
79 rm $(BIN_DIR)/openwrt-$(BOARD)-ext2.vdi || true
80 VBoxManage convertfromraw -format VDI $(BIN_DIR)/openwrt-$(BOARD)-ext2.image $(BIN_DIR)/openwrt-$(BOARD)-ext2.vdi
81 endif
82 endef
83 endif
84
85 ifeq ($(CONFIG_X86_VMDK_IMAGES),y)
86 define Image/Build/vmdk
87 # left here because the image builder doesnt need these
88 ifeq ($(1),ext2)
89 rm $(BIN_DIR)/openwrt-$(BOARD)-ext2.vmdk || true
90 qemu-img convert -f raw $(BIN_DIR)/openwrt-$(BOARD)-ext2.image \
91 -O vmdk $(BIN_DIR)/openwrt-$(BOARD)-ext2.vmdk
92 endif
93 endef
94 endif
95
96 ROOTDELAY=10
97
98 ifeq ($(CONFIG_OLPC_BOOTSCRIPT_IMAGES),y)
99 define Image/cmdline/squashfs
100 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootdelay=$(ROOTDELAY)
101 endef
102
103 define Image/cmdline/jffs2-64k
104 block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
105 endef
106
107 define Image/cmdline/jffs2-128k
108 block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
109 endef
110
111 define Image/cmdline/ext2
112 root=$(ROOTPART) rootfstype=ext2 rootwait
113 endef
114
115 define Image/Build/bootscript
116 # left here because the image builder doesnt need these
117 $(INSTALL_DIR) $(KDIR)/root.bootscript/boot
118 $(CP) $(KDIR)/bzImage $(KDIR)/root.bootscript/boot/vmlinuz
119 sed -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1))) $(BOOTOPTS)#g' \
120 ./olpc.fth > $(KDIR)/root.bootscript/boot/olpc.fth
121 PADDING="$(CONFIG_OLPC_BOOTSCRIPT_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_olpc.sh $(BIN_DIR)/openwrt-$(BOARD)-$(1).image $(CONFIG_OLPC_BOOTSCRIPT_KERNELPART) $(KDIR)/root.bootscript $(CONFIG_TARGET_ROOTFS_FSPART) $(KDIR)/root.$(1)
122 endef
123 endif
124
125 define Image/Prepare
126 $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
127 ifeq ($(CONFIG_TARGET_x86_olpc),y)
128 $(call Image/Prepare/bootscript)
129 else
130 $(call Image/Prepare/grub)
131 endif
132 endef
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 $(STAGING_DIR_HOST)/usr/lib/grub/i386-openwrt/stage2_eltorito \
142 $(KDIR)/root.grub/boot/grub/stage2_eltorito
143 sed \
144 -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1))) $(BOOTOPTS)#g' \
145 -e 's#@BAUDRATE@#$(CONFIG_X86_GRUB_BAUDRATE)#g' \
146 -e 's#(hd0,0)#(cd)#g' \
147 ./menu.lst > $(KDIR)/root.grub/boot/grub/menu.lst
148 $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
149 mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table \
150 -o $(KDIR)/root.iso $(KDIR)/root.grub
151 endef
152
153 define Image/BuildKernel
154 $(CP) $(KDIR)/bzImage $(BIN_DIR)/openwrt-$(BOARD)-vmlinuz
155 endef
156
157 define Image/Build
158 $(call Image/Build/$(1))
159 $(call Image/Build/bootscript,$(1))
160 ifneq ($(1),iso)
161 $(call Image/Build/grub,$(1))
162 $(call Image/Build/vdi,$(1))
163 $(call Image/Build/vmdk,$(1))
164 endif
165 $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/openwrt-$(BOARD)-$(1).fs
166 $(CP) $(KDIR)/bzImage $(BIN_DIR)/openwrt-$(BOARD)-vmlinuz
167 ifeq ($(1),ext2)
168 gzip -f9 $(BIN_DIR)/openwrt-$(BOARD)-$(1).image
169 endif
170 endef
171
172 $(eval $(call BuildImage))
173
174 ifeq ($(CONFIG_X86_VDI_IMAGES),y)
175 $(eval $(call RequireCommand,VBoxManage, \
176 You need VBoxManage to generate VirtualBox images. \
177 ))
178 endif
179
180 ifeq ($(CONFIG_X86_VMDK_IMAGES),y)
181 $(eval $(call RequireCommand,qemu-img, \
182 You need qemu-img to generate VMware images. \
183 ))
184 endif