1. 程式人生 > >BeagleBone Black eMMC燒寫指南

BeagleBone Black eMMC燒寫指南

   本文描述通過SD卡,對BeagleBone Black板載的eMMC進行燒寫。

AM335X啟動流程,開機檢測硬體BOOT引腳,決定從哪個儲存的介質讀取MLO與uboot.img 、進入uboot階段後,uboot根據配置好的啟動順序依次檢測對應介質是否存在。檢測到對應介質後進行啟動,進入Linux階段。

SD卡燒寫流程。按住BeagleBone Black上的boot按鍵。讓BeagleBone Black從SD卡中讀取MLO,uboot.img,從SD卡讀取LINUX 啟動系統後。通過事先編寫好的指令碼,對內部的eMMC進行分割槽。檔案的拷貝。

 

準備的資料:

MLO uboot.img

檔案系統。

對eMMC操作的指令碼:debrick.sh

 

 

0檔案的準備

這裡使用了2個檔案系統。1個是燒寫到SD卡中的最簡的檔案系統。1個是燒寫到SD卡中的檔案系統。

原始檔:

基礎檔案系統:arago-base-tisdk-image-am335x-evm-20181203012028.rootfs.tar.xz

TISDK檔案系統:tisdk-rootfs-image-am335x-evm-20181204081425.rootfs.tar.xz

MLO

u-boot.img

debrick.sh:原始碼在附錄中給出

得到以上的檔案系統後開始製作檔案:

1.SD卡中的檔案準備:

MLO u-boot.img ----------->>>>>>>boot_partition.tar.gz

tisdk-rootfs-image-am335x-evm-20181204081425.rootfs.tar.xz -------------->>>>>>>>>>>> rootfs_partition.tar.xz

SD卡第一分割槽:MLO,u-boot.img

SD卡第二分割槽:解壓arago-base-tisdk-image-am335x-evm-20181203012028.rootfs.tar.xz到rootfs資料夾下。

拷貝rootfs_partition.tar.xz 、boot_partition.tar.gz 、debrick.sh到rootfs/home/root/資料夾下。

此時的rootfs資料夾下的內容就是SD卡第二分割槽的檔案系統。

 

2.SD卡啟動盤的製作。

2.1通過TISDK中的./bin/create-sdcard.sh指令碼,將SD卡配置成2個分割槽。並將TI 預編譯好的檔案系統燒寫到SD卡中。(這裡檔案系統可以選擇TI預編譯好的完整的TISDK檔案系統,也可以自己製作的檔案系統,只要可以啟動即可)

2.2如果選擇第一步製作的檔案系統資料夾,此時SD卡已經制作完成,若使用TI預編譯好的檔案系統。此時需要

拷貝rootfs_partition.tar.xz 、boot_partition.tar.gz 、debrick.sh到SD卡第二分割槽home/root資料夾下。

至此SD卡製作完成

3.BeagleBone Black從SD卡啟動,以及命令的執行。

3.1.插入SD卡,按住BOOT按鍵上電。BeagleBone Black​​​​​​​從SD卡啟動系統。若啟動失敗。可按住BOOT按鍵。按下reset按鍵鬆開。

3.2.進入~目錄下。執行debrick.sh指令碼。此時便開始對BeagleBone Black​​​​​​​上的eMMC進行分割槽、格式化、檔案拷貝等操作。請耐心等待,拷貝檔案系統事會需要較長的時間。這裡後期可新增到啟動指令碼中實現SD卡啟動後的自動燒寫。

3.3.指令碼執行完成。並自動退出。此時內部eMMC已經燒寫完成。斷電。拔出SD卡,重新上電,此時BeagleBone Black​​​​​​​就會從內部eMMC啟動系統。

 

附錄:

debrick.sh

這裡需要注意sfdisk命令的版本問題。debrick.sh新版本不支援CHS的操作方式。這裡在TI官方提供的指令碼基礎上進行了修改。

 

echo "****************************************************"
echo "****************************************************"
echo ""
echo "Sitara Example Flashing Script - 02/11/2014"
echo ""

STARTTIME=$(date +%s)

##---------Start of variables---------------------##

## Set Server IP here
#SERVER_IP="192.168.100.1"

## Names of the images to grab from TFTP server
BOOT_PARTITION="boot_partition.tar.gz"

## Rename rootfs as needed depending on use of tar or img
ROOTFS_PARTITION="rootfs_partition.tar.xz"
## ROOTFS_PARTITION="rootfs_partition.img.gz"

## Declare eMMC device name here
DRIVE="/dev/mmcblk1"

##----------End of variables-----------------------##

## TFTP files from host.  Edit the files and host IP address for your application.
## We are grabbing two files, one an archive with files to populate a FAT partion,
## which we will create.  Another for a filesystem image to 'dd' onto an unmounted partition.
## Using a compressed tarball can be easier to implement, however, with a large file system
## with a lot of small files, we recommend a 'dd' image of the partition to speed up writes.
#echo "Getting files from server: ${SERVER_IP}"
#time tftp -b 4096 -g -r ${BOOT_PARTITION} ${SERVER_IP} &
#boot_pid=$!
#time tftp -b 4096 -g -r ${ROOTFS_PARTITION} ${SERVER_IP} &
#rootfs_pid=$!


