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