Makefile 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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$(if $(CONFIG_GRUB_FLOWCONTROL),r,)
  29. GRUB_SERIAL_CONFIG := serial --unit=0 --speed=$(CONFIG_GRUB_BAUDRATE) --word=8 --parity=no --stop=1 --rtscts=$(if $(CONFIG_GRUB_FLOWCONTROL),on,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. endef
  81. endif
  82. define Image/Build/squashfs
  83. dd if=/dev/zero bs=128k count=1 >> $(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. -p /boot/grub \
  90. -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
  91. -o $(KDIR)/grub2/eltorito.img \
  92. -O i386-pc \
  93. -c ./grub-early.cfg \
  94. $(GRUB2_MODULES_ISO)
  95. cat \
  96. $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \
  97. $(KDIR)/grub2/eltorito.img \
  98. > $(KDIR)/root.grub/boot/grub/eltorito.img
  99. sed \
  100. -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
  101. -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
  102. -e 's#@CMDLINE@#root=/dev/sr0 rootfstype=iso9660 rootwait $(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
  103. -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
  104. ./grub-iso.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
  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. # XXX: VBoxManage insists on setting perms to 0600
  115. chmod 0644 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
  116. endef
  117. endif
  118. ifneq ($(CONFIG_VMDK_IMAGES),)
  119. define Image/Build/vmdk
  120. rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true
  121. qemu-img convert -f raw -O vmdk \
  122. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  123. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk
  124. endef
  125. endif
  126. define Image/Build/gzip
  127. gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
  128. gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
  129. endef
  130. ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
  131. define Image/Build/gzip/ext4
  132. $(call Image/Build/gzip,ext4)
  133. endef
  134. ifneq ($(CONFIG_TARGET_IMAGES_PAD),)
  135. define Image/Build/gzip/squashfs
  136. $(call Image/Build/gzip,squashfs)
  137. endef
  138. endif
  139. endif
  140. define Image/BuildKernel
  141. $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
  142. endef
  143. define Image/Prepare
  144. $(call Image/Prepare/grub2)
  145. endef
  146. define Image/Build/Initramfs
  147. $(CP) $(KDIR)/bzImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-ramfs.bzImage
  148. endef
  149. define Image/Build
  150. $(call Image/Build/$(1))
  151. ifneq ($(1),iso)
  152. $(call Image/Build/grub2,$(1))
  153. $(call Image/Build/vdi,$(1))
  154. $(call Image/Build/vmdk,$(1))
  155. $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
  156. else
  157. $(CP) $(KDIR)/root.iso $(BIN_DIR)/$(IMG_PREFIX).iso
  158. endif
  159. $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
  160. $(call Image/Build/gzip/$(1))
  161. ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
  162. $(call Image/Build/Initramfs)
  163. endif
  164. endef
  165. $(eval $(call BuildImage))