2024-10-25 17:48:08 +08:00
#!/bin/bash
2025-08-29 10:58:38 +08:00
set -e
set -x
2024-10-25 17:48:08 +08:00
__usage = "
Usage: build_u-boot [ OPTIONS]
2025-02-17 09:46:13 +08:00
Build openEuler SBCs u-boot image.
2024-10-25 17:48:08 +08:00
The target files idbloader.img and u-boot.itb will be generated in the build/u-boot folder of the directory where the build_u-boot.sh script is located.
Options:
2025-02-28 16:37:08 +08:00
--board, BOARD_CONFIG Required! The config of target board in the boards folder, which defaults to firefly-rk3399.
2024-12-03 00:21:11 +08:00
--cores N The number of cpu cores to be used during making.
-h, --help Show command help.
2024-10-25 17:48:08 +08:00
"
help( )
{
echo " $__usage "
exit $1
}
default_param( ) {
2025-02-17 09:46:13 +08:00
board = firefly-rk3399
2025-08-29 10:58:38 +08:00
workdir = ${ cur_dir } /build
2024-10-25 17:48:08 +08:00
u_boot_url = "https://gitlab.arm.com/systemready/firmware-build/u-boot.git"
rk3399_bl31_url = "https://github.com/rockchip-linux/rkbin/raw/master/bin/rk33/rk3399_bl31_v1.36.elf"
2025-08-29 10:58:38 +08:00
log_dir = ${ workdir } /log
2025-09-02 15:44:49 +08:00
nonfree_bin_dir = ${ cur_dir } /bin/rockchip
2024-12-03 00:21:11 +08:00
make_cores = $( nproc)
2024-10-25 17:48:08 +08:00
}
local_param( ) {
2025-08-29 10:58:38 +08:00
if [ -f ${ workdir } /.param ] ; then
board = $( cat ${ workdir } /.param | grep board)
2025-02-17 09:46:13 +08:00
board = ${ board : 6 }
2024-10-25 17:48:08 +08:00
fi
}
parseargs( )
{
if [ " x $# " = = "x0" ] ; then
return 0
fi
while [ " x $# " != "x0" ] ;
do
if [ " x $1 " = = "x-h" -o " x $1 " = = "x--help" ] ; then
return 1
elif [ " x $1 " = = "x" ] ; then
shift
2025-02-17 09:46:13 +08:00
elif [ " x $1 " = = "x--board" ] ; then
board = ` echo $2 `
2024-12-03 00:21:11 +08:00
shift
shift
elif [ " x $1 " = = "x--cores" ] ; then
make_cores = ` echo $2 `
2024-10-25 17:48:08 +08:00
shift
shift
else
echo ` date` - ERROR, UNKNOWN params " $@ "
return 2
fi
done
}
buildid = $( date +%Y%m%d%H%M%S)
builddate = ${ buildid : 0 : 8 }
ERROR( ) {
echo ` date` - ERROR, $* | tee -a ${ log_dir } /${ builddate } .log
}
LOG( ) {
echo ` date` - INFO, $* | tee -a ${ log_dir } /${ builddate } .log
}
build_u-boot( ) {
2025-08-29 10:58:38 +08:00
pushd ${ workdir }
if [ -d ${ workdir } /u-boot ] ; then
pushd ${ workdir } /u-boot
2024-10-25 17:48:08 +08:00
remote_url_exist = ` git remote -v | grep "origin" `
remote_url = ` git ls-remote --get-url origin`
2025-08-29 10:58:38 +08:00
popd
2024-10-25 17:48:08 +08:00
if [ [ ${ remote_url_exist } = "" || ${ remote_url } != ${ u_boot_url } ] ] ; then
2025-08-29 10:58:38 +08:00
rm -rf ${ workdir } /u-boot
2024-10-25 17:48:08 +08:00
git clone --depth= 1 -b ${ u_boot_ver } ${ u_boot_url }
if [ [ $? -eq 0 ] ] ; then
LOG "clone u-boot done."
else
ERROR "clone u-boot failed."
exit 1
fi
fi
else
git clone --depth= 1 -b ${ u_boot_ver } ${ u_boot_url }
LOG "clone u-boot done."
fi
2025-08-29 10:58:38 +08:00
popd
pushd ${ workdir } /u-boot
if [ [ -f ${ workdir } /u-boot/u-boot.itb && -f ${ workdir } /u-boot/idbloader.img ] ] ; then
2024-10-25 17:48:08 +08:00
LOG "u-boot is the latest"
else
if [ -f bl31.elf ] ; then rm bl31.elf; fi
wget -O bl31.elf ${ rk3399_bl31_url }
if [ ! -f bl31.elf ] ; then
ERROR "arm-trusted-firmware(bl31.elf) can not be found!"
exit 2
fi
2025-05-07 18:09:32 +08:00
make ARCH = arm ${ ubootconfig }
2024-12-03 00:21:11 +08:00
make ARCH = arm -j${ make_cores }
make ARCH = arm u-boot.itb -j${ make_cores }
2024-10-25 17:48:08 +08:00
LOG "make u-boot done."
fi
if [ ! -f u-boot.itb ] ; then
ERROR "make u-boot failed!"
exit 2
fi
2025-08-29 10:58:38 +08:00
popd
2024-10-25 17:48:08 +08:00
}
use_prebuild_u-boot( ) {
2025-08-29 10:58:38 +08:00
if [ -d ${ workdir } /u-boot ] ; then
rm -rf ${ workdir } /u-boot
2024-10-25 17:48:08 +08:00
fi
2025-02-17 09:46:13 +08:00
2025-08-29 10:58:38 +08:00
mkdir ${ workdir } /u-boot
2025-02-17 09:46:13 +08:00
if [ [ " x ${ platform } " = = "xrockchip" ] ] ; then
2025-08-29 10:58:38 +08:00
cp ${ local_uboot_dir } /* ${ workdir } /u-boot
2025-02-17 09:46:13 +08:00
elif [ [ " x ${ platform } " = = "xphytium" ] ] ; then
2025-08-29 10:58:38 +08:00
cp ${ local_uboot_dir } /fip-all-sd-boot.bin ${ workdir } /u-boot
mkenvimage -s 0x1000 -o ${ workdir } /u-boot/env.bin ${ local_uboot_dir } /env.txt
dd if = ${ workdir } /u-boot/env.bin of = ${ workdir } /u-boot/fip-all-sd-boot.bin bs = 1k seek = 1472 conv = notrunc
2025-06-03 00:22:27 +08:00
elif [ [ " x ${ platform } " = = "xallwinner" ] ] ; then
2025-08-29 10:58:38 +08:00
cp ${ local_uboot_dir } /* ${ workdir } /u-boot
2025-02-17 09:46:13 +08:00
else
echo "target u-boot can not found!"
exit 2
2024-10-25 17:48:08 +08:00
fi
}
set -e
u_boot_ver = "v2020.10"
2025-05-07 15:38:58 +08:00
cur_dir = $( cd $( dirname $0 ) ; pwd )
2024-10-25 17:48:08 +08:00
default_param
local_param
parseargs " $@ " || help $?
2025-09-18 14:59:31 +08:00
source ${ cur_dir } /boards/${ board } .conf
2025-05-07 18:09:32 +08:00
host_arch = $( arch)
if [ [ " ${ host_arch } " = = "x86_64" && " ${ arch } " = = "arm64" ] ] ; then
LOG " You are running this script on a ${ host_arch } mechine, use cross compile.... "
2025-09-18 14:59:31 +08:00
export CROSS_COMPILE = " ${ workdir } /openeuler_gcc_arm64le/aarch64-openeuler-linux-gnu- "
2025-05-07 18:09:32 +08:00
else
LOG " You are running this script on a ${ host_arch } mechine, progress.... "
fi
2025-08-29 10:58:38 +08:00
if [ ! -d ${ workdir } ] ; then
mkdir ${ workdir }
2024-10-25 17:48:08 +08:00
fi
2025-05-07 15:38:58 +08:00
2024-10-25 17:48:08 +08:00
if [ ! -d ${ log_dir } ] ; then mkdir -p ${ log_dir } ; fi
2025-08-29 10:58:38 +08:00
if [ ! -f ${ workdir } /.done ] ; then
touch ${ workdir } /.done
2024-10-25 17:48:08 +08:00
fi
2025-08-29 10:58:38 +08:00
sed -i 's/u-boot//g' ${ workdir } /.done
2024-10-25 17:48:08 +08:00
LOG "build u-boot..."
2025-08-29 10:58:38 +08:00
if [ " x ${ board } " = = "xraspberrypi" ] ; then
LOG "Skip build u-boot for Raspberry Pi."
2024-10-25 17:48:08 +08:00
else
2025-08-29 10:58:38 +08:00
if [ " x $ubootconfig " = = "x" ] ; then
use_prebuild_u-boot
else
build_u-boot
fi
LOG " The bootloader files are generated in the ${ workdir } /u-boot. "
2024-10-25 17:48:08 +08:00
fi
2025-08-29 10:58:38 +08:00
echo "u-boot" >> ${ workdir } /.done