U-Boot recovery for i.MX6 Q/D/DL/S/ULL via JTAG v2

From Wiki-DB
Jump to navigationJump to search

This guide details the process of flashing U-Boot onto our i.MX6 based DHCOM using OpenOCD. The hardware configuration, software installation, and step-by-step programming procedures are provided.

Required Hardware

All tests and documents were made with this one, but technically all JTAG adapters listed by OpenOCD should work.
  • DHCOM JTAG adapter for FFC connection: Article number FD00037
Note: One cable is included with the DHCOM JTAG adapter.

Installation

This installation was made on the Virtual Machine for Application Development. All console expressions refer to this Debian system, but any other debian based system should also work.

To support all our i.MX6 based DHCOM, it is necessary to have OpenOCD v0.11.0 or higher.

OpenOCD from master branch (before Debian 11 alias Bullseye)

  1. Install needed libraries and tools
    sudo apt-get install git build-essential pkg-config autoconf automake libtool libusb-dev libusb-1.0-0-dev libhidapi-dev libftdi-dev
  2. Clone git repository to local directory and checkout v0.12.0 tag
    git clone -b v0.12.0 https://repo.or.cz/openocd.git
  3. Change working directory to the extracted one
    cd openocd
  4. Prepare source directory and submodules (when building from the git repository)
    ./bootstrap
  5. Generate the Makefiles to build OpenOCD
    ./configure
  6. Build OpenOCD from source
    make -j4
  7. Install OpenOCD to /usr/local
    sudo make install
  8. (optional) Remove openocd source directory
    cd .. && rm -rf openocd

OpenOCD from Debian repositories (since Debian 11 alias Bullseye)

  1. Install OpenOCD from Debian repositories
    sudo apt-get install openocd

Non root access to tty devices

  1. Add your user to the dialout group:
    sudo usermod -a -G dialout ${USER}
  2. Add your user to the plugdev group:
    sudo usermod -a -G plugdev ${USER}
  3. Logout and login to apply new group rights

U-Boot Programming

There are two ways for doing this. The easy way is an automatic shell script, which handles all the commands needed for the programming process. The other one is to type in the required commands. In a few cases the shell script fails then you need to go the other way and program the U-Boot manually. The steps Preparation and Start up OpenOCD are required for both automatic and manual flash programming.

Preparation

Get the needed recovery files

  1. Download and extract the needed files 2023-08-28_imx6_U-Boot_recovery.tar.xz
    wget -O - 'https://www.dropbox.com/scl/fi/bj6s93ym5gwa17ecm7tqb/2023-08-28_imx6_U-Boot_recovery.tar.xz?rlkey=r7p3kwonbfafa81ug4gnyibbz' | tar xJ
  2. Change working directory to the extracted one
    cd 2023-08-28_imx6_U-Boot_recovery

