Advertisement
42n4

MAKERASPI2BUSYBOXKERNEL

Oct 13th, 2016
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 9.12 KB | None | 0 0
  1. #!/usr/bin/make -rf
  2. #!/usr/bin/make -rdf
  3.  
  4. # +------------------------------------------------------------
  5. # | (C) 2011 Pawel Kraszewski <root@linuxpedia.pl>
  6. # | System generujący środowiso i system na procesory ARM
  7. # | Raspberry kernel added by Piotr Wasiewicz <pwasiewi@gmail.com>
  8. # +------------------------------------------------------------
  9.  
  10. HERE=$(PWD)
  11.  
  12. # +------------------------------------------------------------
  13. # | Wersje
  14. # +------------------------------------------------------------
  15.  
  16. BUSYBOX_VER=1.24.2
  17. BUSYBOX_MD5=2eaae519cac1143bcf583636a745381f
  18.  
  19. KERNEL_VER=raspberrypi-kernel_1.20160921-1
  20. KERNEL_MD5=3f3987c4a23f67def52d714f1c918eb1
  21.  
  22. # +------------------------------------------------------------
  23. # | Architektura
  24. # +------------------------------------------------------------
  25.  
  26. ARCH=arm
  27. #CROSS_COMPILE=arm-softfloat-linux-gnueabi-
  28. CROSS_COMPILE=armv7a-hardfloat-linux-gnueabi-
  29.  
  30. # +------------------------------------------------------------
  31. # | Host -j param
  32. # +------------------------------------------------------------
  33.  
  34. MULTICPU=-j10
  35.  
  36. # +------------------------------------------------------------
  37. # | Katalogi
  38. # +------------------------------------------------------------
  39.  
  40. # Katalog na pobrane pliki
  41. DOWNLOAD_DIR=$(HERE)/dl
  42.  
  43. # Katalogi na pliki źródłowe
  44. SRC_DIR=$(HERE)/src
  45. SRC_KERNEL=$(SRC_DIR)/linux-$(KERNEL_VER)
  46. SRC_BUSYBOX=$(SRC_DIR)/busybox-$(BUSYBOX_VER)
  47.  
  48. # Katalogi na binaria
  49. BIN_DIR=$(HERE)/bin
  50. BIN_KERNEL=$(BIN_DIR)/kernel
  51. BIN_BUSYBOX=$(BIN_DIR)/busybox
  52.  
  53. # Katalog źródłowy initrd
  54. INITRD_DIR=$(HERE)/initrd
  55.  
  56. # Katalog emulatora
  57. EMUL_DIR=$(HERE)/emu
  58.  
  59. # +------------------------------------------------------------
  60. # | Ściąganie z sieci
  61. # +------------------------------------------------------------
  62.  
  63. $(DOWNLOAD_DIR)/busybox-$(BUSYBOX_VER).tar.bz2:
  64.     @mkdir -p $(DOWNLOAD_DIR)
  65.     @echo "$(BUSYBOX_MD5)  $(DOWNLOAD_DIR)/busybox-$(BUSYBOX_VER).tar.bz2" > $(DOWNLOAD_DIR)/busybox-$(BUSYBOX_VER).md5
  66.     @if ! md5sum -c --quiet $(DOWNLOAD_DIR)/busybox-$(BUSYBOX_VER).md5; then \
  67.         echo "Pobieranie busybox-$(BUSYBOX_VER).tar.bz2"; \
  68.         wget -O $(DOWNLOAD_DIR)/busybox-$(BUSYBOX_VER).tar.bz2 http://busybox.net/downloads/busybox-$(BUSYBOX_VER).tar.bz2; \
  69.     fi
  70.     touch $(DOWNLOAD_DIR)/busybox-$(BUSYBOX_VER).tar.bz2
  71.  
  72. $(DOWNLOAD_DIR)/linux-$(KERNEL_VER).tar.gz:
  73.     @mkdir -p $(DOWNLOAD_DIR)
  74.     @echo "$(KERNEL_MD5)  $(DOWNLOAD_DIR)/linux-$(KERNEL_VER).tar.gz" > $(DOWNLOAD_DIR)/linux-$(KERNEL_VER).md5
  75.     @if ! md5sum -c --quiet $(DOWNLOAD_DIR)/linux-$(KERNEL_VER).md5; then \
  76.         echo "Pobieranie linux-$(KERNEL_VER).tar.gz"; \
  77.         #wget -O $(DOWNLOAD_DIR)/linux-$(KERNEL_VER).tar.gz http://www.kernel.org/pub/linux/kernel/v4.x/linux-$(KERNEL_VER).tar.gz; \
  78.         wget -O $(DOWNLOAD_DIR)/linux-$(KERNEL_VER).tar.gz https://github.com/raspberrypi/linux/archive/$(KERNEL_VER).tar.gz; \
  79.     fi
  80.     touch $(DOWNLOAD_DIR)/linux-$(KERNEL_VER).tar.gz
  81.  
  82. # +------------------------------------------------------------
  83. # | Rozpakowywanie
  84. # +------------------------------------------------------------
  85.  
  86. $(SRC_BUSYBOX)/Makefile:    $(DOWNLOAD_DIR)/busybox-$(BUSYBOX_VER).tar.bz2
  87.     @mkdir -p $(SRC_DIR)
  88.     tar xjf $(DOWNLOAD_DIR)/busybox-$(BUSYBOX_VER).tar.bz2 -C $(SRC_DIR)
  89.     touch $(SRC_BUSYBOX)/Makefile
  90.  
  91. $(SRC_KERNEL)/Makefile: $(DOWNLOAD_DIR)/linux-$(KERNEL_VER).tar.gz
  92.     @mkdir -p $(SRC_DIR)
  93.     tar xzf $(DOWNLOAD_DIR)/linux-$(KERNEL_VER).tar.gz -C $(SRC_DIR)
  94.     touch $(SRC_KERNEL)/Makefile
  95.  
  96. # +------------------------------------------------------------
  97. # | Zarządzanie downloadami
  98. # +------------------------------------------------------------
  99.  
  100. dl/busybox: $(DOWNLOAD_DIR)/busybox-$(BUSYBOX_VER).tar.bz2
  101. dl/kernel:  $(DOWNLOAD_DIR)/linux-$(KERNEL_VER).tar.gz
  102. dl: dl/busybox dl/kernel
  103.  
  104. # +------------------------------------------------------------
  105. # | Zarządzanie źródłami
  106. # +------------------------------------------------------------
  107.  
  108. src/busybox: $(SRC_BUSYBOX)/Makefile
  109. src/kernel:  $(SRC_KERNEL)/Makefile
  110. src:    src/busybox src/kernel
  111.  
  112. # +------------------------------------------------------------
  113. # | Budowa potrzebnych narzędzi do Gentoo
  114. # +------------------------------------------------------------
  115.  
  116. /etc/gentoo-release:
  117.     @echo "Potrzebujesz do tego Gentoo!"
  118.     exit
  119.  
  120. /usr/bin/arm-softfloat-linux-gnueabi-gcc:
  121.     @USE="-fortran nossp" crossdev --target armv7a-hardfloat-linux-gnueabi --gcc 4.9.3 --libc 2.23 --kernel 4.7.5
  122. #   @USE="-fortran nossp" crossdev --target arm-softfloat-linux-gnueabi --gcc 4.9.3 --libc 2.23 --kernel 4.7.5
  123. #   @USE="-cxx nocxx" crossdev --target arm-softfloat-linux-gnueabi -s1 --without-headers
  124. #   @USE="cxx -nocxx" crossdev --target arm-softfloat-linux-gnueabi
  125.  
  126. /usr/bin/crossdev:
  127.     @emerge -av crossdev
  128.  
  129. gentoo: /etc/gentoo-release
  130.  
  131. crossdev:   gentoo /usr/bin/crossdev
  132.  
  133. toolchain:  crossdev /usr/bin/arm-softfloat-linux-gnueabi-gcc
  134.     @echo $(HERE)
  135.  
  136. # +------------------------------------------------------------
  137. # | Konfiguracja binarek poza drzewo źródłowe
  138. # +------------------------------------------------------------
  139.  
  140. $(BIN_KERNEL)/Makefile: $(SRC_KERNEL)/Makefile
  141.     mkdir -p $(BIN_KERNEL)
  142.     @cd $(SRC_KERNEL) && make O=$(BIN_KERNEL) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) bcm2709_defconfig
  143.  
  144. $(BIN_BUSYBOX)/Makefile: $(SRC_BUSYBOX)/Makefile
  145.     @mkdir -p $(BIN_BUSYBOX)
  146.     @cd $(SRC_BUSYBOX) && make O=$(BIN_BUSYBOX) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) defconfig
  147.  
  148. # +------------------------------------------------------------
  149. # | Konfiguracja
  150. # +------------------------------------------------------------
  151.  
  152. $(BIN_KERNEL)/.config:  $(BIN_KERNEL)/Makefile
  153.  
  154. $(BIN_BUSYBOX)/.config: $(BIN_BUSYBOX)/Makefile
  155.  
  156. kernconf:   $(BIN_KERNEL)/.config
  157.     @cd $(BIN_KERNEL) && make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) menuconfig
  158.  
  159. busyboxconf:    $(BIN_BUSYBOX)/.config
  160.     @cd $(BIN_BUSYBOX) && make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) menuconfig
  161.  
  162. # +------------------------------------------------------------
  163. # | Kompilacja
  164. # +------------------------------------------------------------
  165.  
  166. $(BIN_BUSYBOX)/busybox: $(BIN_BUSYBOX)/.config
  167.     @sed -i "s:.*CONFIG_PREFIX=.*:CONFIG_PREFIX=\"$(INITRD_DIR)\":" $(BIN_BUSYBOX)/.config
  168.     @sed -i "s:.*CONFIG_STATIC=.*:CONFIG_STATIC=y:" $(BIN_BUSYBOX)/.config
  169.     @sed -i "s:.*CONFIG_CROSS_COMPILER_PREFIX=.*:CONFIG_CROSS_COMPILER_PREFIX=\"arm-softfloat-linux-gnueabi-\":" $(BIN_BUSYBOX)/.config
  170.     @cd $(BIN_BUSYBOX) \
  171.      && make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) $(MULTICPU)
  172.  
  173. $(BIN_KERNEL)/arch/arm/boot/zImage: $(BIN_KERNEL)/.config
  174.     @cd $(BIN_KERNEL) \
  175.      && make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) $(MULTICPU)
  176.  
  177. # +------------------------------------------------------------
  178. # | Składanie INITRD
  179. # +------------------------------------------------------------
  180.  
  181. $(INITRD_DIR)/bin/busybox: $(BIN_BUSYBOX)/busybox
  182.     @mkdir -p $(INITRD_DIR)
  183.     @cp -av $(HERE)/init $(INITRD_DIR)
  184.     @cd $(BIN_BUSYBOX) \
  185.      && make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) PREFIX=$(INITRD_DIR) install
  186.  
  187. # +------------------------------------------------------------
  188. # | Składanie Emulatora
  189. # +------------------------------------------------------------
  190.  
  191. $(EMUL_DIR)/vmlinuz:    $(BIN_KERNEL)/arch/arm/boot/zImage
  192.     @mkdir -p $(EMUL_DIR)
  193.     @cd $(BIN_KERNEL) \
  194.      && make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) INSTALL_PATH=$(EMUL_DIR) $(MULTICPU) install
  195.     @cp $(BIN_KERNEL)/arch/arm/boot/zImage $(EMUL_DIR)/vmlinuz
  196.     @touch $(EMUL_DIR)/vmlinuz
  197.  
  198. $(EMUL_DIR)/initrd: $(INITRD_DIR)/bin/busybox $(wildcard $(INITRD_DIR)/bin/*) $(wildcard $(INITRD_DIR)/etc/*) $(wildcard $(INITRD_DIR)/sbin/*) $(BIN_KERNEL)/arch/arm/boot/zImage
  199.     @mkdir -p $(INITRD_DIR)/{bin,sbin,etc,proc,sys,usr/{bin,sbin}}
  200.     @cd $(BIN_KERNEL) \
  201.      && make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) INSTALL_MOD_PATH=$(INITRD_DIR) $(MULTICPU)
  202. #    && make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) INSTALL_MOD_PATH=$(INITRD_DIR) $(MULTICPU) modules_install
  203.     @cd $(INITRD_DIR) \
  204.      && find . | cpio --quiet -H newc -o --owner=0.0 > $(EMUL_DIR)/initrd
  205.  
  206. # +------------------------------------------------------------
  207. # | Emulacja
  208. # | machine ID and DTB address is assigned to linux when bootloader loads linux
  209. # +------------------------------------------------------------
  210.  
  211. emulate: $(EMUL_DIR)/vmlinuz $(EMUL_DIR)/initrd
  212.     qemu-system-arm -M raspi2 -cpu amr1176 -m 256 -kernel $(EMUL_DIR)/vmlinuz -initrd $(EMUL_DIR)/initrd -append "root=/dev/ram ro earlyprintk loglevel=8 console=ttyAMA0,115200 nomodeset nofb vga=normal video=vesafb:off modeset=off" -dtb ./dtb/bcm2709-rpi-2-b.dtb
  213.     #qemu-system-arm -M raspi2 -cpu amr1176 -m 256 -kernel $(EMUL_DIR)/vmlinuz -initrd $(EMUL_DIR)/initrd -append "root=/dev/ram0 ro earlyprintk loglevel=8 console=ttyS0,115200 nomodeset nofb vga=normal video=vesafb:off modeset=off" -nographic -dtb ./dtb/bcm2709-rpi-2-b.dtb
  214.  
  215.  
  216.  
  217. # +------------------------------------------------------------
  218. # | Administracyjne
  219. # +------------------------------------------------------------
  220.  
  221. clean:
  222.     @rm -rf bin emu initrd src
  223.  
  224. .phony: src src/busybox src/kernel toolchain crossdev kernconf busyboxconf emulate dl dl/kernel dl/busybox
  225.  
  226. .PRECIOUS: \
  227. $(DOWNLOAD_DIR)/busybox-$(BUSYBOX_VER).tar.bz2 \
  228. $(DOWNLOAD_DIR)/linux-$(KERNEL_VER).tar.bz2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement