This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/PROCESSOR-SDK-AM335X: Burning eMMC from kernel using flasher script

Part Number: PROCESSOR-SDK-AM335X

Tool/software: Linux

Hi

I'm using flasher.sh to burn the emmc:

1) Is there newer version of flasher.sh, my file

#!/bin/bash
echo "****************************************************"
echo "****************************************************"
echo ""
echo "Sitara Example Flashing Script - 03/11/2016         "
echo ""

STARTTIME=$(date +%s)

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

## Set Server IP here
SERVER_IP=$1

## Set MAC address here, passed from fetcher.sh and U-Boot
MAC_ADDR=$2

## 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="tisdk-rootfs-image-am335x-evm.tar.gz"

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

##----------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. This can either be a archive
## to be uncompressed to the partition, or an 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.
## The -b option in the TFTP command sets the packet size from the default 512 bytes to 
## 1468 bytes, the largest size that avoids IP packet fragmentation. Faster transfers 
## might be achieved with larger packet sizes, so experimentation and optimization is
## encouraged.
echo "Getting files from server: ${SERVER_IP}"
time tftp -b 1468 -g -r ${BOOT_PARTITION} ${SERVER_IP} &
boot_pid=$!
time tftp -b 1468 -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

## Figure out how big the eMMC is in bytes
SIZE=`fdisk -l $DRIVE | grep Disk | awk 'NR==1 {print $5}'`

## Translate size into segments, which traditional tools call Cylinders. eMMC is not a spinning disk.
## We are basically ignoring what FDISK and SFDISK are reporting because it is not really accurate.
## we are translating this info to something that makes more sense for eMMC.
CYLINDERS=`echo $SIZE/255/63/512 | bc`

## 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 = ~1.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 -D -H 255 -S 63 -C $CYLINDERS $DRIVE << EOF
,9,0x0C,*
10,,,-
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
wait $boot_pid
echo "Copying Files..."
time tar -xf ${BOOT_PARTITION} -C tmp_boot
sync
sync
umount ${DRIVE}p1
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.
time tar -xf ${ROOTFS_PARTITION} -C tmp_rootfs
sync
sync
umount ${DRIVE}p2

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

## The files that were transferred will NOT be cleaned up since this is a
## RAM Disk. They will automatically disappear with a reboot.

## A reboot could be initiated here, but it might be nice to have a "completion"
## signal so the user knows to do whatever is necessary for the next stage of
## programming/testing. For example, it may be necessary to do something to set the board
## to boot from the eMMC (or whatever was just programmed) and test the image that was
## just programmed. Or, turn on some LEDs on the board as a visual indicator of completion.

## If using Uniflash, the server is configured to mark completion of a flash
## process when receiving a TFTP get request like below.
tftp -g -r TargetProgrammingComplete:${MAC_ADDR} ${SERVER_IP}  

## Reboot

echo ""
echo "********************************************"
echo "Sitara Example Flash Script is complete."
echo ""



is from 03/11/2016

