Booting from a SD card

24 views
Skip to first unread message

nonrepe...@gmail.com

unread,
Jun 5, 2017, 4:01:52 PM6/5/17
to BeagleBoard
I've been banging my head against a boot problem for a couple of days and have come to the conclusion that I need to ask someone.

Background: I have a bunch of BeagleBone Black Rev C boards. I want to load Gentoo onto a SD card. I used the "beaglebone black" SD creator script to do so, but pretty quickly came to realize that the script was making an "old style" SD image with a small VFAT partition and a ext4 partition. Looking at a current beaglebone SD image (which does boot just fine), I found the link to a page that explains how to create an image. So, I created an image using this script that I threw together based upon the instructions:

#!/bin/bash

# some useful variables
SCRIPTNAME=$(echo $0 | sed 's|^.*/||g')
DEVICE=""
MLOFILE=""
UBOOTIMAGE=""
ROOTFS=""

# text parsing WON'T WORK unless it is in english
export LC_ALL=C

# make sure there are enough options
if [ $# != 4 ]
then
    echo "Usage:"
    echo "  $SCRIPTNAME <device> <MLO> <u-boot.img> <rootfs tar.gz >"
    echo "  Example: $SCRIPTNAME /dev/sdc MLO u-boot.img nfs.tar.gz"
    exit
fi

# make sure the options are valid
if [[ -e $1 ]]
then
    DEVICE=$1
else
    echo "Invalid device!"
    exit
fi

if [[ -e $2 ]]
then
    MLOFILE=$2
else
    echo "Incorrect MLO location!"
    exit
fi

if [[ -e $3 ]]
then
    UBOOTIMAGE=$3
else
    echo "Incorrect u-boot.img location!"
    exit
fi

if [[ -e $4 ]]
then
    ROOTFS=$4
else
    echo "Incorrect rootfs location!"
    exit
fi

# prompt for total destruction
echo "All data on "$1" now will be destroyed! Continue? [y/n]"
read ans
if ! [ $ans == 'y' ]
then
    exit
fi

echo "[ clearing sectors...]"
dd if=/dev/zero of=$DEVICE bs=1M count=1

DISKSIZE=`fdisk -l $DRIVE | grep Disk | awk '{print $5}'`
echo "  DISK SIZE: $DISKSIZE bytes"
echo

echo "[ writing MLO...]"
dd if=$MLOFILE of=$DEVICE count=1 seek=1 conv=notrunc bs=128K

echo "[ writing u-boot image...]"
dd if=$UBOOTIMAGE of=$DEVICE count=2 seek=1 conv=notrunc bs=384K

echo "[ creating root partition...]"
PARTITIONOFFSET=$(echo 384*1024*3 | bc)
echo $PARTITIONOFFSET,,0x83,- | sfdisk $DEVICE

echo "[ creating filesystem...]"
mkfs.ext4 -L rootfs -T small "$DEVICE"1 &> /dev/null

echo "[ copying files...]"
if ! [ -e /mnt/sdcard ]
then
    mkdir /mnt/sdcard
    if [ $? != 0 ]
    then
echo "failed to create mountpoint!"
exit
    fi
fi

mount "$DEVICE"1 /mnt/sdcard
if [ $? != 0 ]
then
    echo "failed to mount filesystem!"
    exit
fi
tar zxvf $ROOTFS -C /mnt/sdcard
chmod 755 /mnt/sdcard
umount "$DEVICE"1

echo "[Done]"

My image does not boot. There seem to be two issues:

1) Watching the serial console during boot, I see "U-Boot SPL 2015.10-00001-g143c9ee (Nov 06 2015 - 15:27:19)
bad magic". Looking on this site, it seems like the U-Boot SPL should be picking up the MLO that I wrote to my disc and boot my new u-boot image, right? What would cause "bad magic"?

2) When I interrupt u-boot and try to take a look at my ext4 partition, I see the following:

=> ext4ls mmc 0:1 /boot 
<DIR>       1024 .
<DIR>    3145753 ..
             102 fsf-funding.7
              11 gpl.7
           11619 gfdl.7

Even if the problem mentioned in #1, above, happens, the default u-boot should be able to boot my kernel as the directory mmc 0:1 /boot is populated with:

$ ls -la
total 10122
drwxrwxrwx  3 root root    1024 Jun  5 14:05 .
drwxrwxrwx 20 root root    1024 Jun  5 14:31 ..
-rw-rw-rw-  1 root root   87161 Jun  2 14:11 am335x-boneblack.dtb
-rw-rw-rw-  1 root root  126411 Jun  2 14:12 .config
-rw-rw-rw-  1 root root     492 Jun  2 14:25 SOC.sh
-rw-rw-rw-  1 root root 2969405 Jun  2 14:11 System.map
drwxrwxrwx  2 root root    1024 May 31 12:56 uboot
-rw-rw-rw-  1 root root     405 Jun  5 14:05 uEnv.txt
-rwxrwxrwx  1 root root 7175152 Jun  2 14:10 vmlinuz-3.14.79

That's what I see on my host system. u-boot seems to be listing files present in /usr/share/gcc-data/armv7a-hardfloat-linux-gnueabi/4.9.4/man/man7 rather than what is present in /boot. That would seem to indicate that u-boot is not reading the ext4 filesystem correctly. Is there some magic that needs to be present in an ext4 filesystem in order for u-boot to read it correctly? I tried shrinking my partition size down to 3.6GB to match the beaglebone SD image, but that had no effect. I didn't see anything about directory depth limits nor about size limits, but clearly something is not working properly.

Any answers or pointers to better (correct) documentation are greatly appreciated.
Reply all
Reply to author
Forward
0 new messages