Jump to content
  • 0

How to use the SPI flash on OPi Zero v1.4?


rocketpenguin
 Share

Question

My Orange Pi Zero (rev 1.4) has a SPI flash module soldered to the underside. I can see the devices /dev/spidev0.0 and /dev/spidev1.0, and I can write to them and read from them (with dd), but the data I read from them is always just null bytes. Obviously then I can't create a filesystem on them.

 

Is it possible to create a small filesystem on the SPI flash to add files? If not, how is it possible to store data on the SPI flash?

 

I'm running Armbian 5.30 with kernel 3.4.113-sun8i. 

Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 0

How do you use "dd" for that ?

You can not use "dd" directly with /dev/spidevX-X, since it doesn't handle SPIFlash commands ...

Either you use "flashrom" utility to write whole image or use python pyspiflash library and manage sector/page erase/read/write yourself.

Don't expect been able to use it as filesystem, first because MTD partition kernel driver is probably not in Legacy builds, and second because those SPIFlash are pretty small.

Those SPIFlash are ususally present to place U-Boot bootloader to allow booting from other devices such USB Storage or Network share.

 

Link to comment
Share on other sites

Donate and support the project!

  • 0
20 minutes ago, martinayotte said:

How do you use "dd" for that ?

You can not use "dd" directly with /dev/spidevX-X, since it doesn't handle SPIFlash commands ...

 

dd could "write" to it without error, but upon reading, there were only null bytes.

 

anyway, seems like it's not really worth bothering with for my purposes (storing small amounts of configuration data), but thanks for the input.

Link to comment
Share on other sites

  • 0

I think you misunderstood how SPIFlashes are working. Even if you write into /dev/spidevX-X, it doesn't write into SPIFlash.

It is simply sending the stream of data over the SPI bus, but the device, SPIFlash, doesn't understand that stream since it is not containing the proper command, since the stream is purely garbage.

For example, to write a sector in SPIFlash, it is expecting to receive the write-enable command 0x06, then block-erase 0x20 followed by block number, then byte-page-program 0x02 along with address, and the 256 data bytes.

 

Link to comment
Share on other sites

  • 0

As I said above, pyspiflash is a good library for that. Plain "C" could achieve that too, but you will need to find library to ease development.

The protocol mentioned is only related to SPIFlashes. SPI itself doesn't have any protocol other than describing how serialization is done.

The protocols are defined by the slave devices, for example, a SPI SDCard, or a SPI LCD Display have there own different protocols, although they can be attached on the same SPI bus.

 

Link to comment
Share on other sites

  • 0

Can you tell me how you got the point of having /dev/spidevX.Y?   With a ]ARMBIAN 5.37 user-built Debian GNU/Linux 9[ I see things on /boot/dtb/overlay/README.* that suggests that I ought to be able the NOR by adding:

spi-jedec-nor to overlays in armbianEnv.txt, and I see uboot loading that dtbo file at boot.  There is a chip on the bottom of the board (which is from spring 2017).

 

https://linux-sunxi.org/Xunlong_Orange_Pi_Zero says that I need to insert some DTB and gives it, but I was sure that it was already available in the overlays.   I got something to give me a spi0.1 in dmesg, but no /dev or mtd entries.

https://linux-sunxi.org/Bootable_SPI_flash gives far more details about the state, but not details as to how to do the DTB work.

I'm pretty sure that Armbian has the right drivers built-in, but I'm really unclear how to enable them.  (Even as a kernel guy, DTB is still a bit of black magic to me)

 

 

Link to comment
Share on other sites

  • 0

Am I right that you wanna flash U-Boot to the SPI? 

Maybe not a propper but a *worked for me* way is to do it with a legacy image. Following this one:

Cause to my knowledge, (and to be honest - I'm not involved in development) newer builds of armbian on OPi0 use both mainline U-Boot. Following this (with legacy Image on SD-Card) and boot from a USB stick after its with mainline Armbian worked fine. But random IO performance of a USB memory stick is a nightmare (maybe Cause it's a cheap one). 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...