1
0

Makefile 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 test vga
  11. GRUB2_MODULES_ISO = biosdisk boot chain configfile iso9660 linux ls part_msdos reboot serial test vga
  12. GRUB_TERMINALS =
  13. GRUB_SERIAL_CONFIG =
  14. GRUB_TERMINAL_CONFIG =
  15. GRUB_CONSOLE_CMDLINE =
  16. USE_ATKBD = generic 64
  17. ifneq ($(strip $(foreach subtarget,$(USE_ATKBD),$(CONFIG_TARGET_x86_$(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$(if $(CONFIG_GRUB_FLOWCONTROL),r,)
  28. GRUB_SERIAL_CONFIG := serial --unit=0 --speed=$(CONFIG_GRUB_BAUDRATE) --word=8 --parity=no --stop=1 --rtscts=$(if $(CONFIG_GRUB_FLOWCONTROL),on,off)
  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 perl -e 'printf("%08x", rand(0xFFFFFFFF))')
  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. GRUB_TITLE:=$(call qstrip,$(CONFIG_GRUB_TITLE))
  39. ifneq ($(CONFIG_GRUB_IMAGES),)
  40. BOOTOPTS:=$(call qstrip,$(CONFIG_GRUB_BOOTOPTS))
  41. define Image/cmdline/ext4
  42. root=$(ROOTPART) rootfstype=ext4 rootwait
  43. endef
  44. define Image/cmdline/squashfs
  45. root=$(ROOTPART) rootfstype=squashfs rootwait
  46. endef
  47. define Image/Build/grub2
  48. # left here because the image builder doesnt need these
  49. $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
  50. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  51. grub-mkimage \
  52. -p /boot/grub \
  53. -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
  54. -o $(KDIR)/grub2/core.img \
  55. -O i386-pc \
  56. -c ./grub-early.cfg \
  57. $(GRUB2_MODULES)
  58. $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/grub2/
  59. echo '(hd0) $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img' > $(KDIR)/grub2/device.map
  60. sed \
  61. -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
  62. -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
  63. -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
  64. -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
  65. -e 's#@TITLE@#$(GRUB_TITLE)#g' \
  66. ./grub.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
  67. -$(CP) $(STAGING_DIR_ROOT)/boot/. $(KDIR)/root.grub/boot/
  68. PADDING="$(CONFIG_TARGET_IMAGES_PAD)" SIGNATURE="$(SIGNATURE)" PATH="$(TARGET_PATH)" $(SCRIPT_DIR)/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. endef
  79. endif
  80. define Image/Build/squashfs
  81. dd if=/dev/zero bs=128k count=1 >> $(KDIR)/root.squashfs
  82. endef
  83. define Image/Build/iso
  84. $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
  85. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  86. grub-mkimage \
  87. -p /boot/grub \
  88. -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
  89. -o $(KDIR)/grub2/eltorito.img \
  90. -O i386-pc \
  91. -c ./grub-early.cfg \
  92. $(GRUB2_MODULES_ISO)
  93. cat \
  94. $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \
  95. $(KDIR)/grub2/eltorito.img \
  96. > $(KDIR)/root.grub/boot/grub/eltorito.img
  97. sed \
  98. -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
  99. -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
  100. -e 's#@CMDLINE@#root=/dev/sr0 rootfstype=iso9660 rootwait $(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
  101. -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
  102. -e 's#@TITLE@#$(GRUB_TITLE)#g' \
  103. ./grub-iso.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
  104. -$(CP) $(STAGING_DIR_ROOT)/boot/. $(KDIR)/root.grub/boot/
  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. rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi || true
  111. qemu-img convert -f raw -O vdi \
  112. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  113. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
  114. endef
  115. endif
  116. ifneq ($(CONFIG_VMDK_IMAGES),)
  117. define Image/Build/vmdk
  118. rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true
  119. qemu-img convert -f raw -O vmdk \
  120. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  121. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk
  122. endef
  123. endif
  124. define Image/Build/gzip
  125. gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
  126. gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
  127. endef
  128. ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
  129. define Image/Build/gzip/ext4
  130. $(call Image/Build/gzip,ext4)
  131. endef
  132. define Image/Build/gzip/squashfs
  133. $(call Image/Build/gzip,squashfs)
  134. endef
  135. endif
  136. define Image/BuildKernel
  137. $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
  138. endef
  139. define Image/Prepare
  140. $(call Image/Prepare/grub2)
  141. endef
  142. define Image/Build/Initramfs
  143. $(CP) $(KDIR)/bzImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-ramfs.bzImage
  144. endef
  145. define Image/Build
  146. $(call Image/Build/$(1))
  147. ifneq ($(1),iso)
  148. $(call Image/Build/grub2,$(1))
  149. $(call Image/Build/vdi,$(1))
  150. $(call Image/Build/vmdk,$(1))
  151. $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
  152. else
  153. $(CP) $(KDIR)/root.iso $(BIN_DIR)/$(IMG_PREFIX).iso
  154. endif
  155. $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
  156. $(call Image/Build/gzip/$(1))
  157. ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
  158. $(call Image/Build/Initramfs)
  159. endif
  160. endef
  161. $(eval $(call BuildImage))