Please enable javascript, or click here to visit my ecommerce web site powered by Shopify.
Jump to: navigation, search

Difference between revisions of "Rockpi4/dev/spi-install"

< Rockpi4‎ | dev
(Created page with "{{rockpi4_header}} {{Languages|rockpi4/dev/spi-install}} ROCK Pi 4 > Development > rockpi4/dev/spi-install | Write image to SPI flash fro...")
 
(Requirement)
 
(39 intermediate revisions by 7 users not shown)
Line 3: Line 3:
 
     [[rockpi4 | ROCK Pi 4]] > [[rockpi4/dev | Development]] > [[rockpi4/dev/spi-install | Write image to SPI flash from USB OTG port]]
 
     [[rockpi4 | ROCK Pi 4]] > [[rockpi4/dev | Development]] > [[rockpi4/dev/spi-install | Write image to SPI flash from USB OTG port]]
  
ROCK Pi supports maskrom mode, which is a special running mode the CPU is waiting for command from USB OTG port. The PC tool we use to communicate with ROCK Pi in maskrom mode is rkdevelop tool, an open source tool by Rockchip.
+
== Write image to SPI flash from USB OTG port ==
 +
ROCK Pi 4 supports Maskrom mode, which is a special operation mode for CPU to wait for USB OTG port command. The Linux/macOS PC tool we use to communicate with ROCK Pi in Maskrom mode are the '''rkdeveloptool''' and '''RKDevTool'''. We use tool rkdeveloptool in Linux/macOS and RKDevTool tool under Windows.
  
 
=== Requirement ===
 
