==Spec== {| class="wikitable" | CPU || Dual Cortex®-A53@1.2GHz |- | GPU || PowerVR GE8300@600MHz |- | RAM || 4x512M DDR3L@1856MHz |- | USB || 1xUSB 3.0, 1xUSB 2.0 |- | Video Output || 1xHDMI(From RGB), 2xLVDS |- | Ethernet || RGMII 1Gbps |- | External port || PCI-E x1 |- | Storage || eMMC 16G, SD Card slot |} ==Image Installation== ===Ubuntu 20.04 pre-install apts=== apt install git build-essential flex bison ===Fetch RZ/G2E Linux SDK===
git clone https://git.g77k.com/supercatexpert/rzg2-linux-sdk.git
cd rzg2-linux-sdk
git submodule update --init
===Build RZG2 Flash Burner===
cd rzg2-flash-writer
./build-g2e-emmc.sh
===Build ARM Trusted Firmware===
cd arm-trusted-firmware
./build-ek874-emmc.sh
===Build U-Boot===
cd renesas-u-boot-cip
./build-g2e-emmc.sh
===Boot Flash Burner from serial port=== Set serial port of PC to 115200bps, 8N1. Set boot mode of board to download mode. Connect Debug port of board to the serial port of PC. Power on the board, then something like "please send !" will be printed on terminal. Upload file rzg2-flash-writer/AArch64_output/AArch64_Flash_writer_SCIF_DUMMY_CERT_E6300400_ek874.mot with ASCII mode. After uploading, prompt ">" will appear in terminal. ===Install ARM Trusted Firmware & U-Boot=== {| class="wikitable" |- ! Filename !! Program Top Address !! eMMC Save Partition !! eMMC Save Sectors !! Description |- | arm-trusted-firmware/deploy/bootparam_sa0.srec || E6320000 || boot partition1 || 000000 || Loader(Boot parameter) |- | arm-trusted-firmware/deploy/bl2.srec || E6304000 || boot partition1 || 00001E || Loader |- | arm-trusted-firmware/deploy/cert_header_sa6.srec || E6320000 || boot partition1 || 000180 || Loader(Certification) |- | arm-trusted-firmware/deploy/bl31.srec || 44000000 || boot partition1 || 000200 || ARM Trusted Firmware |- | renesas-u-boot-cip/deploy/u-boot-elf.srec || 50000000 || boot partition2 || 000000 || U-boot |} Use EM_W command to write S-record file into eMMC. e.g:
>EM_W
EM_W Start --------------
---------------------------------------------------------
Please select,eMMC Partition Area.
 0:User Partition Area   : 30535680 KBytes
  eMMC Sector Cnt : H'0 - H'03A3DFFF
 1:Boot Partition 1      : 16384 KBytes
  eMMC Sector Cnt : H'0 - H'00007FFF
 2:Boot Partition 2      : 16384 KBytes
  eMMC Sector Cnt : H'0 - H'00007FFF
---------------------------------------------------------
  Select area(0-2)>1                                         <<<< Enter "1" here
-- Boot Partition 1 Program -----------------------------
Please Input Start Address in sector :0000                   <<<< Enter "0000" here
Please Input Program Start Address : E6320000                <<<< Enter "E6320000" here
Work RAM(H'50000000-H'50FFFFFF) Clear....
please send ! ('.' & CR stop load)
SAVE -FLASH.......
EM_W Complete!
===eMMC Boot Settings=== Please note that for eMMC booting, the following EXT_CSD registers need to be modified:
EXT_CSD[B1] = 0x0A
EXT_CSD[B3] = 0x08
Use EM_SECSD command to modify EXT CSD registers:
>EM_SECSD
  Please Input EXT_CSD Index(H'00 - H'1FF) :b1
  EXT_CSD[B1] = 0x00
  Please Input Value(H'00 - H'FF) :a
  EXT_CSD[B1] = 0x0A

>EM_SECSD
  Please Input EXT_CSD Index(H'00 - H'1FF) :b3
  EXT_CSD[B1] = 0x00
  Please Input Value(H'00 - H'FF) :8
  EXT_CSD[B1] = 0x08
