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: 
Visitor dambedei
Visitor
1,329 Views
Registered: ‎05-15-2018

Update BOOT.bin on QSPI flash from linux

Hi,

I'm using a Zynq XC7Z010. I'm using petalinux 2018.1 to build all components (BOOT.bin, dtb, kernel, rootfs).

BOOT.bin is flashed to QSPI using SDK 2018.1. However, I'd like to be able to flash/update BOOT.bin on the QSPI without a connection to a PC.

 

Is it possible to update BOOT.bin in the QSPI flash from linux running on the Zynq?

 

--

Best regards

0 Kudos
10 Replies
Scholar rfs613
Scholar
1,300 Views
Registered: ‎05-28-2013

Re: Update BOOT.bin on QSPI flash from linux

Yes, this is possible to do. You'll need to transfer the BOOT.bin to the Zynq (you can do this many ways, for example the scp command, or ftp/wget, or using the SD card). Once it is on the Zynq, you can use flashcp command to copy it into the QSPI flash. The syntax is:

flashcp -v BOOT.bin /dev/mtd0    # or /dev/mtd1, mtd2, ...

You do need to be careful to specify the correct /dev/mtdN device. Since BOOT.bin goes at the beginning of the QSPI flash, it is most likely /dev/mtd0. To find out for sure, use the command cat /proc/mtd to display the available partitions.

0 Kudos
Visitor dambedei
Visitor
1,287 Views
Registered: ‎05-15-2018

Re: Update BOOT.bin on QSPI flash from linux

Thanks a lot for your answer, I'll give it a try.

 

From my understanding, ROM-Code is loading FSBL from BOOT.bin.

My follow-up question is:

Is it possible to create another partition on the QSPI flash and decide which partition shall be used to load FSBL/BOOT.bin?

Doesn't have to be another partition, any other solution would work as well for me.

 

My use-case is a fail-safe update of BOOT.bin. So in case something goes wrong while using flashcp, it's always possible to use previous BOOT.bin.

 

--

Best regards

0 Kudos
Scholar rfs613
Scholar
1,276 Views
Registered: ‎05-28-2013

Re: Update BOOT.bin on QSPI flash from linux

For your follow up question, have a look at section 6.3.10 "BootROM Header Search" in the UG585 Tech Ref manual. There is support for having multiple copies of FSBL/BOOT.bin.

0 Kudos
Visitor dambedei
Visitor
1,268 Views
Registered: ‎05-15-2018

Re: Update BOOT.bin on QSPI flash from linux

I tried your suggestion using flashcp to update BOOT.bin.

However, I get the following error:

# flashcp -v BOOT.bin /dev/mtd0
Erasing blocks: 664/664 (100%)
Writing data: 2653k/2653k (100%)
Verifying data: 10k/2653k (0%)File does not seem to match flash data. First mismatch at 0x00000000-0x00002800

After that, booting is no longer working. I need to flash BOOT.bin using SDK to get it working again.

 

These are my partitions:

# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00500000 00001000 "boot"
mtd1: 00020000 00001000 "bootenv"
mtd2: 00a80000 00001000 "kernel"
mtd3: 00060000 00001000 "spare"

Any ideas?

0 Kudos
Scholar rfs613
Scholar
1,258 Views
Registered: ‎05-28-2013

Re: Update BOOT.bin on QSPI flash from linux

There are a few possibilities:

- incorrect erase block size (is it really 4kB? that seems small, 64kB or 128kB is more typical for NOR flash). Check the data sheet of the flash device you're using.

- there might be smaller "boot blocks" at the beginning of the QSPI flash, that are not being handled correctly.

 

To diagnose, I would suggest erasing the using flash_erase or flash_eraseall commands. Then read it back using "hexdump -C /dev/mtd0".  If it has been erased successfully, then all bytes will be 0xFF. If you see anything else, the erase is not working properly, and it is likely related to the erase block size.

 

Once you know it is erasing properly, you can try flashcp again to write data. Usually, once erase is working, write will also work fine.

