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 ""



猜你喜欢

转载自blog.csdn.net/zhang750188474/article/details/84826234