Sunday, May 10, 2015

BeagleBone Black Development Part 5 - Installing Linux to eMMC using Micro SD

This is the fifth tutorial in a series for BeagleBone Black Development.    Earlier posts cover setup and installation of Debian Jessie for cross-development (in Part 1, Part 2, and Part 3) and BeagleBone Black kernel build steps in Part 4.  Part 6 show how to remotely debug an application running on the BeagleBone Black using eclipse and gdb.

This tutorial uses the methods and file links from https://eewiki.net/display/linuxonarm/BeagleBone+Black for a mainline kernel build.

5 Installing Linux to eMMC using MicroSD


Login as root to work with the disk commands.  Enter the root password with the su command (rather than the user password that you use with the sudo command).
user@debian:~$ su -
Password:
root@debian:~#


5.1 Micro SD card partition setup and formatting



Use the lsblk command to see the name of your disk.
root@debian:~# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0    20G  0 disk
├─sda1   8:1    0  19.1G  0 part /
├─sda2   8:2    0     1K  0 part
└─sda5   8:5    0   880M  0 part [SWAP]
sr0     11:0    1  55.4M  0 rom  
sdb      8:16   1   3.7G  0 disk
└─sdb1   8:17   1   3.7G  0 part


The above listing shows a 4GB drive has a partition at /dev/sdb1 on disk /dev/sdb.  We know that it is the microSD because of the size.   We will put the disk into a shell variable for the disk commands.  Make sure you get the correct name (it shouldn’t be sda or sr0).  Replace null in the next command with your disk name.
root@debian:~# export DISK=/dev/null


We will also put the user’s bbb work directory into a variable.
root@debian:~# export BBB=/home/user/bbb


Erase the micro SD card.
root@debian:~# dd if=/dev/zero of=$DISK bs=1M count=10


Install the bootloader.
root@debian:~# dd if=$BBB/u-boot/MLO of=$DISK count=1 seek=1 bs=128k


root@debian:~# dd if=$BBB/u-boot/u-boot.img of=$DISK count=2 seek=1 bs=384k


Create the Linux Partition.
This command is dependent on the version of sfdisk installed on your host. For more information on this step it is worth visiting the eewiki page.  

Blogger isn't rendering the html correctly for the sfdisk command for me at the moment so here is an image for now.


Format the Linux partition.
root@debian:~# mkfs.ext4 ${DISK}1 -L rootfs


Create a mount point to access the drive and mount the partition.
root@debian:~# mkdir -p /media/rootfs
root@debian:~# mount ${DISK}1 /media/rootfs


Copy the root filesystem.  This takes a few minutes.
root@debian:~# tar xfvp $BBB/rootfs/*-*-*-armhf-*/armhf-rootfs-*.tar -C /media/rootfs


Backup the bootloader.
root@debian:~# mkdir -p /media/rootfs/opt/backup/uboot
root@debian:~# cp -v $BBB/u-boot/MLO /media/rootfs/opt/backup/uboot
root@debian:~# cp -v $BBB/u-boot/u-boot.img /media/rootfs/opt/backup/uboot


Export the kernel version from the kernel build if you haven’t already.
root@debian:~# source $BBB/bb-kernel/kernel_version


Set kernel version in uEnv.txt
root@debian:~# echo “uname_r=$kernel_version” >> /media/rootfs/boot/uEnv.txt


Copy the kernel image file.
root@debian:~# cp -v $BBB/bb-kernel/deploy/${kernel_version}.zImage
/media/rootfs/boot/vmlinuz-${kernel_version}


Copy the kernel device tree binaries.
root@debian:~# mkdir -p /media/rootfs/boot/dtbs/$kernel_version/
root@debian:~# tar xfv $BBB/bb-kernel/deploy/${kernel_version}-dtbs.tar.gz -C
/media/rootfs/boot/dtbs/$kernel_version


Copy the kernel modules.
root@debian:~# tar xfv $BBB/bb-kernel/deploy/${kernel_version}-modules.tar.gz -C
/media/rootfs


Set up the file systems table.
root@debian:~# echo '/dev/mmcblk0p1  /  auto  errors=remount-ro  0  1' >> /media/rootfs/etc/fstab


Set up networking.
root@debian:~# echo -e “\\nauto lo\\niface lo inet loopback” >>
/media/rootfs/etc/network/interfaces
root@debian:~# echo -e “\\nauto eth0\\niface eth0 inet dhcp” >>
/media/rootfs/etc/network/interfaces


root@debian:~# sync


It’s still mounted, unmount before ejecting
root@debian:/home/user/bbb/rootfs$ umount ${DISK}?


5.2 Copying the micro SD Linux OS to eMMC



Now we can remove the microSD and insert the card in the Beaglebone.  


Before you power the up the board Connect the FTDI USB to serial cable and use a terminal program like minicom (Linux) or teraterm (Windows).
Log into the serial console to run the script that copies the files from the SD to the eMMC.


This next step assumes you already have a debian system running on the eMMC and you are updating to your latest development build.  If you don’t have the eMMC set up this way the easiest thing to do is to download the latest debian micro SD image and flash that onto the board first.


Run the flasher on the beaglebone black in the serial terminal program. This script takes a few minutes to complete.
debian@arm:~$ sudo /bin/bash /opt/scripts/tools/eMMC/bbb-eMMC-flasher-eewiki-ext4.sh


If that script is not found you can download the latest flasher from eewiki.net and run it.
debian@arm:~$ wget https://raw.githubusercontent.com/RobertCNelson/boot-scripts/master/tools/eMMC/bbb-eMMC-flasher-eewiki-ext4.sh
debian@arm:~$ chmod +x bbb-eMMC-flasher-eewiki-ext4.sh
debian@arm:~$ sudo /bin/bash bbb-eMMC-flasher-eewiki-ext4.sh


When it's done you will see a row of 4 blue LEDs on the board that are all lit.


Power off the board, remove the micro SD and power on the board.  In the boot output you should see the date on u-boot and version of the kernel match the versions you compiled and copied to the board.  It should output boot information and come up to the login prompt in a minute.

No comments: