Using Fastboot USB in Pigweed with modules specific to i.MX RT595
Published:
Topics: Open software libraries, Open source tools
Pigweed is an open source environment with sets of libraries called modules used for developing embedded systems based on microcontroller units (MCUs). It’s a modular platform enabling you to add new functionalities and test the existing ones. Antmicro has been working on extending Pigweed with new features, and a while back, we implemented a Bluetooth controller for the NXP i.MX RT595 MCU, supported by the MCUxpresso ecosystem, for audio playback in constrained wireless devices.
Now, we have created Fastboot support to use with Pigweed, since Fastboot is known from the Android ecosystem as the most commonly used protocol for diagnosing and flashing devices over USB. Through our implementation, you can use it to flash and update the firmware of MCUs running Pigweed. Since working with Pigweed is a multi-stage process, the support for Fastboot has been added in the form of a series of modules. As our platform, we have chosen the MIMXRT595 evaluation kit board, which features the i.MX RT595 MCU.
In this article, we take a look at the way Antmicro has implemented Fastboot to use with Pigweed, and at how you can take advantage of it as presented by our sample.
Antmicro’s work on implementing Fastboot support
To communicate with Pigweed through USB, we have created the transport.h interface, a general option used for various transport methods. To send information through USB on the i.MX RT595 MCU, Antmicro has created the pw_fastboot_usb_mcuxpresso module. Although it uses the MCUxpresso family’s software development kit (SDK), Pigweed’s modularity makes it at the same time generic because SDKs need to be abstracted according to Pigweed interfaces.
To parse and interpret Fastboot commands, we have created the pw_fastboot module that is based on the existing Android Open Source Project implementation of the protocol, and that interacts with pw_fastboot_usb_mcuxpresso. For that interaction, we have supplemented pw_fastboot with the pw_fastboot_usb module, which serves as an adapter for the former to be able to use any USB stack.
To flash the i.MX RT595 MCU with a previously saved image by uploading it to a non-volatile memory through USB, we have created the pw_flash and the pw_flash_mcuxpresso modules. The first one is generic, so you can use it to flash all kinds of boards. The second is its specific implementation for the i.MX RT595 MCU. The pw_flash module exposes the internal structure of the board’s underlying flash memory, allowing reading, writing to, and erasing from it.
Below, you can find a dependency diagram of all the new modules, with 02_fastboot being our custom bootloader created for our sample described in the next section:
Using Antmicro’s Fastboot modules to flash the i.MX RT595 MCU
As a demo sample, we have created a custom bootloader supporting the Fastboot protocol for the i.MX RT595 MCU. This bootloader uses the modules described in the previous section. To build our Fastboot sample, you need to run bazelisk as follows:
bazelisk build //examples/02_usb_fastboot:usb_fastboot.elf
Next, follow the Running and debugging section of the Pigweed documentation. After connecting to the GNU Debugger, pass the sample executable to the file command:
>>> target remote :2331
Remote debugging using :2331
warning: No executable has been specified and target does not support
determining executable automatically. Try using the "file" command.
0x20081ad4 in ?? ()
>>> file bazel-bin/examples/02_usb_fastboot/usb_fastboot.elf
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Reading symbols from bazel-bin/examples/02_usb_fastboot/usb_fastboot.elf...
>>> moni reset
Resetting target
>>> load
Loading section .flash_config, size 0x200 lma 0x8000400
Loading section .vector_table, size 0x168 lma 0x8001000
Loading section .code, size 0x17a3c8 lma 0x8001180
Loading section .ARM, size 0x8 lma 0x817b548
Loading section .static_init_ram, size 0x1124 lma 0x817b550
Start address 0x08003130, load size 1554524
Transfer rate: 46002 KB/sec, 15545 bytes/write.
>>> c
Afterward, a GPIO or devkit button needs to be held. For our platform specifically, it’s the SW1 button you need to hold while resetting the board (either through the dedicated SW3 reset button or by power cycling the board). You should see the following output on the FLEXCOMM12 UART:
INF System init
INF Registering RPC services
INF Starting threads
INF Running RPC server
INF Fastboot bootloader: fastboot mode
INF Ready to accept fastboot commands, connect to USB port J38..
At this point, you can connect the board’s J38 USB port to the host computer. The device should be detected by the host, which you can verify by running the following command:
sudo fastboot devices
To flash an application, run the fastboot flash command as shown below, with the partition name being system and the path pointing to one of the sample Fastboot binaries:
sudo fastboot flash system bazel-bin/examples/03_user_hello/user_hello.fastboot
If no application is selected, the bootloader runs the previously flashed application. We had created a few demo applications, and if you had tested some of them, that application may be our Bluetooth audio. For full instructions on how to use our Pigweed samples, refer to the README file.
We also included the possibility to provide additional partitions that can be flashed using our Fastboot sample. To do that, provide the starting point, the size, and the name of the partition, and the bootloader will flash it for you. This ability can be useful in the following cases:
- A/B updates, where you can flash back an application without interruptions in case of a fault.
- Partitioning custom application data, where you can flash only the selected files.
- Updating the bootloader itself through Fastboot mode.
To flash the board in Fastboot mode, you can also use the stock Android Fastboot tool.
Antmicro is currently working on USB simulation support for the i.MX RT595 MCU in Renode, so that you can enter Fastboot mode on your computer and let Renode simulate the device that’s being flashed.
Using Antmicro’s Fastboot modules in your embedded development
Antmicro’s expertise with embedded solutions enabled using the Fastboot protocol to flash MCUs efficiently within the Pigweed framework, which is well-suited to run on constrained devices. This streamlines the updating process, while leaving room for data backups, selective flashing of data sectors, and even direct access to the devices’ flash memories for precise control.
Antmicro’s continuously enhancing the Pigweed platform, and this includes a possibility to use Pigweed as a speaker microphone through Bluetooth. We will describe it in a future article.
If you would like to implement Fastboot or Pigweed on your platforms or require software integration with this open source environment and its modules, we provide commercial services to help with that. Antmicro is also proficient in customizing the Android system to its customers’ needs. Write to us at contact@antmicro.com, so we can discuss your use case and tailor a solution to your requirements.