Difference between revisions of "Pinebook Pro SPI"

From PINE64
Jump to navigation Jump to search
(fixes)
Line 3: Line 3:
Boot data can be written to the SPI via two methods: either from within PBP or from a second machine connected to the PBP by USB.
Boot data can be written to the SPI via two methods: either from within PBP or from a second machine connected to the PBP by USB.


= Writing to SPI from within PBP =
== Writing to SPI from within PBP ==


[https://forum.pine64.org/member.php?action=profile&uid=15527 Forum user pcm720] showed an example of writing to the SPI from within PBP in [https://github.com/pcm720/u-boot-build-scripts/releases their self-published version of U-Boot] that offers boot functionality for NVMe drives. It involves use of <code>flash_erase</code> command (available in the mtd-utils package on Arch/Manjaro) and the <code>dd</code> command.
[https://forum.pine64.org/member.php?action=profile&uid=15527 Forum user pcm720] showed an example of writing to the SPI from within PBP in [https://github.com/pcm720/u-boot-build-scripts/releases their self-published version of U-Boot] that offers boot functionality for NVMe drives. It involves use of <code>flash_erase</code> command (available in the mtd-utils package on Arch/Manjaro) and the <code>dd</code> command.


= Writing to SPI from a second machine =
== Writing to SPI from a second machine ==


Writing to the SPI from a second machine is more complicated than the other method, but it is the only option when troubleshooting an SPI flash gone wrong. This method works by bringing the PBP into <code>maskrom mode</code> and issuing commands on the second machine that download the flash image onto the PBP.
Writing to the SPI from a second machine is more complicated than the other method, but it is the only option when troubleshooting an SPI flash gone wrong. This method works by bringing the PBP into <code>maskrom mode</code> and issuing commands on the second machine that download the flash image onto the PBP.
Line 15: Line 15:
There are two ways to reach <code>maskrom mode</code>, but the first tends to be less reliable.
There are two ways to reach <code>maskrom mode</code>, but the first tends to be less reliable.


== Maskrom mode (unreliable method) ==
=== Maskrom mode (unreliable method) ===


According to Rockchip documentation, these steps should work; unfortunately, many users have reported them to be unsuccessful. You may need to repeat these steps several times for them to work.
According to Rockchip documentation, these steps should work; unfortunately, many users have reported them to be unsuccessful. You may need to repeat these steps several times for them to work.
Line 30: Line 30:
The button works by shorting two pins in the SPI device. But in some cases it just does nothing. Fortunately, the two pins can shorted by hand, as described in the next method.
The button works by shorting two pins in the SPI device. But in some cases it just does nothing. Fortunately, the two pins can shorted by hand, as described in the next method.


== Maskrom mode (reliable method) ==
=== Maskrom mode (reliable method) ===


# Build and install <code>rkdeveloptool</code> (see [https://github.com/rockchip-linux/rkdeveloptool project repository] for instructions)
# Build and install <code>rkdeveloptool</code> (see [https://github.com/rockchip-linux/rkdeveloptool project repository] for instructions)
Line 47: Line 47:
# Check if the PBP connected by running <code>rkdeveloptool ld</code>. If successful, the output should be like: <code>DevNo=1 Vid=0x2207,Pid=0x330c,LocationID=1401 Maskrom</code>
# Check if the PBP connected by running <code>rkdeveloptool ld</code>. If successful, the output should be like: <code>DevNo=1 Vid=0x2207,Pid=0x330c,LocationID=1401 Maskrom</code>


== After entering maskrom mode ==
=== After entering maskrom mode ===


Now that the PBP is in <code>maskrom mode</code>, you can use <code>rkdeveloptool</code> to write data to the SPI. To do so you'll need the binary file you'll be writing to SPI, which will be referred to as <code>SPI_new.bin</code>, and a helper file named [https://dl.radxa.com/rockpi4/images/loader/spi/rk3399_loader_spinor_v1.15.114.bin rk3399_loader_spinor_v1.15.114.bin].
Now that the PBP is in <code>maskrom mode</code>, you can use <code>rkdeveloptool</code> to write data to the SPI. To do so you'll need the binary file you'll be writing to SPI, which will be referred to as <code>SPI_new.bin</code>, and a helper file named [https://dl.radxa.com/rockpi4/images/loader/spi/rk3399_loader_spinor_v1.15.114.bin rk3399_loader_spinor_v1.15.114.bin].
Line 56: Line 56:
# Run <code>rkdeveloptool rd</code> to reboot your Pinebook Pro.
# Run <code>rkdeveloptool rd</code> to reboot your Pinebook Pro.


== Zeroing out the SPI ==
=== Zeroing out the SPI ===


In case, you wrote something bad to your SPI, it's helpful to wipe away that data with zeros. To do that, you follow the same steps above to enter <code>maskrom mode</code> and then write a binary file that consists of all zeros.
In case, you wrote something bad to your SPI, it's helpful to wipe away that data with zeros. To do that, you follow the same steps above to enter <code>maskrom mode</code> and then write a binary file that consists of all zeros.

Revision as of 21:26, 2 April 2023

The Pinebook Pro comes equipped with two non-volatile storage components, the eMMC and the SPI. The capacity of the SPI is 128Mbit (16MiB) and it may be used in the boot process.

Boot data can be written to the SPI via two methods: either from within PBP or from a second machine connected to the PBP by USB.

Writing to SPI from within PBP

Forum user pcm720 showed an example of writing to the SPI from within PBP in their self-published version of U-Boot that offers boot functionality for NVMe drives. It involves use of flash_erase command (available in the mtd-utils package on Arch/Manjaro) and the dd command.

Writing to SPI from a second machine

Writing to the SPI from a second machine is more complicated than the other method, but it is the only option when troubleshooting an SPI flash gone wrong. This method works by bringing the PBP into maskrom mode and issuing commands on the second machine that download the flash image onto the PBP.

Upon entering maskrom mode, the power LED on your PBP won't light up and neither will the display. Instead, your second machine, the one connected to your PBP via USB, will indicate maskrom mode by logging to journalctl.

There are two ways to reach maskrom mode, but the first tends to be less reliable.

Maskrom mode (unreliable method)

According to Rockchip documentation, these steps should work; unfortunately, many users have reported them to be unsuccessful. You may need to repeat these steps several times for them to work.

  1. Press and hold recovery button.
  2. Short press reset.
  3. Release recovery button after about 3 seconds.

Why this procedure is unreliable is not clear, but there are two suspicions:

  • The button is not working correctly or is just prone to failures.
  • The problem occurs only when the SPI was previously flashed.

The button works by shorting two pins in the SPI device. But in some cases it just does nothing. Fortunately, the two pins can shorted by hand, as described in the next method.

Maskrom mode (reliable method)

  1. Build and install rkdeveloptool (see project repository for instructions)
  2. Verify successful installation. Running rkdeveloptool --version should output: rkdeveloptool ver 1.3
  3. Run journalctl -f and keep it running. Once the Pinebook Pro is connected and maskrom mode is reached it will produce additional output.
  4. Power off the Pinebook Pro.
  5. Unscrew the bottom cover.
  6. Remove the metal shield surrounding the main CPU. The shield is held in place by a tape and micro clamps on the board. The clamps can be released with a pry tool and some force. This forum post with photos shows how it can be done.
  7. Disconnect all (!!!) boot devices (emmc, sdcard, usb).
  8. Locate SPI flash (component number 29 on this photo of the Pinebook Pro internals).
  9. Connect your PBP with USB-C - USB-A cable to second machine (PBP on USB-C side)
  10. Short pins CLK and VSS (see chip diagram to the right for the names of pins). This can be done with a pair of tweezers when short on tools.
    Spi.png
  11. Power on the Pinebook Pro.
  12. Press the reset button (component number 28).
  13. Check if there is new output from journalctl program.
  14. Check if the PBP connected by running rkdeveloptool ld. If successful, the output should be like: DevNo=1 Vid=0x2207,Pid=0x330c,LocationID=1401 Maskrom

After entering maskrom mode

Now that the PBP is in maskrom mode, you can use rkdeveloptool to write data to the SPI. To do so you'll need the binary file you'll be writing to SPI, which will be referred to as SPI_new.bin, and a helper file named rk3399_loader_spinor_v1.15.114.bin.

  1. Flash the flash helper db file: rkdeveloptool db rk3399_loader_spinor_v1.15.114.bin. If successful, the output should read Downloading bootloader succeeded.
  2. Flash the new SPI binary: rkdeveloptool wl 0 SPI_new.bin. If successful, the output should read: Write LBA from file (100%).
  3. Test the installation: rkdeveloptool td. If successful, output should read Reset Device OK.
  4. Run rkdeveloptool rd to reboot your Pinebook Pro.

Zeroing out the SPI

In case, you wrote something bad to your SPI, it's helpful to wipe away that data with zeros. To do that, you follow the same steps above to enter maskrom mode and then write a binary file that consists of all zeros.

  1. Create the binary file dd if=/dev/zero of=zero.bin bs=1M count=16
  2. Flash the flash helper db file: rkdeveloptool db rk3399_loader_spinor_v1.15.114.bin. If successful, the output should read Downloading bootloader succeeded.
  3. Flash the new SPI binary: rkdeveloptool wl 0 zero.bin. If successful, the output should read: Write LBA from file (100%).
  4. Test the installation: rkdeveloptool td. If successful, output should read Reset Device OK.
  5. Run rkdeveloptool rd to reboot your Pinebook Pro.