===Check Bootloader=== Power off the board. Set boot mode to eMMC boot. Then power on. It should be able to boot into u-boot:
[    0.000096] NOTICE:  BL2: RZ G2E Initial Program Loader(CA53)
[    0.004372] NOTICE:  BL2: Initial Program Loader(Rev.2.0.7)
[    0.009905] NOTICE:  BL2: PRR is RZG G2E Ver.1.1
[    0.014478] NOTICE:  BL2: PLL1 nonSSCG Clock select
[    0.019327] NOTICE:  BL2: Board is EK874 RZ/G2E Rev.1.0
[    0.024502] NOTICE:  BL2: Boot device is eMMC(50MHz x8)
[    0.029682] NOTICE:  BL2: LCM state is CM
[    0.033647] NOTICE:  BL2: 0x400000000 - 0x47fffffff, 2 GiB
[    0.039080] NOTICE:  BL2: DDR1856(rev.0.12)
[    0.043231] NOTICE:  BL2: [COLD_BOOT]
[    0.048483] NOTICE:  BL2: DRAM Split is OFF
[    0.051179] NOTICE:  BL2: QoS is default setting(rev.0.05)
[    0.056622] NOTICE:  BL2: DRAM refresh interval 3.9 usec
[    0.068842] NOTICE:  BL2: v1.5(release):61eac60f5-dirty
[    0.072573] NOTICE:  BL2: Built : 19:44:42, Dec 16 2020
[    0.077761] NOTICE:  BL2: Normal boot
[    0.081399] NOTICE:  BL2: eMMC boot from partition 1
[    0.086539] NOTICE:  BL2: Load dst=0xe6312100 src=(p:1)0x30000(384) len=0x200(1)
[    0.093922] NOTICE:  BL2: Load dst=0x43f00000 src=(p:1)0x30400(386) len=0x1800(12)
[    0.101589] NOTICE:  BL2: Load dst=0x44000000 src=(p:1)0x40000(512) len=0x10000(128)
[    0.110783] NOTICE:  BL2: Load dst=0x50000000 src=(p:2)0x0(0) len=0x100000(2048)
[    0.139578] NOTICE:  BL2: Booting BL31


U-Boot 2018.09-g3bc3f7369f-dirty (Dec 17 2020 - 16:51:50 +0900)

CPU: Renesas Electronics R8A774C0 rev 1.1
Model: Silicon Linux EK874 RZ/G2E board
DRAM:  1.9 GiB
Bank #0: 0x048000000 - 0x0bfffffff, 1.9 GiB

Watchdog: Not found by seq!
WDT:   watchdog@00000000e6020000
Watchdog: Started!
MMC:   sd@ee100000: 0, sd@ee160000: 1
Loading Environment from MMC... OK
In:    serial@e6e88000
Out:   serial@e6e88000
Err:   serial@e6e88000
Net:   
Error: ethernet@e6800000 address not set.
eth-1: ethernet@e6800000
Hit any key to stop autoboot:  2 
===Build Linux Kernel===
cd linux-cip
./build-g2e.sh
===Create Linux root filesystem=== Prepare a SD card with capacity of 16GB or more. Use partition tool like fdisk, create 2 partitions on SD card: first partition should be FAT16/32, with size at least 64MiB, secord partition should be ext4, size should be at least 8GiB. Copy files below into first partition (replace /dev/sdb1 to the first partition of your real SD card device path):
sudo -s
mount /dev/sdb1 /mnt
cp -v linux-cip/deploy/g2e/Image /mnt
cp -v linux-cip/deploy/g2e/r8a774c0-rzg2e-novotech.dtb /mnt
cp -v linux-cip/deploy/g2e/modules.tar.gz /mnt
umount /dev/sdb1
exit
Then create Debian 10 (Buster) rootfs:
sudo -s
apt-get install qemu-user-static debootstrap schroot

