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