Toradex Colibri T30

The Toradex Colibri T30 is an embedded platform released by Toradex around 2013. It comes with an Nvidia Tegra T30, 1 GB of RAM and 2/4 GB of eMMC depending on the version of the board. The Colibri T30 is a module that can be used with different carrier boards. The prebuilt nvidia-tegra-armv7 image works on this device.
== Contributors ==
* Aston moople
== Users owning this device ==
= Installation =
Depending on what is installed on your system, it might be better to start off with a "clean" state by setting up an installation of Ångström Linux that comes from an image file provided by Toradex.
This guide assumes that you have a working U-Boot bootloader on your system. If that is not the case, please refer to the guide provided by Toradex to install one.
 
You can then access U-Boot by connecting the board to your computer and run screen (or whatever software you want to use) to use the serial connection. For my board, I used this command : 
$ sudo screen /dev/ttyUSB0 115200
You may not see anything on your terminal because the system is already booted. If that is the case, you will need to restart it. The procedure is different on each board, but on mine, there is a button that can reset the device. When I push it, the system restart, and I can interrupt the countdown on U-Boot before the system starts in order to use the console on the Colibri.
== Restore the system to its default state ==
For this, you will need a micro SD card. Then, you will have to download the recovery files from Toradex.
Extract the archive with this command (you'll need elevated privileges) :
$ sudo tar xjvf Colibri-T30_LXDE-Image_2.8b7.-20200610.tar.bz2
Go to the directory of the extracted files and use the updater to write the files on the SD card. The path to your SD card (here /run/media/user/E2DE-AD92, which you'll have to change) is not the device file, but the folder where it is mounted.
Be warned that the files on your SD card may be deleted after this command.
$ cd Colibri-T30_LXDE-Image_2.8.7 && sudo ./update.sh -m 0 -o /run/media/user/E2DE-AD92
When that's done, put the micro SD to your Colibri T30, connect it to your computer and start U-Boot. Depending on what version of Ångström Linux (and U-Boot) you use, the update command might be different from mine (in that case, please refer to the documentation provided by Toradex to get the correct commands.
Because I had no setupdate defined in my U-Boot environment, here are the commands and the process I used :
1. Setup setupdate command
setenv drive 1
setenv setupdate 'mmc dev ${drive}; mmc rescan; fatload mmc ${drive}:1 ${loadaddr} flash_blk.img; source ${loadaddr}'
saveenv
2. Update U-Boot
run setupdate
run update
3. Restart the module
4. Update Ångström Linux :
run setupdate; run migrate_v2.3b1
5. If the board does not boot after the last command, reset the U-Boot config
env default -a
saveenv
6. Restart the board
reset
Now, you should have a working Ångström Linux installation on your device. Not for long because we'll be switching soon to PostmarketOS !
== Flash a newer version of U-Boot ==
Now that you have a working environment, you need to update the U-Boot bootloader on your board, otherwise, you will have problems to boot PostmarketOS (the countdown of extlinux is not working with this older version of U-Boot).
First, we'll build the newest build of U-Boot, and then, we will flash it on the device.
=== Build U-Boot ===
We're going to build U-Boot according to its documentation available here : https://docs.u-boot.org/en/latest/build/gcc.html
Assuming you're using a Debian based system (you can also use a Docker container, which is what I did), you'll have to install some dependencies first.
$ sudo apt update && sudo apt upgrade
$ sudo apt-get install gcc gcc-arm-linux-gnueabi git
$ sudo apt-get install bc bison build-essential coccinelle device-tree-compiler dfu-util efitools flex gdisk graphviz imagemagick liblz4-tool libgnutls28-dev libguestfs-tools libncurses-dev libpython3-dev libsdl2-dev libssl-dev lz4 lzma lzma-alone openssl pkg-config python3 python3-asteval python3-coverage python3-filelock python3-pkg-resources python3-pycryptodome python3-pyelftools python3-pytest python3-pytest-xdist python3-sphinxcontrib.apidoc python3-sphinx-rtd-theme python3-subunit python3-testtools python3-virtualenv swig uuid-dev
Then we can clone the U-Boot project :
$ git clone https://source.denx.de/u-boot/u-boot.git --depth=1 && cd u-boot/
You then need to specify some parameters like the system which U-Boot will run, and then, you can build U-Boot.
$ export CROSS_COMPILE=arm-linux-gnueabi-
$ make colibri_t30_defconfig
$ make
Many files will be created inside the u-boot folder. The file we are interested with is u-boot-dtb-tegra.bin.
=== Flash U-Boot on the Colibri T30 ===
I couldn't make tegrarcm, the flashing tool, to work on my device.
Instead, we're going to modify the files of Toradex installer to include our generated U-Boot binary, write that to the SD card and then flash it on the eMMC from U-Boot itself.
Copy the u-boot-dtb-tegra.bin file from the u-boot directory to the Toradex installer files (adapt the path if needed) :
$ sudo cp u-boot-dtb-tegra.bin ../Colibri-T30_LXDE-Image_2.8.7/colibri-t30_bin/u-boot-dtb-tegra.bin
And then, like in the restore part of the guide, use the updater tool to write these files to the SD card (adapt the path to the mounted directory of the SD card) :
$ cd ../Colibri-T30_LXDE-Image_2.8.7 && sudo ./update.sh -m 0 -o /run/media/user/E2DE-AD92
You can now eject the SD card and insert it in the carrier board of your Colibri T30. Start U-Boot, and because we only want to update U-Boot instead of reflashing the whole Linux distribution, enter these commands : 
run setupdate
run update_uboot
reset
After the reset command, you will see that U-Boot uses a newer build. You will also notice that Ångström Linux does not start anymore (the board keeps resetting at startup). 
== Install PostmarketOS ==
Because Ångström Linux is not booting anymore, we're going to boot PostmarketOS from USB (for some reason, PostmarketOS does not start from the SD card) and then use it to flash the system on the eMMC.
=== Build PostmarketOS ===
We're using pmbootstrap to create our image. Run pmbootstrap init to choose the options you want to use on your image. For this board, I used the 'edge' Channel, with 'nvidia' as a vendor and 'tegra-armv7' for the device codename. For the user interface, choose console and use 512 MB of extra space size. Add 'parted' as an extra package. You can leave the other options as default.
Now that the init is done, you can use pmbootstrap install to build the image. Once that's done, export the image with the command pmbootstrap export. 
The image will be located on '/tmp/postmarketOS-export' You can flash your USB device with dd or another tools of your choice (replace /dev/sda with your USB drive, and double check what you're doing because all of its content will be destroyed).
$ sudo dd if=/tmp/postmarketOS-export/nvidia-tegra-armv7.img of=/dev/sda bs=1M status=progress
Once that's done, you'll need to make a copy of nvidia-tegra-armv7.img on either another drive, or another partition of that thumb drive (the image is what we're going to flash on the eMMC afterwards). If you want to use another desktop environment or default settings on your Colibri T30, you can also build another image and copy this one to your secondary drive/partition instead.
=== Start PostmarketOS from USB and install it on the eMMC ===
Plug your USB thumb drive on your Colibri T30 and start U-Boot. To start PostmarketOS from USB, you'll have to enter these commands :
setenv fdtfile tegra30-colibri-eval-v3.dtb
saveenv
usb start
load usb 0:1 ${kernel_addr_r} /vmlinuz
load usb 0:1 ${fdt_addr_r} /dtbs/${fdtfile}
load usb 0:1 ${ramdisk_addr_r} /initramfs
bootz ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r}
Once PostmarketOS is booted, login to your account and mount the partition or USB device containing the previously copied nvidia-tegra-armv7.img :
$ cd /mnt
$ sudo mkdir setup
$ sudo mount /dev/sda3 ./setup
$ cd setup
And then you can flash the image on the eMMC with dd :
$ sudo dd if=nvidia-tegra-armv7.img of=/dev/mmcblk1
When it is done, use parted and resize2fs to resize the / partition to use the full space available to your eMMC :
$ sudo parted
$ select /dev/mmcblk1
$ resizepart 2 100%
$ quit
$ sudo resize2fs /dev/mmcblk1p2
Now, you can remove your USB drives and power cycle your board. The board will not boot directly to PostmarketOS though, you will need to restore the settings of U-Boot to the default with these commands :
env default -a
setenv fdtfile tegra30-colibri-eval-v3.dtb
saveenv
reset
Now, PostmarketOS is installed and should boot each time the board is powered on.