Forum Discussion
Questions About GSFI, QSPI Flash XIP Boot, and HAL API Support
I am currently using the 10M50 Evaluation Kit and trying to boot from QSPI Flash using XIP (Execute In Place).
I am using the Generic Serial Flash Interface (GSFI) IP, and I would also like to read and write data to the QSPI Flash after the software has started.
I have the following questions:
1. Is it possible to use both XIP boot from QSPI Flash and dual configuration simultaneously?
I have read the Nios® V Embedded Processor Design Handbook and believe that this should be possible from a system configuration point of view. However, I would like to confirm whether there are any limitations or considerations.
2. Regarding the GSFI HAL API support
According to the Generic Serial Flash Interface Intel® FPGA IP User Guide, the GSFI HAL API supports Quartus Prime Pro Edition. Does this mean that the GSFI HAL API cannot be used with Quartus Prime Lite Edition?
3. QSPI Flash device support
The 10M50 Evaluation Kit is equipped with a QSPI Flash device, the N25Q512A83GSF40F. However, this device is not listed in the section "HAL API supports the following QSPI flash device families."
Does this mean that the GSFI HAL API cannot be used with this Flash device?
4. Alternative method if HAL API is not available
If the GSFI HAL API cannot be used with this Flash device or with Quartus Prime Lite Edition, what is the recommended method for reading and writing data to the QSPI Flash?
For example, should I directly control the GSFI registers and issue Flash commands manually, or is there another recommended software driver or method?
Thank you for your support.
9 Replies
- LiangYuG_Altera
Contributor
Hi watanabe
watanabe wrote:
1. I selected "LPDDR2 SDRAM Controller with UniPHY IP" as the EMIF IP. Is it possible to use this IP together with Nios V?
You can refer to this design example. It is also a 10M50 Evaluation Kit, with LPDDR2 SDRAM Controller with UniPHY IP.
watanabe wrote:
2. Is it possible to copy the boot image to DDR2 during boot and then run the bootloader from DDR2?
Yes, you can copy the boot image into LPDDR2, and run the bootloader from LPDDR2.
Just understanding your proposal more...
Is it like this?
- Inside GSFI - 1st stage bootloader + boot image (2nd stage bootloader & application)
- 1st stage bootloader is XIP from GSFI
- boot image is XIP from LPDDR2
- Nios V processor's reset vector is GSFI.
- XIP from GSFI - Run 1st stage bootloader, copy boot image to LPDDR2, and "jr" to LPDDR2
- XIP from LPDDR2 - Run 2nd stage bootloader, and run application.
Since the boot image is XIP from LPDDR2, the GSFI flash is released after 1st stage bootloader. You are free to access the GSFI flash to modify/update the boot image.
Regards,
Liang Yu - watanabe
New Contributor
I made a mistake in my second question.
If booting and running the bootloader from DDR2 is not possible, I plan to use a boot copier that copies the boot image to on-chip RAM (OCRAM) instead of on-chip flash (OC Flash).
Thank you for your support.
- BoonBengT_Altera
Moderator
Dear Customer,
As there is no further follow‑up questions have been raised, we will assume the issue has been resolved.
This thread will now be transitioned to community support, where other users can continue to assist with any additional inquiries.
For new questions, please feel free to open a fresh thread — we’ll be happy to support you there.
Thank you for being part of the community!
Best regards,
Altera Technical Support
- watanabe
New Contributor
Thank you for your reply.
First, I enabled compiler optimization by setting CMAKE_BUILD_TYPE=Release when running CMake. However, the software size was still over 100 KB, so I decided to stop pursuing further size reduction.
Next, I started considering the use of EMIF and a boot copier mechanism.
Since the 10M50 Evaluation Kit I am currently using includes LPDDR2, this approach seems feasible and may also solve the issues I have been facing. Therefore, I am trying to proceed with this method.
I have the following questions:
1. I selected "LPDDR2 SDRAM Controller with UniPHY IP" as the EMIF IP. Is it possible to use this IP together with Nios V?
(It may be due to an incorrect setting on my side, but Platform Designer fails during the Generate process.)
2. Is it possible to copy the boot image to DDR2 during boot and then run the bootloader from DDR2?
If this is not possible, my alternative plan is:
Boot from on-chip flash using a boot copier.
Copy the application image from QSPI Flash to DDR2.
Jump to the application in DDR2 and execute it.
Would this be a valid approach?
Thank you for your support.
- LiangYuG_Altera
Contributor
Hi watanabe
watanabe wrote:
However, the OCRAM capacity is only 165 KB, so there is not enough space to store both the bootloader (approximately 100 KB) and the application (approximately 100 KB) in OCRAM at the same time. Therefore, using a boot copier to load the boot software from the QSPI flash into OCRAM also seems difficult due to the limited OCRAM capacity.
If you apply the Bootloader via GSFI approach, it will XIP boot the bootloader (inside the GSFI) first, then bootloader will copy the application into OCRAM, and jump to the OCRAM.
As such, only 100KB application is present in the OCRAM as .text section.
(Not 100KM + 100KB = 200 KB for both bootloader & application)watanabe wrote:
1. Why has the boot software size increased so much when migrating from Nios II to Nios V?
It is migrating from Nios II ISA to RISC-V ISA. Thus, the compiler is different (from Altera proprietary Nios II ISA to standardized RISC-V ISA), which leads to different ELF size.
After adding the compiler optimization, did you use CMAKE_BUILD_TYPE=Release when running cmake?cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -B software/app/debug -S software/app make -C software/app/debugwatanabe wrote:
2. Is there any way to test the boot process with my current development kit?
- With the need to access flash after booting, that prevents XIP approach.
- With ELF size > OCRAM size, that prevents bootcopier (Bootloader via GSFI) approach.
The only way is to pursue the bootcopier approach.
Perhaps the following might still be possible to continue with bootcopier.
- Have an EMIF to replace the small OCRAM,
- "100KB Bootloader via GSFI is XIP booted" earlier is valid for your use case
- Ensure that CMAKE_BUILD_TYPE=Release is present to enforce the compiler optimizations
Regards,
Liang Yu - watanabe
New Contributor
Thank you for your previous answers.
Your advice has been very helpful, but it has also made me reconsider my current system architecture.
Originally, I planned to boot the system using XIP (Execute In Place) from the UFM. However, the UFM has a capacity of only 65 KB, while the boot software has grown to over 100 KB. Therefore, I abandoned the idea of executing the boot software directly from the UFM and changed the architecture to use XIP from the QSPI flash instead.
I also want the bootloader to copy the application stored in the QSPI flash into OCRAM and then jump to the application.
However, the OCRAM capacity is only 165 KB, so there is not enough space to store both the bootloader (approximately 100 KB) and the application (approximately 100 KB) in OCRAM at the same time. Therefore, using a boot copier to load the boot software from the QSPI flash into OCRAM also seems difficult due to the limited OCRAM capacity.
I have two additional questions.
1. Why has the boot software size increased so much when migrating from Nios II to Nios V?
I am currently migrating existing boot software from a Nios II environment to a Nios V environment. The original Nios II version was less than 30 KB, but the Nios V version has grown to over 100 KB.
What could be causing such a significant increase in code size when migrating from Nios II to Nios V?
Are there any ways to further reduce the code size? I have already tried adjusting the BSP settings and compiler optimization options to minimize the code size.
2. Is there any way to test the boot process with my current development kit?
My current development kit has only one QSPI flash device. Given this limitation and the OCRAM capacity constraints described above, implementing a boot copier also seems difficult.
Under these conditions, I believe it may be difficult to test the intended boot architecture with my current development kit.
Is there any recommended approach or alternative architecture that would allow me to test the boot process with the current hardware?
If testing this configuration with the current development kit is not feasible, I am prepared to give up on testing it on this kit.
Any advice or suggestions would be greatly appreciated.
Thank you for your help.
- LiangYuG_Altera
Contributor
Hi watanabe
Based on your explanation, you are designing a:
- Max 10 RSU + Nios V design
- Nios V is booted from N25Q512A83GSF40F
- Nios V use HAL API to access the same N25Q512A83GSF40F
watanabe wrote:
1. Is it possible to use both XIP boot from QSPI Flash and dual configuration simultaneously?
The Max 10 configuration CFM & general purpose N25Q512A83GSF40F are two separate memories. For now (please continue reading below), XIP boot will not conflict with Max 10 RSU.
watanabe wrote:
4. Alternative method if HAL API is not available
The act of accessing flash is not possible with XIP boot. XIP boot fully owns the N25Q512A83GSF40F, other flash access cannot take place.
Imagine that there are two functions in the Nios V application, (1) XIP booting & (2) Customer's Read/Write operations - (1) will never release the N25Q512A83GSF40F for (2).
You need to switch to the (3) Bootloader via GSFI approach - (3) will release the N25Q512A83GSF40F after bootcopy completes, so that (2) can begin.
After switching to Bootloader via GSFI with dual configuration,
watanabe wrote:
2. Regarding the GSFI HAL API support
4. Alternative method if HAL API is not available
Correct, there is no GSFI HAL API in Quartus Standard and Lite.
As an alternative, you can pick one of the alternative below:
- Create custom API based on this System Console example with IOWR / IORD.
- Copy the GSFI HAL API from Quartus Pro, paste it in the Max 10 project & improvise the BSP CMakeLists.txt (Similar reference with Mailbox Client IP HAL API)
C:\altera_pro\26.1.1\ip\altera\eip\intel_generic_serial_flash_interface\intel_generic_serial_flash_interface_top\HAL\inc\intel_generic_serial_flash_interface_top.h C:\altera_pro\26.1.1\ip\altera\eip\intel_generic_serial_flash_interface\intel_generic_serial_flash_interface_top\HAL\src\intel_generic_serial_flash_interface_top.c C:\altera_pro\26.1.1\ip\altera\eip\intel_generic_serial_flash_interface\intel_generic_serial_flash_interface_top\inc\intel_generic_serial_flash_interface_top_regs.hSince both are creating API from scratch, remember to test the API extensively.
Nirav_Altera wrote:
3. N25Q512A83GSF40F support in the HAL API
If you are going with custom API, this concern is not applicable. You are going design the custom API with N25Q512A83GSF40F in mind yourselves.
If you are going with "copy & paste HAL API", this concern is applicable. Use the HAL API source code as references, and review the flash-specific "#define" or flash's programming model.
Regards,
Liang Yu - Nirav_Altera
New Contributor
Hi Wantanabe,
Thank you for the detailed questions. Please see my answers below.
1. XIP boot from QSPI flash together with dual configuration
From a system architecture point of view, this combination should work. On MAX 10, the two configuration images are stored in the internal configuration flash (CFM). The QSPI flash connected through the GSFI is general purpose memory and is not used for FPGA configuration, so FPGA configuration and Nios V XIP boot are independent of each other. Please note that we do not have a documented reference design that combines the two, so I recommend validating it on your board.
One documented requirement for the XIP flow: in the BSP Editor, disable the GSFI driver (intel_generic_serial_flash_interface_top) on the BSP Drivers tab, as described in the Nios V Embedded Processor Design Handbook. If the driver initializes the GSFI while the CPU is fetching code from it, the boot does not complete.
In addition, I would suggest the following considerations for your design:
Each configuration image has its own Nios V system. If both images run the same application, they can share the same software location in QSPI. If they run different applications, we recommend placing each application at a different offset in the QSPI flash and setting the Nios V Reset Agent offset in each image to match.Reconfiguring the FPGA (for example through the Dual Configuration IP) does not power cycle the external QSPI flash, so the flash should keep its current state, such as the addressing mode. Please make sure the addressing mode setting (bit 8 of the Control Register in the GSFI Default Settings) matches the flash state in both images, and avoid triggering reconfiguration while a flash erase or program operation is in progress.
Our guidance for the MAX 10 FPGA Development Kit, which uses the same N25Q512A83GSF40F device, is that the flash is in 4-byte addressing mode after power cycle, and that the SPI Clock Baud-rate Register should be set to 0x1 (/2) when the GSFI runs on a 50 MHz clock. The default /32 divisor can cause a race condition during XIP. If your 10M50 Evaluation Kit is a different board, please confirm these settings against your board schematic and the flash datasheet.
2. GSFI HAL API with Quartus Prime Lite Edition
That is correct. The GSFI User Guide states that the HAL driver is supported in Quartus Prime Pro Edition software only. MAX 10 devices are supported in Quartus Prime Standard and Lite Edition, so the GSFI HAL API is not available for your setup. The GSFI IP itself supports MAX 10 for general purpose memory. Only the HAL software driver is not available.
Reference: Generic Serial Flash Interface IP User Guide, section Intel HAL Driver
hal-driver3. N25Q512A83GSF40F support in the HAL API
The HAL API supports only the flash families listed in the same section of the user guide (for Micron, the MT25QL and MT25QU variants). The N25Q512A is not on that list, so it is not a supported device for the HAL driver. Because of point 2, the HAL driver is not an option in Lite Edition in any case. This does not affect the XIP boot itself, since the XIP flow does not use the HAL driver.
4. Recommended way to read and write the QSPI flash
We do not recommend erasing or programming the same QSPI flash that the Nios V is executing from. The GSFI services only one of its two Avalon ports (avl_csr or avl_mem) at a time, and while an erase or program operation is running, the flash is generally not able to return instruction data for the CPU. This can stall or hang the processor. Depending on your requirements, we suggest one of the following approaches:
Read only: If you only need to read data (for example constants or parameters), you can keep XIP and read the data directly through the memory-mapped GSFI avl_mem region, for example with a pointer or memcpy(). No driver is needed for this.
Read and write with a single flash: Use the boot copier method instead of XIP (Nios V processor application copied from general purpose QSPI flash to RAM using Bootloader via GSFI, described in the Nios V Embedded Processor Design Handbook). The application then runs from OCRAM or external RAM, and the flash is free for erase and program commands through the GSFI CSR interface.
Read and write while keeping XIP: Add a second QSPI flash device to your board, connected to FPGA general purpose I/O pins, with its own GSFI instance for data storage, and keep the boot flash read only. Please note that this requires additional hardware, for example an add-on flash on an expansion header or a custom board. A separate GSFI instance is needed because a single GSFI cannot service code fetches from the boot flash while it performs erase or program operations, even if both flashes are connected to it through different chip selects.
Since the HAL driver is not available in Lite Edition, the erase and program operations need to be implemented by accessing the GSFI registers directly. The section "Flash Access Using the Generic Serial Flash Interface IP" in the GSFI IP User Guide describes the register sequences (write enable, erase, program, and reading the status and flag status registers). Please use the command opcodes from the N25Q512A datasheet. As described in the user guide, always issue write enable before any write or erase operation, and read the flag status register after every write or erase command until the operation completes. Also make sure your commands use the same addressing mode (3-byte or 4-byte) as the flash and the GSFI Control Register setting.
- ai_responder
Community Manager
Thank you for your inquiry. To ensure an accurate response, your request has been routed to an Altera application engineer for further review and assistance.
Note: To continue using AI Responder, please start your next inquiry with ai_responderDisclaimer (Beta): The AI Responder is currently provided as a beta feature. AI-generated responses may contain errors or omissions. Please verify technical guidance with official Altera documentation before implementation.
Thank you very much.