环境配置脚本
env.sh
. /opt/petalinux/2021.1/environment-setup-cortexa9t2hf-neon-xilinx-linux-gnueabi
echo "CC=$CC"
echo "sysroots=$SDKTARGETSYSROOT"
echo "ARCH=$ARCH"
echo "CROSS_COMPILE=$CROSS_COMPILE"
echo "${CROSS_COMPILE}gcc $(${CROSS_COMPILE}gcc -v 2>&1 | grep "gcc version")"
export HOME_DIR=$(pwd)
echo "HOME_DIR=$HOME_DIR "
export SRC_DIR=${HOME_DIR}/source
export SCRIPT_DIR=${HOME_DIR}/script
export CFG_DIR=${HOME_DIR}/config
export OUT=${HOME_DIR}/images
export BUILD_DIR=${HOME_DIR}/build
export U_BOOT_DIR=${SRC_DIR}/u-boot-xlnx
export KERNEL_DIR=${SRC_DIR}/linux-xlnx
export DEVICE_TREE_DIR=${SRC_DIR}/device-tree-xlnx
export ZYNQ_APP_DIR=${SRC_DIR}/LJ7900-XT-XC7Z035-APP
export BUILD_U_BOOT_DIR=${BUILD_DIR}/u-boot-xlnx
export BUILD_KERNEL_DIR=${BUILD_DIR}/linux-xlnx
export BUILD_DEVICE_TREE_DIR=${BUILD_DIR}/device-tree
export BUILD_ZYNQ_APP_DIR=${BUILD_DIR}/zynq_app
function echo_ok()
{
msg="${@}"
dirreg=$(echo "$HOME_DIR/" | sed 's/\//\\\//g' )
msg=$(echo $msg | sed "s/$dirreg//g")
echo -e "\033[32m ${msg} \033[0m" >&1
}
export -f echo_ok
function echo_err()
{
msg="${@}"
dirreg=$(echo "$HOME_DIR/" | sed 's/\//\\\//g' )
msg=$(echo $msg | sed "s/$dirreg//g")
echo -e "\033[31m ${msg} \033[0m" >&2
}
export -f echo_err
function OS_MAKE()
{
echo_ok "build $@"
make -j $(grep -c "^processor" /proc/cpuinfo) ARCH="$ARCH" CROSS_COMPILE="$CROSS_COMPILE" CC="$CC" HOSTCC="gcc" "$@" > /dev/null
}
export -f OS_MAKE
function cp_target_to_out()
{
target=$1
if [ -f ${target} ];then
outfile=${OUT}/$(basename ${target})
cp -dr ${target} ${outfile}
echo_ok "${outfile} is Ready"
else
echo_err "no found ${outfile} error"
fi
}
export -f cp_target_to_out
function get_package_name()
{
echo $(${SCRIPT_DIR}/setlocalversion ${HOME_DIR})
}
export -f get_package_name
mkdir -p build
mkdir -p images
script/create_sd_img.sh
#! /bin/sh
fw_package=$1
if [ -z "$fw_package" ];then
fw_package=${OUT}/$(printf "XC7Z035-FW-%s.tar.gz" $(get_package_name))
fi
target=${OUT}/sd_boot_$(get_package_name).img
dd if=/dev/zero of=${target} bs=1M count=256
fdisk ${target} <<EOF
n
p
1
+127M
n
p
2
+127M
wq
EOF
dev_loop="$(losetup -f)"
echo_ok "${dev_loop}"
sudo losetup -P ${dev_loop} ${target}
lsblk | grep "${dev_loop}"
sudo mkfs.vfat "${dev_loop}"p1
sudo mkfs.vfat "${dev_loop}"p2
rm -rf ${BUILD_DIR}/create_sd_img/boot
mkdir -p ${BUILD_DIR}/create_sd_img/boot
sudo mount "${dev_loop}"p1 ${BUILD_DIR}/create_sd_img/boot
rm -rf ${BUILD_DIR}/create_sd_img/app
mkdir -p ${BUILD_DIR}/create_sd_img/app
sudo mount "${dev_loop}"p2 ${BUILD_DIR}/create_sd_img/app
sudo tar -xzvf ${fw_package} --no-same-owner -C ${BUILD_DIR}/create_sd_img/boot
sudo umount ${BUILD_DIR}/create_sd_img/boot
sudo umount ${BUILD_DIR}/create_sd_img/app
sudo losetup -d ${dev_loop}
echo_ok "$0"
echo_ok $target