mkdir debian-rootfs
cd debian-rootfs
export ROOTFS="$(pwd)"
qemu-debootstrap --arch arm64 --variant buildd --include=ca-certificates,apt,wget,sudo,debootstrap,isc-dhcp-client,nano,network-manager buster "${ROOTFS}" http://deb.debian.org/debian

chroot "${ROOTFS}"
passwd root
#Input your root password

exit

tar -xf ../linux-cip/deploy/g2e/modules.tar.gz
tar -czpf ../debian-buster-rootfs.tar.gz .

exit
Mount and extract rootfs to the second partition of your SD card (replace /dev/sdb2 to your one).
sudo -s
mount /dev/sdb2 /mnt
tar -xpzf debian-buster-rootfs.tar.gz -C /mnt

# Copy rootfs to SD card so that you can install it to eMMC (Optional):
cp -v debian-buster-rootfs.tar.gz /mnt

umount /dev/sdb2
exit
===Boot kernel & rootfs from SD card=== At u-boot auto booting count down, press enter to break into u-boot command-line. Use commands below to boot from SD card:
setenv bootargs 'root=/dev/mmcblk0p2 rootwait rw'
fatload mmc 0:1 0x48080000 Image; fatload mmc 0:1 0x48000000 r8a774c0-rzg2e-novotech.dtb; booti 0x48080000 - 0x48000000
The device path of SD card is /dev/mmcblk0, and the path of eMMC is /dev/mmcblk2. Kernel and rootfs can be written into eMMC with the same partition structure as SD card. ==Using GPIO== {| class="wikitable" |- ! GPIO Bank !! Address |- | GPIO 0 || 494 |- | GPIO 1 || 471 |- | GPIO 2 || 445 |- | GPIO 3 || 429 |- | GPIO 4 || 418 |- | GPIO 5 || 398 |- | GPIO 6 || 380 |} GPIO Number = GPIO Bank Address + Pin Number. e.g, GPIO number of GPIO 2-2 is 445+2=447. You use user level interfaces in /sys/class/gpio to operate GPIOs. Just like other ARM platforms. You can check GPIO stats by reading /sys/kernel/debug/gpio:
sudo cat /sys/kernel/debug/gpio
==Using Audio SoC== At first running, ALSA should be configured with the commands below:
amixer cset name="HP Playback Switch" on
amixer cset name="HPO MIDAC1 Switch" on
amixer cset name="Stereo DAC MIXL DAC L1 Switch" on
amixer cset name="Stereo DAC MIXR DAC R1 Switch" on
amixer cset name="DAC MIXL INF1 Switch" on
amixer cset name="DAC MIXR INF1 Switch" on
amixer cset name="DAC MIXL Stereo ADC Switch" off
amixer cset name="DAC MIXR Stereo ADC Switch" off
amixer cset name="ADC Capture Switch" on
amixer cset name="Stereo1 ADC MIXL ADC1 Switch" on
amixer cset name="Stereo1 ADC MIXR ADC1 Switch" on

amixer cset name="HPO MIX DAC1 Switch" on
amixer cset name="LOUT MIX DAC L1 Switch" on

amixer cset name="RECMIXL INL1 Switch" on
amixer cset name="RECMIXR INR1 Switch" on
amixer cset name="RECMIXL BST1 Switch" on
amixer cset name="RECMIXR BST1 Switch" on

alsactl store
If you are using non-standard Linux distributions (like customized Yocto or buildroot), you should write the mixer configurations in startup script. ==Using Camera== Camera Module: OV5640 On Debian rootfs, use commands below to initialize media controller: FHD(1920x1080) mode:
media-ctl -d /dev/media0 -r
media-ctl -d /dev/media0 -l "'rcar_csi2 feaa0000.csi2':1 -> 'VIN4 output':0 [1]"
media-ctl -d /dev/media0 -V "'rcar_csi2 feaa0000.csi2':1 [fmt:UYVY8_2X8/1920x1080 field:none]"
media-ctl -d /dev/media0 -V "'ov5640 0-003c':0 [fmt:UYVY8_2X8/1920x1080 field:none]"
On Yocto rootfs, you can use script below to initialize media controller:
/home/root/setup_ov5645.sh
Camera device will be /dev/video0 on Debian rootfs, and /dev/video8 on Yocto rootfs. Camera subdev device will be /dev/v4l-subdev1 on Debian rootfs, and /dev/v4l-subdev18 on Yocto rootfs. You can use mediactl -d /dev/media0 -p to check device status. You can use commands below to configure camera parameters (on Debian rootfs):
#Set exposure
v4l2-ctl -d /dev/v4l-subdev1 --set-ctrl exposure=260

