| 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 | GRUB2_MODULES = biosdisk boot chain configfile ext2 linux ls part_msdos reboot serial vga |
| 13 | GRUB2_MODULES_ISO = biosdisk boot chain configfile iso9660 linux ls part_msdos reboot serial vga |
| 14 | GRUB_TERMINALS = |
| 15 | GRUB_SERIAL_CONFIG = |
| 16 | GRUB_TERMINAL_CONFIG = |
| 17 | GRUB_CONSOLE_CMDLINE = |
| 18 | |
| 19 | USE_ATKBD = generic kvm_guest |
| 20 | |
| 21 | ifneq ($(strip $(foreach subtarget,$(USE_ATKBD),$(CONFIG_TARGET_x86_$(subtarget)))),) |
| 22 | GRUB2_MODULES += at_keyboard |
| 23 | GRUB2_MODULES_ISO += at_keyboard |
| 24 | endif |
| 25 | |
| 26 | ifneq ($(CONFIG_X86_GRUB_CONSOLE),) |
| 27 | GRUB_CONSOLE_CMDLINE += console=tty0 |
| 28 | GRUB_TERMINALS += console |
| 29 | endif |
| 30 | |
| 31 | ifneq ($(CONFIG_X86_GRUB_SERIAL),) |
| 32 | GRUB_CONSOLE_CMDLINE += console=$(call qstrip,$(CONFIG_X86_GRUB_SERIAL)),$(CONFIG_X86_GRUB_BAUDRATE)n8 |
| 33 | GRUB_SERIAL_CONFIG := serial --unit=0 --speed=$(CONFIG_X86_GRUB_BAUDRATE) --word=8 --parity=no --stop=1 |
| 34 | GRUB_TERMINALS += serial |
| 35 | endif |
| 36 | |
| 37 | ifneq ($(GRUB_TERMINALS),) |
| 38 | GRUB_TERMINAL_CONFIG := terminal_input $(GRUB_TERMINALS); terminal_output $(GRUB_TERMINALS) |
| 39 | endif |
| 40 | |
| 41 | ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME)) |
| 42 | |
| 43 | GRUB_TIMEOUT:=$(call qstrip,$(CONFIG_X86_GRUB_TIMEOUT)) |
| 44 | |
| 45 | ifneq ($(CONFIG_X86_GRUB_IMAGES),) |
| 46 | |
| 47 | BOOTOPTS:=$(call qstrip,$(CONFIG_X86_GRUB_BOOTOPTS)) |
| 48 | |
| 49 | define Image/cmdline/ext4 |
| 50 | root=$(ROOTPART) rootfstype=ext4 rootwait |
| 51 | endef |
| 52 | |
| 53 | define Image/cmdline/jffs2-64k |
| 54 | block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait |
| 55 | endef |
| 56 | |
| 57 | define Image/cmdline/jffs2-128k |
| 58 | block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait |
| 59 | endef |
| 60 | |
| 61 | define Image/cmdline/squashfs |
| 62 | block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootwait |
| 63 | endef |
| 64 | |
| 65 | define Image/Build/grub2 |
| 66 | # left here because the image builder doesnt need these |
| 67 | $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2 |
| 68 | $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz |
| 69 | grub-mkimage \ |
| 70 | -o $(KDIR)/grub2/core.img \ |
| 71 | -O i386-pc \ |
| 72 | -c ./grub-early.cfg \ |
| 73 | $(GRUB2_MODULES) |
| 74 | $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/grub2/ |
| 75 | echo '(hd0) $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img' > $(KDIR)/grub2/device.map |
| 76 | sed \ |
| 77 | -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \ |
| 78 | -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \ |
| 79 | -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \ |
| 80 | -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \ |
| 81 | ./grub.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg |
| 82 | PADDING="$(CONFIG_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_generic.sh \ |
| 83 | $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \ |
| 84 | $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.grub \ |
| 85 | $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1) \ |
| 86 | 256 |
| 87 | grub-bios-setup \ |
| 88 | --device-map="$(KDIR)/grub2/device.map" \ |
| 89 | -d "$(KDIR)/grub2" \ |
| 90 | -r "hd0,msdos1" \ |
| 91 | "$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img" |
| 92 | $(call Image/Build/grub/$(1)) |
| 93 | endef |
| 94 | endif |
| 95 | |
| 96 | ROOTDELAY=10 |
| 97 | |
| 98 | ifneq ($(CONFIG_OLPC_BOOTSCRIPT_IMAGES),) |
| 99 | |
| 100 | define Image/cmdline/ext4 |
| 101 | root=$(ROOTPART) rootfstype=ext4 rootwait |
| 102 | endef |
| 103 | |
| 104 | define Image/cmdline/jffs2-64k |
| 105 | block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY) |
| 106 | endef |
| 107 | |
| 108 | define Image/cmdline/jffs2-128k |
| 109 | block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY) |
| 110 | endef |
| 111 | |
| 112 | define Image/cmdline/squashfs |
| 113 | block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootdelay=$(ROOTDELAY) |
| 114 | endef |
| 115 | |
| 116 | define Image/Build/bootscript |
| 117 | # left here because the image builder doesnt need these |
| 118 | $(INSTALL_DIR) $(KDIR)/root.bootscript/boot |
| 119 | $(CP) $(KDIR)/bzImage $(KDIR)/root.bootscript/boot/vmlinuz |
| 120 | sed -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1))) $(BOOTOPTS)#g' \ |
| 121 | ./olpc.fth > $(KDIR)/root.bootscript/boot/olpc.fth |
| 122 | PADDING="$(CONFIG_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_olpc.sh \ |
| 123 | $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \ |
| 124 | $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.bootscript \ |
| 125 | $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1) |
| 126 | endef |
| 127 | |
| 128 | endif |
| 129 | |
| 130 | define Image/Build/squashfs |
| 131 | $(call prepare_generic_squashfs,$(KDIR)/root.squashfs) |
| 132 | endef |
| 133 | |
| 134 | define Image/Build/iso |
| 135 | $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2 |
| 136 | $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz |
| 137 | grub-mkimage \ |
| 138 | -o $(KDIR)/grub2/eltorito.img \ |
| 139 | -O i386-pc \ |
| 140 | -c ./grub-early.cfg \ |
| 141 | $(GRUB2_MODULES_ISO) |
| 142 | cat \ |
| 143 | $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \ |
| 144 | $(KDIR)/grub2/eltorito.img \ |
| 145 | > $(KDIR)/root.grub/boot/grub/eltorito.img |
| 146 | sed \ |
| 147 | -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \ |
| 148 | -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \ |
| 149 | -e 's#@CMDLINE@#root=/dev/sr0 rootfstype=iso9660 rootwait $(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \ |
| 150 | -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \ |
| 151 | ./grub-iso.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg |
| 152 | $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz |
| 153 | mkisofs -R -b boot/grub/eltorito.img -no-emul-boot -boot-info-table \ |
| 154 | -o $(KDIR)/root.iso $(KDIR)/root.grub $(TARGET_DIR) |
| 155 | endef |
| 156 | |
| 157 | ifneq ($(CONFIG_X86_VDI_IMAGES),) |
| 158 | define Image/Build/vdi |
| 159 | # left here because the image builder doesnt need these |
| 160 | ifeq ($(1),ext4) |
| 161 | rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi || true |
| 162 | qemu-img convert -f raw -O vdi \ |
| 163 | $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \ |
| 164 | $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi |
| 165 | # XXX: VBoxManage insists on setting perms to 0600 |
| 166 | chmod 0644 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi |
| 167 | endif |
| 168 | endef |
| 169 | endif |
| 170 | |
| 171 | ifneq ($(CONFIG_X86_VMDK_IMAGES),) |
| 172 | define Image/Build/vmdk |
| 173 | # left here because the image builder doesnt need these |
| 174 | ifeq ($(1),ext4) |
| 175 | rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true |
| 176 | qemu-img convert -f raw -O vmdk \ |
| 177 | $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \ |
| 178 | $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk |
| 179 | endif |
| 180 | endef |
| 181 | endif |
| 182 | |
| 183 | define Image/Build/gzip |
| 184 | gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img |
| 185 | gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img |
| 186 | endef |
| 187 | |
| 188 | ifneq ($(CONFIG_TARGET_IMAGES_GZIP),) |
| 189 | define Image/Build/gzip/ext4 |
| 190 | $(call Image/Build/gzip,ext4) |
| 191 | endef |
| 192 | ifneq ($(CONFIG_TARGET_IMAGES_PAD),) |
| 193 | define Image/Build/gzip/squashfs |
| 194 | $(call Image/Build/gzip,squashfs) |
| 195 | endef |
| 196 | define Image/Build/gzip/jffs2-64k |
| 197 | $(call Image/Build/gzip,jffs2-64k) |
| 198 | endef |
| 199 | define Image/Build/gzip/jffs2-128k |
| 200 | $(call Image/Build/gzip,jffs2-128k) |
| 201 | endef |
| 202 | endif |
| 203 | endif |
| 204 | |
| 205 | define Image/BuildKernel |
| 206 | $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz |
| 207 | ifneq ($(CONFIG_X86_ETHERBOOT_IMAGES),) |
| 208 | rm -f $(BIN_DIR)/$(IMG_PREFIX)-etherboot |
| 209 | $(STAGING_DIR_HOST)/bin/mkelfImage \ |
| 210 | --append=$(CONFIG_X86_ETHERBOOT_BOOTOPTS) \ |
| 211 | $(KDIR)/bzImage \ |
| 212 | $(BIN_DIR)/$(IMG_PREFIX)-etherboot |
| 213 | endif |
| 214 | endef |
| 215 | |
| 216 | define Image/Build/Profile/ar525w |
| 217 | cp $(KDIR)/bzImage $(KDIR)/bzImage.tmp |
| 218 | $(SCRIPT_DIR)/pad_image $(1) $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) 32 |
| 219 | $(STAGING_DIR_HOST)/bin/airlink -b 1 $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) \ |
| 220 | $(BIN_DIR)/$(IMG_PREFIX)-$(1)-ar525w.img |
| 221 | $(STAGING_DIR_HOST)/bin/airlink -e -b 1 $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) \ |
| 222 | $(BIN_DIR)/$(IMG_PREFIX)-$(1)-ar525w-web.img |
| 223 | endef |
| 224 | |
| 225 | define Image/Build/Profile/sitecom |
| 226 | cp $(KDIR)/bzImage $(KDIR)/bzImage.tmp |
| 227 | #32k config data + 20 bytes header + 2 bytes checksum after kernel image |
| 228 | $(SCRIPT_DIR)/pad_image $(1) $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) 32790 |
| 229 | $(TOPDIR)/target/linux/rdc/image/mkimg_sitecom.pl $(KDIR)/bzImage.tmp > $(KDIR)/tmp.img |
| 230 | cat $(KDIR)/root.$(1) >> $(KDIR)/tmp.img |
| 231 | cp $(KDIR)/tmp.img $(BIN_DIR)/$(IMG_PREFIX)-$(1)-sitecom.img |
| 232 | rm $(KDIR)/tmp.img $(KDIR)/bzImage.tmp |
| 233 | endef |
| 234 | |
| 235 | define Image/Build/Profile/bifferboard |
| 236 | $(TOPDIR)/target/linux/rdc/image/mkimg_bifferboard.py $(KDIR)/bzImage $(KDIR)/root.$(1) \ |
| 237 | $(BIN_DIR)/$(IMG_PREFIX)-$(1)-bifferboard.img |
| 238 | endef |
| 239 | |
| 240 | define Image/Prepare |
| 241 | $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage |
| 242 | $(call Image/Prepare/bootscript) |
| 243 | $(call Image/Prepare/grub2) |
| 244 | endef |
| 245 | |
| 246 | define Image/Build/Initramfs |
| 247 | $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-ramfs.bzImage |
| 248 | endef |
| 249 | |
| 250 | define Image/Build |
| 251 | $(call Image/Build/$(1)) |
| 252 | $(call Image/Build/bootscript,$(1)) |
| 253 | ifneq ($(1),iso) |
| 254 | $(call Image/Build/grub2,$(1)) |
| 255 | $(call Image/Build/vdi,$(1)) |
| 256 | $(call Image/Build/vmdk,$(1)) |
| 257 | $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img |
| 258 | else |
| 259 | $(CP) $(KDIR)/root.iso $(BIN_DIR)/$(IMG_PREFIX).iso |
| 260 | endif |
| 261 | $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz |
| 262 | $(call Image/Build/gzip/$(1)) |
| 263 | $(call Image/Build/Profile/$(PROFILE),$(1)) |
| 264 | ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y) |
| 265 | $(call Image/Build/Initramfs) |
| 266 | endif |
| 267 | endef |
| 268 | |
| 269 | $(eval $(call BuildImage)) |
| 270 | |