RZ/G2 BSP Porting - Flash Writer

From Renesas.info
Revision as of 12:26, 19 September 2022 by MicBis (talk | contribs) (→‎DDR test routines: Avoid duplication of information)

← Back to RZ-G/RZ-G2_BSP_Porting

Cloning repository

SoC: RZ/G2E, RZ/G2N, RZ/G2M, RZ/G2H

git clone https://github.com/renesas-rz/rzg2_flash_writer

Then what you may want to do is to create a new branch for your own experiments, e.g.:

git checkout -b my_custom_board_branch

SoC: RZ/G2L, RZ/V2L

git clone https://github.com/renesas-rz/rzg2_flash_writer
git checkout origin/rz_g2l

Then what you may want to do is to create a new branch for your own experiments, e.g.:

git switch -c my_custom_board_branch

Add New DDR Settings

SoC: RZ/G2N, RZ/G2M, RZ/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.

Instructions:
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.

DDR test routines

To test DDR, have a look a this section.

SoC: RZ/G2E

Flash Writer version: TBD

Content: DDR3L instead of LPDDR4.

SoC: RZ/G2L, RZ/V2L

Flash Writer version: 1.0+

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 (RZ-G2L_DDR_config_generation_tool_Rev.X.YZ_rN.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.
  • Notes about the Excel sheet
    • The "guide" tab are general instruction. The code modification instructions are for Trusted Firmware-A (not FlashWriter)
    • For RZ/V2L, use RZ/G2L (they are the same)
    • The "01_Condition" tab is just for references to select your "Condition#" value.
    • The "02_Connection" tab is just for references to select your "Connection#" value.
    • The "03_Topology" tab is just for references to select your "Topology#" value.
    • The "04_Analog" tab can be modified and really depends on your schematic and layout.
    • The "05_CA_Remap" tab should be modified if your pin remapping didn't match what was used for the Renesas EVK boards.
    • On the "GenParam" tab, use the pulldown on the yellow cells to make your selection. Then press the "Generate param files" button.

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/

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 */

Add Support for New SPI Flash

SoC: All

  • Flash writer version: All

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.

include/dgmodul4.h

  • 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

dgmodul4.c

  • 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;
	break;

🎈 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

SoC: RZ/G2E, RZ/G2N, RZ/G2M, RZ/G2H

Content: TBD

SoC: RZ/G2L, RZ/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).