source: trunk/target/linux/x86/image/Makefile @ 21609

Last change on this file since 21609 was 21609, checked in by nbd, 7 years ago

x86: build fully functional images on Mac OS X, now that grub is fixed

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