Tool/software:
HI
Using our own AM623 board, the SD card can start normally, but it cannot start when using EMMC. The program in EMMC is programmed through script burning after starting from an SD card. The attachment contains the script for burning and running screenshots

this is sh
#!/bin/bash
set -e
# Major version
MAJOR_VERSION="4"
# Minor version
MINOR_VERSION="1"
# eMMC device
EMMC_DEVICE=/dev/mmcblk0
# SD device
SD_DEVICE=/dev/mmcblk1
# SD mount point
SD_MOUNT_POINT=/run/media/mmcblk1
# eMMC default unit size (1024 * 1024 = 1048576Byte = 1MB)
SIZE_MB=$((1024 * 1024))
# eMMC boot partition size (128MB)
EMMC_BOOT_PART_SIZE=$((128 * 1024 * 1024))
# The reserved capacity of rootfs partition is 800MB
# Since inode also takes up space, the actual free space is insufficient for 800MB.
ROOTFS_RESERVE_SIZE=$((800 * 1024 * 1024))
# Print error log
function err() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $@" >&2
}
# Check the SD card is mounted
function check_sdboot_mount() {
if [[ ! -e ${SD_DEVICE} ]]; then
err "ERROR! Can not find SD."
err "Abort, work not done!"
exit 1
fi
sdboot_mount_status=$(df ${SD_DEVICE}p1 | grep ${SD_DEVICE}p1 | awk '{print $6}')
if [[ -z ${sdboot_mount_status} ]]; then
err "ERROR! ${SD_DEVICE}p1 not mounted."
err "Abort, work not done!"
exit 1
fi
sdboot_mount_status=$(df ${SD_DEVICE}p3 | grep ${SD_DEVICE}p3 | awk '{print $6}')
if [[ -z ${sdboot_mount_status} ]]; then
err "ERROR! ${SD_DEVICE}p3 not mounted."
err "Abort, work not done!"
exit 1
fi
echo "SD card is mounted."
}
# Check emmc device is exist.
function check_emmc_device() {
# Check whether the eMMC device exists
if [[ ! -b ${EMMC_DEVICE} || -z ${EMMC_DEVICE} ]]; then
err "ERROR: ${EMMC_DEVICE} is not exist."
err "Abort, work not done!"
exit 1
fi
echo "eMMC device is exist."
# Check whether the EMMC capacity is sufficient
# Calculate eMMC and filesystem size
emmc_size=$(($(fdisk -s ${EMMC_DEVICE}) * 1024))
fs_size=$(($(du -s ${SD_MOUNT_POINT}p3 | awk '{print $1}') * 1024))
# The eMMC capacity must be larger than the size of the filesystem
if [[ $(($emmc_size - $EMMC_BOOT_PART_SIZE)) -lt ${fs_size} ]]; then
err "ERROR: Create eMMC partition failed, The eMMC capacity is not sufficient!"
exit 1
fi
echo "eMMC capacity is satisfied."
}
# Create emmc partition
function create_emmc_partition() {
echo "Partitioning ${EMMC_DEVICE}..."
# umount them in case mounted already.
for i in $(cat /proc/mounts | grep ${EMMC_DEVICE}p | awk '{print $1}'); do
umount $i 2>/dev/null
done
# Clear the head of emmc.
dd if=/dev/zero of=${EMMC_DEVICE} bs=1024 count=1024
# Divide boot partition
partition_start=1
partition_end=$((${EMMC_BOOT_PART_SIZE} / ${SIZE_MB} + ${partition_start}))
parted -s ${EMMC_DEVICE} mklabel msdos
parted -s ${EMMC_DEVICE} unit MiB mkpart primary fat32 -- ${partition_start} ${partition_end}
parted -s ${EMMC_DEVICE} set 1 boot on
# Divide rootfs partition
# The rootfs partition is twice the size of the filesystem
partition_start=${partition_end}
partition_end=$(($((${fs_size} + ${ROOTFS_RESERVE_SIZE})) / ${SIZE_MB} + ${partition_start}))
if [[ $(($emmc_size - $EMMC_BOOT_PART_SIZE)) -lt $((${fs_size} + ${ROOTFS_RESERVE_SIZE})) ]]; then
# If the rootfs partition cannot reserve 800MB of free space,
# a warning prompt is printed, but it can be flash normally.
err "WARNING: Due to insufficient eMMC space, The rootfs partition cannot reserve 800MB of space."
# Since the rootfs partition cannot be divided into twice the free space,
# all the remaining space in the emmc is divided into the rootfs partition.
partition_end=-2
fi
parted -s ${EMMC_DEVICE} unit MiB mkpart primary ext4 -- ${partition_start} ${partition_end}
sleep 15 #FIXME Make sure partition emmc is finished
# Format partition
partition_list=(${EMMC_DEVICE}p1 ${EMMC_DEVICE}p2)
for partition in ${partition_list[*]}; do
mount_state=$(cat /proc/mounts | grep ${partition} | awk '{print $1}')
# Umount in case mounted alraady
if [[ ! -z "${mount_state}" ]]; then
umount ${partition}
fi
done
mkfs.vfat -F 32 -n BOOT ${partition_list[0]}
sleep 1
mkfs.ext4 -F -L rootfs ${partition_list[1]}
sleep 1
echo "Partition done!"
}
# Check that the environment is satisfied
function check_environment() {
echo "Checking flash environment..."
# Check the SD card is mounted
check_sdboot_mount
# Check emmc device is exist
check_emmc_device
echo "Check flash environment done."
}
# Get MTD partition
function get_mtd_partition() {
mtd_partition=$(cat /proc/mtd | grep $1 | awk -F ':' '{print $1}' | awk -F 'mtd' '{print $2}')
if [[ -z "${mtd_partition}" ]]; then
err "ERROR! Get MTD partition number of $1 failed!"
err "Abort, work not done!"
exit 1
fi
echo ${mtd_partition}
}
# Erase u-boot environment variable
function erase_uboot_env() {
local emmc_boot_partition="${EMMC_DEVICE}boot0"
local profile="/sys/block/mmcblk0boot0/force_ro"
echo "Erasing u-boot environment variable..."
if [[ ! -e ${profile} ]]; then
err "ERROR: ${profile} is not exist."
exit 1
fi
if [[ ! -e ${emmc_boot_partition} ]]; then
err "ERROR: ${emmc_boot_partition} is not exist."
exit 1
fi
# Enable to can write the boot partition
echo 0 > ${profile}
# Erase environment variable
# ENV_SIZE: 0x20000
# ENV_OFFSET: 0x380000
dd if=/dev/zero of=${emmc_boot_partition} bs=1k count=128 seek=3584
echo "Erase u-boot environment variable done."
}
# Flash u-boot/dtb/kernel/rootfs
function flash_system() {
local emmc_boot_partition="${EMMC_DEVICE}boot0"
local profile="/sys/block/mmcblk0boot0/force_ro"
echo "Flashing system..."
# Flash u-boot
echo "-> Flashing tiboot3/tispl/u-boot..."
# Enable to can write the boot partition
echo 0 > ${profile}
# Flash tiboot3.bin
dd if=/media/mmcblk1p1/tiboot3.bin of=${emmc_boot_partition} bs=1K
# Flash tispl.bin
dd if=/media/mmcblk1p1/tispl.bin of=${emmc_boot_partition} bs=1K seek=512
# Flash u-boot.img
dd if=/media/mmcblk1p1/u-boot.img of=${emmc_boot_partition} bs=1K seek=1536
echo "-> Flash tiboot3/tispl/u-boot done."
echo "-> Flashing dtb/kernel/rootfs to ${EMMC_DEVICE}p2..."
# Mount points of rootfs partition.
local rootfs_mount_point="/tmp/$$-rootfs"
if [[ ! -d ${rootfs_mount_point} ]]; then
mkdir -p ${rootfs_mount_point}
fi
mount ${EMMC_DEVICE}p2 ${rootfs_mount_point}
# Copy file to dtb/kernel/rootfs from backup partition of SD
sd_p3_mount_point=$(df ${SD_DEVICE}p3 | grep ${SD_DEVICE}p3 | awk '{print $6}')
cp -rf ${sd_p3_mount_point}/. ${rootfs_mount_point}
# Umount rootfs partition
rootfs_partition=$(cat /proc/mounts | grep ${EMMC_DEVICE}p2 | awk '{print $1}')
if [[ ! -z "${rootfs_partition}" ]]; then
umount ${EMMC_DEVICE}p2
fi
echo "-> Flash dtb/kernel/rootfs done."
echo "Flash system done."
}
######### MAIN ENTRANCE#########
function main() {
echo -e "\nVersion: mkemmcboot_${MAJOR_VERSION}.${MINOR_VERSION}"
# Check the flash environment
echo -e "\n1/4:"
check_environment
# Erases the u-boot environment variable
echo -e "\n2/4:"
erase_uboot_env
# Create emmc partition
echo -e "\n3/4:"
create_emmc_partition
# Flash u-boot/kernel/rootfs etc
echo -e "\n4/4:"
flash_system
sync
}
main

