Following this article I wrote a while back, I decided to do something similar on a USB Armory that I've had for quite some time but couldn't really find a use of.

It comes with a vanila Debian installation (except for the kernel). I decided to try and have it running Apline Linux, since it's minimalistic, and can run with disk image and persistence.

Of course, I took my time to practice with my Pi Zero. Alpine wiki has a nice guide on how to do exactly that! After I became confident enough, I carried on with my plan.

The USB Armory boots off a microSD card. So I went ahead and prepared it with a new DOS partition table and a single ext2 volume of 1GiB. I then extracted the tar package into the partition I created.

$ wget https://dl-cdn.alpinelinux.org/alpine/v3.19/releases/armv7/alpine-uboot-3.19.1-armv7.tar.gz
$ tar -xf alpine-uboot-3.19.1-armv7.tar.gz

Building U-Boot

uboot-list

As I looked thru the u-boot images that was provided, I noticed it doesn't have it for my board. So I decided to build it myself.

The USB Armory repo provides quite an extensive detail on how their stock OS was built. I was able to figure out from their Makefile on how u-boot was compiled for their system.

Of course, I would need the proper toolchain for compiling ARM binaries.

sudo apt install gcc-arm-linux-gnueabihf

The script has the u-boot version in a variable, avoiding hardcoding. I think that's a great idea!

export UBOOT_VER=2024.04

First, I downloaded the u-boot source package, as well as a patch from the USB Armory main repo.

wget ftp://ftp.denx.de/pub/u-boot/u-boot-${UBOOT_VER}.tar.bz2 -O u-boot-${UBOOT_VER}.tar.bz2
wget ftp://ftp.denx.de/pub/u-boot/u-boot-${UBOOT_VER}.tar.bz2.sig -O u-boot-${UBOOT_VER}.tar.bz2.sig
gpg --verify u-boot-${UBOOT_VER}.tar.bz2.sig
wget https://raw.githubusercontent.com/usbarmory/usbarmory/master/software/u-boot/0001-Fix-microSD-detection-for-USB-armory-Mk-I.patch

Then I started the build process.

cd u-boot-${UBOOT_VER} && make distclean
patch -p1i ../0001-Fix-microSD-detection-for-USB-armory-Mk-I.patch
sed -ie 's/fdt_addr_r=0x71000000/fdt_addr_r=0x72000000/' include/configs/usbarmory.h
make usbarmory_config;
CROSS_COMPILE=arm-linux-gnueabihf- ARCH=arm make -j8

Finally, I flashed the compiled image to the microSD

$ sudo dd if=u-boot-dtb.imx of=/dev/mmcblk0 bs=512 seek=2 conv=fsync conv=notrunc

However, when I turned it on, the usual heartbeat LED pattern did not appear.

So I hooked up its UART to a Bus Pirate to see what's going on.

Bus Pirate pinout for the UART function is as follows:

Pin Function
1 Ground
3 5V
5 Vpu
8 Tx
10 Rx

Meanwhile, the UART pinout of USB Armory GPIO is as follows:

Pin Function
1 Ground
2 USB 5V
5 Tx
6 Rx

buspirate-usbarmory

$ screen /dev/ttyUSB0 115200
HiZ>m
1. HiZ
2. 1-WIRE
3. UART
4. I2C
5. SPI
6. 2WIRE
7. 3WIRE
8. LCD
9. DIO
x. exit(without change)

(1)>3
Set serial port speed: (bps)
 1. 300
 2. 1200
 3. 2400
 4. 4800
 5. 9600
 6. 19200
 7. 38400
 8. 57600
 9. 115200
10. BRG raw value

(1)>9
Data bits and parity:
 1. 8, NONE *default 
 2. 8, EVEN 
 3. 8, ODD 
 4. 9, NONE
(1)>
Stop bits:
 1. 1 *default
 2. 2
(1)>
Receive polarity:
 1. Idle 1 *default
 2. Idle 0
(1)>
Select output type:
 1. Open drain (H=Hi-Z, L=GND)
 2. Normal (H=3.3V, L=GND)
(1)>2
Ready
UART>(2)
Raw UART input
Any key to exit
0�p  @ � 7"�@ 0Ҁ�J5
                   Reset �X�����&"�٥��ͱ 0#��,����0
