UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Adventurer
Adventurer
10,208 Views
Registered: ‎01-10-2014

Using QSPI Flash like EEPROM under Linux on Zedboard

Jump to solution

Hello everyone!

 

Here's the question.

I have Linux booted on my Zynq PS. It has a connection to Quad SPI Flash. I'd like to use it like it is a EEPROM. I just want to make a read/write C sample.

 

I have already looked at the spi_spl_load.c file in u-boot-xlnx directory and tried to compile and launch it under Linux. It does not compile. If I understand it right I cannot launch a program for u-boot under full Linux and that is the problem.

 

I've checked /linux/drivers/spi in Xilinx kernel module and I found spi-zynq-qspi.c driver. So if I understand it right this is the one I have to use. Am I right? And if I am, does anybody have an example of using this driver in Linux application?

0 Kudos
1 Solution

Accepted Solutions
Scholar rfs613
Scholar
16,134 Views
Registered: ‎05-28-2013

Re: Using QSPI Flash like EEPROM under Linux on Zedboard

Jump to solution
Right, so your flash device isn't being picked up. I don't have a zedboard myself, but looking at https://github.com/Xilinx/linux-xlnx/blob/master/arch/arm/boot/dts/zynq-zed.dts suggests that the flash device is n25q128 rather than m25p80.

I also notice that the 14.4 release is the first to support zedboard, and it mentions QSPI is functional. http://www.wiki.xilinx.com/Zynq+Release+14.4
0 Kudos
6 Replies
Adventurer
Adventurer
10,206 Views
Registered: ‎01-10-2014

Re: Using QSPI Flash like EEPROM under Linux on Zedboard

Jump to solution
I have also looked here:
http://www.wiki.xilinx.com/Zynq+QSPI+Driver
But I have no partitions on my SPI Flash. I'm using SD card as HDD.
I just want to write and read several bytes.
0 Kudos
Scholar rfs613
Scholar
10,192 Views
Registered: ‎05-28-2013

Re: Using QSPI Flash like EEPROM under Linux on Zedboard

Jump to solution
You can't really treat flash like an EEPROM. The reason is technological: flash memory is organized into larger blocks (often 64kB or 128kB) and you can only erase the entire block at a time.

So to program an arbitrary byte would require:
- read whole block into RAM
- erase the block (takes a long time)
- write modified block from RAM back to device
This is not practical for a number of reasons: erase operating is slow, and flash devices have a limited number of erase cycles (much lower than EEPROM).

That is why in general, you would use something more sophisticated to manage your flash. You want to avoid the need to constantly erase. New data is appended in a free area, while the old data is marked as "old". This is repeated until all space has been used, then "old" blocks are erased.

Linux supports this kind of thing using the MTD subsystem. The stock Xilinx Zynq kernels have this enabled, check your kernel boot messages for "mtd". Typically a filesystem such as JFFS2 or UBIFS are used on top of the MTD interface. However, this is not required, you can treat it as block device if that suites your application.

The following article explains the same concepts, and also shows you how you can access flash through /dev/mtdX interface:
http://www.opensourceforu.com/2012/01/working-with-mtd-devices/
Adventurer
Adventurer
10,186 Views
Registered: ‎01-10-2014

Re: Using QSPI Flash like EEPROM under Linux on Zedboard

Jump to solution

Gee, thanks! That's the explanation I needed!

I just wanted to try out working with the SPI bus. And QSPI is the only onboard SPI device for Zedboard if I understand it right.

So QSPI flash is not a suitable device to make sample SPI reads/writes. It is better to use a real SPI EEPROM,

 

But I see something strange after doing cat /proc/mtd. I see this:

dev:    size   erasesize  name

And no devices listed.

fdisk -l also gives nothing. It is just an empty string.

I do not have mtd mentioned in my boot log. But I have a qspi entry in my device tree and it is also enabled in hardware.

So, if I understand it right, Linux does not see the QSPI flash. What can be wrong?

Here is the dts entry:

 

qspi0: qspi@e000d000 {
#address-cells = <1>;
#size-cells = <0>;
bus-num = <0>;
compatible = "xlnx,zynq-qspi-1.00.a", "xlnx,ps7-qspi-1.00.a";
interrupt-parent = <&gic>;
interrupts = <0 19 4>;
clock-names = "ref_clk", "aper_clk";
clocks = <&clkc 10>, <&clkc 43>;
is-dual = <0>;
num-chip-select = <1>;
reg = <0xe000d000 0x1000>;
xlnx,fb-clk = <0x1>;
xlnx,qspi-clk-freq-hz = <0xbebc200>;
xlnx,qspi-mode = <0x0>;
primary_flash: ps7-qspi@0 {
#address-cells = <1>;
#size-cells = <1>;
compatible = "st,m25p80";
reg = <0x0>;
spi-max-frequency = <50000000>;
partition@0x00000000 {
label = "boot";
reg = <0x00000000 0x00500000>;
};
partition@0x00500000 {
label = "bootenv";
reg = <0x00500000 0x00020000>;
};
partition@0x00520000 {
label = "config";
reg = <0x00520000 0x00020000>;
};
partition@0x00540000 {
label = "image";
reg = <0x00540000 0x00a80000>;
};
partition@0x00fc0000 {
label = "spare";
reg = <0x00fc0000 0x00000000>;
};
};
};

0 Kudos
Adventurer
Adventurer
10,177 Views
Registered: ‎01-10-2014

Re: Using QSPI Flash like EEPROM under Linux on Zedboard

Jump to solution

And I have also no mtd entries in /dev/.
mtdinfo says:
Count of MTD devices: 0

What can be wrong?

Thank you in advance!

0 Kudos
Scholar rfs613
Scholar
16,135 Views
Registered: ‎05-28-2013

Re: Using QSPI Flash like EEPROM under Linux on Zedboard

Jump to solution
Right, so your flash device isn't being picked up. I don't have a zedboard myself, but looking at https://github.com/Xilinx/linux-xlnx/blob/master/arch/arm/boot/dts/zynq-zed.dts suggests that the flash device is n25q128 rather than m25p80.

I also notice that the 14.4 release is the first to support zedboard, and it mentions QSPI is functional. http://www.wiki.xilinx.com/Zynq+Release+14.4
0 Kudos
Adventurer
Adventurer
10,148 Views
Registered: ‎01-10-2014

Re: Using QSPI Flash like EEPROM under Linux on Zedboard

Jump to solution

Thank you!

Well, I've copied the qspi and qspi_linear entries from the device-tree following the link to my own one and now it's o'k and my QSPI Flash is visible in Linux.

It is some kind of strange because I've got a device-tree from the same source. But maybe it is an old version or something.

0 Kudos