Makefile 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #
  2. # Copyright (C) 2006 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. ifeq ($(CONFIG_X86_GRUB_IMAGES),y)
  20. ifneq ($(HOST_OS),Darwin)
  21. define Image/cmdline/squashfs
  22. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootwait
  23. endef
  24. define Image/cmdline/jffs2-64k
  25. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
  26. endef
  27. define Image/cmdline/jffs2-128k
  28. block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
  29. endef
  30. define Image/cmdline/ext2
  31. root=$(ROOTPART) rootfstype=ext2 rootwait
  32. endef
  33. define Image/Build/grub
  34. # left here because the image builder doesnt need these
  35. $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub
  36. $(CP) \
  37. $(KDIR)/*stage* \
  38. $(KDIR)/root.grub/boot/grub/
  39. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  40. sed \
  41. -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1))) $(BOOTOPTS)#g' \
  42. -e 's#@BAUDRATE@#$(CONFIG_X86_GRUB_BAUDRATE)#g' \
  43. ./menu.lst > $(KDIR)/root.grub/boot/grub/menu.lst
  44. 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)
  45. $(call Image/Build/grub/$(1))
  46. endef
  47. define Image/Prepare/grub
  48. # for the image builder
  49. $(CP) \
  50. $(STAGING_DIR_HOST)/usr/lib/grub/i386-*/stage1 \
  51. $(STAGING_DIR_HOST)/usr/lib/grub/i386-*/stage2 \
  52. $(STAGING_DIR_HOST)/usr/lib/grub/i386-*/e2fs_stage1_5 \
  53. $(KDIR)/
  54. endef
  55. else
  56. define Image/Build/grub
  57. 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)
  58. endef
  59. endif
  60. endif
  61. ifeq ($(CONFIG_X86_VDI_IMAGES),y)
  62. define Image/Build/vdi
  63. # left here because the image builder doesnt need these
  64. ifeq ($(1),ext2)
  65. rm $(BIN_DIR)/openwrt-$(BOARD)-ext2.vdi || true
  66. VBoxManage convertfromraw -format VDI $(BIN_DIR)/openwrt-$(BOARD)-ext2.image $(BIN_DIR)/openwrt-$(BOARD)-ext2.vdi
  67. endif
  68. endef
  69. endif
  70. ifeq ($(CONFIG_X86_VMDK_IMAGES),y)
  71. define Image/Build/vmdk
  72. # left here because the image builder doesnt need these
  73. ifeq ($(1),ext2)
  74. rm $(BIN_DIR)/openwrt-$(BOARD)-ext2.vmdk || true
  75. qemu-img convert -f raw $(BIN_DIR)/openwrt-$(BOARD)-ext2.image \
  76. -O vmdk $(BIN_DIR)/openwrt-$(BOARD)-ext2.vmdk
  77. endif
  78. endef
  79. endif
  80. ROOTDELAY=10
  81. ifeq ($(CONFIG_OLPC_BOOTSCRIPT_IMAGES),y)
  82. define Image/cmdline/squashfs
  83. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootdelay=$(ROOTDELAY)
  84. endef
  85. define Image/cmdline/jffs2-64k
  86. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
  87. endef
  88. define Image/cmdline/jffs2-128k
  89. block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
  90. endef
  91. define Image/cmdline/ext2
  92. root=$(ROOTPART) rootfstype=ext2 rootwait
  93. endef
  94. define Image/Build/bootscript
  95. # left here because the image builder doesnt need these
  96. $(INSTALL_DIR) $(KDIR)/root.bootscript/boot
  97. $(CP) $(KDIR)/bzImage $(KDIR)/root.bootscript/boot/vmlinuz
  98. sed -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1))) $(BOOTOPTS)#g' \
  99. ./olpc.fth > $(KDIR)/root.bootscript/boot/olpc.fth
  100. 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)
  101. endef
  102. endif
  103. define Image/Prepare
  104. $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
  105. ifeq ($(CONFIG_TARGET_x86_olpc),y)
  106. $(call Image/Prepare/bootscript)
  107. else
  108. $(call Image/Prepare/grub)
  109. endif
  110. endef
  111. define Image/Build/squashfs
  112. $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
  113. endef
  114. define Image/Build/iso
  115. $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub
  116. $(CP) \
  117. $(STAGING_DIR_HOST)/usr/lib/grub/i386-openwrt/stage2_eltorito \
  118. $(KDIR)/root.grub/boot/grub/stage2_eltorito
  119. sed \
  120. -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1))) $(BOOTOPTS)#g' \
  121. -e 's#@BAUDRATE@#$(CONFIG_X86_GRUB_BAUDRATE)#g' \
  122. -e 's#(hd0,0)#(cd)#g' \
  123. ./menu.lst > $(KDIR)/root.grub/boot/grub/menu.lst
  124. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  125. mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table \
  126. -o $(KDIR)/root.iso $(KDIR)/root.grub
  127. endef
  128. define Image/BuildKernel
  129. $(CP) $(KDIR)/bzImage $(BIN_DIR)/openwrt-$(BOARD)-vmlinuz
  130. endef
  131. define Image/Build
  132. $(call Image/Build/$(1))
  133. $(call Image/Build/bootscript,$(1))
  134. ifneq ($(1),iso)
  135. $(call Image/Build/grub,$(1))
  136. $(call Image/Build/vdi,$(1))
  137. $(call Image/Build/vmdk,$(1))
  138. endif
  139. $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/openwrt-$(BOARD)-$(1).fs
  140. $(CP) $(KDIR)/bzImage $(BIN_DIR)/openwrt-$(BOARD)-vmlinuz
  141. endef
  142. $(eval $(call BuildImage))
  143. ifeq ($(CONFIG_X86_VDI_IMAGES),y)
  144. $(eval $(call RequireCommand,VBoxManage, \
  145. You need VBoxManage to generate VirtualBox images. \
  146. ))
  147. endif
  148. ifeq ($(CONFIG_X86_VMDK_IMAGES),y)
  149. $(eval $(call RequireCommand,qemu-img, \
  150. You need qemu-img to generate VMware images. \
  151. ))
  152. endif