0 Kudos
Visitor dambedei
Visitor
1,237 Views
Registered: ‎05-15-2018

Re: Update BOOT.bin on QSPI flash from linux

I checked the datasheet and it seems that the 4kB erase block size is correct (see section 9.6.1)

https://www.mouser.de/datasheet/2/100/001-98282_S25FL127S_128_MBIT_16_MBYTE_3.0_V_SPI_FL-1299705.pdf

 

Also I tried your suggestion with hexdump and flash_erase.

Here is the output of hexdump with a correct / booting BOOT.bin (after flashing it using SDK):

# hexdump -C /dev/mtd0 -n 3000                                                                                                                                                                                                                                       
00000000  fe ff ff ea fe ff ff ea  fe ff ff ea fe ff ff ea  |................|
*
00000020  66 55 99 aa 58 4e 4c 58  00 00 00 00 00 00 01 01  |fU..XNLX........|
00000030  00 17 00 00 08 80 01 00  00 00 00 00 00 00 00 00  |................|
00000040  08 80 01 00 01 00 00 00  30 45 16 fc 00 00 00 00  |........0E......|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000090  00 00 00 00 00 00 00 00  c0 08 00 00 80 0c 00 00  |................|
000000a0  ff ff ff ff 00 00 00 00  ff ff ff ff 00 00 00 00  |................|
*
000007d0
root@k2l:~# hexdump -C /dev/mtd0 -n 3000                                                                                                                                                                                                                                        
00000000  fe ff ff ea fe ff ff ea  fe ff ff ea fe ff ff ea  |................|
*
00000020  66 55 99 aa 58 4e 4c 58  00 00 00 00 00 00 01 01  |fU..XNLX........|
00000030  00 17 00 00 08 80 01 00  00 00 00 00 00 00 00 00  |................|
00000040  08 80 01 00 01 00 00 00  30 45 16 fc 00 00 00 00  |........0E......|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000090  00 00 00 00 00 00 00 00  c0 08 00 00 80 0c 00 00  |................|
000000a0  ff ff ff ff 00 00 00 00  ff ff ff ff 00 00 00 00  |................|
*
000008a0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
000008c0  00 00 02 01 03 00 00 00  20 03 00 00 40 02 00 00  |........ ...@...|
000008d0  00 00 00 00 ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
000008e0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00000900  50 02 00 00 20 03 00 00  00 00 00 00 01 00 00 00  |P... ...........|
00000910  71 6e 79 7a 62 73 66 5f  6c 65 2e 6c 00 00 00 66  |qnyzbsf_le.l...f|
00000920  00 00 00 00 ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00000930  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
00000940  60 02 00 00 30 03 00 00  00 00 00 00 01 00 00 00  |`...0...........|
00000950  74 73 79 73 62 2e 6d 65  00 00 74 69 00 00 00 00  |tsysb.me..ti....|
00000960  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00000980  00 00 00 00 40 03 00 00  00 00 00 00 01 00 00 00  |....@...........|
00000990  6f 62 2d 75 65 2e 74 6f  00 00 66 6c 00 00 00 00  |ob-ue.to..fl....|
000009a0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
*
00000bb0 ...

Then I use

# flash_erase /dev/mtd0 0 0

 

Only the first 10kByte are erased correctly:

# hexdump -C /dev/mtd0                                                                                                                                                                                                                                   
00000000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00010000  33 00 00 00 50 60 00 f8  ff 8f 0f ff 00 08 01 77  |3...P`.........w|                                                                                                                                                                                                  
00010010  33 00 00 00 58 60 00 f8  ff ff 01 00 01 01 00 00  |3...X`..........|                                                                                                                                                                                                  
00010020  33 00 00 00 5c 60 00 f8  ff ff 00 00 03 50 00 00  |3...\`.......P..|                                                                                                                                                                                                  
00010030  33 00 00 00 60 60 00 f8  ff 17 00 00 3e 00 00 00  |3...``......>...|                                                                                                                                                                                                  
00010040  33 00 00 00 64 60 00 f8  e0 1f 02 00 00 00 02 00  |3...d`..........|                                                                                                                                                                                                  
00010050  33 00 00 00 68 60 00 f8  ff ff ff 03 41 41 28 00  |3...h`......AA(.|                                                                                                                                                                                                  
00010060  33 00 00 00 6c 60 00 f8  ff ff 00 00 10 16 00 00  |3...l`..........|                                                                                                                                                                                                  
00010070  33 00 00 00 a0 60 00 f8  ff ff ff 00 00 80 00 00  |3....`..........|                                                                                                                                                                                                  
00010080  33 00 00 00 a4 60 00 f8  ff ff ff ff 02 08 20 10  |3....`........ .|                                                                                                                                                                                                  
00010090  33 00 00 00 a8 60 00 f8  ff ff ff 0f 73 cb 90 06  |3....`......s...|
...

After trying to copy BOOT.bin using flashcp, the output of hexdump looks like this:

# hexdump -C /dev/mtd0 -n 5000                                                                                                                                                                                                                                        
00000000  ff ff ff ff 00 00 00 00  ff ff ff ff 00 00 00 00  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000100  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000200  ff ff ff ff 00 00 00 00  ff ff ff ff 00 00 00 00  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000300  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000400  ff ff ff ff 00 00 00 00  ff ff ff ff 00 00 00 00  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000500  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000600  ff ff ff ff 00 00 00 00  ff ff ff ff 00 00 00 00  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000700  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000800  50 02 00 00 20 03 00 00  00 00 00 00 01 00 00 00  |P... ...........|                                                                                                                                                                                                  
00000810  71 6e 79 7a 62 73 66 5f  6c 65 2e 6c 00 00 00 66  |qnyzbsf_le.l...f|                                                                                                                                                                                                  
00000820  00 00 00 00 ff ff ff ff  ff ff ff ff ff ff ff ff  |................|                                                                                                                                                                                                  
00000830  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|                                                                                                                                                                                                  
00000840  60 02 00 00 30 03 00 00  00 00 00 00 01 00 00 00  |`...0...........|                                                                                                                                                                                                  
00000850  74 73 79 73 62 2e 6d 65  00 00 74 69 00 00 00 00  |tsysb.me..ti....|                                                                                                                                                                                                  
00000860  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000880  00 00 00 00 40 03 00 00  00 00 00 00 01 00 00 00  |....@...........|                                                                                                                                                                                                  
00000890  6f 62 2d 75 65 2e 74 6f  00 00 66 6c 00 00 00 00  |ob-ue.to..fl....|                                                                                                                                                                                                  
000008a0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000c00  5c 04 02 00 5c 04 02 00  5c 04 02 00 00 00 40 00  |\...\...\.....@.|                                                                                                                                                                                                  
00000c10  00 00 40 00 c0 58 08 00  10 00 00 00 01 00 00 00  |..@..X..........|                                                                                                                                                                                                  
00000c20  00 00 00 00 60 02 00 00  00 00 00 00 00 00 00 00  |....`...........|                                                                                                                                                                                                  
00000c30  00 00 00 00 00 00 00 00  00 00 00 00 ba 97 71 ff  |..............q.|                                                                                                                                                                                                  
00000c40  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000c70  00 00 00 00 00 00 00 00  00 00 00 00 ff ff ff ff  |................|                                                                                                                                                                                                  
00000c80  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00001380

Up to 00000800 to content looks different, after that it matches.

0 Kudos
Highlighted
Scholar rfs613
Scholar
1,225 Views
Registered: ‎05-28-2013

Re: Update BOOT.bin on QSPI flash from linux

Couple of comments...

 


@@dambedei wrote:

I checked the datasheet and it seems that the 4kB erase block size is correct (see section 9.6.1)

https://www.mouser.de/datasheet/2/100/001-98282_S25FL127S_128_MBIT_16_MBYTE_3.0_V_SPI_FL-1299705.pdf


Thanks for that link. In section 7.2 it shows that the device has (mostly) 64kB sector size. It also has a few smaller 4kB sectors,  either at the beginning or at the end (this is fairly typical as well). And it can also be operated in a 256kB sector mode. Yikes!

 


Then I use
# flash_erase /dev/mtd0 0 0

 

Only the first 10kByte are erased correctly:

# hexdump -C /dev/mtd0                                                                                                                                                                                                                                   
00000000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00010000  33 00 00 00 50 60 00 f8  ff 8f 0f ff 00 08 01 77  |3...P`.........w|                                                                                                                                                                                                  
00010010  33 00 00 00 58 60 00 f8  ff ff 01 00 01 01 00 00  |3...X`..........|                                                                                                                                                                                                  
00010020  33 00 00 00 5c 60 00 f8  ff ff 00 00 03 50 00 00  |3...\`.......P..|                                                                                                                                                                                                  
00010030  33 00 00 00 60 60 00 f8  ff 17 00 00 3e 00 00 00  |3...``......>...|                                                                                                                                                                                                  
00010040  33 00 00 00 64 60 00 f8  e0 1f 02 00 00 00 02 00  |3...d`..........|                                                                                                                                                                                                  
00010050  33 00 00 00 68 60 00 f8  ff ff ff 03 41 41 28 00  |3...h`......AA(.|                                                                                                                                                                                                  
00010060  33 00 00 00 6c 60 00 f8  ff ff 00 00 10 16 00 00  |3...l`..........|                                                                                                                                                                                                  
00010070  33 00 00 00 a0 60 00 f8  ff ff ff 00 00 80 00 00  |3....`..........|                                                                                                                                                                                                  
00010080  33 00 00 00 a4 60 00 f8  ff ff ff ff 02 08 20 10  |3....`........ .|                                                                                                                                                                                                  
00010090  33 00 00 00 a8 60 00 f8  ff ff ff 0f 73 cb 90 06  |3....`......s...|
...

Two things here:

 

1) The flash_erase might not be able to automatically get the size of the partition. So while a start address of 0 is fine, I would suggest trying an non-zero value for size. At least for now.

 

2) The output from hexdump is in hex, including the first column. So it is not the first 10kB that has been erased, but rather the first 0x00010000 (which is 64kB in decimal).

 

So, I think what happened here is that your device has erased one sector, and sectors are 64kB. Perhaps your device has the smaller 4kB sectors at the top rather than the bottom, so this could make sense (eg. Table 16 in section7.2 of datasheet).

 


After trying to copy BOOT.bin using flashcp, the output of hexdump looks like this:

# hexdump -C /dev/mtd0 -n 5000                                                                                                                                                                                                                                        
00000000  ff ff ff ff 00 00 00 00  ff ff ff ff 00 00 00 00  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000100  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000200  ff ff ff ff 00 00 00 00  ff ff ff ff 00 00 00 00  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000300  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000400  ff ff ff ff 00 00 00 00  ff ff ff ff 00 00 00 00  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000500  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000600  ff ff ff ff 00 00 00 00  ff ff ff ff 00 00 00 00  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000700  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000800  50 02 00 00 20 03 00 00  00 00 00 00 01 00 00 00  |P... ...........|                                                                                                                                                                                                  
00000810  71 6e 79 7a 62 73 66 5f  6c 65 2e 6c 00 00 00 66  |qnyzbsf_le.l...f|                                                                                                                                                                                                  
00000820  00 00 00 00 ff ff ff ff  ff ff ff ff ff ff ff ff  |................|                                                                                                                                                                                                  
00000830  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|                                                                                                                                                                                                  
00000840  60 02 00 00 30 03 00 00  00 00 00 00 01 00 00 00  |`...0...........|                                                                                                                                                                                                  
00000850  74 73 79 73 62 2e 6d 65  00 00 74 69 00 00 00 00  |tsysb.me..ti....|                                                                                                                                                                                                  
00000860  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000880  00 00 00 00 40 03 00 00  00 00 00 00 01 00 00 00  |....@...........|                                                                                                                                                                                                  
00000890  6f 62 2d 75 65 2e 74 6f  00 00 66 6c 00 00 00 00  |ob-ue.to..fl....|                                                                                                                                                                                                  
000008a0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000c00  5c 04 02 00 5c 04 02 00  5c 04 02 00 00 00 40 00  |\...\...\.....@.|                                                                                                                                                                                                  
00000c10  00 00 40 00 c0 58 08 00  10 00 00 00 01 00 00 00  |..@..X..........|                                                                                                                                                                                                  
00000c20  00 00 00 00 60 02 00 00  00 00 00 00 00 00 00 00  |....`...........|                                                                                                                                                                                                  
00000c30  00 00 00 00 00 00 00 00  00 00 00 00 ba 97 71 ff  |..............q.|                                                                                                                                                                                                  
00000c40  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00000c70  00 00 00 00 00 00 00 00  00 00 00 00 ff ff ff ff  |................|                                                                                                                                                                                                  
00000c80  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|                                                                                                                                                                                                  
*                                                                                                                                                                                                                                                                               
00001380

Up to 00000800 to content looks different, after that it matches.


I can't entirely explain what we are seeing here. Since the first 64kB got erased, we should be able to write data to it and have it match.

 

For the part from 00000000 to 00000800, the data bears no resemblance to the "good" version (should start with fe ff ff ea ff ...) I'm not sure what is happening here, or where this is coming from.

 

The data at 00000800 does match, however it appears to be shifted - in the "good" data it appears starting at 00000900 rather than 800.

 

Perhaps do a hexdump on the file you're using with flashcp, to make sure the source is good?

0 Kudos
Visitor dambedei
Visitor
1,109 Views
Registered: ‎05-15-2018

Re: Update BOOT.bin on QSPI flash from linux

Because lots of forums (including this post) and the official Xilinx Wiki (https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18842364/Zc702+Linux#Zc702Linux-QSPIFlashMemory) mention this way should work I tried several kernel versions of the different petalinux versions:

Here is the result:

petalinux 2017.3 (kernel 4.9): works

2018.1, 2018.2, 2018.3 (kernel 4.14): doesn't work

 

So it must be a driver problem in my opinion.

0 Kudos
Moderator
Moderator
1,090 Views
Registered: ‎05-10-2017

Re: Update BOOT.bin on QSPI flash from linux

This has been fixed in the 2018.3 release. See commit here

https://github.com/Xilinx/linux-xlnx/commit/c2c4333422281f48018c68b20fba5f9e984df4cd#diff-4df1cc2eea43805aed92602fb38a0ab7

 

-------------------------------------------------------------------------
Don’t forget to reply, kudo, and accept as solution.
-------------------------------------------------------------------------
0 Kudos
Visitor dambedei
Visitor
1,075 Views
Registered: ‎05-15-2018

Re: Update BOOT.bin on QSPI flash from linux

I tried three different approaches to your comment:

1) I used the kernel used by petalinux 2018.3 in my petalinux 2018.1 project. To do so, I replaced the content in components/yocto/source/arm/layers/meta-xilinx/meta-xilinx-bsp/recipes-kernel/linux/linux-xlnx_2018.1.bb with the content of  meta-xilinx/meta-xilinx-bsp/recipes-kernel/linux/linux-xlnx_2018.3.bb

The I rebuilt the project. Using

uname -a

confirmed that I'm using kernel 4.14.0-xilinx-v2018.3

 

However, the flashcp command failed.

 

2) I create a patch out of the commit you mentioned using

git format-patch -1 c2c433342228

and applied the patch to the petalinux 2018.1 kernel as described here: https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18842475/PetaLinux+Yocto+Tips#PetaLinuxYoctoTips-PatchingtheLinuxKernelofaPetaLinuxProject

 

However, the flashcp command still doesn't work.

 

3) I created backport patches to the kernel used with petalinux 2017.4 (4.9.0) for

  • drivers/mtd/spi-nor/spi-nor.c
  • include/linux/mtd/spi-nor.h
  • drivers/mtd/devices/m25p80.c

and applied the patches to the petalinux 2018.1 kernel

 

This solution worked for me.

0 Kudos