002-33855 Support For SEMPER Quad SPI Flash in Linux From Xilinx
002-33855 Support For SEMPER Quad SPI Flash in Linux From Xilinx
Intended audience
This application note is intended for users who use Linux with UltraScale+ MPSoC devices from Xilinx and
Infineon SEMPER™ NOR flash memory.
Table of contents
Table of contents ............................................................................................................................ 1
1 Introduction .......................................................................................................................... 2
2 Set up the environment .......................................................................................................... 3
2.1 Mount SEMPER™ NOR flash memory on UltraScale+ MPSoC board from Xilinx ................................... 3
2.2 Set up toolchains from Xilinx .................................................................................................................. 5
2.3 Download the Linux source code ........................................................................................................... 5
3 Apply the Linux patch file ........................................................................................................ 7
4 Merge the Linux patch file manually ......................................................................................... 8
4.1 Modify drivers/mtd/spi-nor/core.c........................................................................................................... 8
4.1.1 Set 4-byte addressing mode .............................................................................................................. 8
4.1.2 Modify the function to find the best erase type ................................................................................ 8
4.1.3 Modify the function to initialize erase command list ....................................................................... 8
4.1.4 Create Any Register Read/Write functions ........................................................................................ 8
4.1.5 Set QSPI mode using the volatile register ......................................................................................... 8
4.1.6 Fix and manage parameter sectors to erase ..................................................................................... 9
4.1.7 Modify the source code ...................................................................................................................... 9
4.2 Modify drivers/mtd/spi-nor/core.h ........................................................................................................ 15
4.3 Modify drivers/mtd/ spi-nor/sfdp.c ........................................................................................................ 15
4.3.1 Set the overlay bit when the region is overlaid ............................................................................... 15
4.3.2 Moify the initialization of the non-uniform erase map ................................................................... 16
4.3.3 Modify the source code .................................................................................................................... 16
4.4 Modify drivers/mtd/spi-nor/spansion.c ................................................................................................. 17
4.4.1 Add SPI NOR fixups structure and create fixup functions .............................................................. 18
4.4.2 Add SEMPER™ flash memory devices .............................................................................................. 18
4.4.3 Modify the source code .................................................................................................................... 18
4.5 Modify include/linux/mtd/spi-nor.h ....................................................................................................... 20
5 Conclusion ........................................................................................................................... 21
Revision history............................................................................................................................. 22
Application Note Please read the Important Notice and Warnings at the end of this document 002-33855 Rev.**
www.infineon.com page 1 of 23 2021-09-16
Support for SEMPER™ Quad SPI flash in Linux from Xilinx
Introduction
1 Introduction
Open source-based projects are frequently improved and expanded by several contributors. Linux is also
periodically changed by many contributors in this way. This changing project is managed based on tags by the
maintainer; platform designers or system designers download the project and perform porting work according
to their platform design.
Even though you can develop your own flash driver source code according to the SEMPER™ flash datasheet to
use Linux with SEMPER™ flash devices, it is easier to use a patch file for the project from the device
manufacturer while downloading the open source-based project.
Infineon also provides patch files for open source-based projects. However, open source-based projects are
frequently changed; this may make the patch file incompatible with your target platform. When this happens,
you have to break up the patch file and apply it manually one by one. This application note explains how to use
a Linux patch file from Infineon to enable SEMPER™ flash memory.
1
Only LQSPI provides a linear address space which XiP requires. However, based on the data provided in the spec sheet from Xilinx,
GQSPI can provide limited support for XiP when the configuration security unit (CSU) boot ROM uses the GQSPI controller for system
boot.
Application Note 3 of 23 002-33855 Rev.**
2021-09-16
Support for SEMPER™ Quad SPI flash in Linux from Xilinx
This application note shows how to use two Infineon SEMPER™ QSPI NOR flash memory devices by applying
dual CS# parallel mode. For this, the existing NOR flash memory devices of UltraScale+ MPSoC board from
Xilinx are removed and two SEMPER™ 1.8-V QSPI 1-Gbit (S25HS01GT) flash memory devices are attached as
follows. In Figure 2, a small socket is attached and the flash memory is installed for the subsequent flash
memory test.
This test uses two 1-Gbit devices, but 2-Gbit or 4-Gbit devices also can be used; the sf command will be
changed to support these devices.
Note: You don't need to download the entire Vivado or Vitis software from Xilinx to set up a build
environment for the Linux driver code; you can use the Xilinx SDK for that. Also, you do not need to
install the GUI tool because you will be using the command-line options. See the “Batch Mode
Installation Flow” section in the ug973-vivado-release-notes-install-license.pdf document.
The build starts using the default configuration. This process may take several hours. When the build is
completed without errors, verify that Image* files are created in the arch/arm64/boot/ folder.
linux-xlnx$ make distclean
linux-xlnx$ make xilinx_zynqmp_defconfig
linux-xlnx$ make menuconfig
linux-xlnx$ make
...
3. If there are no errors, build again to generate Image* files to which the patch was applied:
linux-xlnx$ make
...
2. Modify the function to return to its caller with a pointer to a structure of spi_nor_erase_type when the
function finds that the sector has overlaid region. In the following source code, note that the return order of
the corresponding part in the loop is different from the source code provided by Xilinx.
Code Listing 2 Modify the function to find the best erase type
001 static const struct spi_nor_erase_type *
002 spi_nor_find_best_erase_type(const struct spi_nor_erase_map
*map,
003 const struct spi_nor_erase_region
*region,
004 u64 addr, u32 len)
005 {
006 const struct spi_nor_erase_type *erase;
007 u32 rem;
008 int i;
009 u8 erase_mask = region->offset & SNOR_ERASE_TYPE_MASK;
010
011 /*
012 * Erase types are ordered by size, with the smallest
erase type at
013 * index 0.
014 */
015 for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) {
016 /* Does the erase region support the tested erase
type? */
017 if (!(erase_mask & BIT(i)))
018 continue;
019
020 erase = &map->erase_type[i];
021
022 /* Alignment is not mandatory for overlaid
regions */
023 if (region->offset & SNOR_OVERLAID_REGION &&
024 region->size <= len)
025 return erase;
026
027 /* Don't erase more than what the user has asked
for. */
028 if (erase->size > len)
029 continue;
030
031 spi_nor_div_by_erase_size(erase, addr, &rem);
032 if (rem)
033 continue;
034 else
035 return erase;
036 }
037
038 return NULL;
039 }
3. Find the spi_nor_init_erase_cmd_list function, and then add one erase size comparison condition
where the result of the conditional statement can be true to call the spi_nor_init_erase_cmd
function.
Code Listing 3 Modify the function to initialize the erase command list
001 if (prev_erase != erase ||
002 erase->size != cmd->size ||
003 region->offset & SNOR_OVERLAID_REGION) {
004 cmd = spi_nor_init_erase_cmd(region,
erase);
005 if (IS_ERR(cmd)) {
006 ret = PTR_ERR(cmd);
007 goto destroy_erase_cmd_list;
008 }
009
010 list_add_tail(&cmd->list, erase_list);
011 } else {
012 cmd->count++;
013 }
5. Create the spansion_quad_enable_volatile function. This function sets the SEMPER™ NOR flash
memory that is not set as Quad interface to have a Quad interface temporarily by setting a volatile register.
Because the function receives the address of Any Registers as an argument, the register can be accessed
individually by selecting the lower die or upper die of the MCP.
Code Listing 5 Enable the Quad interface by setting a volatile register
001 static int spansion_quad_enable_volatile(struct spi_nor *nor,
u32 reg_addr_base,
002 u8 reg_dummy)
003 {
004 u32 reg_addr = reg_addr_base + SPINOR_REG_CYPRESS_CFR1V;
005 u8 cfr1v, cfr1v_written;
006 int ret;
007
008 /* Check current Quad Enable bit value. */
6. SEMPER™ NOR flash memory can be composed of several erasable sectors of different sizes, and a group of
sectors of the same size is called a region. These region settings are generally completed based on the
values specified in the SFDP, but it is necessary to directly specify them in the source code as follows and
modify them so that they can be used in the Linux MTD layer. Modify the information for each region
according to the SEMPER™ NOR flash memory that you use in your deign as follows:
Code Listing 6 Add a function to fix SEMPER™ flash erase map
001 void s25hx_t_fix_erase_map(struct spi_nor *nor)
002 {
003 struct spi_nor_erase_region *region = nor->params-
>erase_map.regions;
004 u8 erase_type_256k, erase_type_4k, erase_type_r0;
005
006 /*
007 * Uniform: Only one region is allocated. Unsupported
Map IDs are rolled
008 * back to the Uniform.
Application Note 13 of 23 002-33855 Rev.**
2021-09-16
Support for SEMPER™ Quad SPI flash in Linux from Xilinx
054
055 } else if (erase_type_r0 == erase_type_4k) {
056 pr_info("Enter s25hx_t_fix_erase_map 2");
057 /*
058 * Erase Map is populated as Split and needs to
be fixed to Top.
059 */
060 region[0].size = nor->params->size - SZ_256K;
061 region[1].size = SZ_128K;
062 region[2].size = SZ_128K;
063
064 region[0].offset = 0;
065 region[1].offset = region[0].size;
066 region[2].offset = region[1].offset +
region[1].size;
067
068 region[0].offset |= erase_type_256k;
069 region[1].offset |= erase_type_256k |
SNOR_OVERLAID_REGION;
070 region[2].offset |= erase_type_4k |
SNOR_LAST_REGION;
071 }
072 }
2. Change the call location of the spi_nor_region_mark_end function from the end of the
spi_nor_init_non_uniform_erase_map function to after the loop, which changes the erase
property of each region.
Code Listing 9 Modify the initialization of the non-uniform erase map function
001 static int
002 spi_nor_init_non_uniform_erase_map(struct spi_nor *nor,
003 struct spi_nor_flash_parameter
*params,
004 const u32 *smpt)
005 {
006
007 ......
008
009 /* Populate regions. */
010 for (i = 0; i < region_count; i++) {
011 j = i + 1; /* index for the region dword */
012 region[i].size = SMPT_MAP_REGION_SIZE(smpt[j]);
013 erase_type = SMPT_MAP_REGION_ERASE_TYPE(smpt[j]);
014 region[i].offset = offset | erase_type;
015
016 spi_nor_region_check_overlay(®ion[i], erase,
erase_type);
017
018 /*
019 * Save the erase types that are supported in all
regions and
020 * can erase the entire flash memory.
021 */
022 uniform_erase_type &= erase_type;
023
024 /*
025 * regions_erase_type mask will indicate all the
erase types
026 * supported in this configuration map.
027 */
028 regions_erase_type |= erase_type;
029
030 offset = (region[i].offset &
~SNOR_ERASE_FLAGS_MASK) +
031 region[i].size;
032 }
033 spi_nor_region_mark_end(®ion[i - 1]);
034
035 ......
036
037 return 0;
038 }
4.4.1 Add SPI NOR fixups structure and create fixup functions
To correct the parsing result of the basic flash parameter table (BFPT) and serial flash discoverable parameter
(SFDP), create a fixups structure for this. The structure consists of three function pointers that provide places
for a correction of the page program buffer size, a correction of the sector size, and a masking of the commands
not supported by the SEMPER™ NOR flash memory. This must reflect the changes such as in configuration
registers.
2. Add the s25hx_t_post_sfdp_fixups function. This function modifies the result of parsing the serial flash
discoverable parameter (SFDP).
Code Listing 11 Add the s25hx_t_post_sfdp_fixups function
001 void s25hx_t_post_sfdp_fixups(struct spi_nor *nor)
002 {
003 /* Fast Read 4B requires mode cycles */
004 nor->params->reads[SNOR_CMD_READ_FAST].num_mode_clocks =
8;
005
006 s25hx_t_fix_erase_map(nor);
007 }
3. Add a spi_nor_fixups structure variable named s25hx_t_fixups and initialize it by creating default,
BFPT, and SFDP hook functions.
Code Listing 12 Add the s25hx_t_post_sfdp_fixups function
001 static struct spi_nor_fixups s25hx_t_fixups = {
002 .post_bfpt = s25hx_t_post_bfpt_fixups,
003 .post_sfdp = s25hx_t_post_sfdp_fixups
004 };
4. Add the following SEMPER™ NOR flash memory ID and sector geometry information to a flash_info
structure variable named spansion_parts.
Code Listing 13 Add the s25hx_t_post_sfdp_fixups function
001 { "s25hl256t", INFO6(0x342a19, 0x0f0390, 256 * 1024,
128,
002 SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ
| USE_CLSR)
003 .fixups = &s25hx_t_fixups },
004 { "s25hl512t", INFO6(0x342a1a, 0x0f0390, 256 * 1024,
256,
005 SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ
| USE_CLSR)
006 .fixups = &s25hx_t_fixups },
007 { "s25hl01gt", INFO6(0x342a1b, 0x0f0390, 256 * 1024,
512,
008 SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ
| USE_CLSR)
009 .fixups = &s25hx_t_fixups },
010 { "s25hl02gt", INFO6(0x342a1c, 0x0f0390, 256 * 1024,
1024,
011 SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ
| USE_CLSR)
012 .fixups = &s25hx_t_fixups },
013 { "s25hl04gt", INFO6(0x342a1d, 0x0f0390, 256 * 1024,
2048,
014 SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ
| USE_CLSR)
015 .fixups = &s25hx_t_fixups },
Conclusion
5 Conclusion
It may be difficult to patch files for updating the source code when the target source code is being frequently
updated. If the source code is not directly managed by Infineon, it is difficult to predict the time of the change,
and it is difficult to maintain consistency in the change due to the supported by many contributors from
externals.
With this approach, you can determine the scope of changes with each release and apply the appropriate patch
file for major releases of the Linux source code from Xilinx.
Revision history
Revision history
Document Date of release Description of changes
version
** 2021-09-16 New application note
IMPORTANT NOTICE
Edition 2021-09-16 The information contained in this application note is For further information on the product, technology,
given as a hint for the implementation of the product delivery terms and conditions and prices please
Published by only and shall in no event be regarded as a contact your nearest Infineon Technologies office
description or warranty of a certain functionality, (www.infineon.com).
Infineon Technologies AG condition or quality of the product. Before
81726 Munich, Germany implementation of the product, the recipient of this
application note must verify any function and other WARNINGS
technical information given herein in the real Due to technical requirements products may contain
© 2021 Infineon Technologies AG. application. Infineon Technologies hereby disclaims dangerous substances. For information on the types
any and all warranties and liabilities of any kind in question please contact your nearest Infineon
All Rights Reserved. (including without limitation warranties of non- Technologies office.
infringement of intellectual property rights of any
Do you have a question about this third party) with respect to any and all information
given in this application note. Except as otherwise explicitly approved by Infineon
document? Technologies in a written document signed by
authorized representatives of Infineon
Go to www.cypress.com/support The data contained in this document is exclusively Technologies, Infineon Technologies’ products may
intended for technically trained staff. It is the not be used in any applications where a failure of the
responsibility of customer’s technical departments product or any consequences of the use thereof can
Document reference to evaluate the suitability of the product for the reasonably be expected to result in personal injury.
intended application and the completeness of the
002-33855 Rev.** product information given in this document with
respect to such application.