Makefile 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. 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
  28. GRUB_SERIAL_CONFIG := serial --unit=0 --speed=$(CONFIG_GRUB_BAUDRATE) --word=8 --parity=no --stop=1 --rtscts=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 dd if=/dev/urandom bs=4 count=1 2>/dev/null | hexdump -v -e '"%08x"')
  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. 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. endef
  119. endif
  120. ifneq ($(CONFIG_VMDK_IMAGES),)
  121. define Image/Build/vmdk
  122. rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true
  123. qemu-img convert -f raw -O vmdk \
  124. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  125. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk
  126. endef
  127. endif
  128. define Image/Build/gzip
  129. gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
  130. gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
  131. endef
  132. ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
  133. define Image/Build/gzip/ext4
  134. $(call Image/Build/gzip,ext4)
  135. endef
  136. ifneq ($(CONFIG_TARGET_IMAGES_PAD),)
  137. define Image/Build/gzip/squashfs
  138. $(call Image/Build/gzip,squashfs)
  139. endef
  140. define Image/Build/gzip/jffs2-64k
  141. $(call Image/Build/gzip,jffs2-64k)
  142. endef
  143. define Image/Build/gzip/jffs2-128k
  144. $(call Image/Build/gzip,jffs2-128k)
  145. endef
  146. endif
  147. endif
  148. define Image/BuildKernel
  149. $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
  150. ifneq ($(CONFIG_X86_ETHERBOOT_IMAGES),)
  151. rm -f $(BIN_DIR)/$(IMG_PREFIX)-etherboot
  152. $(STAGING_DIR_HOST)/bin/mkelfImage \
  153. --append=$(CONFIG_X86_ETHERBOOT_BOOTOPTS) \
  154. $(KDIR)/bzImage \
  155. $(BIN_DIR)/$(IMG_PREFIX)-etherboot
  156. endif
  157. endef
  158. define Image/Build/Profile/ar525w
  159. cp $(KDIR)/bzImage $(KDIR)/bzImage.tmp
  160. $(SCRIPT_DIR)/pad_image $(1) $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) 32
  161. $(STAGING_DIR_HOST)/bin/airlink -b 1 $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) \
  162. $(BIN_DIR)/$(IMG_PREFIX)-$(1)-ar525w.img
  163. $(STAGING_DIR_HOST)/bin/airlink -e -b 1 $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) \
  164. $(BIN_DIR)/$(IMG_PREFIX)-$(1)-ar525w-web.img
  165. endef
  166. define Image/Build/Profile/sitecom
  167. cp $(KDIR)/bzImage $(KDIR)/bzImage.tmp
  168. #32k config data + 20 bytes header + 2 bytes checksum after kernel image
  169. $(SCRIPT_DIR)/pad_image $(1) $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) 32790
  170. $(TOPDIR)/target/linux/rdc/image/mkimg_sitecom.pl $(KDIR)/bzImage.tmp > $(KDIR)/tmp.img
  171. cat $(KDIR)/root.$(1) >> $(KDIR)/tmp.img
  172. cp $(KDIR)/tmp.img $(BIN_DIR)/$(IMG_PREFIX)-$(1)-sitecom.img
  173. rm $(KDIR)/tmp.img $(KDIR)/bzImage.tmp
  174. endef
  175. define Image/Build/Profile/bifferboard
  176. $(TOPDIR)/target/linux/rdc/image/mkimg_bifferboard.py $(KDIR)/bzImage $(KDIR)/root.$(1) \
  177. $(BIN_DIR)/$(IMG_PREFIX)-$(1)-bifferboard.img
  178. endef
  179. define Image/Prepare
  180. $(call Image/Prepare/grub2)
  181. endef
  182. define Image/Build/Initramfs
  183. $(CP) $(KDIR)/bzImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-ramfs.bzImage
  184. endef
  185. define Image/Build
  186. $(call Image/Build/$(1))
  187. ifneq ($(1),iso)
  188. $(call Image/Build/grub2,$(1))
  189. $(call Image/Build/vdi,$(1))
  190. $(call Image/Build/vmdk,$(1))
  191. $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
  192. else
  193. $(CP) $(KDIR)/root.iso $(BIN_DIR)/$(IMG_PREFIX).iso
  194. endif
  195. $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
  196. $(call Image/Build/gzip/$(1))
  197. $(call Image/Build/Profile/$(PROFILE),$(1))
  198. ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
  199. $(call Image/Build/Initramfs)
  200. endif
  201. endef
  202. $(eval $(call BuildImage))