@@ -1,101 +1,101 | |||
|
1 | 1 | #!/bin/bash |
|
2 | 2 | # |
|
3 | 3 | # Build and Setup U-Boot |
|
4 | 4 | # |
|
5 | 5 | |
|
6 | 6 | # Load utility functions |
|
7 | 7 | . ./functions.sh |
|
8 | 8 | |
|
9 | 9 | # Fetch and build U-Boot bootloader |
|
10 | 10 | if [ "$ENABLE_UBOOT" = true ] ; then |
|
11 | 11 | # Install c/c++ build environment inside the chroot |
|
12 | 12 | chroot_install_cc |
|
13 | 13 | |
|
14 | 14 | # Copy existing U-Boot sources into chroot directory |
|
15 | 15 | if [ -n "$UBOOTSRC_DIR" ] && [ -d "$UBOOTSRC_DIR" ] ; then |
|
16 | 16 | # Copy local U-Boot sources |
|
17 | 17 | cp -r "${UBOOTSRC_DIR}" "${R}/tmp" |
|
18 | 18 | else |
|
19 | 19 | # Create temporary directory for U-Boot sources |
|
20 | 20 | temp_dir=$(as_nobody mktemp -d) |
|
21 | 21 | |
|
22 | 22 | # Fetch U-Boot sources |
|
23 | 23 | as_nobody git -C "${temp_dir}" clone "${UBOOT_URL}" |
|
24 | 24 | |
|
25 | 25 | # Copy downloaded U-Boot sources |
|
26 | 26 | mv "${temp_dir}/u-boot" "${R}/tmp/" |
|
27 | 27 | |
|
28 | 28 | # Set permissions of the U-Boot sources |
|
29 | 29 | chown -R root:root "${R}/tmp/u-boot" |
|
30 | 30 | |
|
31 | 31 | # Remove temporary directory for U-Boot sources |
|
32 | 32 | rm -fr "${temp_dir}" |
|
33 | 33 | fi |
|
34 | 34 | |
|
35 | 35 | # Build and install U-Boot inside chroot |
|
36 | 36 | chroot_exec make -j"${KERNEL_THREADS}" -C /tmp/u-boot/ "${UBOOT_CONFIG}" all |
|
37 | 37 | |
|
38 | 38 | # Copy compiled bootloader binary and set config.txt to load it |
|
39 | 39 | install_exec "${R}/tmp/u-boot/tools/mkimage" "${R}/usr/sbin/mkimage" |
|
40 | 40 | install_readonly "${R}/tmp/u-boot/u-boot.bin" "${BOOT_DIR}/u-boot.bin" |
|
41 | 41 | printf "\n# boot u-boot kernel\nkernel=u-boot.bin\n" >> "${BOOT_DIR}/config.txt" |
|
42 | 42 | |
|
43 | 43 | install_readonly files/boot/uboot.mkimage "${BOOT_DIR}/uboot.mkimage" |
|
44 | 44 | printf "# Set the kernel boot command line\nsetenv bootargs \"earlyprintk ${CMDLINE}\"\n\n$(cat ${BOOT_DIR}/uboot.mkimage)" > "${BOOT_DIR}/uboot.mkimage" |
|
45 | 45 | |
|
46 | 46 | if [ "$ENABLE_INITRAMFS" = true ] ; then |
|
47 | 47 | # Convert generated initramfs for U-Boot using mkimage |
|
48 | 48 | chroot_exec /usr/sbin/mkimage -A "${KERNEL_ARCH}" -T ramdisk -C none -n "initramfs-${KERNEL_VERSION}" -d "/boot/firmware/initramfs-${KERNEL_VERSION}" "/boot/firmware/initramfs-${KERNEL_VERSION}.uboot" |
|
49 | 49 | |
|
50 | 50 | # Remove original initramfs file |
|
51 | 51 | rm -f "${BOOT_DIR}/initramfs-${KERNEL_VERSION}" |
|
52 | 52 | |
|
53 | 53 | # Configure U-Boot to load generated initramfs |
|
54 | 54 | printf "# Set initramfs file\nsetenv initramfs initramfs-${KERNEL_VERSION}.uboot\n\n$(cat ${BOOT_DIR}/uboot.mkimage)" > "${BOOT_DIR}/uboot.mkimage" |
|
55 | 55 | else # ENABLE_INITRAMFS=false |
|
56 | 56 | # Remove initramfs from U-Boot mkfile |
|
57 | 57 | sed -i '/.*initramfs.*/d' "${BOOT_DIR}/uboot.mkimage" |
|
58 | 58 | |
|
59 | 59 | if [ "$BUILD_KERNEL" = false ] ; then |
|
60 | 60 | # Remove dtbfile from U-Boot mkfile |
|
61 | 61 | sed -i '/.*dtbfile.*/d' "${BOOT_DIR}/uboot.mkimage" |
|
62 | 62 | printf "\nbootz \${kernel_addr_r}" >> "${BOOT_DIR}/uboot.mkimage" |
|
63 | 63 | else |
|
64 | 64 | printf "\nbootz \${kernel_addr_r} - \${fdt_addr_r}" >> "${BOOT_DIR}/uboot.mkimage" |
|
65 | 65 | fi |
|
66 | 66 | fi |
|
67 | 67 | |
|
68 | 68 | if [ "$SET_ARCH" = 64 ] ; then |
|
69 | 69 | echo "Setting up config.txt to boot 64bit uboot" |
|
70 | 70 | |
|
71 | 71 | printf "\n# 64bit-mode" >> "${BOOT_DIR}/config.txt" |
|
72 | 72 | printf "\n# arm_control=0x200 is deprecated https://www.raspberrypi.org/documentation/configuration/config-txt/misc.md" >> "${BOOT_DIR}/config.txt" |
|
73 | 73 | printf "\narm_64bit=1" >> "${BOOT_DIR}/config.txt" |
|
74 | 74 | sed -i "s|bootz|booti|g" "${BOOT_DIR}/uboot.mkimage" |
|
75 | 75 | fi |
|
76 | 76 | |
|
77 | # instead of sd, boot from usb device | |
|
77 | 78 | if [ "$ENABLE_UBOOTUSB" = true ] ; then |
|
78 | 79 | sed -i "s|mmc|usb|g" "${BOOT_DIR}/uboot.mkimage" |
|
79 | 80 | fi |
|
80 | 81 | |
|
81 | ||
|
82 | 82 | # Set mkfile to use the correct mach id |
|
83 | 83 | if [ "$ENABLE_QEMU" = true ] ; then |
|
84 | 84 | sed -i "s/^\(setenv machid \).*/\10x000008e0/" "${BOOT_DIR}/uboot.mkimage" |
|
85 | 85 | fi |
|
86 | 86 | |
|
87 | 87 | # Set mkfile to use the correct dtb file |
|
88 | 88 | sed -i "s/^\(setenv dtbfile \).*/\1${DTB_FILE}/" "${BOOT_DIR}/uboot.mkimage" |
|
89 | 89 | |
|
90 | 90 | # Set mkfile to use kernel image |
|
91 | 91 | sed -i "s/^\(fatload mmc 0:1 \${kernel_addr_r} \).*/\1${KERNEL_IMAGE}/" "${BOOT_DIR}/uboot.mkimage" |
|
92 | 92 | |
|
93 | 93 | # Remove all leading blank lines |
|
94 | 94 | sed -i "/./,\$!d" "${BOOT_DIR}/uboot.mkimage" |
|
95 | 95 | |
|
96 | 96 | # Generate U-Boot bootloader image |
|
97 | 97 | chroot_exec /usr/sbin/mkimage -A "${KERNEL_ARCH}" -O linux -T script -C none -a 0x00000000 -e 0x00000000 -n "RPi${RPI_MODEL}" -d /boot/firmware/uboot.mkimage /boot/firmware/boot.scr |
|
98 | 98 | |
|
99 | 99 | # Remove U-Boot sources |
|
100 | 100 | rm -fr "${R}/tmp/u-boot" |
|
101 | 101 | fi |
General Comments 0
Vous devez vous connecter pour laisser un commentaire.
Se connecter maintenant