Preparing i.MX6 to boot from SD Card

March 9th, 2018

Let us assume that you have compiled the u-boot for freescale/nxp i.MX6 and are now trying to prepare the SD Card to boot the i.MX6 from it.

Before you do that, you need to make sure your hardware is ready for it. The i.MX6 should not have been fused to prevent it from booting from external SD Card. Also the Config Pins should be properly set, so that it can boot from SD Card ( and not from SPI Flash as in Sabre Lite Board).

Once you do that, all you need to do is just burn an SD Card with the following command.

sudo dd if=some/directory/u-boot.imx of=/dev/sdb bs=1k seek=1 conv=fsync

It is good idea to spend some time on to understand the bs and the seek parameter in the command. The bs is block size and in our case it is 1K or 1024 bytes. The seek parameter is a pointer on the SD Card. If we set seek to 1, it will move forward by 1 block size on the SD Card before write.

If your u-boot.imx file, for example, already has padded 0s in the beginning, you do not need the bs=1k seek=1

Why Do we need u-boot start from 1K ( 0x0400) ?

This requirement comes from i.MX6. The i.MX6 will look at the address 1024 to load the data into its ROM and execute from there. Notice that at this point we have not created any partition whatsoever and the board will still boot. The u-boot does not care about the Master Boot Record. Though we will need some kid of partition information information to read file system later in the boot process.

A typical SD Card with MBR partition will look as follows ...

+-----+------+--------+-----+---------------+---------------+-----------------

| MBR | ... | u-boot | ... | Partition1 |...Partition2 |...Partition3

+-----+------+--------+-----+---------------+---------------+-----------------

0 512 1024 2M 20M 100MB

The Master Boot Record is stored in the first 512 Bytes of the SD Card. This contains the details of the partition of the SD Card. With all its limitations ( number of partitions it can store etc), the MBR works good. Though, we do not need it for the very first boot from u-boot of i.MX6.

Now you understand why i.MX6 was not designed to boot from the address 1K Byte in place of 0x0000. If it were designed to boot from 0x0000, we will be writing the u-boot right at 0x0000 - and it will then destroy the MBR.

The MBR Vs GPT

GPT (GUID Partition Table) brings with it many advantages, including support for bigger cards / disks and ability to store larger partition tables. The GPT starts at location 512 Bytes and a typical scenario looks like

+-----+------+--------+-----+---------------+---------------+-----------------

| |GPT | u-boot | ... | Partition1 |...Partition2 |...Partition3

+-----+------+--------+-----+---------------+---------------+-----------------

0 512 1024 2M 20M 100MB

With reference to u-boot, the scheme still works, with one caveat - the GPT partition table can extend ( because it is large) to the u-boot area that starts at 1024 Bytes. So if you create the GPT first and then write the u-boot, the u-boot writing process will destroy the GPT Table ( at least partially, unless it is really small). If you write u-boot first and then create GPT, the GPT creation process will destroy the u-boot.

So is there a solution ? Fortunately Yes. The GPT allows relocation of the Partition table. What we basically do is create an entry in the first few bytes of the GPT Table that tells where the rest of Table is going to be. We can then reserve some other place in the boot partition to store the GPT Table.

Uncategorized

Cheat Sheet installing Android 7.1.2 nouget on i.mx6

March 6th, 2018

It has been a while since Freescale released nouget 7.1.2. We have clubbed together a cheat sheet to build Android for the Sabre SD platform. This should help you to do a quick copy paste to get whole thing going.

Install following packages

It is possible that you have following packages already installed - but just make sure

sudo apt-get install uuid uuid-dev
sudo apt-get install zlib1g-dev liblz-dev
sudo apt-get install liblzo2-2 liblzo2-dev
sudo apt-get install lzop
sudo apt-get install git-core curl
sudo apt-get install u-boot-tools
sudo apt-get install mtd-utils
sudo apt-get install android-tools-fsutils
sudo apt-get install openjdk-8-jdk

Create a directory - call it myandroid to hold all the packages

$ cd ~
$ mkdir myandroid
$ mkdir bin
$ cd myandroid
$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
$ ~/bin/repo init -u https://android.googlesource.com/platform/manifest -b android-7.1.2_r9
$ ~/bin/repo sync
# Please make sure you have plenty of time. It may take overnight.
$cd ~/myandroid/system/tools
$ git clone https://android.googlesource.com/platform/system/tools/bpt
$ cd bpt
$ git checkout -b n7.1.2_2.0.0-gab7c3059e5d8c408f60222edc898ef1c229d8fc2d

No Get the kernel source code

$cd ~/myandroid
$git clone git://git.freescale.com/imx/linux-imx.git kernel_imx
#the kernel repo is large. Therefore, this process can take a while.
cd kernel_imx
$git checkout n7.1.2_2.0.0-ga

