Makefile 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #
  2. # Copyright (C) 2006-2010 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. ifneq ($(CONFIG_TARGET_x86_olpc),y)
  11. BOOTOPTS=$(strip $(subst ",, $(CONFIG_X86_GRUB_BOOTOPTS)))
  12. ROOTPART=$(strip $(subst ",, $(CONFIG_X86_GRUB_ROOTPART)))
  13. #"))")) # fix vim's broken syntax highlighting
  14. endif
  15. ifeq ($(CONFIG_TARGET_x86_olpc),y)
  16. ROOTPART=$(strip $(subst ",, $(CONFIG_OLPC_BOOTSCRIPT_ROOTPART)))
  17. endif
  18. #"))")) # fix vim's broken syntax highlighting
  19. GRUB_TERMINALS =
  20. GRUB_SERIAL_CONFIG =
  21. GRUB_TERMINAL_CONFIG =
  22. GRUB_CONSOLE_CMDLINE =
  23. ifeq ($(CONFIG_X86_GRUB_CONSOLE),y)
  24. GRUB_CONSOLE_CMDLINE += console=tty0
  25. GRUB_TERMINALS += console
  26. endif
  27. ifneq ($(CONFIG_X86_GRUB_SERIAL),)
  28. GRUB_CONSOLE_CMDLINE += console=$(strip $(subst ",, $(CONFIG_X86_GRUB_SERIAL))),$(CONFIG_X86_GRUB_BAUDRATE)n8
  29. GRUB_SERIAL_CONFIG = serial --unit=0 --speed=$(CONFIG_X86_GRUB_BAUDRATE) --word=8 --parity=no --stop=1
  30. GRUB_TERMINALS += serial
  31. endif
  32. ifneq ($(GRUB_TERMINALS),)
  33. GRUB_TERMINAL_CONFIG = terminal --timeout=2 $(GRUB_TERMINALS)
  34. endif
  35. ifeq ($(CONFIG_X86_GRUB_IMAGES),y)
  36. ifneq ($(HOST_OS),Darwin)
  37. define Image/cmdline/squashfs
  38. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootwait
  39. endef
  40. define Image/cmdline/jffs2-64k
  41. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
  42. endef
  43. define Image/cmdline/jffs2-128k
  44. block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
  45. endef
  46. define Image/cmdline/ext2
  47. root=$(ROOTPART) rootfstype=ext2 rootwait
  48. endef
  49. define Image/Build/grub
  50. # left here because the image builder doesnt need these
  51. $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub
  52. $(CP) \
  53. $(KDIR)/*stage* \
  54. $(KDIR)/root.grub/boot/grub/
  55. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  56. sed \
  57. -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
  58. -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
  59. -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
  60. ./menu.lst > $(KDIR)/root.grub/boot/grub/menu.lst
  61. PADDING="$(CONFIG_X86_GRUB_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_x86.sh $(BIN_DIR)/openwrt-$(BOARD)-$(1).image $(CONFIG_X86_GRUB_KERNELPART) $(KDIR)/root.grub $(CONFIG_TARGET_ROOTFS_FSPART) $(KDIR)/root.$(1)
  62. $(call Image/Build/grub/$(1))
  63. endef
  64. define Image/Prepare/grub
  65. # for the image builder
  66. $(CP) \
  67. $(STAGING_DIR_HOST)/usr/lib/grub/i386-*/stage1 \
  68. $(STAGING_DIR_HOST)/usr/lib/grub/i386-*/stage2 \
  69. $(STAGING_DIR_HOST)/usr/lib/grub/i386-*/e2fs_stage1_5 \
  70. $(KDIR)/
  71. endef
  72. else
  73. define Image/Build/grub
  74. PADDING="$(CONFIG_X86_GRUB_IMAGES_PAD)" PATH="$(TARGET_PATH)" NOGRUB=1 ./gen_image_x86.sh $(BIN_DIR)/openwrt-$(BOARD)-$(1).image $(CONFIG_X86_GRUB_KERNELPART) "" $(CONFIG_TARGET_ROOTFS_FSPART) $(KDIR)/root.$(1)
  75. endef
  76. endif
  77. endif
  78. ifeq ($(CONFIG_X86_VDI_IMAGES),y)
  79. define Image/Build/vdi
  80. # left here because the image builder doesnt need these
  81. ifeq ($(1),ext2)
  82. rm $(BIN_DIR)/openwrt-$(BOARD)-ext2.vdi || true
  83. VBoxManage convertfromraw -format VDI $(BIN_DIR)/openwrt-$(BOARD)-ext2.image $(BIN_DIR)/openwrt-$(BOARD)-ext2.vdi
  84. endif
  85. endef
  86. endif
  87. ifeq ($(CONFIG_X86_VMDK_IMAGES),y)
  88. define Image/Build/vmdk
  89. # left here because the image builder doesnt need these
  90. ifeq ($(1),ext2)
  91. rm $(BIN_DIR)/openwrt-$(BOARD)-ext2.vmdk || true
  92. qemu-img convert -f raw $(BIN_DIR)/openwrt-$(BOARD)-ext2.image \
  93. -O vmdk $(BIN_DIR)/openwrt-$(BOARD)-ext2.vmdk
  94. endif
  95. endef
  96. endif
  97. ROOTDELAY=10
  98. ifeq ($(CONFIG_OLPC_BOOTSCRIPT_IMAGES),y)
  99. define Image/cmdline/squashfs
  100. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootdelay=$(ROOTDELAY)
  101. endef
  102. define Image/cmdline/jffs2-64k
  103. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
  104. endef
  105. define Image/cmdline/jffs2-128k
  106. block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
  107. endef
  108. define Image/cmdline/ext2
  109. root=$(ROOTPART) rootfstype=ext2 rootwait
  110. endef
  111. define Image/Build/bootscript
  112. # left here because the image builder doesnt need these
  113. $(INSTALL_DIR) $(KDIR)/root.bootscript/boot
  114. $(CP) $(KDIR)/bzImage $(KDIR)/root.bootscript/boot/vmlinuz
  115. sed -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1))) $(BOOTOPTS)#g' \
  116. ./olpc.fth > $(KDIR)/root.bootscript/boot/olpc.fth
  117. PADDING="$(CONFIG_OLPC_BOOTSCRIPT_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_olpc.sh $(BIN_DIR)/openwrt-$(BOARD)-$(1).image $(CONFIG_OLPC_BOOTSCRIPT_KERNELPART) $(KDIR)/root.bootscript $(CONFIG_TARGET_ROOTFS_FSPART) $(KDIR)/root.$(1)
  118. endef
  119. endif
  120. define Image/Prepare
  121. $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
  122. ifeq ($(CONFIG_TARGET_x86_olpc),y)
  123. $(call Image/Prepare/bootscript)
  124. else
  125. $(call Image/Prepare/grub)
  126. endif
  127. endef
  128. define Image/Build/squashfs
  129. $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
  130. endef
  131. define Image/Build/iso
  132. $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub
  133. $(CP) \
  134. $(STAGING_DIR_HOST)/usr/lib/grub/i386-openwrt/stage2_eltorito \
  135. $(KDIR)/root.grub/boot/grub/stage2_eltorito
  136. sed \
  137. -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
  138. -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
  139. -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
  140. -e 's#(hd0,0)#(cd)#g' \
  141. ./menu.lst > $(KDIR)/root.grub/boot/grub/menu.lst
  142. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  143. mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table \
  144. -o $(KDIR)/root.iso $(KDIR)/root.grub
  145. endef
  146. define Image/BuildKernel
  147. $(CP) $(KDIR)/bzImage $(BIN_DIR)/openwrt-$(BOARD)-vmlinuz
  148. endef
  149. define Image/Build
  150. $(call Image/Build/$(1))
  151. $(call Image/Build/bootscript,$(1))
  152. ifneq ($(1),iso)
  153. $(call Image/Build/grub,$(1))
  154. $(call Image/Build/vdi,$(1))
  155. $(call Image/Build/vmdk,$(1))
  156. endif
  157. $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/openwrt-$(BOARD)-$(1).fs
  158. $(CP) $(KDIR)/bzImage $(BIN_DIR)/openwrt-$(BOARD)-vmlinuz
  159. ifeq ($(1),ext2)
  160. gzip -f9 $(BIN_DIR)/openwrt-$(BOARD)-$(1).image
  161. endif
  162. endef
  163. $(eval $(call BuildImage))
  164. ifeq ($(CONFIG_X86_VDI_IMAGES),y)
  165. $(eval $(call RequireCommand,VBoxManage, \
  166. You need VBoxManage to generate VirtualBox images. \
  167. ))
  168. endif
  169. ifeq ($(CONFIG_X86_VMDK_IMAGES),y)
  170. $(eval $(call RequireCommand,qemu-img, \
  171. You need qemu-img to generate VMware images. \
  172. ))
  173. endif