LeMaker Guitar:How to make LeMaker Guitar OS image

From BananaPro/Pi
Jump to: navigation, search
This page is a translated version of the page LeMaker Guitar:How to make LeMaker Guitar OS image and the translation is 100% complete.

Other languages:

Note: These instructions are for a Linux computer, not the LeMaker Guitar.
The LeMaker Guitar can boot operating system from the two different media which include EMMC NAND Flash and MicroSD card. This page describes the process of how to make the EMMC system image(.fw) and SD Card system image(.img) based on the platform firmware package and the available linux file system.


Obtain linux platform firmware package

The platform firmware package include bootloader.bin, u-boot-dtb.img, misc.img and so on. There are two ways to obtain it:

Make a root filesystem

Before building OS image, we need a corresponding filesystem, and can refer the three methods below to get it.

Using an existing rootfs tarball

From the internet, we can find many OS tarballs such as Ubuntu, Fedora, Archlinux, and so on. Just download a tarball, and then extract it to the second partition of the SD card/EMMC. (As mentioned above in the opening paragraph, it is assumed that we have already created two partitions, the first is for the boot partition, while the second is for the rootfs partition). For example, we can download the ubuntu mate rootfs for armhf at https://ubuntu-mate.org/armhf-rootfs/.

Linaro rootfs

Linaro offers a set of different root file systems. we can download any pre-built images or rootfs from http://www.linaro.org/downloads/#dev-builds and then copy the root filesystem onto the SD card/EMMC.

Using debootstrap

debootstrap is a tool which will install a Debian/Ubuntu based system into a sub-directory of another and already installed system. It doesn't require an installation CD, just access to a Debian/Ubuntu repository.
Changing to root here is necessary, since we are going to be doing a lot of things that require superuser access:

su root

Install the required packages

To install Debian into a directory, we need debootstrap. For chrooting (child rooting) into the ARM environment, we also need qemu to be present within that environment. Install the required packages by using the command:

apt-get install qemu-user-static binfmt-support

Install Debian/Ubuntu using debootstrap

Execute debootstrap:

mkdir ~/rootfs
debootstrap --arch=armhf --foreign $distro ~/rootfs

Replace the phrase $distro with an appropriate Ubuntu or Debian version, such as 'saucy 'for Ubuntu or 'wheezy' for Debian, and save the root filesystem to ~/rootfs.

We are now just a few steps away from chrooting into our Debian/Ubuntu environment, but before we can proceed we need to copy two files from our host system:

cp /usr/bin/qemu-arm-static ~/rootfs/usr/bin/
cp /etc/resolv.conf ~/rootfs/etc
chroot ~/rootfs
export LANG=C

We can now continue with the debootstrap process using:

/debootstrap/debootstrap --second-stage

# for Ubuntu
cat <<EOT > etc/apt/sources.list
deb http://ports.ubuntu.com/ $distro main universe
deb-src http://ports.ubuntu.com/ $distro main universe
deb http://ports.ubuntu.com/ $distro-security main universe
deb-src http://ports.ubuntu.com/ $distro-security main universe
deb http://ports.ubuntu.com/ $distro-updates main universe
deb-src http://ports.ubuntu.com/ $distro-updates main universe

# for Debian
cat <<EOT > etc/apt/sources.list
deb http://http.debian.net/debian $distro main contrib non-free
deb-src http://http.debian.net/debian $distro main contrib non-free
deb http://http.debian.net/debian $distro-updates main contrib non-free
deb-src http://http.debian.net/debian $distro-updates main contrib non-free
deb http://security.debian.org/debian-security $distro/updates main contrib non-free
deb-src http://security.debian.org/debian-security $distro/updates main contrib non-free

For the next step, we can set up apt:

cat <<EOT > /etc/apt/apt.conf.d/71-no-recommends
APT::Install-Recommends "0";
APT::Install-Suggests "0";

Update to the latest database from the servers:

apt-get update

And we should set locales (Debian) with dpkg scripts or they tend to complain otherwise:

apt-get install locales
dpkg-reconfigure locales

Choose en_US.UTF-8 or whatever we want:

export LANG=en_US.UTF-8

Install some useful packages inside the chroot:

apt-get install openssh-server

Set a root password so we can log in:


Set the hostname:

echo lemaker > /etc/hostname

Exit the chroot session:

/etc/init.d/ssh stop

Clean up the support files

rm ~/rootfs/usr/bin/qemu-arm-static ~/rootfs/etc/resolv.conf

Make linux system image

We can refer the tutorial below to create different system image when the platform firmware package and root filesystem are ready.

Make an image for MicroSD card

MicroSD Card Layout

MicroSD card layout.png

MicroSD Card Layout
Name Start Usage
mbr 0 The first bootable partition of SD card
gpt 0x200 gtb partition table
environment 0x5000 uboot environment variables
bootloader 0x200200 The first stage boottraps (bootloader.bin)
uboot 0x300000 uboot bootloader (u-boot-dtb.img)
misc 0x800000 fat partions, including kernel, initramfs, kernel configure files, uEnv.txt etc…(misc.img)
rootfs 0x3800000 filesystem(rootfs.img)

