Makefile 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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 kvm_guest
  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
  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. ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME))
  35. GRUB_TIMEOUT:=$(call qstrip,$(CONFIG_GRUB_TIMEOUT))
  36. ifneq ($(CONFIG_GRUB_IMAGES),)
  37. BOOTOPTS:=$(call qstrip,$(CONFIG_GRUB_BOOTOPTS))
  38. define Image/cmdline/ext4
  39. root=$(ROOTPART) rootfstype=ext4 rootwait
  40. endef
  41. define Image/cmdline/jffs2-64k
  42. block2mtd.block2mtd=$(ROOTPART),65536,rootfs,5 root=/dev/mtdblock0 rootfstype=jffs2 rootwait
  43. endef
  44. define Image/cmdline/jffs2-128k
  45. block2mtd.block2mtd=$(ROOTPART),131072,rootfs,5 root=/dev/mtdblock0 rootfstype=jffs2 rootwait
  46. endef
  47. define Image/cmdline/squashfs
  48. block2mtd.block2mtd=$(ROOTPART),65536,rootfs,5 root=/dev/mtdblock0 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. -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
  56. -o $(KDIR)/grub2/core.img \
  57. -O i386-pc \
  58. -c ./grub-early.cfg \
  59. $(GRUB2_MODULES)
  60. $(CP) $(STAGING_DIR_HOST)/lib/grub/i386-pc/*.img $(KDIR)/grub2/
  61. echo '(hd0) $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img' > $(KDIR)/grub2/device.map
  62. sed \
  63. -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
  64. -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
  65. -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
  66. -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
  67. ./grub.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
  68. PADDING="$(CONFIG_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./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. $(call Image/Build/grub/$(1))
  79. endef
  80. endif
  81. ROOTDELAY=10
  82. ifneq ($(CONFIG_OLPC_BOOTSCRIPT_IMAGES),)
  83. define Image/cmdline/ext4
  84. root=$(ROOTPART) rootfstype=ext4 rootwait
  85. endef
  86. define Image/cmdline/jffs2-64k
  87. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
  88. endef
  89. define Image/cmdline/jffs2-128k
  90. block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
  91. endef
  92. define Image/cmdline/squashfs
  93. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootdelay=$(ROOTDELAY)
  94. endef
  95. define Image/Build/bootscript
  96. # left here because the image builder doesnt need these
  97. $(INSTALL_DIR) $(KDIR)/root.bootscript/boot
  98. $(CP) $(KDIR)/bzImage $(KDIR)/root.bootscript/boot/vmlinuz
  99. sed -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1))) $(BOOTOPTS)#g' \
  100. ./olpc.fth > $(KDIR)/root.bootscript/boot/olpc.fth
  101. PADDING="$(CONFIG_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_olpc.sh \
  102. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  103. $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.bootscript \
  104. $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1)
  105. endef
  106. endif
  107. define Image/Build/squashfs
  108. $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
  109. endef
  110. define Image/Build/iso
  111. $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub $(KDIR)/grub2
  112. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  113. grub-mkimage \
  114. -d $(STAGING_DIR_HOST)/lib/grub/i386-pc \
  115. -o $(KDIR)/grub2/eltorito.img \
  116. -O i386-pc \
  117. -c ./grub-early.cfg \
  118. $(GRUB2_MODULES_ISO)
  119. cat \
  120. $(STAGING_DIR_HOST)/lib/grub/i386-pc/cdboot.img \
  121. $(KDIR)/grub2/eltorito.img \
  122. > $(KDIR)/root.grub/boot/grub/eltorito.img
  123. sed \
  124. -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
  125. -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
  126. -e 's#@CMDLINE@#root=/dev/sr0 rootfstype=iso9660 rootwait $(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
  127. -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
  128. ./grub-iso.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg
  129. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  130. mkisofs -R -b boot/grub/eltorito.img -no-emul-boot -boot-info-table \
  131. -o $(KDIR)/root.iso $(KDIR)/root.grub $(TARGET_DIR)
  132. endef
  133. ifneq ($(CONFIG_VDI_IMAGES),)
  134. define Image/Build/vdi
  135. rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi || true
  136. qemu-img convert -f raw -O vdi \
  137. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  138. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
  139. # XXX: VBoxManage insists on setting perms to 0600
  140. chmod 0644 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
  141. endef
  142. endif
  143. ifneq ($(CONFIG_VMDK_IMAGES),)
  144. define Image/Build/vmdk
  145. rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true
  146. qemu-img convert -f raw -O vmdk \
  147. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  148. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk
  149. endef
  150. endif
  151. define Image/Build/gzip
  152. gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
  153. gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
  154. endef
  155. ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
  156. define Image/Build/gzip/ext4
  157. $(call Image/Build/gzip,ext4)
  158. endef
  159. ifneq ($(CONFIG_TARGET_IMAGES_PAD),)
  160. define Image/Build/gzip/squashfs
  161. $(call Image/Build/gzip,squashfs)
  162. endef
  163. define Image/Build/gzip/jffs2-64k
  164. $(call Image/Build/gzip,jffs2-64k)
  165. endef
  166. define Image/Build/gzip/jffs2-128k
  167. $(call Image/Build/gzip,jffs2-128k)
  168. endef
  169. endif
  170. endif
  171. define Image/BuildKernel
  172. $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
  173. ifneq ($(CONFIG_X86_ETHERBOOT_IMAGES),)
  174. rm -f $(BIN_DIR)/$(IMG_PREFIX)-etherboot
  175. $(STAGING_DIR_HOST)/bin/mkelfImage \
  176. --append=$(CONFIG_X86_ETHERBOOT_BOOTOPTS) \
  177. $(KDIR)/bzImage \
  178. $(BIN_DIR)/$(IMG_PREFIX)-etherboot
  179. endif
  180. endef
  181. define Image/Build/Profile/ar525w
  182. cp $(KDIR)/bzImage $(KDIR)/bzImage.tmp
  183. $(SCRIPT_DIR)/pad_image $(1) $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) 32
  184. $(STAGING_DIR_HOST)/bin/airlink -b 1 $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) \
  185. $(BIN_DIR)/$(IMG_PREFIX)-$(1)-ar525w.img
  186. $(STAGING_DIR_HOST)/bin/airlink -e -b 1 $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) \
  187. $(BIN_DIR)/$(IMG_PREFIX)-$(1)-ar525w-web.img
  188. endef
  189. define Image/Build/Profile/sitecom
  190. cp $(KDIR)/bzImage $(KDIR)/bzImage.tmp
  191. #32k config data + 20 bytes header + 2 bytes checksum after kernel image
  192. $(SCRIPT_DIR)/pad_image $(1) $(KDIR)/bzImage.tmp $(KDIR)/root.$(1) 32790
  193. $(TOPDIR)/target/linux/rdc/image/mkimg_sitecom.pl $(KDIR)/bzImage.tmp > $(KDIR)/tmp.img
  194. cat $(KDIR)/root.$(1) >> $(KDIR)/tmp.img
  195. cp $(KDIR)/tmp.img $(BIN_DIR)/$(IMG_PREFIX)-$(1)-sitecom.img
  196. rm $(KDIR)/tmp.img $(KDIR)/bzImage.tmp
  197. endef
  198. define Image/Build/Profile/bifferboard
  199. $(TOPDIR)/target/linux/rdc/image/mkimg_bifferboard.py $(KDIR)/bzImage $(KDIR)/root.$(1) \
  200. $(BIN_DIR)/$(IMG_PREFIX)-$(1)-bifferboard.img
  201. endef
  202. define Image/Prepare
  203. $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
  204. $(call Image/Prepare/bootscript)
  205. $(call Image/Prepare/grub2)
  206. endef
  207. define Image/Build/Initramfs
  208. $(CP) $(KDIR)/bzImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-ramfs.bzImage
  209. endef
  210. define Image/Build
  211. $(call Image/Build/$(1))
  212. $(call Image/Build/bootscript,$(1))
  213. ifneq ($(1),iso)
  214. $(call Image/Build/grub2,$(1))
  215. $(call Image/Build/vdi,$(1))
  216. $(call Image/Build/vmdk,$(1))
  217. $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
  218. else
  219. $(CP) $(KDIR)/root.iso $(BIN_DIR)/$(IMG_PREFIX).iso
  220. endif
  221. $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
  222. $(call Image/Build/gzip/$(1))
  223. $(call Image/Build/Profile/$(PROFILE),$(1))
  224. ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
  225. $(call Image/Build/Initramfs)
  226. endif
  227. endef
  228. $(eval $(call BuildImage))