RZ/G2 BSP Porting - Flash Writer

From Renesas.info

← Back to RZ-G/RZ-G2_BSP_Porting

Read First

On this page, please note the following:

  • "RZ/G2L" = RZ/G2L, RZ/G2LC, RZ/G2UL. The instructions are the same.

Source Code Repository

The source code for Flash writer is stored on github.

Refer to the table in the wiki section of the repository to determine which branch you should use based on your SoC.

After you clone the repository and check out the correct branch, you may want to do is to create a new branch for your edits. This will make it easier to pull in future updates.


$ git clone https://github.com/renesas-rz/rzg2_flash_writer
$ cd rzg2_flash_writer
$ git checkout rz_g2l          # This is the branch for RZ/G2L
$ git checkout -b my_board     # This will make a new branch named 'my_board'

Add New DDR Settings

/G2N, /G2M, /G2H

Flash Writer version: v1.50+

  • DDR settings for each board are stored in a "struct _boardcnf" that is used by the DDR initialization code.
  • For Renesas evaluation boards, the Flash writer source contains an array of all the possible evaluation boards.
  • When porting Flash Writer to your own custom board, you will need to create your own "struct _boardcnf" that matches the DDR memory on your board.
  • In general, only the structure is needed (no DDR init executable code needs to be modified).
  • In Flash Writer, the function boardcnf_get_brd_type() is declared as '__attribute__((weak))' such that you can provide your own version of this function and gcc will ignore the function provided in the Flash Writer code that is specific for Renesas evaluation boards. This method allows you to not modify source files that might be updated later by Renesas as new evaluation boards are added and might cause merge conflicts with your local modification.
  • A sample DDR configuration structure has been provided. Please refer to file ddr/lpddr4/boot_init_dram_config-preset.c for example configurations used by Renesas evaluation boards.

1. Make a copy of the template file ddr/lpddr4/my_boot_dram_config.c

$ cp ddr/lpddr4/my_boot_dram_config.c  ddr/lpddr4/xyz_boot_dram_config.c

2. Add your new file to the build system by editing the makefile ddr/lpddr4/ddr.mk

SRC_FILE += ddr/lpddr4/boot_init_dram.c ddr/lpddr4/boot_init_dram_config-preset.c
# SRC_FILE += ddr/lpddr4/my_boot_dram_config.c
SRC_FILE += ddr/lpddr4/xyz_boot_dram_config.c             <<<<<<<<<<<< Example <<<<<<<<<<

3. Edit your new file and adjust the settings for your DDR memory on your board.


Edit the file rzg2_flash_writer/ddr/ddr3l/ddr.mk to add support for your board.

The settings for CFLAGS are as below:


/G2L, /V2L

Flash Writer version: 1.0+

DDR Excel Sheet

📰 DDR configuration generation tool (Excel Sheet)

  • Unless the DDR RAM connection and topology is exactly the same on your custom board as the Renesas reference board, you will have to adapt the parameters. In order to do so, please get from Renesas the RZ/G2L DDR configuration generation tool which is an Excel sheet.
  • There are different excel files for different devices:
    • For RZ/G2L and RZ/Five: RZG2L_G2UL_Five_A3UL_DDR_config_generation_tool_v3.0.1.xlsm
    • For RZ/V2L: RZ-V2L_DDR_config_generation_tool_v1.13.1.xlsm
  • Using this Excel sheet you can generate two files (param_mc.c and param_swizzle.c) that have to be added to Flash Writer.

⚠️ Precautions

  • This sheet only works with the latest version of Excel (Excel 365 from Office 365).
  • Some have reported that it only works after switching Windows system language to English and reinstalling Office for the English version.