Building SD card image

Step 1: Create a specified-size file.

sudo dd if=/dev/zero of=[system_name].img bs=1M count=3500

Step 2: Virtualize the image file into the block device file

sudo losetup -f --show {system_name}.img 

Step 3: Create the partions

sudo parted /dev/loop0
GNU Parted 2.3
Using /dev/loop0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt             #create gpt partition table 
(parted) print                   #list partitions
Model: Loopback device (loop)
Disk /dev/loop0: 3670MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number  Start  End  Size  File system  Name  Flags
(parted) unit s                        #set partition unit be sector(512Byte)                                   
(parted) mkpart primary 16384 114687   #create the first partition:8M-56M                                     
(parted) mkpart primary 114688 -1       #create the second partition:56M-END                                    
Warning: You requested a partition from 114688s to 7167999s.              
The closest location we can manage is 114688s to 7167966s.
Is this still acceptable to you?
Yes/No? yes                                                               
(parted) print                          #list partitions                                                      
Model: Loopback device (loop)
Disk /dev/loop0: 7168000s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number  Start    End       Size      File system  Name     Flags
 1      16384s   114687s   98304s                 primary
 2      114688s  7167966s  7053279s               primary
(parted) q                                #exit
Information: You may need to update /etc/fstab.

Step 4: List virtual devices block partitions

sudo kpartx -av /dev/loop0
add map loop0p1 (252:0): 0 98304 linear /dev/loop0 16384
add map loop0p2 (252:1): 0 7053279 linear /dev/loop0 114688

Notice: If can’t find kpartx, please install kpartx firstly.

apt-get install kpartx

Step 5: List the partitions listed by kpartx

ls -l /dev/mapper/
lrwxrwxrwx 1 root root       7 Aug 10 02:28 loop0p1 -> ../dm-0
lrwxrwxrwx 1 root root       7 Aug 10 02:28 loop0p2 -> ../dm-1

Step 6: Format partitions

sudo mkfs.vfat /dev/mapper/loop0p1   #format the first partition as fat farmat
mkfs.vfat 3.0.12 (29 Oct 2011)        
unable to get drive geometry, using default 255/63
sudo mkfs.ext4 /dev/mapper/loop0p2   #format the second partition as ext4 format 
mke2fs 1.42 (29-Nov-2011)
Discarding device blocks: done                            
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
220752 inodes, 881659 blocks
44082 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=905969664
27 block groups
32768 blocks per group, 32768 fragments per group
8176 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

Step 7: Extract the platform firmware package.

sudo mkdir ~/hwpack
sudo tar xf lemaker_guitar_xxx_hwpack_xxxxxx.tar.xz -C ~/hwpack

Step 8: Write bootloader image into SD card image. Start address:0x200200, the 4097th sector.

sudo dd if=~/hwpack/bootloader/bootloader.bin of=/dev/loop0  bs=512 seek=4097

Step 9: Write uboot image into SD card image.Start address:0x300000.

sudo dd if=~/hwpack/bootloader/u-boot-dtb.img of=/dev/loop0 bs=512 seek=6144

Step 10: Write misc image into the first partitions of SD card image.

sudo dd if=~/hwpack/kernel/misc.img of=/dev/mapper/loop0p1

Step 11: Write our rootfs into the seond partitions of SD card image.

sudo mount /dev/mapper/loop0p2 /mnt
sudo cp -a ~/rootfs/* /mnt
sudo rm -rf /mnt/lib/modules/
sudo cp -rf ~/hwpack/rootfs/lib /mnt/
sudo umount /mnt

Step 12: umount image file

sudo kpartx -d /dev/loop0
sudo losetup -d /dev/loop0

So far, building SD card system image is completed, we can refer LeMaker_Guitar:Quick_Start#Installing_the_OS_image_into_MicroSD_card to write the image into SD card by Win32DiskImager tool.

Make a firmware for eMMC NAND Flash

Install image-create-tools tool

git clone https://github.com/LeMaker/image-create-tools.git

we can execute “./linux-image-create -h” to know how to use linux-image-create tool

cd image-create-tools
sudo ./make-linux-emmc-fw -h
Usage:  make-linux-emmc-fw [options] [parameters]
	-g --cfg     Configure partition of the system image
	-p --hwpack  Choose platform firmware compression package
	-r --rootfs  Specify file system directory
	-h --help    Help information
	-c --clean   Clean all object file
	-o --output  Configure output file name
	./make-linux-emmc-fw --hwpack xxx_hwpack.tar.[xz|bz2|gz] --rootfs xxx_directory <--cfg xxx/partition.conf> <--output s500_lemaker_guitar>

Make a .fw firmwave file

./make-linux-emmc-fw -p [hwpack_pathname]/lemaker_guitar_bbb_hwpack_xxxxxx.tar.xz -r [rootfs_pathname]/rootfs -o s500_lemaker_guitar

Now, building eMMC NAND Flash system image is completed, we can refer LeMaker_Guitar:Quick_Start#Installing_OS_image_into_eMMC_NAND_Flash to write the image into eMMC NAND Flash by IH FW Burning Tool.