Prepare a bootable MicroSD Card

From IGEP - ISEE Wiki

Jump to: navigation, search

Introduction

This page explain how to create a microSD card to boot IGEP boards with  software distributions ( yocto, Ubuntu, Debian ...).

  • Now we can see an image of which are the steps to boot any module.

With a general processor all start with MLO file and U-Boot.img. Also it is the same procedure for Freescale- NXP. If you want to see how to create these files follow this link.

Next step is that once the processor is initialized,call the linux kernel making the execution of  your operative system available.

Finally your OS runs and you can initialize the board correctly 


How to SD.PNG


General Processors

Inside General processors we can find Texas Instruments

  • The microsd card must be content at latest 2 partitions.
  • The first one must be primary partition with the boot flag mark and formated using FAT(16 or 32) file system.
  • All names used in this partition must be msdos names (applies to OLD OMAP35xx processor).
  • The processor must load a first program called MLO, this program must reside in the first partition, this program it's also called x-loader or uboot-spl.

The processor when boot ONLY load and execute the MLO program and ignore all the rest it's the X-loader(MLO) the program responsible to load the next programs such kernel or uboot if you use this last one approach.


Information.jpg Freescale has a different structure


Freescale-NXP Processors

  • The microsd card must be content at latest 1 partitions.
  • The primary partition can be formatted with any filesystem that u-boot can mount.
  • The Processor will load the u-boot.imx it include the SPL and u-boot.

After load this u-boot.imx, u-boot will be ready for boot the kernel.

Therefore, we are going to setup a microSD card with these requirements and install a custom software distribution into it.


Prerequisites

  • PC with Linux (We use for this how to Ubuntu 16.04 LTS)
  • MicroSD Card (4 Gbytes - class 4) or bigger ...
  • Tools such, fdisk, mkfs.ext3, mkfs.vfat, gparted ...
  • Cross Toolchain included in Ubuntu 16.04 LTS gcc version 4.9.3 (Ubuntu/Linaro 4.9.3-13ubuntu2).


ToolChain


In order to start developing with an IGEP PROCESSOR BOARD we can use a microSD Card to flash our system and boot from it. Most of the cases is the easiest way to boot a board.

The following steps details how to prepare a booteable MicroSD Card

Prepare a SD to boot

Information.jpg The following steps has been tested using an Ubuntu 16.04
First of all it is important to detect which device is our microSD Card. In order to do that we can follow this instructions in a Linux terminal:
1- Clean the dmesg information:
sudo dmesg -c

2- Insert the microSD Card and show the dmesg information:

dmesg

The result have to be similar to this:


dev.png

We can see the name of our device in the system: /dev/sdX where X is the character assigned by our system, in this case /dev/sdc.
Now we have to ensure that the MicroSD Card is completely clean. We can use the following command to do that:
sudo dd if=/dev/zero of=/dev/sdX bs=1024 count=1024

Where X is the character returned previously by your system, for example, in the previous situation:

sudo dd if=/dev/zero of=/dev/sdc bs=1024 count=1024

Before use anyway of partition one good practise is unmount the dev where is inserted the SD. -> umount /dev/sdx

Now we are ready to create the corresponding partitions in our MicroSD Card.

How to partition the MicroSD card

There are several ways to partition a MicroSD Card. In this post we are using the GParted tool that can be installed as:
sudo apt-get install gparted

Other tools as sfdisk and mkfs are useful too.

It is important to difference between a MicroSD Card for a NXP processor and the other cases. The process of partition is similar but, in the case of NXP chips, there exists some differences. 

Using Gparted:

GENERAL CASE
NXP PROCESSORS
1- Select the corresponding device 1- Select the corresponding device
1.png 1.png
2- Create a partition table 2- Create a partition table
2.pngSD4.png 2.pngSD4.png
3- Create a FAT32 boot partition 3- Create a FAT32 boot partition leaving 8MB before

2.pngfat32 c121.png

We will configure the partition as:

  • Free Space Preceding: 1MB
  • Primary Partition
  • File system/ Format: FAT32
  • Size: 100 MB
  • Label: Boot
  • Align to: cylinder

2.pngim 1.png

We will configure the partition as:

  • Free Space Preceding: 8MB
  • Primary Partition
  • File system/ Format: FAT32
  • Size: 100 MB
  • Label: Boot
  • Align to: cylinder
4- Create a ext4 rootfs partition 4- Create a ext4 rootfs partition
fat32 c2.png7- Check the results are similar to the followings: fat32 c2.png
5- Apply changes
5- Apply changes
fat32 c3.png im 2.png
6- Set boot flag to boot partition 6- Set boot flag to boot partition

fat32 c4.png

fat32 c5.png

IM 25.png

fat32 c5.png

7- Check the results are similar to the followings: 7- Check the results are similar to the followings:
fat32 c6.png im 3.png

By doing that we will have ready the microSD Card in order to copy our files.


Using SFDISK & MKFS

Another method is to use the following commands in order to prepare the microSD card. These commands will perform the same operations that in the previous part.

GENERAL CASE NXP PROCESSORS
sudo sfdisk /dev/ <<EOF
label: dos
63,144522,0x0C,*
160650,,,-
EOF
sudo sfdisk /dev/ <<EOF
label: dos
16065,128520,0x0C,*
144585,,,-
EOF
sudo mkfs.vfat -F32 /dev/ -n boot
sudo mkfs.vfat -F32 /dev/ -n boot
sudo mkfs.ext4 /dev/ -L rootfs
sudo mkfs.ext4 /dev/ -L rootfs
For example: For example:
sudo sfdisk /dev/sdc <<EOF
label: dos
63,144522,0x0C,*
160650,,,-
EOF

sudo mkfs.vfat -F32 /dev/sdc1 -n boot

sudo mkfs.ext4 /dev/sdc2 -L rootfs

sudo sfdisk /dev/sdc <<EOF
label: dos
16065,128520,0x0C,*
144585,,,-
EOF

sudo mkfs.vfat -F32 /dev/sdc1 -n boot

sudo mkfs.ext4 /dev/sdc2 -L rootfs

How to copy everything into the MicroSD Card

Once the MicroSD is completely prepared, it is time to copy the u-boot, kernel and root dile system to the MicroSD Card.

U-Boot

General processors

After build or download the MLO and u-boot you should follow the next steps:

  • Copy MLO and u-boot.img to primary into the root folder of the boot partition
cp [your_u-boot_directory]/u.boot.img /media/user/boot

cp [your_u-boot_directory]/MLO /media/user/boot

You can follow this post U-boot Bootloader if you want build the MLO and u-boot


Freescale processors

  • Copy u-boot.imx using dd before primary partition in raw mode as
sudo dd if=/[your_u-boot_directory]/u-boot.imx of=/dev/[your_sd] bs=512 seek=2

You can follow this post U-boot Bootloader you want build the u-boot.imx


How to configure Uenv

It is need to indicate how start the boot. For this reason it will be created a file called uenv.txt with the correct configuration.

We present two examples of help to start the system from the MicroSD Card or from an nfs server.

  • If we want boot from the bootable microSD Card. uenv.txt
  • If we want boot from nfs server. uenv.txt

These two examples have an ip address assigned to them that can be modified as you want.

Kernel

Kernel files, zImage and .dtb, can be copied into the root folder of the boot partition

Kernel Modules have to be copied using the command indicated in the kernel compilation post into the rootfs partition


Root file System

The root file system have to be extracted into the root folder  of the rootfs partition. Where can be downloaded here.