j0 *�0!
       (��0�) @^Z��to stop at`��  ��!!�� ����!���.��сdevice
�!(�0�hmB 0b`p  �5
                  Retr�e~�!��8�H�8�<W����L`C(@
                                             P�� cnti���������variables
Nn����9�0 @ ��d
               ��������сEFI v� ~emovable meDP8���PF8`N�8`N
                                                          ȡ�T�!!! !0;47mWeLh ��:�@����!�!!�!�'Rm[1;1H�8T W�89� ,0H(�8 �K�thg ~���W��k�             ����

After I changed to better shielded usb cable for usbarmory:

. . . .
UART>(2)
Raw UART input
Any key to exit
��,@��͕� POR
�0�� usin�00se Path USB ar�j� 0
Out:   serial@5������P�0 ���cN�%������file: /extlinux/extlinux.conf
1:      ̥���lt� �0 �01U %1P���!�ե���..
���Bm[6��ѕ��p�R��ɥ�0 �0�����ȡ̀� �����5
                                     Loading Boot0000 'mmc 0' failed
EFI boot �s9�����i�such de�?25h   ��0�ba``o`F�
                                              �d@����word, TAB   
   lists possible command completj

UART>

UART>(2)
Raw UART input
Any key to exit
�i.M��<�@ L� ��aU�*(
                    ɵ���5
                         Board: Inverse Path USB armory } �� �cErial@53fbc000
