Read/Write to SPI NAND using RPI

Viewed 133 times

I have an SPI NAND flash that I want to read/write the data to it using Raspberry Pi but since flashrom doesn’t support SPI NAND and I couldn’t find any tools that can do SPI NAND reading raw from the SPI interface either.

Apparently the Linux kernel can read SPI NAND using mtd driver but the jedec-nor-spi overlay only support SPI NOR flash and it won’t work with the SPI NAND.

Anyone knows how I can read/write this chip? Preferrably using a RPI but I also have a FT2232H and a CH341, the chip model number is MX35LF1GE4AB and link to the datasheet: https://www.macronix.com/Lists/Datasheet/Attachments/7666/MX35LF2GE4AB,%203V,%202Gb,%20v1.7.pdf

  • Ah let me see. I once played with I2C EEPROM and found it easy to read write using python. I googled and found I2C EEPROM and SPI FLASH read write commands are equally tedious but not difficult. I would suggest to use cheapy US$1 W25Q64 8MByte SPI FLASH module to do experiments. – tlfong01 Dec 28 ’19 at 5:35   
  • 1
    (1) 3V, 1Gb/2G-bit Serial NAND Flash Memory MX35LFxGE4AB macronix.com/Lists/Datasheet/Attachments/7666/… (2) W25Q16DV 3V 16M-Bit Serial Flash Memory with Dual and Quad SPI winbond.com/resource-files/w25q16dv_revi_nov1714_web.pdf – tlfong01 Dec 28 ’19 at 5:35   
  • (3) CJMCU-2516 2516 memory module, W25Q16BVSIG serial SPI flash memory, 16M-BIT – US$1 de.aliexpress.com/item/… – tlfong01 Dec 28 ’19 at 5:36   
  • (4) W25Q64 64Mbit 8MByte flash memory module DataFlash SPI interface BV FV For arduino – US$1 de.aliexpress.com/item/… – tlfong01 Dec 28 ’19 at 5:36   
  • (5) W25Q64 Summary 1/2 imgur.com/gallery/9jg0nS8. – tlfong01 Dec 28 ’19 at 5:41   
  • 1
    I don’t have the expertise to rolling my own code from scratch, also I don’t really understand how NAND flash works so I do prefer a pre-made solution, but thanks! – SandPox Dec 28 ’19 at 8:03
  • 1
    @SandPox, Did you download and compile the correct driver ? Read the README.txt in the ZIP archive – Ephemeral Dec 28 ’19 at 10:30
  • 1
    I have seen that code but I don’t think it will work out of the box with SPI dev though… my C skills is not enough to fully understand and modify that code – SandPox Dec 28 ’19 at 13:28
  • 2
    @SandPox, Ah, #Ephemeral’s driver is actually a tutorial and 8051 ANSI C sample for newbie developer to port to any hardware such as Rpi. The only prerequisite is Rpi Python SpiDev or equivalent Rpi C/C++ SPI basic knowledge. See my quick and dirty reading notes: penzu.com/p/f5a3d9e2. – tlfong01 Dec 28 ’19 at 14:50   
  • 1
    This is Macronix, they named it “Low Level Driver” in Technical Documents parts. – Ephemeral Dec 29 ’19 at 4:19
  • 2
    @Ephemeral, Yes, Macronix’ readme and sample codes are newbie friendly. This morning I ordered from Tao this RMB9 SPI NAND flash toy which will hopefully arrive tomorrow evening. First thing first is to write the two basic python testing functions (1) Read device ID, (2) write/read memory. The is an update (Version 0.2)) of my penzu learnng notes: penzu.com/p/418b74e3. – tlfong01 Dec 29 ’19 at 8:08    
  • 1
    Don’t know if this will helps but there’s someone who made a pull request to flashrom for adding support for SPI NAND, I’ve tried it, it kinda works but it detected wrong NAND size thus only managed to extract 64kb out of it: github.com/flashrom/flashrom/pull/62 – SandPox Dec 29 ’19 at 11:53
  • Ah, let me see. One guy there says this ” …Doesn’t really work… only outputting a 65.5kb file from a 1Gbit chip, …”. So it appears there is a stupid design bug somewhere. I skim what they are doing but found their method a bit complicated. Of course if their NAND driver works then all problem solved. Perhaps I might look back if my python driver doesn’t work. – tlfong01 Dec 29 ’19 at 13:04   
  • And actually I dont’ know nothing about the difference between NAND and NOR flash. I only remember there are things like DRAM and SRAM, and not sure if my SSD HD is SRAM or not. EitherI know the I2C EEPROM is NAND or NOR. I once thought that anything NOR can do NAND can do better. So before my bad Arduino friends discover that I am so ignorant, I need to secretly read something, to lose less face than I ought to: embedded.com/flash-101-nand-flash-vs-nor-flash. After reading the article I now know why they are using ECC, and block and page read/write etc. – tlfong01 Dec 29 ’19 at 13:29   
  • Actually there are more things in the datasheet that I don’t understand, eg, blocak to page address mapping etc. I think I need to read the datasheet couple of more times. – tlfong01 Dec 29 ’19 at 13:35   
  • My toy arived this evening. Now I am thinking of how to DIY a breakout: penzu: penzu.com/p/d563af03 – tlfong01 Dec 30 ’19 at 13:42   

Categories: Uncategorized

8 replies »

  1. Ah, I stalled the project, because I got distracted by other more interesting things, including I2C EEPROM. Perhaps you can ask me again in stackexchange.


    • By the way, my username in the above stack exchange is @tlfong01. If you visit the above post and ask me any question with the useername @tlfong01, the I will be notified and I will try to help. If you do not start with your question with @tlfong01, then I might miss you comments.


  2. I tried to ask but it was deleted. I took a look at the github code that you posted a few months ago but I found out why it was always returning 64k. It was hardcoded for toshiba, write function was never implemented.


    • If you indicate your project details, like my penzu: Macronix MX35 SPI Flash learning notes V0.3 Mon. 12/30/2019
      https://penzu.com/public/d563af03, then I know if I can help. You see, I posted the penzu diary, but no one seems interested to comment anything. So I thought no one would like to share their experience, so I gave up and switched to other things which more users would share knowledge together.


    • There seems to be some more misunderstanding: (1) I did NOT post anything to the GitHub. (2) I must confess that I am just a hobbyist programmer, I have some experience as a user in I2C EEPROM, but ZERO experience in SPI EEPROM, and that is why I thought I would get some samples and learn something. In other words, I knew nothing about the toshiba implementation of their memory chips. Looking back, I think it is a mistake to ask the question in the Rpi forum, instead of in the EE forum. My apologies for any confusion caused.


  3. Ah, there seems to be some misunderstanding. The original post is the following: https://raspberrypi.stackexchange.com/questions/106661/read-write-to-spi-nand-using-rpi. I found the subject interesting. So I bought a couple of chips hoping to try it. However, the original poster (OP) seems not interested in my suggestion and did not comment on it. I originally thought that the the OP would give me some advice, so I was disappointed and stalled by project.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: