Makefile 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. SIGNATURE:=$(shell dd if=/dev/urandom bs=4 count=1 2>/dev/null | hexdump -v -e '"%02x"')
  35. ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME))
  36. ROOTPART:=$(if $(ROOTPART),$(ROOTPART),PARTUUID=$(SIGNATURE)-02)
  37. GRUB_TIMEOUT:=$(call qstrip,$(CONFIG_GRUB_TIMEOUT))
  38. ifneq ($(CONFIG_GRUB_IMAGES),)
  39. BOOTOPTS:=$(call qstrip,$(CONFIG_GRUB_BOOTOPTS))
  40. define Image/cmdline/ext4
  41. root=$(ROOTPART) rootfstype=ext4 rootwait
  42. endef
  43. define Image/cmdline/jffs2-64k
  44. block2mtd.block2mtd=$(ROOTPART),65536,rootfs,5 root=/dev/mtdblock0 rootfstype=jffs2 rootwait
  45. endef
  46. define Image/cmdline/jffs2-128k
  47. block2mtd.block2mtd=$(ROOTPART),131072,rootfs,5 root=/dev/mtdblock0 rootfstype=jffs2 rootwait
  48. endef
  49. define Image/cmdline/squashfs
  50. block2mtd.block2mtd=$(ROOTPART),65536,rootfs,5 root=/dev/mtdblock0 rootfstype=squashfs rootwait
  51. endef
  52. define Image/Build/grub2
  53. # left here because the image builder doesnt need these
  54. $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
  55. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  56. grub-mkimage \
  57. -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
  58. -o $(KDIR)/grub2/core.img \
  59. -O i386-pc \
  60. -c ./grub-early.cfg \
  61. $(GRUB2_MODULES)
  62. $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/grub2/
  63. echo '(hd0) $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img' > $(KDIR)/grub2/device.map
  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. -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
  69. ./grub.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
  70. PADDING="$(CONFIG_TARGET_IMAGES_PAD)" SIGNATURE="$(SIGNATURE)" PATH="$(TARGET_PATH)" ./gen_image_generic.sh \
  71. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  72. $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.grub \
  73. $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1) \
  74. 256
  75. grub-bios-setup \
  76. --device-map="$(KDIR)/grub2/device.map" \
  77. -d "$(KDIR)/grub2" \
  78. -r "hd0,msdos1" \
  79. "$(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img"
  80. $(call Image/Build/grub/$(1))
  81. endef
  82. endif
  83. ROOTDELAY=10
  84. define Image/Build/squashfs
  85. $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
  86. endef
  87. define Image/Build/iso
  88. $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
  89. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  90. grub-mkimage \
  91. -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
  92. -o $(KDIR)/grub2/eltorito.img \
  93. -O i386-pc \
  94. -c ./grub-early.cfg \
  95. $(GRUB2_MODULES_ISO)
  96. cat \
  97. $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \
  98. $(KDIR)/grub2/eltorito.img \
  99. > $(KDIR)/root.grub/boot/grub/eltorito.img
  100. sed \
  101. -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
  102. -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
  103. -e 's#@CMDLINE@#root=/dev/sr0 rootfstype=iso9660 rootwait $(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
  104. -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
  105. ./grub-iso.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
  106. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  107. mkisofs -R -b boot/grub/eltorito.img -no-emul-boot -boot-info-table \
  108. -o $(KDIR)/root.iso $(KDIR)/root.grub $(TARGET_DIR)
  109. endef
  110. ifneq ($(CONFIG_VDI_IMAGES),)
  111. define Image/Build/vdi
  112. # left here because the image builder doesnt need these
  113. ifeq ($(1),ext4)
  114. rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi || true
  115. qemu-img convert -f raw -O vdi \
  116. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  117. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
  118. # XXX: VBoxManage insists on setting perms to 0600
  119. chmod 0644 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
  120. endif
  121. endef
  122. endif
  123. ifneq ($(CONFIG_VMDK_IMAGES),)
  124. define Image/Build/vmdk
  125. # left here because the image builder doesnt need these
  126. ifeq ($(1),ext4)
  127. rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true
  128. qemu-img convert -f raw -O vmdk -o adapter_type=lsilogic \
  129. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  130. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk
  131. rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1)-esxi.vmdk || true
  132. qemu-img convert -f raw -O vmdk -o adapter_type=lsilogic,subformat=monolithicFlat \
  133. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  134. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1)-esxi.vmdk
  135. endif
  136. endef
  137. endif
  138. define Image/Build/gzip
  139. gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
  140. gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
  141. endef
  142. ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
  143. define Image/Build/gzip/ext4
  144. $(call Image/Build/gzip,ext4)
  145. endef
  146. ifneq ($(CONFIG_TARGET_IMAGES_PAD),)
  147. define Image/Build/gzip/squashfs
  148. $(call Image/Build/gzip,squashfs)
  149. endef
  150. define Image/Build/gzip/jffs2-64k
  151. $(call Image/Build/gzip,jffs2-64k)
  152. endef
  153. define Image/Build/gzip/jffs2-128k
  154. $(call Image/Build/gzip,jffs2-128k)
  155. endef
  156. endif
  157. endif
  158. define Image/BuildKernel
  159. $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
  160. endef
  161. define Image/Prepare
  162. $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
  163. $(call Image/Prepare/bootscript)
  164. $(call Image/Prepare/grub2)
  165. endef
  166. define Image/Build/Initramfs
  167. $(CP) $(KDIR)/bzImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-ramfs.bzImage
  168. endef
  169. define Image/Build
  170. $(call Image/Build/$(1))
  171. $(call Image/Build/bootscript,$(1))
  172. ifneq ($(1),iso)
  173. $(call Image/Build/grub2,$(1))
  174. $(call Image/Build/vdi,$(1))
  175. $(call Image/Build/vmdk,$(1))
  176. $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
  177. else
  178. $(CP) $(KDIR)/root.iso $(BIN_DIR)/$(IMG_PREFIX).iso
  179. endif
  180. $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
  181. $(call Image/Build/gzip/$(1))
  182. $(call Image/Build/Profile/$(PROFILE),$(1))
  183. ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
  184. $(call Image/Build/Initramfs)
  185. endif
  186. endef
  187. $(eval $(call BuildImage))
  188. $(eval $(call RequireCommand,qemu-img, \
  189. Please install qemu-img (package qemu-utils in Ubuntu/Debian). \
  190. ))