Ok I found the solution! Based on provided scripts from FriendlyARM (sd-fuse_rk3399), I made this script to flash parameters, kernel and dtb files only into the first raw partition.
I copied usefull files next to my script :
- kernel.img (kernel binary)
- resource.img (dtb, logo, etc)
- param4sd.txt (from sd-fuse_rk3399 repo)
- parameter.txt (from sd-fuse_rk3399 repo)
- partmap.txt (from sd-fuse_rk3399 repo)
- sd_update (from sd-fuse_rk3399 repo)
Code: Select all
#!/bin/bash
# flash=mmc,1:kern:raw:0x2000000,0x2000000:kernel.img;
# flash=mmc,1:boot:raw:0x4000000,0x2000000:boot.img;
# Checking device for fusing
if [ $# -eq 0 ]; then
echo "Usage: $0 DEVICE"
exit 0
fi
case $1 in
/dev/sd[a-z] | /dev/loop[0-9]* | /dev/mmcblk[0-9]*)
if [ ! -e $1 ]; then
echo "Error: $1 does not exist."
exit 1
fi
DEV_NAME=`basename $1`
BLOCK_CNT=`cat /sys/block/${DEV_NAME}/size` ;;&
/dev/sd[a-z])
DEV_PART=${DEV_NAME}1
REMOVABLE=`cat /sys/block/${DEV_NAME}/removable` ;;
/dev/mmcblk[0-9]* | /dev/loop[0-9]*)
DEV_PART=${DEV_NAME}p1
REMOVABLE=1 ;;
*)
echo "Error: Unsupported SD reader"
exit 0
esac
if [ ${REMOVABLE} -le 0 ]; then
echo "Error: $1 is a non-removable device. Stop."
exit 1
fi
if [ -z ${BLOCK_CNT} -o ${BLOCK_CNT} -le 0 ]; then
echo "Error: $1 is inaccessible. Stop fusing now!"
exit 1
fi
let DEV_SIZE=${BLOCK_CNT}/2
if [ ${DEV_SIZE} -gt 64000000 ]; then
echo "Error: $1 size (${DEV_SIZE} KB) is too large"
exit 1
fi
true ${MIN_SIZE:=600000}
if [ ${DEV_SIZE} -le ${MIN_SIZE} ]; then
echo "Error: $1 size (${DEV_SIZE} KB) is too small"
echo " please try another SD card."
exit 1
fi
# ----------------------------------------------------------
cp ../kernel-rockchip/*.img $(dirname $0)
# ----------------------------------------------------------
RKPARAM=$(dirname $0)/parameter.txt
RKPARAM2=$(dirname $0)/param4sd.txt
# Automatically re-run script under sudo if not root
if [ $(id -u) -ne 0 ]; then
echo "Need sudo..."
sudo "$0" "$@"
fi
# ----------------------------------------------------------
# Get host machine
ARCH=
if uname -mpi | grep aarch64 >/dev/null; then
ARCH=aarch64/
fi
# ----------------------------------------------------------
# umount all at first
umount /dev/${DEV_NAME}* > /dev/null 2>&1
sync
# ----------------------------------------------------------
# partition card & fusing filesystem
true ${SD_UPDATE:=$(dirname $0)/sd_update}
[[ ! -f "${RKPARAM}" ]] && exit 0
PARTMAP=$(dirname $0)/partmap.txt
PARAM4SD=$(dirname $0)/param4sd.txt
# ----------------------------------------------------------
# Prepare image for sd raw img
# emmc boot: need parameter.txt, do not need partmap.txt
# sdraw: all need parameter.txt and partmap.txt
if [ ! -f "${PARTMAP}" ]; then
echo "File not found: ${PARTMAP}, please download the latest version of the image files from http://dl.friendlyarm.com/nanopct4"
exit 1
fi
if [ ! -f "${PARAM4SD}" ]; then
echo "File not found: ${PARAM4SD}, please download the latest version of the image files from http://dl.friendlyarm.com/nanopct4"
exit 1
fi
# write ext4 image
${SD_UPDATE} -d /dev/${DEV_NAME} -p ${PARTMAP}
if [ $? -ne 0 ]; then
echo "Error: filesystem fusing failed, Stop."
exit 1
fi
if [ -z ${ARCH} ]; then
partprobe /dev/${DEV_NAME} -s 2>/dev/null
fi
if [ $? -ne 0 ]; then
echo "Warning: Re-reading the partition table failed"
else
sleep 1
resize2fs -f /dev/${DEV_PART}
fi
sync
echo "---------------------------------"
echo "All done."