=== Requirement ===
* ROCK Pi 4 mainboard
+
* ROCK (Pi) 4 mainboard
* SPI flash soldered on ROCK Pi 4
+
** ROCK (Pi) 4A, 4B, 4C, and some [[Rockpi4/hardware/revision#V1.73.284A.2B.2F4B.2B.29 | older version]] of 4A+/4B+
 +
** Latest ROCK 4 SE, 4A+, 4B+, and 4C+ is unsupported, since there is no SPI Flash on the board
 
* Power adapter
 
* Power adapter
 
* '''USB Male A to Male A cable'''(important) USB-C has been seen as not working, an adaptor for USB-C to USB-A has worked. [https://forum.radxa.com/t/otg-flashing-not-working/717 See discussion].
 
* '''USB Male A to Male A cable'''(important) USB-C has been seen as not working, an adaptor for USB-C to USB-A has worked. [https://forum.radxa.com/t/otg-flashing-not-working/717 See discussion].
  
=== Make sure rkdeveloptool is set up on host computer ===
+
=== Install Tools&Drivers ===
==== Linux====
+
Please check this guide, [[rockpi4/install/rockchip-flash-tools | Install rockchip flash tools,  rkdeveloptool/RKDevTool, under Windows/Linux/MacOS PC]].
To build rkdeveloptool on a debain based Linux distribution, follow the instruction below:
+
  
Install build dependecy:
+
=== Boot the board to maskrom mode ===
  sudo apt-get install libudev-dev libusb-1.0-0-dev dh-autoreconf
+
  
Clone the source code and build:
+
==== Case 1: Empty SPI flash ====
  git clone https://github.com/rockchip-linux/rkdeveloptool
+
  cd rkdeveloptool
+
  autoreconf -i
+
  ./configure
+
  make
+
  
If you encounter compile error like below
+
To boot ROCK Pi 4 into maskrom mode is simple, you don't need to press any key
    ./configure: line 4269: syntax error near unexpected token `LIBUSB1,libusb-1.0'
+
    ./configure: line 4269: `PKG_CHECK_MODULES(LIBUSB1,libusb-1.0)'
+
  
 +
* Power off the board and '''remove any bootable storage media''', remove microSD card, remove eMMC module.
 +
* Plug the USB Male A to Male A cable to ROCK Pi 4 OTG port (the upper USB3 port), the other side to PC
 +
* Power on the board
  
You should install pkg-config libusb-1.0
+
==== Case 2: Update SPI flash with bootloader inside ====
    sudo apt-get install pkg-config libusb-1.0
+
  
Then re-run
+
If the SPI flash already contains a bootable bootloader, you need to disable the SPI flash at boot time by shortcut the SPI1_CLK to GND. Use wire to connect PIN '''23''' and '''25'''. Checkout the [https://wiki.radxa.com/Rockpi4/hardware/rockpi4#gpio Pinout].
    autoreconf -i
+
    ./configure
+
    make
+
  
Now you have rkdeveloptool executable at the current directory.
+
Shown as following:
  sudo cp rkdeveloptool /usr/local/bin/
+
  
==== MacOS ====
+
[[File:Spi_clk_gnd.jpg | 500px]]
  
To build rkdeveloptool on macOS, you need [https://brew.sh/ homebrew](or similar package manager) to install required packages.
+
* Use cable to connect PIN23 and PIN25
 +
* Power off the board
 +
* Remove any bootable storage media microSD card
 +
* Remove/Disable eMMC module
 +
** In case of eMMC is not on board: Remove eMMC module
 +
** In case of eMMC is on board: Press and hold the Maskrom button to disable eMMC (Location of the button is described [https://wiki.radxa.com/Rockpi4/dev/usb-install#Boot_the_board_to_maskrom_mode here])
 +
* Plug the USB Male A to Male A cable to ROCK Pi 4 OTG port (the upper USB3 port), the other side to PC
 +
* Power on the board
 +
* Release Maskrom button only when eMMC is on board
 +
* '''Remove the cable and disconnect PIN23 and PIN25'''
  
Install build dependency:
+
Now on your Linux PC, '''lsusb''' command show show the following usb devices
  
     brew install automake autoconf libusb
+
     Bus 003 Device 005: ID 2207:330c
  
Clone the source code and build:
+
It means the device is in '''maskrom mode''' now.
  
    git clone https://github.com/rockchip-linux/rkdeveloptool
+
* Now we can proceed the next step to flash.
    cd rkdeveloptool
+
    autoreconf -i
+
    ./configure
+
    make
+
  
If you encounter compile error like below
+
=== Step 3: Write to SPI flash via USB ===
    ./configure: line 4269: syntax error near unexpected token `LIBUSB1,libusb-1.0'
+
On your PC, run the rkdeveloptool
    ./configure: line 4269: `PKG_CHECK_MODULES(LIBUSB1,libusb-1.0)'
+
  
 +
    rkdeveloptool ld        # List the device
 +
    DevNo=1 Vid=0x2207,Pid=0x330c,LocationID=305 Maskrom
  
You should install pkg-config libusb-1.0
+
Download the '''SPI loader''' (flash helper, important) to init the ram and prepare the flashing environment etc. If you don't have it, you can download it from [https://dl.radxa.com/rockpi/images/loader/spi/ here] downlad the rk3399_loader_spinor_v1.15.114.bin
    brew install pkg-config
+
  
Then re-run
+
According to [https://forum.radxa.com/t/spi-nor-loader-flashing-doesnt-work-on-v1-72/7709 this thread] boards with v1.72 like the Rock 4C Plus require v1.20.126 of the SPI loader.bin, that can be found in [https://github.com/radxa/rkbin/blob/master/bin/rk33/rk3399_loader_spinor_v1.20.126.bin this git repo].
    autoreconf -i
+
    ./configure
+
    make
+
  
Now you have rkdeveloptool executable at the current directory.
+
    sudo rkdeveloptool db /path/to/rk3399_loader_spinor_v1.15.114.bin  # will output: Downloading bootloader succeeded.
  
    sudo cp rkdeveloptool /usr/local/bin/
+
Write the packed SPI image of u-boot and trust.img, start to write from offset '''0'''. If you don't have it, you can download it from [https://dl.radxa.com/rockpi/images/loader/spi/ here] download the SPI Bootloader image.
  
=== Boot the board to maskrom mode ===
+
The latest version is '''2017.09-2697-ge41695afe3_20201219'''.
  
==== Empty SPI flash ====
+
* For ROCK Pi 4A
  
To boot ROCK Pi into maskrom mode is simple, you don't need to press any key
+
    sudo rkdeveloptool wl 0 /path/to/rockpi4a-uboot-trust-spi_2017.09-2697-ge41695afe3_20201219.img    # will output: Write LBA from file (100%)
  
* Power off the board and '''remove any bootable storage media''', remove microSD card, remove eMMC module.
+
* For ROCK Pi 4B
* Plug the USB Male A to Mail A cable to ROCK Pi 4 OTG port(the upper USB3 port), the other side to PC
+
* Power on the board
+
  
==== Update SPI FLash with bootloader inside ====
+
    sudo rkdeveloptool wl 0 /path/to/rockpi4b-uboot-trust-spi_2017.09-2697-ge41695afe3_20201219.img    # will output: Write LBA from file (100%)
  
If the SPI flash already contains a bootable bootloader, you need to disable the SPI flash at boot time by shortcut the SPI1_CLK to GND. Use wire to connect PIN '''23''' and '''25'''. Checkout the [https://wiki.radxa.com/Rockpi4/hardware/rockpi4#gpio Pinout].
+
* For ROCK Pi 4C
  
Shown as following:
+
    sudo rkdeveloptool wl 0 /path/to/rockpi4c-uboot-trust-spi_2017.09-2697-ge41695afe3_20201219.img    # will output: Write LBA from file (100%)
  
[[File:Spi_clk_gnd.jpg | 500px]]
+
Notes that writing SPI Bootloader image will take at least 15 seconds. If it goes fast, less than 3 seconds, there is something wrong with SPI Flash. Maybe need to change the SPI Flash.
  
* Use cable to connect PIN23 and PIN25
+
Reboot the device
* Power off the board and '''remove any bootable storage media''', remove microSD card, remove eMMC module.
+
* Plug the USB Male A to Mail A cable to ROCK Pi 4 OTG port(the upper USB3 port), the other side to PC
+
* Power on the board
+
* Remove the cable and disconnect PIN23 and PIN25
+
  
 +
    sudo rkdeveloptool rd    # will output: Reset Device OK.
  
Now on your Linux PC, '''lsusb''' command show show the following usb devices
+
Now the device should boot from the SPI flash now.
  
    Bus 003 Device 005: ID 2207:330c
+
=== FAQs ===
  
It means the device is in '''maskrom mode''' now.
+
==== Erase SPI flash on Windows PC ====
  
* Now we can proceed the next step to flash.
+
When ROCK (Pi) 4 is in Maskrom, before flashing, please make sure that '''PIN23 and PIN25 on 40-PIN header is not connected.'''
  
=== Write to SPI flash via USB ===
+
Double click the '''RKDevTool.exe''' and click button "Advanced Function" to get into '''Advanced Function''' window.
On your PC, run the rkdeveloptool
+
  
    rkdeveloptool ld        # List the device
+
[[File:Rockpi-4-erase-spi-nor-flash-1.png  | 1000px]]
    DevNo=1 Vid=0x2207,Pid=0x330c,LocationID=305 Maskrom
+
 
 +
===== Step 1: Confirm "Found One Maskrom  Device" =====
 +
If your ROCK (Pi) 4 is in Maskrom mode and connects to PC, you can see that RKDevTool shows '''Found one MASKROM Device'''.
 +
 
 +
===== Step 2: Download RK3399 Loader =====
 +
Choose loader rk3399_loader_spinor_v1.15.114.bin and download it.
 +
 
 +
[[File:Rockpi-4-erase-spi-nor-flash-2.png  | 1000px]]
 +
 
 +
===== Step 3: Erase device =====
 +
Click button "EraseAll" to erase device.
 +
 
 +
[[File:Rockpi-4-erase-spi-nor-flash-3.png  | 1000px]]
 +
 
 +
===== Step 4: Reset device =====
 +
Click button "ResetDevice" to reset device.
 +
 
 +
[[File:Rockpi-4-erase-spi-nor-flash-4.png  | 1000px]]
 +
 
 +
Erasing job is done.
 +
 
 +
==== Erase images on SPI flash on Linux/macOS PC ====
 +
 
 +
To erase images on SPI device, it's the same as writing the image to SPI flash, just the image we write is empty.
 +
 
 +
Firstly, follow '''Step 1''' and  '''Step 2: Boot the board to maskrom mode, Case 2: Update SPI flash with bootloader inside''' above
 +
to boot ROCK (Pi) 4 to maskrom mode.
 +
 
 +
Secondly, on your Linux PC, create zero.img.
 +
 
 +
    dd if=/dev/zero of=./zero.img bs=1M count=4
  
Download the '''SPI loader''' (flash helper, important) to init the ram and prepare the flashing environment etc. If you don't have it, you can download it from [https://dl.radxa.com/rockpi/images/loader/ here]
+
Thirdly, flash zero.img to SPI device.
  
 
     rkdeveloptool db rk3399_loader_spinor_v1.15.114.bin
 
     rkdeveloptool db rk3399_loader_spinor_v1.15.114.bin
 +
    rkdeveloptool wl 0 zero.img
 +
    rkdeveloptool rd    # will output: Reset Device OK.
  
Write the packed SPI image of u-boot and trust.img, start to write from offset '''0'''.
+
Finally, on your Linux PC, '''lsusb''' command show show the following usb devices
  
     rkdeveloptool wl 0 /path/to/uboot-trust-spi.img
+
     Bus 003 Device 005: ID 2207:330c
  
Reboot the device
+
It means the SPI image is erased successfully.
  
    rkdeveloptool rd
+
==== Erase images on SPI flash on ROCK (Pi) 4 ====
  
Now the device should boot from the SPI flash now.
+
If you could boot into Linux and you have /dev/mtd* device available, you can use the following to erase the SPI flash.
 +
 
 +
* For ROCK (Pi) 4A
 +
 
 +
    sudo /usr/local/sbin/rockpi4a_erase_spi_flash.sh #related package: rockpi4a-rk-u-boot-latest
 +
 
 +
* For ROCK (Pi) 4B
 +
 
 +
    sudo /usr/local/sbin/rockpi4b_erase_spi_flash.sh #related package: rockpi4b-rk-u-boot-latest
 +
 
 +
* For ROCK (Pi) 4C
  
 +
    sudo /usr/local/sbin/rockpi4c_erase_spi_flash.sh #related package: rockpi4c-rk-u-boot-latest
  
 
=== Troubleshooting ===
 
=== Troubleshooting ===
  
 
* If you have issue with flashing via USB OTG, start a new post on the forum. https://forum.radxa.com/c/dev
 
* If you have issue with flashing via USB OTG, start a new post on the forum. https://forum.radxa.com/c/dev

Latest revision as of 03:28, 13 April 2023

    ROCK Pi 4 >  Development >  Write image to SPI flash from USB OTG port

Write image to SPI flash from USB OTG port

ROCK Pi 4 supports Maskrom mode, which is a special operation mode for CPU to wait for USB OTG port command. The Linux/macOS PC tool we use to communicate with ROCK Pi 4 in Maskrom mode are the rkdeveloptool and RKDevTool. We use tool rkdeveloptool in Linux/macOS and RKDevTool tool under Windows.

Requirement

  • ROCK (Pi) 4 mainboard
    • ROCK (Pi) 4A, 4B, 4C, and some older version of 4A+/4B+
    • Latest ROCK 4 SE, 4A+, 4B+, and 4C+ is unsupported, since there is no SPI Flash on the board
  • Power adapter
  • USB Male A to Male A cable(important) USB-C has been seen as not working, an adaptor for USB-C to USB-A has worked. See discussion.

Install Tools&Drivers

Please check this guide, Install rockchip flash tools, rkdeveloptool/RKDevTool, under Windows/Linux/MacOS PC.

Boot the board to maskrom mode

Case 1: Empty SPI flash

To boot ROCK Pi 4 into maskrom mode is simple, you don't need to press any key

  • Power off the board and remove any bootable storage media, remove microSD card, remove eMMC module.
  • Plug the USB Male A to Male A cable to ROCK Pi 4 OTG port (the upper USB3 port), the other side to PC
  • Power on the board

Case 2: Update SPI flash with bootloader inside

If the SPI flash already contains a bootable bootloader, you need to disable the SPI flash at boot time by shortcut the SPI1_CLK to GND. Use wire to connect PIN 23 and 25. Checkout the Pinout.

Shown as following:

Spi clk gnd.jpg

  • Use cable to connect PIN23 and PIN25
  • Power off the board
  • Remove any bootable storage media microSD card
  • Remove/Disable eMMC module
    • In case of eMMC is not on board: Remove eMMC module
    • In case of eMMC is on board: Press and hold the Maskrom button to disable eMMC (Location of the button is described here)
  • Plug the USB Male A to Male A cable to ROCK Pi 4 OTG port (the upper USB3 port), the other side to PC
  • Power on the board
  • Release Maskrom button only when eMMC is on board
  • Remove the cable and disconnect PIN23 and PIN25

Now on your Linux PC, lsusb command show show the following usb devices

   Bus 003 Device 005: ID 2207:330c

It means the device is in maskrom mode now.

  • Now we can proceed the next step to flash.

Step 3: Write to SPI flash via USB

On your PC, run the rkdeveloptool

   rkdeveloptool ld        # List the device
   DevNo=1	Vid=0x2207,Pid=0x330c,LocationID=305	Maskrom

Download the SPI loader (flash helper, important) to init the ram and prepare the flashing environment etc. If you don't have it, you can download it from here downlad the rk3399_loader_spinor_v1.15.114.bin

According to this thread boards with v1.72 like the Rock 4C Plus require v1.20.126 of the SPI loader.bin, that can be found in this git repo.

   sudo rkdeveloptool db /path/to/rk3399_loader_spinor_v1.15.114.bin  # will output: Downloading bootloader succeeded.

Write the packed SPI image of u-boot and trust.img, start to write from offset 0. If you don't have it, you can download it from here download the SPI Bootloader image.

The latest version is 2017.09-2697-ge41695afe3_20201219.

  • For ROCK Pi 4A
   sudo rkdeveloptool wl 0 /path/to/rockpi4a-uboot-trust-spi_2017.09-2697-ge41695afe3_20201219.img    # will output: Write LBA from file (100%)
  • For ROCK Pi 4B
   sudo rkdeveloptool wl 0 /path/to/rockpi4b-uboot-trust-spi_2017.09-2697-ge41695afe3_20201219.img    # will output: Write LBA from file (100%)
  • For ROCK Pi 4C
   sudo rkdeveloptool wl 0 /path/to/rockpi4c-uboot-trust-spi_2017.09-2697-ge41695afe3_20201219.img    # will output: Write LBA from file (100%)

Notes that writing SPI Bootloader image will take at least 15 seconds. If it goes fast, less than 3 seconds, there is something wrong with SPI Flash. Maybe need to change the SPI Flash.

Reboot the device

   sudo rkdeveloptool rd    # will output: Reset Device OK.

Now the device should boot from the SPI flash now.

FAQs

Erase SPI flash on Windows PC

When ROCK (Pi) 4 is in Maskrom, before flashing, please make sure that PIN23 and PIN25 on 40-PIN header is not connected.

Double click the RKDevTool.exe and click button "Advanced Function" to get into Advanced Function window.

Rockpi-4-erase-spi-nor-flash-1.png

Step 1: Confirm "Found One Maskrom Device"

If your ROCK (Pi) 4 is in Maskrom mode and connects to PC, you can see that RKDevTool shows Found one MASKROM Device.

Step 2: Download RK3399 Loader

Choose loader rk3399_loader_spinor_v1.15.114.bin and download it.

Rockpi-4-erase-spi-nor-flash-2.png

Step 3: Erase device

Click button "EraseAll" to erase device.

Rockpi-4-erase-spi-nor-flash-3.png

Step 4: Reset device

Click button "ResetDevice" to reset device.

Rockpi-4-erase-spi-nor-flash-4.png

Erasing job is done.

Erase images on SPI flash on Linux/macOS PC

To erase images on SPI device, it's the same as writing the image to SPI flash, just the image we write is empty.

Firstly, follow Step 1 and Step 2: Boot the board to maskrom mode, Case 2: Update SPI flash with bootloader inside above to boot ROCK (Pi) 4 to maskrom mode.

Secondly, on your Linux PC, create zero.img.

   dd if=/dev/zero of=./zero.img bs=1M count=4

Thirdly, flash zero.img to SPI device.

   rkdeveloptool db rk3399_loader_spinor_v1.15.114.bin
   rkdeveloptool wl 0 zero.img
   rkdeveloptool rd    # will output: Reset Device OK.

Finally, on your Linux PC, lsusb command show show the following usb devices

   Bus 003 Device 005: ID 2207:330c

It means the SPI image is erased successfully.

Erase images on SPI flash on ROCK (Pi) 4

If you could boot into Linux and you have /dev/mtd* device available, you can use the following to erase the SPI flash.

  • For ROCK (Pi) 4A
   sudo /usr/local/sbin/rockpi4a_erase_spi_flash.sh #related package: rockpi4a-rk-u-boot-latest
  • For ROCK (Pi) 4B
   sudo /usr/local/sbin/rockpi4b_erase_spi_flash.sh #related package: rockpi4b-rk-u-boot-latest
  • For ROCK (Pi) 4C
   sudo /usr/local/sbin/rockpi4c_erase_spi_flash.sh #related package: rockpi4c-rk-u-boot-latest

Troubleshooting