Makefile 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. GRUB_TERMINALS =
  11. GRUB_SERIAL_CONFIG =
  12. GRUB_TERMINAL_CONFIG =
  13. GRUB_CONSOLE_CMDLINE =
  14. ifneq ($(CONFIG_X86_GRUB_CONSOLE),)
  15. GRUB_CONSOLE_CMDLINE += console=tty0
  16. GRUB_TERMINALS += console
  17. endif
  18. ifneq ($(CONFIG_X86_GRUB_SERIAL),)
  19. GRUB_CONSOLE_CMDLINE += console=$(call qstrip,$(CONFIG_X86_GRUB_SERIAL)),$(CONFIG_X86_GRUB_BAUDRATE)n8
  20. GRUB_SERIAL_CONFIG := serial --unit=0 --speed=$(CONFIG_X86_GRUB_BAUDRATE) --word=8 --parity=no --stop=1
  21. GRUB_TERMINALS += serial
  22. endif
  23. ifneq ($(GRUB_TERMINALS),)
  24. GRUB_TERMINAL_CONFIG := terminal --timeout=2 $(GRUB_TERMINALS)
  25. endif
  26. ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME))
  27. GRUB_TIMEOUT:=$(call qstrip,$(CONFIG_X86_GRUB_TIMEOUT))
  28. ifneq ($(CONFIG_X86_GRUB_IMAGES),)
  29. BOOTOPTS:=$(call qstrip,$(CONFIG_X86_GRUB_BOOTOPTS))
  30. define Image/cmdline/ext4
  31. root=$(ROOTPART) rootfstype=ext4 rootwait
  32. endef
  33. define Image/cmdline/jffs2-64k
  34. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
  35. endef
  36. define Image/cmdline/jffs2-128k
  37. block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
  38. endef
  39. define Image/cmdline/squashfs
  40. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootwait
  41. endef
  42. define Image/Build/grub
  43. # left here because the image builder doesnt need these
  44. $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub
  45. $(CP) \
  46. $(KDIR)/stage1 \
  47. $(KDIR)/stage2 \
  48. $(KDIR)/e2fs_stage1_5 \
  49. $(KDIR)/root.grub/boot/grub/
  50. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  51. sed \
  52. -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
  53. -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
  54. -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
  55. -e 's#@TIMEOUT@#$(GRUB_TIMEOUT)#g' \
  56. ./menu.lst > $(KDIR)/root.grub/boot/grub/menu.lst
  57. PADDING="$(CONFIG_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_x86.sh \
  58. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  59. $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.grub \
  60. $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1)
  61. $(call Image/Build/grub/$(1))
  62. endef
  63. define Image/Prepare/grub
  64. # for the image builder
  65. $(CP) \
  66. $(STAGING_DIR)/usr/lib/grub/i386-openwrt/stage1 \
  67. $(STAGING_DIR)/usr/lib/grub/i386-openwrt/stage2 \
  68. $(STAGING_DIR)/usr/lib/grub/i386-openwrt/stage2_eltorito \
  69. $(STAGING_DIR)/usr/lib/grub/i386-openwrt/e2fs_stage1_5 \
  70. $(KDIR)/
  71. endef
  72. endif
  73. ROOTDELAY=10
  74. ifneq ($(CONFIG_OLPC_BOOTSCRIPT_IMAGES),)
  75. define Image/cmdline/ext4
  76. root=$(ROOTPART) rootfstype=ext4 rootwait
  77. endef
  78. define Image/cmdline/jffs2-64k
  79. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
  80. endef
  81. define Image/cmdline/jffs2-128k
  82. block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
  83. endef
  84. define Image/cmdline/squashfs
  85. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootdelay=$(ROOTDELAY)
  86. endef
  87. define Image/Build/bootscript
  88. # left here because the image builder doesnt need these
  89. $(INSTALL_DIR) $(KDIR)/root.bootscript/boot
  90. $(CP) $(KDIR)/bzImage $(KDIR)/root.bootscript/boot/vmlinuz
  91. sed -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1))) $(BOOTOPTS)#g' \
  92. ./olpc.fth > $(KDIR)/root.bootscript/boot/olpc.fth
  93. PADDING="$(CONFIG_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_olpc.sh \
  94. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  95. $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.bootscript \
  96. $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1)
  97. endef
  98. endif
  99. define Image/Build/squashfs
  100. $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
  101. endef
  102. define Image/Build/iso
  103. $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub
  104. $(CP) \
  105. $(KDIR)/stage2_eltorito \
  106. $(KDIR)/root.grub/boot/grub/
  107. sed \
  108. -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
  109. -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
  110. -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
  111. -e 's#(hd0,0)#(cd)#g' \
  112. ./menu.lst > $(KDIR)/root.grub/boot/grub/menu.lst
  113. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  114. mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table \
  115. -o $(KDIR)/root.iso $(KDIR)/root.grub
  116. endef
  117. ifneq ($(CONFIG_X86_VDI_IMAGES),)
  118. define Image/Build/vdi
  119. # left here because the image builder doesnt need these
  120. ifeq ($(1),ext4)
  121. rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi || true
  122. qemu-img convert -f raw -O vdi \
  123. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  124. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
  125. # XXX: VBoxManage insists on setting perms to 0600
  126. chmod 0644 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
  127. endif
  128. endef
  129. endif
  130. ifneq ($(CONFIG_X86_VMDK_IMAGES),)
  131. define Image/Build/vmdk
  132. # left here because the image builder doesnt need these
  133. ifeq ($(1),ext4)
  134. rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true
  135. qemu-img convert -f raw -O vmdk \
  136. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  137. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk
  138. endif
  139. endef
  140. endif
  141. define Image/Build/gzip
  142. gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
  143. gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
  144. endef
  145. ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
  146. define Image/Build/gzip/ext4
  147. $(call Image/Build/gzip,ext4)
  148. endef
  149. ifneq ($(CONFIG_TARGET_IMAGES_PAD),)
  150. define Image/Build/gzip/squashfs
  151. $(call Image/Build/gzip,squashfs)
  152. endef
  153. define Image/Build/gzip/jffs2-64k
  154. $(call Image/Build/gzip,jffs2-64k)
  155. endef
  156. define Image/Build/gzip/jffs2-128k
  157. $(call Image/Build/gzip,jffs2-128k)
  158. endef
  159. endif
  160. endif
  161. define Image/BuildKernel
  162. $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
  163. ifneq ($(CONFIG_X86_ETHERBOOT_IMAGES),)
  164. rm -f $(BIN_DIR)/$(IMG_PREFIX)-etherboot
  165. $(STAGING_DIR_HOST)/bin/mkelfImage \
  166. --append=$(CONFIG_X86_ETHERBOOT_BOOTOPTS) \
  167. $(KDIR)/bzImage \
  168. $(BIN_DIR)/$(IMG_PREFIX)-etherboot
  169. endif
  170. endef
  171. define Image/Prepare
  172. $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
  173. $(call Image/Prepare/bootscript)
  174. $(call Image/Prepare/grub)
  175. endef
  176. define Image/Build
  177. $(call Image/Build/$(1))
  178. $(call Image/Build/bootscript,$(1))
  179. ifneq ($(1),iso)
  180. $(call Image/Build/grub,$(1))
  181. $(call Image/Build/vdi,$(1))
  182. $(call Image/Build/vmdk,$(1))
  183. endif
  184. $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
  185. $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
  186. $(call Image/Build/gzip/$(1))
  187. endef
  188. $(eval $(call BuildImage))