Root/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#
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 ifneq ($(HOST_OS),Darwin)
36
37  BOOTOPTS:=$(call qstrip,$(CONFIG_X86_GRUB_BOOTOPTS))
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_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_x86.sh \
70        $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
71        $(CONFIG_TARGET_KERNEL_PARTSIZE) $(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_TARGET_KERNEL_PARTSIZE) "" \
92        $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1)
93  endef
94
95 endif
96endif
97
98ROOTDELAY=10
99
100ifneq ($(CONFIG_OLPC_BOOTSCRIPT_IMAGES),)
101
102  define Image/cmdline/ext2
103    root=$(ROOTPART) rootfstype=ext2 rootwait
104  endef
105
106  define Image/cmdline/jffs2-64k
107    block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
108  endef
109
110  define Image/cmdline/jffs2-128k
111    block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
112  endef
113
114  define Image/cmdline/squashfs
115    block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootdelay=$(ROOTDELAY)
116  endef
117
118  define Image/Build/bootscript
119    # left here because the image builder doesnt need these
120    $(INSTALL_DIR) $(KDIR)/root.bootscript/boot
121    $(CP) $(KDIR)/bzImage $(KDIR)/root.bootscript/boot/vmlinuz
122    sed -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1))) $(BOOTOPTS)#g' \
123        ./olpc.fth > $(KDIR)/root.bootscript/boot/olpc.fth
124    PADDING="$(CONFIG_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_olpc.sh \
125        $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
126        $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.bootscript \
127        $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1)
128  endef
129
130endif
131
132define Image/Build/squashfs
133    $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
134endef
135
136define Image/Build/iso
137    $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub
138    $(CP) \
139        $(KDIR)/stage2_eltorito \
140        $(KDIR)/root.grub/boot/grub/
141    sed \
142        -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
143        -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
144        -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
145        -e 's#(hd0,0)#(cd)#g' \
146        ./menu.lst > $(KDIR)/root.grub/boot/grub/menu.lst
147    $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
148    mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table \
149        -o $(KDIR)/root.iso $(KDIR)/root.grub
150endef
151
152ifneq ($(CONFIG_X86_VDI_IMAGES),)
153  define Image/Build/vdi
154    # left here because the image builder doesnt need these
155    ifeq ($(1),ext2)
156        rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi || true
157        qemu-img convert -f raw -O vdi \
158            $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
159            $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
160        # XXX: VBoxManage insists on setting perms to 0600
161        chmod 0644 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
162    endif
163  endef
164endif
165
166ifneq ($(CONFIG_X86_VMDK_IMAGES),)
167  define Image/Build/vmdk
168    # left here because the image builder doesnt need these
169    ifeq ($(1),ext2)
170        rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true
171        qemu-img convert -f raw -O vmdk \
172            $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
173            $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk
174    endif
175  endef
176endif
177
178define Image/BuildKernel
179    $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
180endef
181
182define Image/Prepare
183    $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
184    $(call Image/Prepare/bootscript)
185    $(call Image/Prepare/grub)
186endef
187
188define Image/Build
189    $(call Image/Build/$(1))
190    $(call Image/Build/bootscript,$(1))
191  ifneq ($(1),iso)
192    $(call Image/Build/grub,$(1))
193    $(call Image/Build/vdi,$(1))
194    $(call Image/Build/vmdk,$(1))
195  endif
196    $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
197    $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
198  ifeq ($(1),ext2)
199    gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
200    gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
201  endif
202endef
203
204$(eval $(call BuildImage))
205

Archive Download this file



interactive