#Check camera controllers
v4l2-ctl -d /dev/v4l-subdev1 --list-ctrls
Use GStreamer to get a photo (on Debian rootfs):
gst-launch-1.0 v4l2src device=/dev/video0 num-buffers=1 ! video/x-raw,format=UYVY,width=1920,height=1080,framerate=30/1 ! videoconvert ! jpegenc ! filesink location=camsnap.jpg
Use GStreamer to show video from camera (on Yocto rootfs, need Wayland support):
gst-launch-1.0 v4l2src device=/dev/video8 io-mode=dmabuf ! video/x-raw,format=UYVY,width=1920,height=1080,framerate=30/1 ! vspfilter ! video/x-raw,format=BGRA,width=1280,height=720 ! waylandsink qos=false
Use GStreamer to record video (H.264, on Yocto rootfs, need Hardware H.264 encoding support):
gst-launch-1.0 -e v4l2src device=/dev/video8 io-mode=dmabuf ! video/x-raw,format=UYVY,width=1920,height=1080,framerate=30/1 ! vspfilter ! omxh264enc use-dmabuf=true target-bitrate=10485760 ! h264parse ! mp4mux ! filesink location=record.mp4
Use Ctrl+C to stop recording. Use GStreamer to send H.264 RTP stream (on Yocto rootfs, need Hardware H.264 encoding support, assume the IP address of your PC is 192.168.0.2):
gst-launch-1.0 -e v4l2src device=/dev/video8 io-mode=dmabuf ! video/x-raw,format=UYVY,width=1920,height=1080,framerate=30/1 ! vspfilter ! omxh264enc use-dmabuf=true target-bitrate=10485760 ! h264parse ! rtph264pay ! udpsink host=192.168.0.2 port=5003
And on your PC (need gst-launch-1.0 from GStreamer 1.0 tools, use ximagesink instead of xvimagesink if you are using virtual machine):
gst-launch-1.0 udpsrc port=5003 ! application/x-rtp ! rtph264depay ! avdec_h264 ! xvimagesink
==Known problems== ===WiFi module does not support random MAC=== By default, Network Manager will use random MAC for better security, somehow the module used on this board does not support it. You should disable it by edit file /etc/NetworkManager/NetworkManager.conf, add add lines below:
[device]
wifi.scan-rand-mac-address=no
===Set MAC address of ethernet card=== There is no EEPROM or SPI Flash to save MAC address for ethernet card. So you can set MAC address by yourself. e.g. Using Network Manager:
sudo nmtui
Edit your ethernet connection, unfold ETHERNET option, set "Cloned MAC address" to the address you want. Then exit the tool to save your settings. Or you can set MAC address in u-boot, press Enter key when u-boot is waiting for interrupting, then set MAC address with commands below:
setenv ethaddr "AC:F3:5F:1E:87:53"
saveenv
You can replace the address with the one you want. ===No Graphic Accelerations on Debian rootfs=== 2D/3D Graphic Accelerations are only supported in Renesas's customized Yocto, and only Wayland is supported. ===No Bayer Color Encoding Support=== Some cameras (like Sony IMX219) can only output RAW bayer video data, which is not supported by hardware encoders on the board. Even through you can convert color space with GStreamer element like bayer2rgb, it will cost lots of CPU resources and RAM bandwidth. ==Test== ===Enable Speaker Output===
echo 393 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio393/direction
echo 1 > /sys/class/gpio/gpio393/value
gst-launch-1.0 audiotestsrc ! audioconvert ! audioresample ! autoaudiosink
===Use Mic===
arecord -Dhw:0,0 -f S16_LE -t wav -r44100 -c 2 record.wav
Note: not support sample rate 48000
===RS485 Port===
TTY: ttySC2
Note:
1. disable flow control
2. bitrate less than 230400
==Tools== ===Bootloader Download===
The following operations are performed on Win10.
Get the download tool through the path:\\192.168.8.25\share\G2E\BootLoader Download
Copy the following five files to the "firmware" directory
      AArch64_Flash_writer_SCIF_DUMMY_CERT_E6300400_ek874.mot
      bl2.srec
      bl31.srec
      bootparam_sa0.srec
      cert_header_sa6.srec
      u-boot-elf.srec
