RZ-G/RZ-G2 BSP Porting OpenWRT

From Renesas.info

← Back to RZ-G/RZ-G2_BSP_Porting

SoC: All

Specification

Target OpenWRT OS Version: openwrt-22.03

Target reference board: RZ/G2L,/G2LC,/G2UL SMARC

Host PC Environment: Ubuntu20.04

OpenWRT build system setup bese on Ubuntu20.04

Run below command on Host Ubuntu PC

sudo apt update

sudo apt install build-essential ccache ecj fastjarfileg++gawk\

gettextgitjava-propose-classpath libelf-dev libncurses5-dev\

libncursesw5-dev libssl-dev python python2.7-dev python3unzipwget\

python-distutils-extra python3-setuptools python3-dev rsync subversion\

swigtimexsltproc zlib1g-dev

Download source code

git clone https://git.openwrt.org/openwrt/openwrt.git

The reasion why we need to choise 22.03 branch is because openwrt-22.03 use the same kernel version linux-5.10.xxx with RZ/G2L VLP3.0.x yocto sdk, so we can reduce the hard difficulty when portting renesas's smarc board driver to the kernel.

openwrt23.05 base on kernel version 5.15.134

openwrt22.03 base on kernel version 5.10.116

openwrt21.02 base on kernel version 5.4.194

openwrt19.07 base on kernel version 4.14.275

openwrt18.06 base on kernel version 4.14.206


Check out branch code
cd openwrt
 git branch -a
 * master
   remotes/origin/HEAD -> origin/master
   remotes/origin/lede-17.01
   remotes/origin/main
   remotes/origin/master
   remotes/origin/openwrt-18.06
   remotes/origin/openwrt-19.07
   remotes/origin/openwrt-21.02
   remotes/origin/openwrt-22.03
   remotes/origin/openwrt-23.05
git checkout openwrt-22.03 

Branch 'openwrt-22.03' set up to track remote branch 'openwrt-22.03' from 'origin'. Switched to a new branch 'openwrt-22.03'

git branch -a
   master
 * openwrt-22.03
   remotes/origin/HEAD -> origin/master
   remotes/origin/lede-17.01
   remotes/origin/master
   remotes/origin/openwrt-18.06
   remotes/origin/openwrt-19.07
   remotes/origin/openwrt-21.02
   remotes/origin/openwrt-22.03
   remotes/origin/openwrt-23.05

Get current branch's application source code

cd openwrt
./scripts/feeds update -a  && ./scripts/feeds install -a

Create project for Renesas RZ/G2L SMARC EVK

Create Renesas's target system

cd openwrt
mkdir target/linux/renesas
cd target/linux/renesas
Add target system Makefile
include $(TOPDIR)/rules.mk
ARCH:=aarch64
BOARD:=renesas
BOARDNAME:=Renesas RZ/G2
FEATURES:=ext4 audio usb usbgadget display gpio fpu pci pcie rootfs-part boot-part squashfs
SUBTARGETS:=r9a07g044
KERNEL_PATCHVER:=5.10
KERNELNAME:=Image dtbs
define Target/Description
    Build firmware image for Renesas SoC devices.
endef
include $(INCLUDE_DIR)/target.mk
DEFAULT_PACKAGES += uboot-envtools partx-utils e2fsprogs mkf2fs 
$(eval $(call BuildTarget))

Create subtarget r9a07g044

mkdir r9a07g044
cd r9a07g044 
Add target.mk
BOARDNAME:=RZ/G2L SMARC EVK board 
CPU_TYPE:=r9a07g044
CPU_SUBTYPE:=l2
define Target/Description
    Build firmware image for Renesas RZ/G2L SMARC EVK board.
endef

Create image generation dependency

cd ..
mkdir image
cd image
Add Makefile
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/image.mk
include $(SUBTARGET).mk
$(eval $(call BuildImage))
Add r9a07g044.mk
define Build/Compile
   $(CP) $(LINUX_DIR)/COPYING $(KDIR)/COPYING.linux
endef
### Image scripts ###
define Build/boot-common
    # This creates a new folder copies the dtb 
    # and the kernel image (as Image)
    rm -fR $@.boot
    mkdir -p $@.boot
    $(CP) $(DTS_DIR)/$(DEVICE_DTS).dtb $@.boot
    $(CP) $(KDIR)/$(KERNEL_NAME) $@.boot
