Makefile 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #
  2. # Copyright (C) 2006-2013 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. export PATH=$(TARGET_PATH):/sbin
  10. GRUB2_MODULES = biosdisk boot chain configfile ext2 linux ls part_msdos reboot serial vga
  11. GRUB2_MODULES_ISO = biosdisk boot chain configfile iso9660 linux ls part_msdos reboot serial vga
  12. GRUB_TERMINALS =
  13. GRUB_SERIAL_CONFIG =
  14. GRUB_TERMINAL_CONFIG =
  15. GRUB_CONSOLE_CMDLINE =
  16. USE_ATKBD = generic kvm_guest
  17. ifneq ($(strip $(foreach subtarget,$(USE_ATKBD),$(CONFIG_TARGET_x86_64_$(subtarget)))),)
  18. GRUB2_MODULES += at_keyboard
  19. GRUB2_MODULES_ISO += at_keyboard
  20. endif
  21. ifneq ($(CONFIG_GRUB_CONSOLE),)
  22. GRUB_CONSOLE_CMDLINE += console=tty0
  23. GRUB_TERMINALS += console
  24. endif
  25. GRUB_SERIAL:=$(call qstrip,$(CONFIG_GRUB_SERIAL))
  26. ifneq ($(GRUB_SERIAL),)
  27. GRUB_CONSOLE_CMDLINE += console=$(GRUB_SERIAL),$(CONFIG_GRUB_BAUDRATE)n8
  28. GRUB_SERIAL_CONFIG := serial --unit=0 --speed=$(CONFIG_GRUB_BAUDRATE) --word=8 --parity=no --stop=1
  29. GRUB_TERMINALS += serial
  30. endif
  31. ifneq ($(GRUB_TERMINALS),)
  32. GRUB_TERMINAL_CONFIG := terminal_input $(GRUB_TERMINALS); terminal_output $(GRUB_TERMINALS)
  33. endif
  34. ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME))
  35. GRUB_TIMEOUT:=$(call qstrip,$(CONFIG_GRUB_TIMEOUT))
  36. ifneq ($(CONFIG_GRUB_IMAGES),)
  37. BOOTOPTS:=$(call qstrip,$(CONFIG_GRUB_BOOTOPTS))
  38. define Image/cmdline/ext4
  39. root=$(ROOTPART) rootfstype=ext4 rootwait
  40. endef
  41. define Image/cmdline/jffs2-64k
  42. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
  43. endef
  44. define Image/cmdline/jffs2-128k
  45. block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
  46. endef
  47. define Image/cmdline/squashfs
  48. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootwait
  49. endef
  50. define Image/Build/grub2
  51. # left here because the image builder doesnt need these
  52. $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
  53. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  54. grub-mkimage \
  55. -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
  56. -o $(KDIR)/grub2/core.img \
  57. -O i386-pc \
  58. -c ./grub-early.cfg \
  59. $(GRUB2_MODULES)
  60. $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/grub2/
  61. echo '(hd0) $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img' > $(KDIR)/grub2/device.map
  62. sed \
  63. -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
  64. -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
  65. -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
  66. -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
  67. ./grub.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
  68. PADDING="$(CONFIG_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_generic.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. 256
  73. grub-bios-setup \
  74. --device-map="$(KDIR)/grub2/device.map" \
  75. -d "$(KDIR)/grub2" \
  76. -r "hd0,msdos1" \
  77. "$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img"
  78. $(call Image/Build/grub/$(1))
  79. endef
  80. endif
  81. ROOTDELAY=10
  82. define Image/Build/squashfs
  83. $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
  84. endef
  85. define Image/Build/iso
  86. $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
  87. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  88. grub-mkimage \
  89. -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
  90. -o $(KDIR)/grub2/eltorito.img \
  91. -O i386-pc \
  92. -c ./grub-early.cfg \
  93. $(GRUB2_MODULES_ISO)
  94. cat \
  95. $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \
  96. $(KDIR)/grub2/eltorito.img \
  97. > $(KDIR)/root.grub/boot/grub/eltorito.img
  98. sed \
  99. -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
  100. -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
  101. -e 's#@CMDLINE@#root=/dev/sr0 rootfstype=iso9660 rootwait $(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
  102. -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
  103. ./grub-iso.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
  104. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  105. mkisofs -R -b boot/grub/eltorito.img -no-emul-boot -boot-info-table \
  106. -o $(KDIR)/root.iso $(KDIR)/root.grub $(TARGET_DIR)
  107. endef
  108. ifneq ($(CONFIG_VDI_IMAGES),)
  109. define Image/Build/vdi
  110. # left here because the image builder doesnt need these
  111. ifeq ($(1),ext4)
  112. rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi || true
  113. qemu-img convert -f raw -O vdi \
  114. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  115. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
  116. # XXX: VBoxManage insists on setting perms to 0600
  117. chmod 0644 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
  118. endif
  119. endef
  120. endif
  121. ifneq ($(CONFIG_VMDK_IMAGES),)
  122. define Image/Build/vmdk
  123. # left here because the image builder doesnt need these
  124. ifeq ($(1),ext4)
  125. rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true
  126. qemu-img convert -f raw -O vmdk -o adapter_type=lsilogic \
  127. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  128. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk
  129. rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1)-esxi.vmdk || true
  130. qemu-img convert -f raw -O vmdk -o adapter_type=lsilogic,subformat=monolithicFlat \
  131. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  132. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1)-esxi.vmdk
  133. endif
  134. endef
  135. endif
  136. define Image/Build/gzip
  137. gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
  138. gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
  139. endef
  140. ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
  141. define Image/Build/gzip/ext4
  142. $(call Image/Build/gzip,ext4)
  143. endef
  144. ifneq ($(CONFIG_TARGET_IMAGES_PAD),)
  145. define Image/Build/gzip/squashfs
  146. $(call Image/Build/gzip,squashfs)
  147. endef
  148. define Image/Build/gzip/jffs2-64k
  149. $(call Image/Build/gzip,jffs2-64k)
  150. endef
  151. define Image/Build/gzip/jffs2-128k
  152. $(call Image/Build/gzip,jffs2-128k)
  153. endef
  154. endif
  155. endif
  156. define Image/BuildKernel
  157. $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
  158. endef
  159. define Image/Prepare
  160. $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
  161. $(call Image/Prepare/bootscript)
  162. $(call Image/Prepare/grub2)
  163. endef
  164. define Image/Build/Initramfs
  165. $(CP) $(KDIR)/bzImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-ramfs.bzImage
  166. endef
  167. define Image/Build
  168. $(call Image/Build/$(1))
  169. $(call Image/Build/bootscript,$(1))
  170. ifneq ($(1),iso)
  171. $(call Image/Build/grub2,$(1))
  172. $(call Image/Build/vdi,$(1))
  173. $(call Image/Build/vmdk,$(1))
  174. $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
  175. else
  176. $(CP) $(KDIR)/root.iso $(BIN_DIR)/$(IMG_PREFIX).iso
  177. endif
  178. $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
  179. $(call Image/Build/gzip/$(1))
  180. $(call Image/Build/Profile/$(PROFILE),$(1))
  181. ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
  182. $(call Image/Build/Initramfs)
  183. endif
  184. endef
  185. $(eval $(call BuildImage))
  186. $(eval $(call RequireCommand,qemu-img, \
  187. Please install qemu-img (package qemu-utils in Ubuntu/Debian). \
  188. ))