Double click to open launcher.exe
Select the serial port connected to the development board from the drop-down box
If you have downloaded bootloader before, you need to plug in the jumper;Otherwise, ignore this step
Click the "Download" button
Click the reset button on the development board
When "Bootloader burning completed" appears in the log, the download has completed
===Kernal Upgrade Without SD Card===
Prepare kernel and root file system according to the previous instructions
Start tftpd service on a Linux server,refer to the following steps
          sudo apt-get install tftpd-hpa
          sudo vim /etc/default/tftpd-hpa
                    TFTP_USERNAME="tftp"
                    TFTP_DIRECTORY="/mnt/ssd3/yds/g2eroot"  # Replace the path according to your actual situation
                    TFTP_OPTIONS="-l -c -s"
                    TFTP_ADDRESS="0.0.0.0:69"
          sudo service tftpd-hpa restart
Copy the following two files to the tftpd server.My path is "/mnt/ssd3/yds/g2eroot",Replace the path according to your actual situation
Prepare a USB flash disk refer to "Create Linux root filesystem",Just change the SD card into a USB flash drive
Copy the upgrade package to the  path "/home/root" of the U disk
Insert the U-disk on the development board,Set serial port of PC to 115200bps, 8N1. Set boot mode of board to download mode. Connect Debug port of board to the serial port of PC. 
Power on the board, then something like "Hit any key to stop autoboot" will be printed on terminal,press enter key, "=>" will be printed.
Enter the following commands one after another, serverip is the IP of tftpd service host. for me, it is 192.168.10.246
          setenv bootargs 'root=/dev/sda2 rootwait rw'
          setenv ethaddr 00:a8:44:1f:1f:10
          setenv ipaddr 192.168.10.245
          setenv serverip 192.168.10.246
          setenv netmask 255.255.0.0
          saveenv
          tftp 0x48080000  Image
          tftp 0x48000000 r8a774c0-rzg2e-novotech.dtb
          booti 0x48080000 - 0x48000000
          gunzip -c rzg2e-debian-buster-sd-20210429.img.gz | dd of=/dev/mmcblk2 status=progress    #"rzg2e-debian-buster-sd-20210429.img.gz" is the name of upgrade packege,replace it according to your actual situation
Restart the system after upgrading, when something like "Hit any key to stop autoboot" is printed on terminal,press enter key.
Enter the following commands one after another
          env default -a
          saveenv
          boot
The upgrade is now complete

【Tools】You can also use tools to complete the above work
The following operations are performed on Win10.
Get the download tool through the path:\\192.168.8.25\share\G2E\G2E_Kernel_Download
Copy the following two files to the "KernelSource" directory
      r8a774c0-rzg2e-novotech.dtb
      Image
Prepare a USB flash disk refer to "Create Linux root filesystem",Just change the SD card into a USB flash drive
Copy the upgrade package to the  path "/home/root" of the U disk.
Double click to open launcher.exe
Select the serial port connected to the development board from the drop-down box
Click the "Open TFTP"    Notes:After this step,it is open the tftp service on your host, you should not prepare another tftp service computor.
Input the upgrade package name in the textedit box.
Click the "Download" button
Click the reset button on the development board
When "The kernel has been successfully updated." appears in the log, the download has completed