2)  When listing the emmc devices i got the following (sd card isn't inserted):

-rw-r--r--    1 root     root           512 Feb 26 20:55 /dev/mmcblk0p1
-rw-r--r--    1 root     root          4096 Feb 26 20:55 /dev/mmcblk0
brw-rw----    1 root     disk      179,   0 Jan  1  1970 /dev/mmcblk1
brw-rw----    1 root     disk      179,  16 Jan  1  1970 /dev/mmcblk1boot0
brw-rw----    1 root     disk      179,  32 Jan  1  1970 /dev/mmcblk1boot1
brw-rw----    1 root     disk      179,  48 Jan  1  1970 /dev/mmcblk1rpmb

whice device is the eMMC ? and what are the mmcblk1boot and mmcblk1rpmb?

Thanks

  • Hello Joni,

    Joni 14324 said:
    1) Is there newer version of flasher.sh, my file (Please visit the site to view this file)is from 03/11/2016

    No, you already have the latest.


    Joni 14324 said:
    whice device is the eMMC ? and what are the mmcblk1boot and mmcblk1rpmb?

    Your eMMC device is.
    brw-rw----    1 root     disk      179,   0 Jan  1  1970 /dev/mmcblk1

    These are the boot partitions where the boot files and their configuration files are saved, but booting from these partitions is not supported on AM335x devices.
    brw-rw----    1 root     disk      179,  16 Jan  1  1970 /dev/mmcblk1boot0
    brw-rw----    1 root     disk      179,  32 Jan  1  1970 /dev/mmcblk1boot1

    This is secure data partition which is used to hold applications secure data.
    brw-rw----    1 root     disk      179,  48 Jan  1  1970 /dev/mmcblk1rpmb

    Best regards,
    Kemal

  • Hi Kemal,

    Thanks for your reply, I had to make some change in script for example change the $device from mmc0 to mmc1.

    Another issue, there is use of mkfs.ext3 and we would like to work with ext4 which is missing from the filesystem,
    How can i update the am335x-tiny-filesystem with mkfs.ext4?

    Thanks
  • You need to download the latest Processor SDK. It contains arago-tiny-image-am335x-evm.tar.xz image in <Processor SDK>/filesystem/ directory with mkfs.ext4 support.

  • OK, I' ll check the arago-tiny-image-am335x-evm.tar.xz of latest SDK.
  • I try to use the new fs, but it's not working well with usb rndis.

    Thanks

  • Hello Joni,

    You can add ext4 support to am335x-tiny-filesystem in this way.

    Execute these commands in your host computer, to generate the ext4 support files.

    $ sudo dpkg-reconfigure dash
    (Select "No" when prompted)

    Close the current terminal where you have executed dpkg-reconfigure dash command and open a new one.

    $ sudo apt-get install git build-essential python diffstat texinfo gawk chrpath dos2unix wget unzip socat doxygen libc6:i386 libncurses5:i386 libstdc++6:i386 libz1:i386

    $ wget http://releases.linaro.org/archive/15.05/components/toolchain/binaries/arm-linux-gnueabihf/gcc-linaro-4.9-2015.05-x86_64_arm-linux-gnueabihf.tar.xz
    $ tar -Jxvf gcc-linaro-4.9-2015.05-x86_64_arm-linux-gnueabihf.tar.xz -C $HOME

    Create or make 20GB SWAP partition as shown in this thread.

    $ git clone git://arago-project.org/git/projects/oe-layersetup.git tisdk
    $ cd tisdk
    $ ./oe-layertool-setup.sh -f configs/processor-sdk/processor-sdk-02.00.00.00-config.txt
    $ cd build
    $ . conf/setenv
    $ export PATH=$HOME/gcc-linaro-4.9-2015.05-x86_64_arm-linux-gnueabihf/bin:$PATH
    $  MACHINE=am335x-evm bitbake e2fsprogs -c build

    When the build is completed download and install the Processor SDK 4.3.0.5 on your host computer, extract the am335x_tiny_filesystem.tar.gz and install the needed ext4 support and its dependencies in this exact order and archive it back with the demonstrated commands below.

    $ mkdir am335x_tiny_filesystem
    $ sudo tar xvf am335x_tiny_filesystem.tar.gz -C am335x_tiny_filesystem/
    $ sudo <Processor SDK>/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/opkg -o am335x_tiny_filesystem --add-arch cortexa8hf-vfp-neon:71 install <tisdk>/build/arago-tmp-external-linaro-toolchain/deploy/ipk/cortexa8hf-vfp-neon/libc6_2.19-2014.08-1-git-r0-arago28_cortexa8hf-vfp-neon.ipk
    $ sudo <Processor SDK>/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/opkg -o am335x_tiny_filesystem --add-arch cortexa8hf-vfp-neon:71 install <tisdk>/build/arago-tmp-external-linaro-toolchain/deploy/ipk/cortexa8hf-vfp-neon/libuuid1_2.25.2-r1_cortexa8hf-vfp-neon.ipk
    $ sudo <Processor SDK>/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/opkg -o am335x_tiny_filesystem --add-arch cortexa8hf-vfp-neon:71 install <tisdk>/build/arago-tmp-external-linaro-toolchain/deploy/ipk/cortexa8hf-vfp-neon/libblkid1_2.25.2-r1_cortexa8hf-vfp-neon.ipk
    $ sudo <Processor SDK>/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/opkg -o am335x_tiny_filesystem --add-arch cortexa8hf-vfp-neon:71 install <tisdk>/build/arago-tmp-external-linaro-toolchain/deploy/ipk/cortexa8hf-vfp-neon/libcom-err2_1.42.9-r0_cortexa8hf-vfp-neon.ipk
    $ sudo <Processor SDK>/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/opkg -o am335x_tiny_filesystem --add-arch cortexa8hf-vfp-neon:71 install <tisdk>/build/arago-tmp-external-linaro-toolchain/deploy/ipk/cortexa8hf-vfp-neon/libe2p2_1.42.9-r0_cortexa8hf-vfp-neon.ipk
    $ sudo <Processor SDK>/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/opkg -o am335x_tiny_filesystem --add-arch cortexa8hf-vfp-neon:71 install <tisdk>/build/arago-tmp-external-linaro-toolchain/deploy/ipk/cortexa8hf-vfp-neon/libext2fs2_1.42.9-r0_cortexa8hf-vfp-neon.ipk
    $ sudo <Processor SDK>/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/opkg -o am335x_tiny_filesystem --add-arch cortexa8hf-vfp-neon:71 install <tisdk>/build/arago-tmp-external-linaro-toolchain/deploy/ipk/cortexa8hf-vfp-neon/e2fsprogs-mke2fs_1.42.9-r0_cortexa8hf-vfp-neon.ipk
    $ cd am335x_tiny_filesystem/
    $ sudo tar czvf ../am335x_tiny_filesystem_ext4_support.tar.gz *

    You will find the am335x_tiny_filesystem_ext4_support.tar.gz in your previous directory.
    I am attaching you the ext4_support_files.tar.gz for reference.

    Best regards,
    Kemal