endef
define Build/boot-image
    # Creates the final SD/eMMC images, 
    # combining boot partition, root partition.
    PADDING=1 $(SCRIPT_DIR)/gen_image_generic.sh \
       $@ \
       $(CONFIG_TARGET_KERNEL_PARTSIZE) $@.boot \
       $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(IMAGE_ROOTFS) \
       32768
endef
### Devices ###
define Device/Default
  PROFILES := Default
  IMAGES := sdcard.img.gz
  KERNEL_NAME := Image
  KERNEL := kernel-bin
  DEVICE_DTS = renesas/$$(SOC)-$$(DEVICE_VENDOR)-$(lastword $(subst _, ,$(1)))
endef
define Device/smarc_rzg2l
  DEVICE_VENDOR := smarc
  DEVICE_MODEL := rzg2l
  SOC := r9a07g044l2
  IMAGE/sdcard.img.gz := boot-common | boot-image | gzip | append-metadata
  DEVICE_DTS = renesas/$$(SOC)-$$(DEVICE_VENDOR)
endef
TARGET_DEVICES += smarc_rzg2l
define Device/smarc_rzg2lc
  DEVICE_VENDOR := smarc
  DEVICE_MODEL := rzg2lc
  SOC := r9a07g044c2
  IMAGE/sdcard.img.gz := boot-common | boot-image | gzip | append-metadata
  DEVICE_DTS = renesas/$$(SOC)-$$(DEVICE_VENDOR)
endef
TARGET_DEVICES += smarc_rzg2lc
define Device/smarc_rzg2ul
  DEVICE_VENDOR := smarc
  DEVICE_MODEL := rzg2ul
  SOC := r9a07g043u11
  IMAGE/sdcard.img.gz := boot-common | boot-image | gzip | append-metadata
  DEVICE_DTS = renesas/$$(SOC)-$$(DEVICE_VENDOR)
endef
TARGET_DEVICES += smarc_rzg2ul

Prepare kernel source code

Because openwrt22.03 default use kernel version 5.10.xxx come from kernel.org, but this version source code download form kernel.org don't support RZ/G2L SMRAC EVK board build. So, we need to use external kernel code come from Renesas's GitHub.

git clone https://github.com/renesas-rz/rz_linux-cip
cd rz_linux_cip
git checkout rz-5.10-cip3

Select project to be build by menuconfig

cd  openwrt
make defconfig && make menuconfig

Select red box information

Target System () ---> Renesas

Subtarget ( ) ---> RZ/G2L SMRAC EVK board

Target Profile (smarc rzg2l) ---> smarc rzg2l

project select.png

Target Images ---> (16) Kernel partition size (in MiB) (NEW)

Change Kernel partition size 16M ==> 64M

Select Advanced configuration options (for developers) (NEW) ---> Use external kernel tree (NEW)

Input your kernel source code path dir:$YOUR_KERNEL_DIR/rz_linux-cip

Select Image configuration ---> Separate feed repositories ---> Enable feef luci

Save all your select and exit menuconfig

Because we use external kernel tree So, we need do kernel menuconfig

make kernel_menuconfig  -j8

This command will take a long time. Just wait, No need to select anything just use default config.

Save and exit kernel_menuconfig

Start build the whole system and generate sdcard.img

make -j8   V=99

Use rufus tools to burn sdcard.img Select openwrt-renesas-armv8-smarc_rzg2l-ext4-sdcard.img.gz to be burn.

Boot OpenWRT form SD card

Insert SD card and set u-boot boot parameter:

setenv boot_openwrt 'mmc dev 1; ext4load mmc 1:1 0x48080000 Image; ext4load mmc 1:1 0x48000000 r9a07g044l2-smarc.dtb; setenv bootargs rootwait root=/dev/mmcblk1p2; booti 0x48080000 - 0x48000000'
setenv bootcmd 'run boot_openwrt'
saveenv 
boot

Then OpenWRT boot success like that:

Set password for root login Luci web need this password.

Because RZ/G2L SMARC EVK board has two net interfaces eth0 and eth1, so change eth0 as Lan and eth1 as Wan.

After change the interface Lan, need restart network.

Connect eth0 to your pc by rj45 cable, Then you can login Luci web server by web browser. http://192.168.1.1

You can also ssh to OpenWRT : ssh root@192.168.1.1

Now OpenWRT has been ported and run on RZG2L SMARC EVK board.