USB Wifi on Freescale i.MX6

April 12th, 2018

This post is about how to get the USB wifi working. The TP-Link TL-WN721N wifi Module has been used as an example but it should be possible to extend similar thing on other Wifi Modules as well.

1. In the kernel Select the Athroes HTC as module and build the kernel module.
2. Copy the generated four files - ath.ko, ath9k_hw.ko, ath9k_common.ko and ath9k_htc.ko in directory /system/lib/modules/
3. Copy the firmware file in the directory /etc/firmware/ath9k_htc/
4. Install the modules using ath.ko, ath9k_hw.ko, ath9k_common.ko
5. ifconfig wlan0 up
6. iw dev wlano scan
7. To connect to a network that does not need password use
iw wlan0 connect yourssid
8. use wpa_supplicant to connect to network that needs authentication


Order ArduinoPixed

March 19th, 2018

ArduinoPixed has been ranked 9 out of 10 in March 2019 issue of MagPi -

If you missed backing ArduinoPixed on kickstarter here is a chance order .

ArduinoPixed - USB Hub + Arduino for Pi Zero
ArduinoPixed - USB Hub + Arduino for Pi Zero
Hub + Arduino for Pi Zero W , Shipping is $5 in US

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

HubSerialixed - USB Hub + UART for Pi Zero
HubSerialixed - USB Hub + UART for Pi Zero
Hub + UART for Raspberry Pi Zero, Shipping is $7 out US


Spread Spectrum in i.mx6

March 14th, 2018

If the CPU to DDR clock fails due to the EMI, there is a quick software solution - Spread Spectrum. The changes can be made in the u-boot. You will need to create the u-boot in SPL mode. Add the following code ( located at board/freescale/mx6sabresd/).

#include <config.h>

/* Enable Spread Spectrum */
.macro spreadspectrum_vikas
ldr r0, =CCM_BASE_ADDR

ldr r1, [r0,#0x18]
ldr r3, [r0,#0x18]

/*need Delay short time before switch PLL2 it back*/

ldr r4, =0x0
add r4, r4, #0x1
cmp r4, #0x200000
bne pu_delay

/* recovery the previous PLL source setting */
ldr r0, =CCM_BASE_ADDR
str r3, [r0,#0x18]

.macro spreadspectrum_rohitab
ldr r0, =CCM_BASE_ADDR

ldr r1, [r0,#0x18]
ldr r3, [r0,#0x18]

/* set periph_clik2_sel to select OSC_CLK */
and r1, r1, #0xffffcfff
orr r1, r1, #0x00001000
str r1, [r0,#0x18]

/*need Delay short time before switch PLL2 it back*/
ldr r4, =0x0
add r4, r4, #0x1
cmp r4, #0x200000
bne pu_delay

/* recovery the previous PLL source setting */
ldr r0, =CCM_BASE_ADDR
str r3, [r0,#0x18]

.macro spreadspectrum
ldr r0, =CCM_BASE_ADDR

ldr r1, [r0,#0x18]
ldr r3, [r0,#0x18]

/* set periph_clik2_sel to select OSC_CLK */
and r1, r1, #0xffffcfff
orr r1, r1, #0x00001000
str r1, [r0,#0x18]

/* set periph_clk_set to switch to OSC_CLK */
ldr r1, [r0,#0x14]
ldr r2, [r0,#0x14]
orr r1, r1, #0x02000000
str r1, [r0,#0x14]

/* power down PLL2 */
ldr r0, =0x020c8000
ldr r1, [r0,#0x30]
orr r1, r1, #0x00010000
str r1, [r0,#0x30]

/* enable spread spectrum & configure */
ldr r1, =0x00001770
str r1, [r0,#0x60]
ldr r1, =0x05dc8006
str r1, [r0,#0x40]

ldr r1, [r0,#0x30]
and r1, r1, #0xFFFEFFFF
str r1, [r0,#0x30]

/*need Delay short time before switch PLL2 it back*/
ldr r4, =0x0
add r4, r4, #0x1
cmp r4, #0x200000
bne pu_delay

/* recovery the previous PLL source setting */
ldr r0, =CCM_BASE_ADDR
str r2, [r0,#0x14]
str r3, [r0,#0x18]


/* End Enable Spread Spectrum */

.globl blhss
.type blhss,%function

bx lr

Save the file as spreadspectrum.S and then update the Make file to include this file.

obj-y := mx6sabresd.o
obj-y += spreadspectrum.o

In file mx6sabresd.c make following changes

  1. Just before

int dram_init(void);


extern int blhss(void);

2. Just after


Add following



Compile and try. Results will be updated lated.


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.


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.


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 > ~/bin/repo
$ chmod a+x ~/bin/repo
$ ~/bin/repo init -u -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
$ cd bpt
$ git checkout -b n7.1.2_2.0.0-gab7c3059e5d8c408f60222edc898ef1c229d8fc2d

No Get the kernel source code

$cd ~/myandroid
$git clone 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:// 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/
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/

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/
$sudo ./device/fsl/common/tools/ -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.


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






#define CONSOLE_DEV "ttymxc0"


#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[] = {

Also add


in setup_iomux_uart

static void setup_iomux_uart(void)

Compile using

make mx6sabresd_defconfig

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)
#define USDHC3_CD_GPIO IMX_GPIO_NR(7, 0)

2. Make following changes in usdhc3_pads

static iomux_v3_cfg_t const usdhc3_pads[] = {







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;