💡 Notes about using the Excel sheet

  • Note that you select either a Topology or a pair of Condition/Connection that match your design. You don't use both.
    • If there is a Condition/Connection pair that matches your design, then you can select it and ignore the Topology section.
    • If no Condition/Connection pair matches your design, then you must use the Topology section and ignore Condition/Connection sections.
    • You will make your selection in the "GenParam" tab
  • The "guide" tab:
    • This tab contains general instructions for using the sheet.
    • Note that the code modification instructions are for Trusted Firmware-A (not FlashWriter), so follow the instructions on this page for modifying FlashWriter.
  • The "01_Condition" tab:
    • This tab is just for references to select your "Condition#" value. No modifications are needed.
  • The "02_Connection" tab:
    • This tab is just for references to select your "Connection#" value. No modifications are needed.
  • The "03_Topology" tab:
    • This tab is just for references to select your "Topology#" value. No modifications are needed.
  • The "04_Analog" tab:
    • The values in this tab can be modified, but really depends on your schematic and layout.
    • The drive strengths and impedances were determined by the person who did the board design layout and trace simulation, so this tab is used to make sure the DDR inti software will set the registers to the same settings that was used for the design.
    • Again, you only need to modify the column that you will select in the GenParam tab. The other columns will be ignored.
  • The "05_CA_Remap" tab:
    • This tab should be modified if your pin remapping didn't match what was used for the Renesas EVK boards.
    • Again, you only need to modify the column that matches the Condition/Connection or Topology that you are selecting in the GenParam tab.
    • If you have any unused pins in your design, (for example, you are using a smaller DDR), you should leave them mapped in the sheet. The DDR pins are dedicated I/O, so it's not like you can use them for anything else. Also, if you try and leave cell empty, the excel sheet will give you an error.
  • The "GenParam" tab:
    • On this tab, use the pulldown on the yellow cells to make your selections.
    • If you are selecting a Condition/Connection pair, set Topology to "Other" and then set the individual Condition# and Connection# pulldowns to your selctions.
    • If you are selecting a Topology, simply find the correct one in the list. The Condition# and Connection# values will change automatically (you don't need to touch them).
    • Then press the "Generate param files" button to create your output files. They will be created in the same location as the Excel file.

Output Files

Rename param_mc.c and param_swizzle.c:

  • In the Excel sheet, in there "guide" tab, it is recommended to rename the output files. Use the values used in the "GenParam" tab.
    • param_mc.c → param_mc_{Connection#}_{Condition#}.c
      • (ex:param_mc_C-011_D4-01-2.c)
    • param_swizzle.c → param_swizzle_{Topology#}.c
      • (ex:param_swizzle_T3bcud.c, param_swizzle_other.c)

Copy files to rzg2_flash_writer directories:

  • Copy your file param_mc_C-xxx_D4-xxx.c to the directory rzg2_flash_writer/ddr/g2l/ (or ddr/g2ul or ddr/v2l).
  • Copy your file param_swizzle_xxx.c to the directory rzg2_flash_writer/ddr/common/

Code Changes

Force only your file to be loaded:

  • Edit the file rzg2_flash_writer/ddr/common/ddr.c
  • At the top of the file, replace this line:
#if (DDR4 == 1)
  • with these lines:
/* Use My DDR Parameters */
#if (1)
#include "param_mc_C-xxx_D4-xxx.c"
#include "param_swizzle_xxx.c"

#elif (DDR4 == 1) /* changed #if to #elif */

DDR Test Routines

To test DDR in Flash Writer, have a look a this section.

Add Support for New SPI Flash

Flash Writer will read the device ID of the SPI flash device in order to determine what SPI commands it should use as well as the flash block size. Therefore, the specific ID of your flash device needs to be part of the flash writer source code.

The RZ/G2 Flash writer code is posted here. Please review the following files and code and modify as needed.


  • Confirm that the Manufacture ID for your flash devices is listed. For example, you will see these vendors already listed:
#define	CYPRESS_MANUFACTURER_ID		0x01	/* Cypress	*/
#define	WINBOND_MANUFACTURER_ID		0xEF	/* Winbond	*/
#define	MACRONIX_MANUFACTURER_ID	0xC2	/* Macronix	*/
#define	MICRON_MANUFACTURER_ID		0x20	/* Micron	*/
  • Confirm if the Device ID for your flash devices is listed. If not, then add it.
#define	DEVICE_ID_S25FS128S		0x2018


  • If you added a new SPI flash in dgmodule4.h, then you must add it to function CheckQspiFlashId()
  • Add new case statement using your DEVICE_ID_xxx that you created in dgmodule.h
  • Print out the part number of your SPI Flash using PutStr()
  • Set the Flash sector erase size as gQspi_sa_size
  • Set the address of the last Flash sector as gQspi_end_addess
	case DEVICE_ID_S25FS512S:
			PutStr("S25FS512S", 1);
			gQspi_sa_size    = SA_256KB;
			gQspi_end_addess = TOTAL_SIZE_64MB - 0x8000 - 1;

🎈 If you successfully added a new SPI Flash device, please let us know so we can update the code for everyone 🧑‍🤝‍🧑. You can submit a new issue on the github site, or send an email to renesas-rz@renesas.com. Thank you.

Building and Debugging

/G2E, /G2N, /G2M, /G2H

Content: TBD

/G2L, /V2L

You can build Flash Writer by following the Readme, the only difference is that you have to use BOARD=CUSTOM (or the name you chose) as per these instructions.

It is worth to note that in order to enable Flash Writer to program eMMC, it has to be built with a specific flag: EMMC=ENABLE.

You can also use Eclipse to build and debug Flash Writer using OpenOCD as documented here. Obviously there is always the possibility to debug using the good old printf (PutStr function in Flash Writer).