.. include:: ../substitutions.rst Flashing with USB-OTG ===================== The |soc-caps| supports downloading and flashing SPI-NOR Flash via its USB OTG interface. This section explains how to use NXP’s ``blhost`` tool to flash an image from a Linux Ubuntu PC. Requirements ------------ **Hardware** * Ubuntu 24.04 LTS or newer * If using a virtual machine, VMWare Workstation, VMWare Player, and VirtualBox are all viable solutions. * Micro-USB to USB-A cable .. image:: ../../images/phycore-rt1170/installthefw/usb-otg-callout.webp :width: 500px :alt: phyBOARD-Atlas USB-OTG Connector **Software** Prepare the following images by building the firmware (|ref-build-fw|) or downloading the pre-built versions (|ref-prebuilts|). These images will be used to flash the |product| via USB: .. parsed-literal:: * ivt_flashloader.bin * zephyr.bin .. note:: **ivt_flashloader.bin** is only available via |ref-prebuilts| and is not part of the Zephyr build output. Prepare the Development Kit --------------------------- The |product| development kit is configured to boot from SPI-NOR Flash by default. For flashing via USB-OTG, we need to change the boot configuration to the USB-OTG Serial Downloader mode. * Ensure that switch S7 is set to OFF. * Verify that boot switch S5 is configured for USB-OTG Serial Downloader mode. .. image:: ../../images/phycore-rt1170/boot/usb-otg.webp :width: 200px .. image:: ../../images/phycore-rt1170/quickstart/bootswitch.webp :width: 500px .. note:: Pay close attention to switch orientation! * Use the provided 5V USB-C power supply to power the phyCORE-RT1170 development kit through the X9 power connector. The system will automatically boot. .. image:: ../../images/phycore-rt1170/quickstart/power.webp :width: 500px Install & Configure SPSDK -------------------------- * Install Python 3, pip, and the virtual environment tools: .. code-block:: console :substitutions: |host-prompt| sudo apt update && sudo apt install python3 python3-pip python3-venv * Create and activate a Python virtual environment in the same folder where your firmware files are located: .. code-block:: console :substitutions: |host-prompt| python3 -m venv myenv |host-prompt| source myenv/bin/activate * Install SPSDK using pip: .. code-block:: console :substitutions: |host-prompt| pip install spsdk * Add **udev rules** to allow SPSDK to access USB devices: .. code-block:: console :substitutions: |host-prompt| cat <> 50-nxp.rules SUBSYSTEM=="hidraw", KERNEL=="hidraw*", ATTRS{idVendor}=="0d28", MODE="0666" SUBSYSTEM=="hidraw", KERNEL=="hidraw*", ATTRS{idVendor}=="1fc9", MODE="0666" SUBSYSTEM=="hidraw", KERNEL=="hidraw*", ATTRS{idVendor}=="15a2", MODE="0666" EOF |host-prompt| sudo mv 50-nxp.rules /etc/udev/rules.d/ |host-prompt| sudo udevadm control --reload-rules |host-prompt| sudo udevadm trigger * Verify that the host system can communicate with the |soc-caps| via USB: .. code-block:: console :substitutions: |host-prompt| blhost -u 0x1fc9:0x013d get-property 1 Response status = 0 (0x0) Success. Response word 1 = 1258487809 (0x4b030001) Current Version = K3.0.1 Loading the Flashloader ------------------------ Load the ``ivt_flashloader.bin`` image into the |soc-caps|: .. code-block:: console :substitutions: |host-prompt| blhost -u 0x1fc9:0x013d load-image ivt_flashloader_user.bin Once loaded, the |soc-caps| exposes a new USB interface with a different vendor and product ID. Verify the flashloader is running: .. code-block:: console :substitutions: |host-prompt| blhost -u 0x15a2:0x0073 get-property 1 .. note:: After loading the flashloader, the original USB device ID is no longer valid. Use ``0x15a2:0x0073`` for all further communication. Flashing the Firmware --------------------- Configure the SPI-NOR Flash memory by selecting the correct instance and settings: .. code-block:: console :substitutions: |host-prompt| blhost -u 0x15a2:0x0073 fill-memory 0x00002000 4 0xCF900001 |host-prompt| blhost -u 0x15a2:0x0073 configure-memory 9 0x00002000 |host-prompt| blhost -u 0x15a2:0x0073 fill-memory 0x00002000 4 0xC0000007 |host-prompt| blhost -u 0x15a2:0x0073 configure-memory 9 0x00002000 You can verify the SPI-NOR was initialized correctly by listing all available memory regions. The ``FLEX-SPI-NOR`` section represents the SPI-NOR Flash: .. code-block:: console :substitutions: |host-prompt| blhost -u 0x15a2:0x0073 list-memory Internal Flash: Internal RAM: Region 0: 0x00000000 - 0x0003FFFF; Total Size: 256.0 kiB Region 1: 0x20000000 - 0x2003FFFF; Total Size: 256.0 kiB Region 2: 0x20200000 - 0x2037FFFF; Total Size: 1.5 MiB External Memories: SEMC-NAND: Not Configured SPI-NAND: Not Configured SD: Not Configured MMC: Not Configured FLEX-SPI-NOR: Start Address = 0x30000000 Total Size = 8.0 MiB Page Size = 256 Sector Size = 4096 Block Size = 65536 SPI-MEM: Not Configured Before flashing, you need to erase the previous content. Two options are available: **1. Erase the entire flash** (takes ~15 seconds, so we increase the timeout): .. code-block:: console :substitutions: |host-prompt| blhost -u 0x15a2:0x0073 -t 30000 flash-erase-all 9 **2. Erase the first 512 KiB only**, sufficient for a Zephyr binary: .. code-block:: console :substitutions: |host-prompt| blhost -u 0x15a2:0x0073 flash-erase-region 0x30000000 0x80000 Now flash the Zephyr binary to the SPI-NOR Flash: .. code-block:: console :substitutions: |host-prompt| blhost -u 0x15a2:0x0073 write-memory 0x30000000 zephyr.bin Booting the Firmware --------------------- Set the boot switch back to QSPI Flash mode and perform a power cycle. The new firmware should now boot successfully. .. image:: ../../images/phycore-rt1170/boot/qspi.webp :width: 200px .. image:: ../../images/phycore-rt1170/quickstart/bootswitch.webp :width: 500px