Makefile 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. 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. GRUB_ROOT = hd0,msdos1
  17. USE_ATKBD = generic 64
  18. ifneq ($(strip $(foreach subtarget,$(USE_ATKBD),$(CONFIG_TARGET_x86_$(subtarget)))),)
  19. GRUB2_MODULES += at_keyboard
  20. GRUB2_MODULES_ISO += at_keyboard
  21. endif
  22. ifneq ($(CONFIG_GRUB_CONSOLE),)
  23. GRUB_CONSOLE_CMDLINE += console=tty0
  24. GRUB_TERMINALS += console
  25. endif
  26. GRUB_SERIAL:=$(call qstrip,$(CONFIG_GRUB_SERIAL))
  27. ifneq ($(GRUB_SERIAL),)
  28. GRUB_CONSOLE_CMDLINE += console=$(GRUB_SERIAL),$(CONFIG_GRUB_BAUDRATE)n8
  29. GRUB_SERIAL_CONFIG := serial --unit=0 --speed=$(CONFIG_GRUB_BAUDRATE) --word=8 --parity=no --stop=1 --rtscts=off
  30. GRUB_TERMINALS += serial
  31. endif
  32. ifneq ($(GRUB_TERMINALS),)
  33. GRUB_TERMINAL_CONFIG := terminal_input $(GRUB_TERMINALS); terminal_output $(GRUB_TERMINALS)
  34. endif
  35. SIGNATURE:=$(shell perl -e 'printf("%08x", rand(0xFFFFFFFF))')
  36. ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME))
  37. ROOTPART:=$(if $(ROOTPART),$(ROOTPART),PARTUUID=$(SIGNATURE)-02)
  38. GRUB_TIMEOUT:=$(call qstrip,$(CONFIG_GRUB_TIMEOUT))
  39. ifneq ($(CONFIG_TARGET_x86_xen_domu),)
  40. GRUB_ROOT = xen/xvda,msdos1
  41. endif
  42. ifneq ($(CONFIG_GRUB_IMAGES),)
  43. BOOTOPTS:=$(call qstrip,$(CONFIG_GRUB_BOOTOPTS))
  44. define Image/cmdline/ext4
  45. root=$(ROOTPART) rootfstype=ext4 rootwait
  46. endef
  47. define Image/cmdline/squashfs
  48. root=$(ROOTPART) 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. -p /boot/grub \
  56. -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
  57. -o $(KDIR)/grub2/core.img \
  58. -O i386-pc \
  59. -c ./grub-early.cfg \
  60. $(GRUB2_MODULES)
  61. $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/grub2/
  62. echo '(hd0) $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img' > $(KDIR)/grub2/device.map
  63. sed \
  64. -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
  65. -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
  66. -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
  67. -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
  68. -e 's#@ROOT@#$(GRUB_ROOT)#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. dd if=/dev/zero bs=128k count=1 >> $(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. -p /boot/grub \
  92. -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
  93. -o $(KDIR)/grub2/eltorito.img \
  94. -O i386-pc \
  95. -c ./grub-early.cfg \
  96. $(GRUB2_MODULES_ISO)
  97. cat \
  98. $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \
  99. $(KDIR)/grub2/eltorito.img \
  100. > $(KDIR)/root.grub/boot/grub/eltorito.img
  101. sed \
  102. -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
  103. -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
  104. -e 's#@CMDLINE@#root=/dev/sr0 rootfstype=iso9660 rootwait $(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
  105. -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
  106. ./grub-iso.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
  107. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  108. mkisofs -R -b boot/grub/eltorito.img -no-emul-boot -boot-info-table \
  109. -o $(KDIR)/root.iso $(KDIR)/root.grub $(TARGET_DIR)
  110. endef
  111. ifneq ($(CONFIG_VDI_IMAGES),)
  112. define Image/Build/vdi
  113. rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi || true
  114. qemu-img convert -f raw -O vdi \
  115. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  116. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
  117. # XXX: VBoxManage insists on setting perms to 0600
  118. chmod 0644 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
  119. endef
  120. endif
  121. ifneq ($(CONFIG_VMDK_IMAGES),)
  122. define Image/Build/vmdk
  123. rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true
  124. qemu-img convert -f raw -O vmdk \
  125. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  126. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk
  127. endef
  128. endif
  129. define Image/Build/gzip
  130. gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
  131. gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
  132. endef
  133. ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
  134. define Image/Build/gzip/ext4
  135. $(call Image/Build/gzip,ext4)
  136. endef
  137. ifneq ($(CONFIG_TARGET_IMAGES_PAD),)
  138. define Image/Build/gzip/squashfs
  139. $(call Image/Build/gzip,squashfs)
  140. endef
  141. endif
  142. endif
  143. define Image/BuildKernel
  144. $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
  145. endef
  146. define Image/Prepare
  147. $(call Image/Prepare/grub2)
  148. endef
  149. define Image/Build/Initramfs
  150. $(CP) $(KDIR)/bzImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-ramfs.bzImage
  151. endef
  152. define Image/Build
  153. $(call Image/Build/$(1))
  154. ifneq ($(1),iso)
  155. $(call Image/Build/grub2,$(1))
  156. $(call Image/Build/vdi,$(1))
  157. $(call Image/Build/vmdk,$(1))
  158. $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
  159. else
  160. $(CP) $(KDIR)/root.iso $(BIN_DIR)/$(IMG_PREFIX).iso
  161. endif
  162. $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
  163. $(call Image/Build/gzip/$(1))
  164. ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
  165. $(call Image/Build/Initramfs)
  166. endif
  167. endef
  168. $(eval $(call BuildImage))