Makefile 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. 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. ifneq ($(CONFIG_X86_GRUB_IMAGES),)
  28. BOOTOPTS:=$(call qstrip,$(CONFIG_X86_GRUB_BOOTOPTS))
  29. define Image/cmdline/ext4
  30. root=$(ROOTPART) rootfstype=ext4 rootwait
  31. endef
  32. define Image/cmdline/jffs2-64k
  33. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
  34. endef
  35. define Image/cmdline/jffs2-128k
  36. block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootwait
  37. endef
  38. define Image/cmdline/squashfs
  39. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootwait
  40. endef
  41. define Image/Build/grub
  42. # left here because the image builder doesnt need these
  43. $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub
  44. $(CP) \
  45. $(KDIR)/stage1 \
  46. $(KDIR)/stage2 \
  47. $(KDIR)/e2fs_stage1_5 \
  48. $(KDIR)/root.grub/boot/grub/
  49. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  50. sed \
  51. -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
  52. -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
  53. -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
  54. ./menu.lst > $(KDIR)/root.grub/boot/grub/menu.lst
  55. PADDING="$(CONFIG_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_x86.sh \
  56. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  57. $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.grub \
  58. $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1)
  59. $(call Image/Build/grub/$(1))
  60. endef
  61. define Image/Prepare/grub
  62. # for the image builder
  63. $(CP) \
  64. $(STAGING_DIR)/usr/lib/grub/i386-openwrt/stage1 \
  65. $(STAGING_DIR)/usr/lib/grub/i386-openwrt/stage2 \
  66. $(STAGING_DIR)/usr/lib/grub/i386-openwrt/stage2_eltorito \
  67. $(STAGING_DIR)/usr/lib/grub/i386-openwrt/e2fs_stage1_5 \
  68. $(KDIR)/
  69. endef
  70. endif
  71. ROOTDELAY=10
  72. ifneq ($(CONFIG_OLPC_BOOTSCRIPT_IMAGES),)
  73. define Image/cmdline/ext4
  74. root=$(ROOTPART) rootfstype=ext4 rootwait
  75. endef
  76. define Image/cmdline/jffs2-64k
  77. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
  78. endef
  79. define Image/cmdline/jffs2-128k
  80. block2mtd.block2mtd=$(ROOTPART),131072,rootfs root=/dev/mtdblock0 rootfstype=jffs2 rootdelay=$(ROOTDELAY)
  81. endef
  82. define Image/cmdline/squashfs
  83. block2mtd.block2mtd=$(ROOTPART),65536,rootfs root=/dev/mtdblock0 rootfstype=squashfs rootdelay=$(ROOTDELAY)
  84. endef
  85. define Image/Build/bootscript
  86. # left here because the image builder doesnt need these
  87. $(INSTALL_DIR) $(KDIR)/root.bootscript/boot
  88. $(CP) $(KDIR)/bzImage $(KDIR)/root.bootscript/boot/vmlinuz
  89. sed -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1))) $(BOOTOPTS)#g' \
  90. ./olpc.fth > $(KDIR)/root.bootscript/boot/olpc.fth
  91. PADDING="$(CONFIG_TARGET_IMAGES_PAD)" PATH="$(TARGET_PATH)" ./gen_image_olpc.sh \
  92. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  93. $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.bootscript \
  94. $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1)
  95. endef
  96. endif
  97. define Image/Build/squashfs
  98. $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
  99. endef
  100. define Image/Build/iso
  101. $(INSTALL_DIR) $(KDIR)/root.grub/boot/grub
  102. $(CP) \
  103. $(KDIR)/stage2_eltorito \
  104. $(KDIR)/root.grub/boot/grub/
  105. sed \
  106. -e 's#@SERIAL_CONFIG@#$(strip $(GRUB_SERIAL_CONFIG))#g' \
  107. -e 's#@TERMINAL_CONFIG@#$(strip $(GRUB_TERMINAL_CONFIG))#g' \
  108. -e 's#@CMDLINE@#$(strip $(call Image/cmdline/$(1)) $(BOOTOPTS) $(GRUB_CONSOLE_CMDLINE))#g' \
  109. -e 's#(hd0,0)#(cd)#g' \
  110. ./menu.lst > $(KDIR)/root.grub/boot/grub/menu.lst
  111. $(CP) $(KDIR)/bzImage $(KDIR)/root.grub/boot/vmlinuz
  112. mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table \
  113. -o $(KDIR)/root.iso $(KDIR)/root.grub
  114. endef
  115. ifneq ($(CONFIG_X86_VDI_IMAGES),)
  116. define Image/Build/vdi
  117. # left here because the image builder doesnt need these
  118. ifeq ($(1),ext4)
  119. rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi || true
  120. qemu-img convert -f raw -O vdi \
  121. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  122. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
  123. # XXX: VBoxManage insists on setting perms to 0600
  124. chmod 0644 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vdi
  125. endif
  126. endef
  127. endif
  128. ifneq ($(CONFIG_X86_VMDK_IMAGES),)
  129. define Image/Build/vmdk
  130. # left here because the image builder doesnt need these
  131. ifeq ($(1),ext4)
  132. rm $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk || true
  133. qemu-img convert -f raw -O vmdk \
  134. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img \
  135. $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).vmdk
  136. endif
  137. endef
  138. endif
  139. define Image/BuildKernel
  140. $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
  141. endef
  142. define Image/Prepare
  143. $(CP) $(LINUX_DIR)/arch/x86/boot/bzImage $(KDIR)/bzImage
  144. $(call Image/Prepare/bootscript)
  145. $(call Image/Prepare/grub)
  146. endef
  147. define Image/Build
  148. $(call Image/Build/$(1))
  149. $(call Image/Build/bootscript,$(1))
  150. ifneq ($(1),iso)
  151. $(call Image/Build/grub,$(1))
  152. $(call Image/Build/vdi,$(1))
  153. $(call Image/Build/vmdk,$(1))
  154. endif
  155. $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
  156. $(CP) $(KDIR)/bzImage $(BIN_DIR)/$(IMG_PREFIX)-vmlinuz
  157. ifeq ($(1),ext4)
  158. gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-combined-$(1).img
  159. gzip -f9 $(BIN_DIR)/$(IMG_PREFIX)-rootfs-$(1).img
  160. endif
  161. endef
  162. $(eval $(call BuildImage))