创建SD卡烧写镜像脚本

环境配置脚本
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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值