Creating Ubuntu 18.04 Image for EMB-2238

From Estone Technology Wiki
Jump to: navigation, search

Prepare Micro SD Card


  • Host Machine (Linux Ubuntu 16.04.6 LTS)
  • MicroSD Card (Minimum 8GB)

Prepare MicroSD with fdisk

1. Plug MicroSD to the host machine (Linux Ubuntu)
2. Open Terminal by pressing Ctrl+Alt+T keys in your keyboard simultaneously
3. In the terminal type in lsblk command to see what letter your MicroSD card was given
(Example: /dev/sda, /dev/sdb, /dev/sdc, etc..)

$ lsblk                                           


4. Locate the MicroSD card in the Storage Devices menu
Note: MicroSD letter (/dev/sd<x>) is dependent on the amount of storage devices that are connected to the host machine
Example: As shown in the image, MicroSD is located at /dev/sdc

5. Run the fdisk command to begin MicroSD Filesystem preparation

$ sudo fdisk /dev/sd<x> 


  • Here is a list of all available options:

Command (m for help): m 
  a   toggle a bootable flag
  b   edit nested BSD disklabel
  c   toggle the dos compatibility flag
  d   delete a partition
  F   list free unpartitioned space
  l   list known partition types
  n   add a new partition
  p   print the partition table
  t   change a partition type
  v   verify the partition table
  i   print information about a partition
  m   print this menu
  u   change display/entry units
  x   extra functionality (experts only)
  I   load disk layout from sfdisk script file
  O   dump disk layout to sfdisk script file
 Save & Exit
  w   write table to disk and exit
  q   quit without saving changes
 Create a new label
  g   create a new empty GPT partition table
  G   create a new empty SGI (IRIX) partition table
  o   create a new empty DOS partition table
  s   create a new empty Sun partition table

6. We will now create the first partition for the MicroSD

Command (m for help): n 
Partition type
  p   primary (0 primary, 0 extended, 4 free)
  e   extended (container for logical partitions)
Select (default p): p 
Partition number (1-4, default 1): 1 
First sector (2048-124735487, default 2048): 10240 
Last sector, +sectors or +size{K,M,G,T,P} (10240-124735487, default 124735487): +100M 

Created a new partition 1 of type 'Linux' and of size 100 MiB.

7. Now we will create the MicroSD second partition

Command (m for help): n 
Partition type
  p   primary (1 primary, 0 extended, 3 free)
  e   extended (container for logical partitions)
Select (default p): p 
Partition number (2-4, default 2): 2 
First sector (2048-124735487, default 2048): 215040 
Last sector, +sectors or +size{K,M,G,T,P} (215040-124735487, default 124735487): Press 'Enter' key 

Created a new partition 2 of type 'Linux' and of size 59.4 GiB.

8. Once the 2nd partition is created you need to write changes to the MicroSD card

Command (m for help):  w 
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

9. Now we will add partition filesystem type to the 2 partitions that were created

For 1st Partition:

$ sudo mkfs.vfat -n 'BOOT' /dev/sd<x>1

Mkfs vfat.png

For 2nd Partition:

$ sudo mkfs.ext4 /dev/sd<x>2
$ sudo e2label /dev/sd<x>2 ROOT

Mkfs ext4.png

Download UBOOT & KERNEL Image

Note: Download the U-Boot and Kernel image below to install on the Micro SD card

$ cd ~
$ mkdir boot
$ cd ~/Downloads/
$ sudo cp -rv flash.bin fsl-imx8mq-evk.dtb Image ~/boot/

Install U-Boot & Kernel Image

Installing U-Boot

$ cd ~/boot/
$ sudo dd if=flash.bin of=/dev/sdx bs=1k seek=33 status=progress && sync

Installing Kernel

$ cd ~/boot/
$ sudo mount /dev/sdx1 /mnt/
$ sudo cp -rv fsl-imx8mq-evk.dtb Image /mnt/
$ sync
$ sudo umount /dev/sdx1

Build Ubuntu 18.04 ROOTFS

Install host dependencies

$ sudo apt-get update 
$ sudo apt-get install gparted git build-essential libncurses5 wget u-boot-tools zlib1g-dev ncurses-dev
$ sudo apt-get install cmake libc-dev-armhf-cross pkg-config-arm-linux-gnueabihf build-essential checkinstall cmake
$ sudo apt-get install pkg-config lzop libc6 libstdc++6 debootstrap qemu-user-static binfmt-support zlib1g:i386
$ sudo apt-get install qemu-user-static

Remove any current Rootfs from SD Card

$ mkdir -p /mnt/sdx2
$ sudo mount /dev/sdx2 /mnt/sdx2/
$ sudo rm -rvf /mnt/sdx2/*

Run Debootstrap to populate Ubuntu Rootfs

$ sudo debootstrap --arch arm64 --foreign bionic /mnt/sdx2/

Chroot Environment Setup

$ sudo cp /usr/bin/qemu-aarch64-static /mnt/sdx2/usr/bin/
$ sudo LANG=C.UTC-8 chroot /mnt/sdx2/ qemu-aarch64-static /bin/bash

2nd Stage Debootstrap

# /debootstrap/debootstrap --second-stage

Update the Source

# sudo apt-get update

Install Additional software

# apt-get install net-tools openssh-server
# apt-get install sudo
# apt-get install language-pack-en-base
# apt-get install ssh
# apt-get install ethtool 
# apt-get install ifupdown
# apt-get install iputils-ping
# apt-get install rsyslog
# apt-get install htop 
# apt-get install kmod
# apt-get install nano
# apt-get install alsa
# apt-get install zip
# dpkg-reconfigure locales
# dpkg-reconfigure tzdata

Change Hostname

# echo localhost.localdomain > /etc/hostname

Set up the root password

# passwd -d root

Set up the network

# echo auto eth0 > /etc/network/interfaces
# echo iface eth0 inet dhcp >> /etc/network/interfaces

exit chroot

# exit

Sync the Rootfs

$ sync

Unmount SD Card Partition

$ sudo umount /dev/sdx2

Note: Eject SD Card from Host System and plug into EMB-2238 to boot

Boot SD Card in EMB-2238

  • The EMB-2238 has 2 modes of booting 1 is eMMC boot and 2 is SD Card boot

To Boot From eMMC:
eMMC Boot Switch Configuration: 0, 0, 1, 0

To Boot From SD Card:
SD Card Boot Switch Configuration: 1, 1, 0, 0

SD Card Boot

eMMC Boot

Audio Codec (CS47L24-DSP) Setup

  • Download the audio codec files here & copy to EMB-2238 root (~) directory


  • Turn on EMB-2238 and follow commands below:
# cd ~
# wget --max-redirect=20 -O
# unzip
# mkdir /lib/firmware
# alsactl restore -f asound.state
# cp -rv cs47l24-dsp* /lib/firmware
# cp -rv rtl8723b_fw /lib/firmware
# ./ 
# alsactl store 0
# sync; reboot