Get the u-boot

$cd ~/myandroid/bootable
$mkdir bootloader
$cd bootloader
$git clone git://git.freescale.com/imx/uboot-imx.git uboot-imx
$cd uboot-imx
$git checkout n7.1.2_2.0.0-ga

Download the file android_N7.1.2_2.0.0_source.tar.gz from nxp / freescale ( requires login) to directory, say, android7.1.2 and unzip it

$cd android7.1.2
$tar xzvf android_N7.1.2_2.0.0_source.tar.gz

$cd ~/myandroid
$source ~/android7.1.2/android_N7.1.2_2.0.0_source/code/N7.1.2_2.0.0/and_patch.sh
$help
Make sure you see a c_patch command available
$c_patch ~/android7.1.2/android_N7.1.2_2.0.0_source/code/N7.1.2_2.0.0/ imx_N7.1.2_2.0.0-ga

If this is successful you should see a message that says something like - you can build the Android code for FSL.

Building Android

$cd ~/myandroid
$source build/envsetup.sh
$lunch

Select sabresd_6dq-user

The following is required to avoid GC overhead limit error. Increasing heap size helps.


$export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4g"
$./prebuilts/sdk/tools/jack-admin kill-server
$./prebuilts/sdk/tools/jack-admin start-server

Not the make command

$ make 2>&1 | tee build-log.txt

It takes some time ( Like 5 hours of a decent laptop).

The above process generates files for eMMC. To generate it for SD Card, you will need to do following

1. Remove /out/target/product/sabresd_6dq/root directory and boot*.img.
2. Remove /out/target/product/sabresd_6dq/recovery directory and recovery*.img.
3. Build the boot.img and recovery.img as follows:
make bootimage BUILD_TARGET_DEVICE=sd
make recoveryimage BUILD_TARGET_DEVICE=sd

To create SD Card to boot

$cd ~/myandroid/
$sudo chmod +x ./device/fsl/common/tools/fsl-sdcard-partition.sh
$sudo ./device/fsl/common/tools/fsl-sdcard-partition.sh -f /dev/sdX
can is imx6q I.MX6 quad processor

Keep all the required files in the current directory.

Issues and Fixes

Will be coming up with list of issues encountered and their fixes.

Uncategorized

Using SABRE-SD u-boot on Sabre Lite for i.MX6

February 25th, 2018

There are two lines of the evaluation boards for freescale i.mx6 - SABRE SD and Sabre Lite. The two boards have their own lines of u-boot. Some of the features available in the SABRE SD u-boot, for example SPL boot and the Falcon boot are not available in SABRE LITE board.

With some small modifications you can make the SABRE-SD u-boot to work on the Sabre-Lite board.

In include/configs/mx6sabresd.h

Change

#define CONFIG_MXC_UART_BASE UART1_BASE

to

#define CONFIG_MXC_UART_BASE UART2_BASE

Also,

#define CONSOLE_DEV "ttymxc0"

to

#define CONSOLE_DEV "ttymxc1"

The SABRE SD board uses UART1 for the console message while the the Sabre Lite board uses UART2. So the first change is to make the

In board/freescale/mx6sabresd/mx6sabresd.c

Add following to support UART2.