## Kill any partition info that might be there
dd if=/dev/zero of=$DRIVE bs=4k count=1
sync
sync

## Check to see if the eMMC partitions have automatically loaded from the old MBR.
## This might have occured during the boot process if the kernel detected a filesystem
## before we killed the MBR. We will need to unmount and kill them by writing 4k zeros to the
## partitions that were found.

check_mounted(){
  is_mounted=$(grep ${DRIVE}p /proc/mounts | awk '{print $2}')

  if grep -q ${DRIVE}p /proc/mounts; then
      echo "Found mounted partition(s) on " ${DRIVE}": " $is_mounted
      umount $is_mounted
      counter=1
      for i in $is_mounted; do \
          echo "4k erase on ${DRIVE}p${counter}"; 
          dd if=/dev/zero of=${DRIVE}p${counter} bs=4k count=1;
          counter=$((counter+1));
      done
  else
      echo "No partition found. Continuing."
  fi
}

check_mounted;

## Partitioning the eMMC using information gathered.
## Here is where you can add/remove partitions.
## We are building 2 partitions:
##  1. FAT, size = 9 cylinders * 255 heads * 63 sectors * 512 bytes/sec = ~70MB
##  2. EXT3, size = 223 ($CYLINDERS-[9 for fat]) cylinders * 255 heads * 63 sectors * 512 bytes/sec = ~1l.7GB
##
## You will need to change the lines ",9,0c0C,*", "10,,,-" to suit your needs.  Adding is similar,
## but you will need to be aware of partition sizes and boundaries.  Use the man page for sfdisk.
echo "Partitioning the eMMC..."
sfdisk --force /dev/mmcblk1 << EOF
    1,104447,b,*
	,,,
EOF

## This sleep is necessary as there is a service which attempts
## to automount any filesystems that it finds as soon as sfdisk
## finishes partitioning.  We sleep to let it run.  May need to
## be lengthened if you have more partitions.
sleep 2

## Check here if there has been a partition that automounted.
##  This will eliminate the old partition that gets
##  automatically found after the sfdisk command.  It ONLY
##  gets found if there was a previous file system on the same
##  partition boundary.  Happens when running this script more than once.
##  To fix, we just unmount and write some zeros to it.
check_mounted;

## Clean up the dos (FAT) partition as recommended by SFDISK
dd if=/dev/zero of=${DRIVE}p1 bs=512 count=1

## Make sure posted writes are cleaned up
sync
sync

## Format the eMMC into 2 partitions
echo "Formatting the eMMC into 2 partitions..."

## Format the boot partition to fat32
mkfs.vfat -F 32 -n "boot" ${DRIVE}p1

## Format the rootfs to ext3 (or ext4, etc.) if using a tar file.
## We DO NOT need to format this partition if we are 'dd'ing an image
## Comment out this line if using 'dd' of an image.
mkfs.ext3 -L "rootfs" ${DRIVE}p2

## Make sure posted writes are cleaned up
sync
sync
echo "Formatting done."

## Make temp directories for mountpoints
mkdir tmp_boot

## Comment this line out if using 'dd' of an image. It is not needed.
mkdir tmp_rootfs

## Mount partitions for tarball extraction. NOT for 'dd'.
mount -t vfat ${DRIVE}p1 tmp_boot

## If 'dd'ing the rootfs, there is no need to mount it. Comment out the below.
mount -t ext3 ${DRIVE}p2 tmp_rootfs

## Wait for boot to finish tftp
echo "Copying Boot Files..."
time tar -xf ${BOOT_PARTITION} -C tmp_boot
sync
sync
umount ${DRIVE}p1
#rm ${BOOT_PARTITION}

sync
sync

echo "Boot partition done."

## Wait for rootfs to finish tftp
wait $rootfs_pid
## If using a tar archive, untar it with the below.
## If using 'dd' of an img, comment these lines out and use the below.
echo "Copying Rootfs Files..."
time tar -xf ${ROOTFS_PARTITION} -C tmp_rootfs
sync
sync
umount ${DRIVE}p2
#rm ${ROOTFS_PARTITION}

sync
sync

echo "RootFS partition done."

## If using 'dd' of an img, uncomment these lines.
## If using a tar archive, comment out these lines and use the above.
## time gunzip -c ${ROOTFS_PARTITION} | dd of=${DRIVE}p2 bs=4k
## sync
## sync
## echo "Rootfs partition done."

## The block below is only necessary if using 'dd'. 
## Force check the filesystem for consistency and fix errors if any.
## Resize partition to the length specified by the MBR.
## /sbin/e2fsck -fy ${DRIVE}p2
## /sbin/resize2fs ${DRIVE}p2

ENDTIME=$(date +%s)
echo "It took $(($ENDTIME - $STARTTIME)) seconds to complete this task..."
## Reboot
echo ""
echo "********************************************"
echo "Sitara Example Flash Script is complete."
echo ""