Net:   No ethernet found.
HiN�H$mmc0 is current device
���cDlW�(��������� /boot/vmlinuz-lts
��� � �ʋձ�����h���VC��$2���ѕ����Device Tree blob at 72000000
 ����`�`*���8dbcb33d ... OK
Working FDT set to 8db� 8OL�� ��emergency recovery shell launched.

From this I learned it uses extlinux to manage the boot process. There's extlinux/extlinux.conf that has the boot commandline, where I added g_ether on modules option as in the wiki.

Something tells me that it didn't like the ext2 filesystem. So I changed it to vfat.

I also found out that the modloop (simply a SquashFS image) was missing for some reason. Probably something wrong in the extraction process. After re-installing everything, it's working!

I then learned about the open-drain. I learned that to work properly, the resistor might be needed. The Bus Pirate actually has a built-in pull-up resistor. In order to work, the Vpu pin (#5) would need to be connected to the target board's Vcc.

buspirate-usbarmory-drain

. . . .
Select output type:
 1. Open drain (H=Hi-Z, L=GND)
 2. Normal (H=3.3V, L=GND)
(1)>1
UART>P
Pull-up resistors ON
UART>(2)
Raw UART input
Any key to exit

U-Boot 2024.04 (Apr 07 2024 - 21:20:02 +0700)

CPU:   Freescale i.MX53 rev2.1 at 800 MHz
Reset cause: POR
Model: Inverse Path USB armory
Board: Inverse Path USB armory MkI
DRAM:  512 MiB
Core:  28 devices, 13 uclasses, devicetree: separate
MMC:   FSL_SDHC: 0
Loading Environment from MMC... *** Warning - bad CRC, using default environment

In:    serial@53fbc000
Out:   serial@53fbc000
Err:   serial@53fbc000
Net:   No ethernet found.
Hit any key to stop autoboot:  0 
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:1...
Found /extlinux/extlinux.conf
Retrieving file: /extlinux/extlinux.conf
1:      Linux lts
Enter choice: 1:        Linux lts
Retrieving file: /boot/vmlinuz-lts
Retrieving file: /boot/initramfs-lts
append: modules=loop,squashfs,sd-mod,usb-storage,g_ether,ledtrig_heartbeat quiet 
Retrieving file: /boot/dtbs-lts/imx53-usbarmory.dtb
Kernel image @ 0x70800000 [ 0x000000 - 0x6da200 ]
## Flattened Device Tree blob at 72000000
   Booting using the fdt blob at 0x72000000
Working FDT set to 72000000
   Loading Ramdisk to 8dbcc000, end 8e56ec45 ... OK
   Loading Device Tree to 8dbc4000, end 8dbcb33d ... OK
Working FDT set to 8dbc4000

Starting kernel ...
initramfs emergency recovery shell launched. Type 'exit' to continue boot
sh: can't access tty; job control turned off

Much better! I realized that I could actually interact with the serial console. However, the Bus Pirate wasn't allowing me for some reason.

Thankfully, I have FT232RL module.

ft232rl-usbarmory

U-Boot 2024.04 (Apr 07 2024 - 21:20:02 +0700)

CPU:   Freescale i.MX53 rev2.1 at 800 MHz
Reset cause: POR
Model: Inverse Path USB armory
Board: Inverse Path USB armory MkI
DRAM:  512 MiB
Core:  28 devices, 13 uclasses, devicetree: separate
MMC:   FSL_SDHC: 0
Loading Environment from MMC... *** Warning - bad CRC, using default environment

In:    serial@53fbc000
Out:   serial@53fbc000
Err:   serial@53fbc000
Net:   No ethernet found.
Hit any key to stop autoboot:  0
=> 1
Unknown command '1' - try 'help'
=> help
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:1...
Found /extlinux/extlinux.conf
Retrieving file: /extlinux/extlinux.conf
1:      Linux lts
Enter choice: 1:        Linux lts
Retrieving file: /boot/vmlinuz-lts
Retrieving file: /boot/initramfs-lts
append: modules=loop,squashfs,sd-mod,usb-storage,g_ether,ledtrig_heartbeat quiet
Retrieving file: /boot/dtbs-lts/imx53-usbarmory.dtb
Kernel image @ 0x70800000 [ 0x000000 - 0x6da200 ]
## Flattened Device Tree blob at 72000000
   Booting using the fdt blob at 0x72000000
Working FDT set to 72000000
   Loading Ramdisk to 8dbcc000, end 8e56ec45 ... OK
   Loading Device Tree to 8dbc4000, end 8dbcb33d ... OK
Working FDT set to 8dbc4000

Starting kernel ...

   OpenRC 0.52.1 is starting up Linux 6.6.14-0-lts (armv7l)

 * /proc is already mounted
 * Mounting /run ... [ ok ]
 * /run/openrc: creating directory
 * /run/lock: creating directory
 * /run/lock: correcting owner
 * Caching service dependencies ... [ ok ]
 * Clock skew detected with `/etc/init.d/binfmt'
 * Adjusting mtime of `/run/openrc/deptree' to Thu Jan 11 13:43:00 2024

 * WARNING: clock skew detected!
 * Remounting devtmpfs on /dev ... [ ok ]
 * Mounting /dev/mqueue ... [ ok ]
 * Mounting modloop  ... * Verifying modloop
 [ ok ]
 * Mounting security filesystem ... [ ok ]
 * Mounting debug filesystem ... [ ok ]
 * Mounting persistent storage (pstore) filesystem ... [ ok ]
 * Starting busybox mdev ... [ ok ]
 * Scanning hardware for mdev ... [ ok ]
 * Loading hardware drivers ... [ ok ]
 * WARNING: clock skew detected!
 * Loading modules ... [ ok ]
 * Setting system clock using the hardware clock [UTC] ...hwclock: settimeofday: Invalid argument
 * Failed to set the system clock
 [ !! ]
 * Setting the local clock based on last shutdown time ... [ ok ]
 * Checking local filesystems  ... [ ok ]
 * Remounting filesystems ... [ ok ]
 * Mounting local filesystems ... [ ok ]
 * Configuring kernel parameters ... [ ok ]
 * Migrating /var/lock to /run/lock ... [ ok ]
 * Creating user login records ... [ ok ]
 * Cleaning /tmp directory ... [ ok ]
 * Setting hostname ... [ ok ]
 * Starting busybox syslog ... [ ok ]
 * WARNING: clock skew detected!

Welcome to Alpine Linux 3.19
Kernel 6.6.14-0-lts on an armv7l (/dev/ttymxc0)

alpine login: 

Much better!

I'm able to login with root.

I was able to load the ledtrig_heartbeat kernel module to enable the blinking LED. Sadly, the ethernet USB gadget module (named g_ether) is unavailable under the provided kernel. Seems that I have to compile it from scratch!

So compiling from scratch it is! To be continued!

Ref:

  • https://wiki.alpinelinux.org/wiki/Alpine_on_ARM
  • http://dangerousprototypes.com/blog/bus-pirate-manual/bus-pirate-uart-guide/
  • https://github.com/usbarmory/usbarmory/wiki/GPIOs
  • https://github.com/usbarmory/usbarmory-debian-base_image