Connect JTAG adapter

  1. Connect the JTAG adapter with your PC and the Debian VM (Player - Removeable Devices) through USB
  2. Connect the JTAG interface via the DHCOM JTAG adapter to the i.MX6 module (If you don't have a JTAG adapter, please ask DH electronics)
  3. Put the SODIMM-200 module (DHCOM) into the SODIMM-200 slot on your basebord
  4. Connect to the serial console (serial port) of the board like here Enter_Bootloader_Console

Start up OpenOCD

  1. Ensure you have everything properly connected like in Connect JTAG adapter
  2. Power up the i.MX6 board and have a look at the serial output (serial port).
    • i.MX6 Q/D/DL/S
      It is okay if a U-Boot is starting up, because the device will be reset later.
    • i.MX6 ULL
      There must be no output of U-Boot, otherwise go to Troubleshooting.
  3. Open a new terminal window (local shell console)
  4. Ensure you are in the directory with the recovery files
    cd /path/to/2023-08-28_imx6_U-Boot_recovery
  5. Start OpenOCD depending on your hardware
    • i.MX6 Q/D/DL/S
      openocd -f interface/ftdi/olimex-arm-usb-tiny-h.cfg -f target/imx6.cfg -f dhcom-manual-loaded-code.cfg
    • i.MX6 ULL
      openocd -f interface/ftdi/olimex-arm-usb-tiny-h.cfg -f imx6ull.cfg -f target/imx6ul.cfg -f dhcom-manual-loaded-code.cfg

The output should look like:

Open On-Chip Debugger 0.12.0
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
Warn : imx6.sdma: nonstandard IR value
boot_from_sd
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 1000 kHz
Info : JTAG tap: imx6.cpu tap/device found: 0x4ba00477 (mfg: 0x23b (ARM Ltd), part: 0xba00, ver: 0x4)
Info : TAP imx6.sdma does not have valid IDCODE (idcode=0x4323803a)
Info : JTAG tap: imx6.sjc tap/device found: 0x2191c01d (mfg: 0x00e (Freescale (Motorola)), part: 0x191c, ver: 0x2)
Info : imx6.cpu.0: hardware has 6 breakpoints, 4 watchpoints
Info : starting gdb server for imx6.cpu.0 on 3333
Info : Listening on port 3333 for gdb connections

Automated Programming

  1. Ensure OpenOCD is running like in Start up OpenOCD
  2. Open a second terminal window (local shell console)
  3. Ensure you are in the directory with the recovery files
    cd /path/to/2023-08-28_imx6_U-Boot_recovery
  4. Execute the automated bash script with arguments depending on your hardware and desired U-Boot
    • Default DH U-Boot
      • i.MX6 Q/D/DL/S
        sh prog_bl.sh imx6qdl
      • i.MX6 ULL
        sh prog_bl.sh imx6ull
    • Custom U-Boot
      • i.MX6 Q/D/DL/S
        sh prog_bl.sh imx6qdl /path/to/u-boot-with-spl.imx
      • i.MX6 ULL
        sh prog_bl.sh imx6ull /path/to/u-boot-with-spl.imx

On success the output of the script should look like:

Programming: u-boot-with-spl-imx6qdl.imx to imx6qdl
Trying ::1...
Connection failed: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> boot_from_sd
imx6.cpu.0: MPIDR level2 0, cluster 0, core 0, multi core, no SMT
target halted in Thumb state due to debug-request, current mode: Supervisor
cpsr: 0xa00001f3 pc: 0x8ff7a982
MMU: enabled, D-Cache: enabled, I-Cache: enabled
Invalid ACK (0) in DAP response
Could not read DSCR register
Error waiting for cortex_a_exec_opcode
Invalid ACK (0) in DAP response
Could not read DSCR register
Invalid ACK (0) in DAP response
JTAG-DP STICKY ERROR
Could not read DSCR register
Error waiting for dpm prepare

Invalid ACK (7) in DAP response
Polling target imx6.cpu.0 failed, trying to reexamine
Debug regions are unpowered, an unexpected reset might have happened
JTAG-DP STICKY ERROR
Could not initialize the APB-AP
Examination failed, GDB will be halted. Polling again in 100ms
JTAG-DP STICKY ERROR
Polling target imx6.cpu.0 failed, trying to reexamine
imx6.cpu.0: hardware has 6 breakpoints, 4 watchpoints
> prepare_code_load
target halted in Thumb state due to debug-request, current mode: Supervisor
cpsr: 0x800001f3 pc: 0x8ff7a982
MMU: disabled, D-Cache: disabled, I-Cache: disabled
> load_image u-boot-spl-prog-imx6qdl.bin 0x908000
32768 bytes written at address 0x00908000
downloaded 32768 bytes in 1.152152s (27.774 KiB/s)

> resume
> halt
target halted in Thumb state due to debug-request, current mode: Supervisor
cpsr: 0x800001f3 pc: 0x0090ba5e
MMU: disabled, D-Cache: disabled, I-Cache: enabled
> load_image u-boot-with-spl-imx6qdl.imx 0x12000000
567752 bytes written at address 0x12000000
downloaded 567752 bytes in 18.675529s (29.688 KiB/s)

> resume
> Connection closed by foreign host.

On success the output of serial console (serial port) should look like:

U-Boot SPL 2018.05-23076-g8686cf2574 (Mar 10 2020 - 10:26:00 +0100)
SPL: Unsupported Boot Device!
SPL: failed to boot from all boot devices
### ERROR ### Please RESET the board ###
Searching for IVT header at DDR address 0x12000000
....
Found IVT header
Determinded image length: 0x8a9c8

### Recovery ### Trying to program SPI flash ###
Probing SPI flash... ok
Erasing SPI flash... ok
Programming SPI flash... ok

### Recovery ### Finished ###

Note: If some error occures you can try the Manual Programming method below

Manual Programming

  1. Ensure OpenOCD is running like in Start up OpenOCD
  2. Open a second terminal window (local shell console)
  3. Ensure you are in the directory with the recovery files
    cd /path/to/2023-08-28_imx6_U-Boot_recovery
  4. Open a telnet session to OpenOCD
    telnet localhost 4444
    1. Ensure device boot fails by booting from invalid media
      • i.MX6 Q/D/DL/S
        boot_from_sd
      • i.MX6 ULL
        Follow Troubleshooting to ensure no U-Boot starts.
    2. Prepare for running manual loaded code
      prepare_code_load
    3. Load modified U-Boot SPL as flash programmer in SRAM (device dependent)
      • i.MX6 Q/D/DL/S
        load_image u-boot-spl-prog-imx6qdl.bin 0x908000
      • i.MX6 ULL
        load_image u-boot-spl-prog-imx6ull.bin 0x908000
    4. Resume code execution at entry point of loaded U-Boot SPL
      resume 0x00908000
    5. Halt code execution if you see Searching for IVT header at DDR address 0xX2000000 in serial console
      halt
    6. Load desired U-Boot image into RAM (device and customer dependent)
      • i.MX6 Q/D/DL/S
        load_image u-boot-with-spl-imx6qdl.imx 0x12000000
      • i.MX6 ULL
        load_image u-boot-with-spl-imx6ull.imx 0x82000000
    7. Resume code execution after U-Boot image is in RAM
      resume
    8. Wait until the serial output (serial port) looks like in Automated Programming
    9. Exit telnet with exit and close OpenOCD with STRG+C

Troubleshooting

If there is a U-Boot starting, the OpenOCD procedure may not work properly. There are two solutions to prevent the start of U-Boot from the SPI-NOR-Flash.

SDP Boot (only i.MX6 ULL)

  1. Boot in Serial Download Mode to prevent booting the broken U-Boot from SPI-NOR-Flash
    1. Hold the button for sdp boot mode on the SODIMM-200 module (DHCOM) next to the BGA module (DHCOR)
    2. Reset the device. To reset the device, press the reset button on the baseboard or unplug and plug in the power plug.
    3. Release the button for sdp boot mode
  2. If no new output is printed on the serial console (serial port), continue with the flashing procedure

SD Boot (only i.MX6 Q/D/DL/S)

  1. Ensure OpenOCD is running like in Start up OpenOCD
  2. Open a telnet session to OpenOCD
    telnet localhost 4444
  3. Use the following command to trigger a boot from an invalid source by setting the boot source to an invalid media for the next boot and then reset the device.
    boot_from_sd
  4. If no new output is printed on the serial console (serial port), continue with the flashing procedure