static iomux_v3_cfg_t const uart2_pads[] = {
IOMUX_PADS(PAD_EIM_D26__UART2_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
IOMUX_PADS(PAD_EIM_D27__UART2_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
}
;

Also add

SETUP_IOMUX_PADS(uart2_pads)

in setup_iomux_uart

static void setup_iomux_uart(void)
{
SETUP_IOMUX_PADS(uart1_pads);
SETUP_IOMUX_PADS(uart2_pads);
}

Compile using

make mx6sabresd_defconfig
make

Since the SPL mode is supported by default - use the following two stage commands to flash the SD Card with

sudo dd if=SPL of=/dev/sdc bs=1k seek=1
sudo dd if=u-boot.img of=/dev/sdc bs=1k seek=69

Please note that this assumes the u-boot to be in the SD Card. This will require that the fuse in the Sabre Lite is not programed for EEPROM

At this point the board is able to boot with following errors

The MMC Card is not detected and the reason is that the Card Detect Pin is different in Sabre SD and the Sabre Lite.

This required following fixes
1.In board/freescale/mx6sabresd/mx6sabresd.c replace

#define USDHC3_CD_GPIO IMX_GPIO_NR(2, 0)
by
#define USDHC3_CD_GPIO IMX_GPIO_NR(7, 0)

2. Make following changes in usdhc3_pads

static iomux_v3_cfg_t const usdhc3_pads[] = {
IOMUX_PADS(PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
IOMUX_PADS(PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
IOMUX_PADS(PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
IOMUX_PADS(PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
IOMUX_PADS(PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
IOMUX_PADS(PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
IOMUX_PADS(PAD_SD3_DAT4__SD3_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),

/*
IOMUX_PADS(PAD_SD3_DAT5__SD3_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
*/

IOMUX_PADS(PAD_SD3_DAT6__SD3_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
IOMUX_PADS(PAD_SD3_DAT7__SD3_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),

/*
IOMUX_PAD_CTRL(SD3_DAT5__GPIO7_IO00, WEAK_PULLUP),
*/

IOMUX_PADS(PAD_SD3_DAT5__GPIO7_IO00 | MUX_PAD_CTRL(NO_PAD_CTRL)), /* CD */

/*

IOMUX_PADS(PAD_NANDF_D0__GPIO2_IO00 | MUX_PAD_CTRL(NO_PAD_CTRL)),
*/

The board proceeds but stops at next error

As a quick and dirty fix, returned in the beginning of power_init_board without checking for Power ICs in board/freescale/mx6sabresd/mx6sabresd.c .


int power_init_board(void)
{

struct pmic *p;
unsigned int reg;
int ret;

// Vikas dirty return to be fixed
return 0;

p = pfuze_common_init(I2C_PMIC);
if (!p)
return -ENODEV;
.
.

.

Uncategorized

Serial Port in Ubuntu - Using Terminal

February 20th, 2018

We are often required to use Serial COM port in embedded system ( Like console booting in i.MX6). A USB to serial board comes handy in such case. First find out which Serial port corresponds to the hardware using

ls -la /dev/ttyUSB*

It is most likely going to be /dev/ttyUSB0

Next install putty

sudo apt-get install putty

Once it is install, you can launch putty using the following command

sudo putty /dev/ttyUSB0 -serial -sercfg 115200,8,n,1,N

This example assumes you want baud rate of 115200, 8 bit, no Parity

If you want to use the App instead, you will need to do following '
1. install gksudo
sudo apt-get install gksudo

gksudo is the gui compatriot of sudo

Next we need to modify the file /usr/share/applications/putty.desktop

Open /usr/share/applications/putty.desktop

sudo gedit /usr/share/applications/putty.desktop

Change the line

Exec=putty

to

Exec=gksudo -k -u root putty

Uncategorized

Order Notixed

February 5th, 2018

Notixed is up for sale at Reference Designer

Order The Notixed: ( Shipping in US is $4 for first and $1 for each additional)

Notixed - Turn Rpi to USB device
Notixed - Turn Rpi to USB device
Turn Pi Zero into USB device using Notixed, Shipping is $4 in US
$3.50

Out of US : The shipping is $6 for first and $3 for each additional unit.

Notixed - Turn Rpi to USB device
Notixed - Turn Rpi to USB device
Turn Pi Zero into USB device using Notixed, Shipping is $4 in US
$3.50

Uncategorized

ArduinoPixed - Integrated USB Hub and Arduino for Pi Zero

January 30th, 2018

ArduinoOixed has 3 USB Ports and an integrated Arduino Nano circuit and thereby allows you to seriously enhance the usefulness of Raspberry Pi Zero.

null
null

It comes with an On board LED, a Push Button Input and a Thermistor that can be used for temperature measurement.

null

The Arduino functionality is implemented on ATMEGA328 chip and its Pins come on two Headers of 10 pin each.

null

The block diagram below best captures its functionality

null

Arduinopixed builds upon our earlier successful projects including Hubpixed and HubSerialixed. It addressed two of the major concerns of Raspberry Pi Zero users - Lack of useful USB ports and lack of A/D Converters.

The key design element is the pogo pin that connects ArduinoPixed to the Raspberry Pi Zero using 4 provided Pogo Pins. There is no wire, cabling or soldering required. ArduinoPixed can be used as an Educational tool, where you can use a Keyboard and Mouse to hook to Pi Zero and ArduinoPixed to start learning programming. You will not only be able to learn C using Pi Zero, you can actually write programs to check real world sensors, like smoke detectors.

ArduinoPixed is priced competitively at $21 for early birds at Kickstarter ( Normal price is $23 each). If you buy in bulk it is $42 for a pack of two ( and $95 for a pack of 5).

Some FAQ

Q1 - One of the kickstarter enthusiast asked - If I connect it with Raspberry Pi zero W, would the Arduino be able to send data to cloud over WiFi (of R Pi)?

Answer - The way it can potentially work is - Arduino will be throwing the data to Raspberry Pi on its Serial Port. As soon as Pi Zero W receives it, it can upload it to cloud.

If I get time I will try some demo of it.

Uncategorized