Makefile 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. BOOTOPTS=$(strip $(subst ",, $(CONFIG_X86_GRUB_BOOTOPTS)))
  11. ROOTPART=$(strip $(subst ",, $(CONFIG_X86_GRUB_ROOTPART)))
  12. #"))")) # fix vim's broken syntax highlighting
  13. ifeq ($(CONFIG_X86_GRUB_IMAGES),y)
  14. ifneq ($(HOST_OS),Darwin)
  15. define Image/cmdline/squashfs
  16. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs
  17. endef
  18. define Image/cmdline/jffs2-64k
  19. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2
  20. endef
  21. define Image/cmdline/jffs2-128k
  22. block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2
  23. endef
  24. define Image/cmdline/ext2
  25. root=$(ROOTPART) rootfstype=ext2
  26. endef
  27. define Image/Build/grub
  28. # left here because the image builder doesnt need these
  29. $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub
  30. $(CP) \
  31. $(KDIR)/*stage* \
  32. $(KDIR)/root.grub/boot/grub/
  33. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  34. sed \
  35. -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1))) $(BOOTOPTS)#g' \
  36. -e 's#@BAUDRATE@#$(CONFIG_X86_GRUB_BAUDRATE)#g' \
  37. ./menu.lst > $(KDIR)/root.grub/boot/grub/menu.lst
  38. PADDING="$(CONFIG_X86_GRUB_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image.sh $(BIN_DIR)/openwrt-$(BOARD)-$(1).image $(CONFIG_X86_GRUB_KERNELPART) $(KDIR)/root.grub $(CONFIG_TARGET_ROOTFS_FSPART) $(KDIR)/root.$(1)
  39. $(call Image/Build/grub/$(1))
  40. endef
  41. define Image/Prepare/grub
  42. # for the image builder
  43. $(CP) \
  44. $(STAGING_DIR_HOST)/usr/lib/grub/i386-*/stage1 \
  45. $(STAGING_DIR_HOST)/usr/lib/grub/i386-*/stage2 \
  46. $(STAGING_DIR_HOST)/usr/lib/grub/i386-*/e2fs_stage1_5 \
  47. $(KDIR)/
  48. endef
  49. else
  50. define Image/Build/grub
  51. PADDING="$(CONFIG_X86_GRUB_IMAGES_PAD)" PATH="$(TARGET_PATH)" NOGRUB=1 ./gen_image.sh $(BIN_DIR)/openwrt-$(BOARD)-$(1).image $(CONFIG_X86_GRUB_KERNELPART) "" $(CONFIG_TARGET_ROOTFS_FSPART) $(KDIR)/root.$(1)
  52. endef
  53. endif
  54. endif
  55. ifeq ($(CONFIG_X86_VDI_IMAGES),y)
  56. define Image/Build/vdi
  57. # left here because the image builder doesnt need these
  58. ifeq ($(1),ext2)
  59. rm $(BIN_DIR)/openwrt-$(BOARD)-ext2.vdi || true
  60. VBoxManage convertfromraw -format VDI $(BIN_DIR)/openwrt-$(BOARD)-ext2.image $(BIN_DIR)/openwrt-$(BOARD)-ext2.vdi
  61. endif
  62. endef
  63. endif
  64. ifeq ($(CONFIG_X86_VMDK_IMAGES),y)
  65. define Image/Build/vmdk
  66. # left here because the image builder doesnt need these
  67. ifeq ($(1),ext2)
  68. rm $(BIN_DIR)/openwrt-$(BOARD)-ext2.vmdk || true
  69. qemu-img convert -f raw $(BIN_DIR)/openwrt-$(BOARD)-ext2.image \
  70. -O vmdk $(BIN_DIR)/openwrt-$(BOARD)-ext2.vmdk
  71. endif
  72. endef
  73. endif
  74. define Image/Prepare
  75. $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
  76. $(call Image/Prepare/grub)
  77. endef
  78. define Image/Build/squashfs
  79. $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
  80. endef
  81. define Image/Build/iso
  82. $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub
  83. $(CP) \
  84. $(STAGING_DIR_HOST)/usr/lib/grub/i386-openwrt/stage2_eltorito \
  85. $(KDIR)/root.grub/boot/grub/stage2_eltorito
  86. sed \
  87. -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1))) $(BOOTOPTS)#g' \
  88. -e 's#@BAUDRATE@#$(CONFIG_X86_GRUB_BAUDRATE)#g' \
  89. -e 's#(hd0,0)#(cd)#g' \
  90. ./menu.lst > $(KDIR)/root.grub/boot/grub/menu.lst
  91. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  92. mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table \
  93. -o $(KDIR)/root.iso $(KDIR)/root.grub
  94. endef
  95. define Image/BuildKernel
  96. $(CP) $(KDIR)/bzImage $(BIN_DIR)/openwrt-$(BOARD)-vmlinuz
  97. endef
  98. define Image/Build
  99. $(call Image/Build/$(1))
  100. ifneq ($(1),iso)
  101. $(call Image/Build/grub,$(1))
  102. $(call Image/Build/vdi,$(1))
  103. $(call Image/Build/vmdk,$(1))
  104. endif
  105. $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/openwrt-$(BOARD)-$(1).fs
  106. $(CP) $(KDIR)/bzImage $(BIN_DIR)/openwrt-$(BOARD)-vmlinuz
  107. endef
  108. $(eval $(call BuildImage))
  109. ifeq ($(CONFIG_X86_VDI_IMAGES),y)
  110. $(eval $(call RequireCommand,VBoxManage, \
  111. You need VBoxManage to generate VirtualBox images. \
  112. ))
  113. endif
  114. ifeq ($(CONFIG_X86_VMDK_IMAGES),y)
  115. $(eval $(call RequireCommand,qemu-img, \
  116. You need qemu-img to generate VMware images. \
  117. ))
  118. endif