AM335X-啟動SD卡制作
1. AM335X啟動配置
礦闆SYSBOOT位配置資訊,在礦闆反面ANTMINER絲印上方,使用電阻焊接與否來替代撥碼開關,礦闆預設配置表如下
15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 |
R55 | R56 | R57 | R58 | R59 | R60 | R61 | R62 |
1 | |||||||
7 | 6 | 5 | 4 | 3 | 2 | ||
R63 | R64 | R65 | R66 | R67 | R68 | R69 | R70 |
然後參照AM335x Sitara Processors Technical Reference Manual得出礦闆預設的啟動優先級(截圖有剪裁)
2. 擦除NAND上的鏡像
從預設啟動配置可以看出,nand flash啟動優先級高于mmc0和uart0,正常情況下的礦闆都是帶程式的
如果能進uboot,可以使用以下指令擦除nand:
nand erase.chip
如果不能中斷uboot引導過程,或者上電不輸出
ccccc
(xmodem1K的辨別),則可能是nand flash中的mlo或uboot損壞
可以通過短接nand flash上的相關引腳來幹擾預設啟動過程,進而跳到mmc0或者uart0啟動
但首要前提,礦闆PMIC(TPS65217C)各路電壓都正常,晶振0.8V左右,核心1.1V都要有。
短接下圖任一紅色方框中,任意兩個引腳,然後再通電啟動即可破壞預設的NAND優先啟動方式,跳轉到mmc0或者uart0啟動。
3. 格式化TF卡
我使用的windows系統,是以使用DiskGenius來格式化TF卡
首先删除TF卡内原有的分區(如果TF卡内有其他資料,需要提前備份),這裡我使用的是一張拓容卡(萬惡的淘寶奸商),是以請不要吐槽這個容量
建立一個FAT32分區,參數這裡改不了,預設即可,然後點選
儲存更改
先不要格式化,右鍵剛才建立的分區
系統辨別改成
0B
最後格式化剛才建立的分區,拷入一級引導
MLO
和
uboot.img
将TF卡插入礦闆卡槽,上電啟動,完成。
#!/bin/bash
# Authors:
# LT Thomas <[email protected]>
# Chase Maupin
# Franklin Cooper Jr.
#
# create-sdcard.sh v0.3
# Force locale language to be set to English. This avoids issues when doing
# text and string processing.
export LANG=C
# Determine the absolute path to the executable
# EXE will have the PWD removed so we can concatenate with the PWD safely
PWD=`pwd`
EXE=`echo $0 | sed s=$PWD==`
EXEPATH="$PWD"/"$EXE"
clear
cat << EOM
################################################################################
This script will create a bootable SD card from custom or pre-built binaries.
The script must be run with root permissions and from the bin directory of
the SDK
Example:
$ sudo ./create-sdcard.sh path/to/sdcard/files
Formatting can be skipped if the SD card is already formatted and
partitioned properly.
################################################################################
EOM
AMIROOT=`whoami | awk {'print $1'}`
if [ "$AMIROOT" != "root" ] ; then
echo " **** Error *** must run script with sudo"
echo ""
exit
fi
THEPWD=$EXEPATH
check_for_sdcards()
{
# find the avaible SD cards
ROOTDRIVE=`mount | grep 'on / ' | awk {'print $1'} | cut -c6-8`
PARTITION_TEST=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''`
if [ "$PARTITION_TEST" = "" ]; then
echo -e "Please insert a SD card to continue\n"
while [ "$PARTITION_TEST" = "" ]; do
read -p "Type 'y' to re-detect the SD card or 'n' to exit the script: " REPLY
if [ "$REPLY" = 'n' ]; then
exit 1
fi
ROOTDRIVE=`mount | grep 'on / ' | awk {'print $1'} | cut -c6-8`
PARTITION_TEST=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''`
done
fi
}
# find the avaible SD cards
ROOTDRIVE=`mount | grep 'on / ' | awk {'print $1'} | cut -c6-9`
if [ "$ROOTDRIVE" = "root" ]; then
ROOTDRIVE=`readlink /dev/root | cut -c1-3`
else
ROOTDRIVE=`echo $ROOTDRIVE | cut -c1-3`
fi
PARTITION_TEST=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''`
# Check for available mounts
check_for_sdcards
echo -e "\nAvailable Drives to write images to: \n"
echo "# major minor size name "
cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''
echo " "
DEVICEDRIVENUMBER=
while true;
do
read -p 'Enter Device Number or 'n' to exit: ' DEVICEDRIVENUMBER
echo " "
if [ "$DEVICEDRIVENUMBER" = 'n' ]; then
exit 1
fi
if [ "$DEVICEDRIVENUMBER" = "" ]; then
# Check to see if there are any changes
check_for_sdcards
echo -e "These are the Drives available to write images to:"
echo "# major minor size name "
cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''
echo " "
continue
fi
DEVICEDRIVENAME=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n '' | grep "${DEVICEDRIVENUMBER}:" | awk '{print $5}'`
if [ -n "$DEVICEDRIVENAME" ]
then
DRIVE=/dev/$DEVICEDRIVENAME
DEVICESIZE=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n '' | grep "${DEVICEDRIVENUMBER}:" | awk '{print $4}'`
break
else
echo -e "Invalid selection!"
# Check to see if there are any changes
check_for_sdcards
echo -e "These are the only Drives available to write images to: \n"
echo "# major minor size name "
cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<sd.\>\|\<mmcblk.\>' | grep -n ''
echo " "
fi
done
echo "$DEVICEDRIVENAME was selected"
#Check the size of disk to make sure its under 16GB
if [ $DEVICESIZE -gt 17000000 ] ; then
cat << EOM
################################################################################
**********WARNING**********
Selected Device is greater then 16GB
Continuing past this point will erase data from device
Double check that this is the correct SD Card
################################################################################
EOM
ENTERCORRECTLY=0
while [ $ENTERCORRECTLY -ne 1 ]
do
read -p 'Would you like to continue [y/n] : ' SIZECHECK
echo ""
echo " "
ENTERCORRECTLY=1
case $SIZECHECK in
"y") ;;
"n") exit;;
*) echo "Please enter y or n";ENTERCORRECTLY=0;;
esac
echo ""
done
fi
echo ""
DRIVE=/dev/$DEVICEDRIVENAME
NUM_OF_DRIVES=`df | grep -c $DEVICEDRIVENAME`
# This if statement will determine if we have a mounted sdX or mmcblkX device.
# If it is mmcblkX, then we need to set an extra char in the partition names, 'p',
# to account for /dev/mmcblkXpY labled partitions.
if [[ ${DEVICEDRIVENAME} =~ ^sd. ]]; then
echo "$DRIVE is an sdx device"
P=''
else
echo "$DRIVE is an mmcblkx device"
P='p'
fi
if [ "$NUM_OF_DRIVES" != "0" ]; then
echo "Unmounting the $DEVICEDRIVENAME drives"
for ((c=1; c<="$NUM_OF_DRIVES"; c++ ))
do
unmounted=`df | grep '\<'$DEVICEDRIVENAME$P$c'\>' | awk '{print $1}'`
if [ -n "$unmounted" ]
then
echo " unmounted ${DRIVE}$P$c"
sudo umount -f ${DRIVE}$P$c
fi
done
echo " unmounted ${DRIVE}$P"
sudo umount -f ${DRIVE}$P
else
echo " unmounted ${DRIVE}$P"
sudo umount -f ${DRIVE}$P
fi
# Refresh this variable as the device may not be mounted at script instantiation time
# This will always return one more then needed
NUM_OF_PARTS=`cat /proc/partitions | grep -v $ROOTDRIVE | grep -c $DEVICEDRIVENAME`
for ((c=1; c<"$NUM_OF_PARTS"; c++ ))
do
SIZE=`cat /proc/partitions | grep -v $ROOTDRIVE | grep '\<'$DEVICEDRIVENAME$P$c'\>' | awk '{print $3}'`
echo "Current size of $DEVICEDRIVENAME$P$c $SIZE bytes"
done
#Section for partitioning the drive
#create 1 partition
cat << EOM
################################################################################
Now erasing partition table
################################################################################
EOM
dd if=/dev/zero of=$DRIVE bs=1024 count=1024
cat << EOM
################################################################################
Partitioning Boot
################################################################################
EOM
mkfs.vfat -I -F 32 -n "boot" ${DRIVE}${P}
#Add directories for images
export START_DIR=$PWD
export PATH_TO_SDBOOT=boot
echo " "
echo "Mount the partitions "
mkdir $PATH_TO_SDBOOT
sudo mount -t vfat ${DRIVE}${P} boot/
echo " "
echo "Emptying partitions "
echo " "
sudo rm -rf $PATH_TO_SDBOOT/*
echo ""
echo "Syncing...."
echo ""
sync
sync
sync
cat << EOM
################################################################################
Copying files now... will take minutes
################################################################################
Copying boot partition
EOM
echo ""
#copy boot files out of board support
if [ -f "$1/MLO" ] ; then
cp -f $1/* $PATH_TO_SDBOOT/
elif [ -f "$1/tiboot3.bin" ] ; then
cp -f $1/* $PATH_TO_SDBOOT/
else
cat << EOM
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ERROR: SD card file directory does not exist
ERROR: ($1)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
EOM
fi
echo ""
echo ""
echo "Syncing..."
sync
sync
sync
echo " "
echo "Un-mount the partitions "
sudo umount -f $PATH_TO_SDBOOT
echo " "
echo "Remove created temp directories "
sudo rm -rf $PATH_TO_SDBOOT
echo " "
echo "Operation Finished"
echo " "