Steps and principle analysis of porting 2022 U-Boot for Exynos4412

Posted by stallingjohn on Sat, 08 Jan 2022 09:45:51 +0100

This article mainly describes how to transplant u-boot-2022.01-rc4 to the cbt4412 core board (similar to the tiny4412 core board), and analyzes the reasons for modifying the file code. (there is a link to download the source code of GitHub at the end of the article)

To transplant U-Boot, first select the development board with the same processor and the closest hardware configuration. Many bloggers choose exynos4412 original board, which is feasible.
However, the author reminds beginners that Samsung's Exynos4412 needs to use mkbl2 tool, which is not available in U-Boot, so you can download the author's success code first and go through the whole process, including compiling and downloading to the development board for startup. After success, transplant it yourself again. In this way, there will be fewer make errors and compilation errors. Relatively easy, can improve self-confidence.

1, Get the U-Boot source code

See another blog post by the author.1

2, Creation and modification of board level files

1. Copy the folder board / sampling / origin / and rename it board / sampling / cbt4412/

cp -rf board/samsung/origen/ board/samsung/cbt4412

The folder name can be named according to your own development board. In this folder are the relevant files of origen development board. You should change the code of the relevant files to the relevant code of your own development board.

2. Change board / sampling / cbt4412 / origin C file name is cbt4412 c

mv board/samsung/cbt4412/origen.c board/samsung/cbt4412/cbt4412.c

3. Modify board / sampling / cbt4412 / makefile

This is easy to understand. Change the name of the generated target file to cbt4412 (or other development board name).

@@ -6,7 +6,7 @@ ifdef CONFIG_SPL_BUILD
 # necessary to create built-in.o
 obj- := __dummy__.o
 
+hostprogs-y := tools/mkcbt4412spl
-hostprogs-y := tools/mkorigenspl
 always := $(hostprogs-y)
 
 # omit -O2 option to suppress
@@ -14,7 +14,7 @@ always := $(hostprogs-y)
 #
 # TODO:
 # Fix the root cause in tools/mkorigenspl.c and delete the following work-around
+$(obj)/tools/mkcbt4412spl: HOSTCFLAGS:=$(filter-out -O2,$(HOSTCFLAGS))
-$(obj)/tools/mkorigenspl: HOSTCFLAGS:=$(filter-out -O2,$(HOSTCFLAGS))
 else
+obj-y  += cbt4412.o
-obj-y  += origen.o
 endif

4. Modify board / sampling / cbt4412 / maintainers

@@ -1,6 +1,6 @@
+CBT4412 BOARD
-ORIGEN BOARD
 M:     Minkyu Kang <mk7.kang@samsung.com>
 S:     Maintained
+F:     board/samsung/cbt4412/
+F:     include/configs/cbt4412.h
+F:     configs/cbt4412_defconfig
-F:     board/samsung/origen/
-F:     include/configs/origen.h
-F:     configs/origen_defconfig

5. Modify board / sampling / cbt4412 / kconfig

@@ -1,12 +1,12 @@
+if TARGET_CBT4412
-if TARGET_ORIGEN
 
 config SYS_BOARD
+       default "cbt4412"
-       default "origen"
 
 config SYS_VENDOR
        default "samsung"
 
 config SYS_CONFIG_NAME
+       default "cbt4412"
-       default "origen"
 
 endif

6. Change board / sampling / cbt4412 / tools / mkorigenspl C is mkcbt4412spl c

3, Creation and modification of configuration file

1. Change include / configs / origin H file name is cbt4412 h. And modify the code

cp include/configs/origen.h include/configs/cbt4412.h

include/configs/cbt4412.h header file is very important. It should be deeply understood and configured correctly.

@@ -10,17 +10,31 @@
 
 #include <configs/exynos4-common.h>
 
 /* High Level Configuration Options */
  #define CONFIG_EXYNOS4412		1	/* which is a EXYNOS4412 SoC */
- #define CONFIG_ORIGEN4412		1	/* working with ORIGEN4412 */  
+ #define CONFIG_CBT4412			1	/* working with CBT4412*/
 
-/* ORIGEN has 4 bank of DRAM */
+/* CBT4412 has 4 bank of DRAM */
 #define CONFIG_SYS_SDRAM_BASE		0x40000000
 #define PHYS_SDRAM_1			CONFIG_SYS_SDRAM_BASE
 #define SDRAM_BANK_SIZE			(256 << 20)	/* 256 MB */
 
+/* memtest works on */
+/* #define CONFIG_SYS_LOAD_ADDR		(CONFIG_SYS_SDRAM_BASE + 0x3E00000) */
+
+#define CONFIG_MACH_TYPE		MACH_TYPE_EXYNOS4412
+
+/* select serial console configuration */
+
+/* Console configuration */
+#define CONFIG_DEFAULT_CONSOLE		"console=ttySAC0,115200n8\0"
+
+
 #define CONFIG_SYS_MEM_TOP_HIDE	(1 << 20)	/* ram console */
 
 #define CONFIG_SYS_MONITOR_BASE	0x00000000
@@ -38,7 +52,7 @@
 	"rdaddr=0x48000000\0" \
 	"kerneladdr=0x40007000\0" \
 	"ramdiskaddr=0x48000000\0" \
-	"console=ttySAC2,115200n8\0" \
+	"console=ttySAC0,115200n8\0" \
 	"mmcdev=0\0" \
 	"bootenv=uEnv.txt\0" \
 	"loadbootenv=load mmc ${mmcdev} ${loadaddr} ${bootenv}\0" \
@@ -70,15 +84,20 @@
 #define CONFIG_MIU_2BIT_21_7_INTERLEAVED
 
 #define RESERVE_BLOCK_SIZE		(512)
-#define BL1_SIZE			(16 << 10) /*16 K reserved for BL1*/
+#define BL1_SIZE			(8 << 10) /*8 K reserved for BL1*/
+#define BL2_SIZE			(16 << 10) /*16 K reserved for BL2*/
 
 #define CONFIG_SPL_MAX_FOOTPRINT	(14 * 1024)
 
 #define CONFIG_SYS_INIT_SP_ADDR		0x02040000
 
 /* U-Boot copy size from boot Media to DRAM.*/
-#define COPY_BL2_SIZE		0x80000
-#define BL2_START_OFFSET	((CONFIG_ENV_OFFSET + CONFIG_ENV_SIZE)/512)
-#define BL2_SIZE_BLOC_COUNT	(COPY_BL2_SIZE/512)
+#define COPY_UBOOT_SIZE		0xC8000 //800KB
+#define UBOOT_START_OFFSET	((RESERVE_BLOCK_SIZE + BL1_SIZE + BL2_SIZE) /512)
+#define UBOOT_SIZE_BLOC_COUNT	(COPY_UBOOT_SIZE /512)
+
+#define COPY_BL2_SIZE		0x4000
+#define BL2_START_OFFSET	((RESERVE_BLOCK_SIZE + BL1_SIZE) /512)
+#define BL2_SIZE_BLOC_COUNT	(COPY_BL2_SIZE /512)
 
 #endif	/* __CONFIG_H */

(1)#define CONFIG_MACH_TYPE MACH_TYPE_EXYNOS4412

The machine code of u-boot should be consistent with that of linux kernel. On the Internet, most of the machine codes of the modified linux kernel are in arch / arm / tools / Mach types H medium.
Find arch / arm / include / ASM / Mach types in U-Boot h. Exist
#define MACH_TYPE_TINY4412 4608
#define MACH_TYPE_EXYNOS4412 5030
Therefore, configure CONFIG_MACH_TYPE is MACH_TYPE_EXYNOS4412.

(2)#define CONFIG_DEFAULT_CONSOLE "console=ttySAC0,115200n8\0"

The default terminal configuration is serial port 0, baud rate 115200 and data bit 8.

(3) Configuration of BL1 and BL2

BL1 (first boot loader) starts burning from the offset of 512B of SD card, and BL2 starts burning from Block17 of SD card.2
Therefore, the actual addresses and sizes of BL1 and BL2 need to be configured.

 /* U-Boot copy size from boot Media to DRAM.*/
-#define COPY_BL2_SIZE		0x80000
-#define BL2_START_OFFSET	((CONFIG_ENV_OFFSET + CONFIG_ENV_SIZE)/512)
-#define BL2_SIZE_BLOC_COUNT	(COPY_BL2_SIZE/512)
+#define COPY_UBOOT_SIZE		0xC8000 //800KB
+#define UBOOT_START_OFFSET	((RESERVE_BLOCK_SIZE + BL1_SIZE + BL2_SIZE) /512)
+#define UBOOT_SIZE_BLOC_COUNT	(COPY_UBOOT_SIZE /512)
+
+#define COPY_BL2_SIZE		0x4000
+#define BL2_START_OFFSET	((RESERVE_BLOCK_SIZE + BL1_SIZE) /512)
+#define BL2_SIZE_BLOC_COUNT	(COPY_BL2_SIZE /512)

2. Copy configs / origin_ Defconfig is configs/cbt4412_defconfig and modify the code

This file is very important and is the key to automatically generating Makefile. The function of macro identifier can be seen from the macro definition name.
+CONFIG_DEBUG_UART_BASE=0x13800000 is the address for configuring serial port 0
+CONFIG_DEBUG_UART_CLOCK=100000000 is to configure the clock of serial port 0 to 100MHz
+CONFIG_DEFAULT_DEVICE_TREE = "exynos4412-cbt4412" is related to the device tree
+CONFIG_SYS_PROMPT = "CBT4412 #" is the prompt after U-Boot starts

@@ -1,5 +1,16 @@
+CONFIG_SPL_SERIAL_SUPPORT=1
+CONFIG_SPL_GPIO_SUPPORT=1
+CONFIG_DEBUG_UART_S5P=1
+#CONFIG_DEBUG_UART=1
+CONFIG_SPL_SERIAL=1
+CONFIG_DEBUG_UART_BASE=0x13800000
+CONFIG_DEBUG_UART_CLOCK=100000000
+CONFIG_DEBUG_UART_ANNOUNCE=y
+CONFIG_SPL_BUILD=y
+CONFIG_EXYNOS4412=y
+CONFIG_S5P=y
+CONFIG_ARM=y
 CONFIG_SKIP_LOWLEVEL_INIT=y
 CONFIG_SPL_SKIP_LOWLEVEL_INIT=y
 CONFIG_SYS_DCACHE_OFF=y
 CONFIG_ARCH_CPU_INIT=y
@@ -11,7 +22,7 @@ CONFIG_TARGET_CBT4412=y
 CONFIG_ENV_SIZE=0x4000
 CONFIG_ENV_OFFSET=0x4200
-CONFIG_DEFAULT_DEVICE_TREE="exynos4412-origen4412"
+CONFIG_DEFAULT_DEVICE_TREE="exynos4412-cbt4412"
-CONFIG_SPL_TEXT_BASE=0x02021410
+CONFIG_SPL_TEXT_BASE=0x02023400
 CONFIG_SPL=y
 CONFIG_IDENT_STRING=" for CBT4412"
 CONFIG_DISTRO_DEFAULTS=y
@@ -20,7 +31,7 @@ CONFIG_SYS_LOAD_ADDR=0x43e00000
 CONFIG_SYS_CONSOLE_IS_IN_ENV=y
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
 # CONFIG_SPL_FRAMEWORK is not set
-CONFIG_SYS_PROMPT="ORIGEN4412 # "
+CONFIG_SYS_PROMPT="CBT4412 #"

4, Modify equipment tree related configuration

1. Copy / arch / arm / DTS / exynos4210 origin DTS is exynos4412-cbt4412 DTS, and modify

Change the origen source code to the following code.
This is about the configuration of the device tree, which is very important. The function realized here is to configure serial port 0 as the default terminal. If the device tree syntax is wrong, the serial port 0 will not work.

// SPDX-License-Identifier: GPL-2.0+
/*
 * Samsung's Exynos4210 based Origen board device tree source
 *
 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
 *		http://www.samsung.com
 */

/dts-v1/;
#include "skeleton.dtsi"
#include "exynos4412.dtsi"

/ {
	model = "CBt4412 board based on Exynos4412";
	compatible = "samsung,cbt4412", "samsung,exynos4412";

	chosen {
		bootargs ="";
		};

	aliases {
		serial0 = "/serial@13800000";
		serial1 = "/serial@13800020";
		console = "/serial@13800000";
		
	};

};

2. Modify / arch/arm/dts/Makefile

Add cbt4412 core board device tree compilation.

dtb-$(CONFIG_EXYNOS4) += exynos4210-origen.dtb \
	exynos4210-smdkv310.dtb \
	exynos4210-universal_c210.dtb \
	exynos4210-trats.dtb \
	exynos4412-trats2.dtb \
-	exynos4412-odroid.dtb
+	exynos4412-odroid.dtb \
+	exynos4412-cbt4412.dtb

5, SoC level modifications

1. Configuration of clock, DMC and serial port 0

The path arch / arm / Mach exynos / is all about the code of exynos series chips. The modification of clock and the opening of DRAM are all here.
The source files of the design include:
arch/arm/mach-exynos/include/mach/clock.h
clock_init_exynos4412.c
dmc_init_exynos4412.c
exynos4412_setup.h
Makefile (there are further modifications on this basis, see below)
lowlevel_init.c
spl_boot.c
For the specific modification method, please refer to sanzhouzi's blog. My personal test is feasible and correct.3
I suggest beginners directly copy the source file in GitHub.

Among them, lowlevel_ init. The pin taking function of serial port 0 is configured in C to enable serial port 0.

2. Modify arch / arm / Mach exynos / kconfig

This step is important because #define config is generated automatically_ SYS_ BOARD “cbt4412”.
Add the following code where appropriate.

+config TARGET_CBT4412
+	bool "Exynos4412 CBT4412 board"	
+	select SUPPORT_SPL

+source "board/samsung/cbt4412/Kconfig"

3. Modify / arch / arm / Mach exynos / makefile

If you do not add + obj-$(CONFIG_S5P) += s5p_gpio.o. Errors will be reported during compilation, and several function definitions cannot be found.

# SPDX-License-Identifier: GPL-2.0+
#
# Copyright (C) 2009 Samsung Electronics
# Minkyu Kang <mk7.kang@samsung.com>

obj-y	+= soc.o
obj-$(CONFIG_CPU_V7A) += clock.o pinmux.o power.o system.o
obj-$(CONFIG_ARM64)	+= mmu-arm64.o

obj-$(CONFIG_EXYNOS5420)	+= sec_boot.o
+obj-$(CONFIG_S5P)	+= s5p_gpio.o
@@ -13,6 +13,7 @@
 obj-$(CONFIG_EXYNOS5)	+= clock_init_exynos5.o
 obj-$(CONFIG_EXYNOS5)	+= dmc_common.o dmc_init_ddr3.o
 obj-$(CONFIG_EXYNOS4210)+= dmc_init_exynos4.o clock_init_exynos4.o
+obj-$(CONFIG_EXYNOS4412)+= dmc_init_exynos4412.o clock_init_exynos4412.o
 obj-y	+= spl_boot.o tzpc.o
 obj-y	+= lowlevel_init.o
 endif

6, Add whitelist scripts/config_whitelist.txt

In scripts/config_whitelist.txt
CONFIG_CBT4412
CONFIG_EXYNOS4412
CONFIG_DEFAULT_CONSOLE
Otherwise, an error is reported: make Error: you must add new config options using kconfig The following new ad-hoc CONFIG options were detected.
Note that the following must be added in alphabetical order:

@@ -100,6 +100,7 @@ CONFIG_BS_SIZE
 CONFIG_BTB
 CONFIG_BUILD_ENVCRC
 CONFIG_BUS_WIDTH
+CONFIG_CBT4412
 CONFIG_CDP_APPLIANCE_VLAN_TYPE
 CONFIG_CDP_CAPABILITIES
 CONFIG_CDP_DEVICE_ID
@@ -189,6 +190,7 @@ CONFIG_DEBUG_UART_LINFLEXUART
 CONFIG_DEBUG_WRITECOUNT
 CONFIG_DEEP_SLEEP
 CONFIG_DEFAULT
+CONFIG_DEFAULT_CONSOLE
 CONFIG_DEFAULT_IMMR
 CONFIG_DESIGNWARE_ETH
 CONFIG_DEVICE_TREE_LIST
@@ -294,6 +296,7 @@ CONFIG_EXT_PHY
 CONFIG_EXT_USB_HOST_BASE
 CONFIG_EXYNOS4
 CONFIG_EXYNOS4210
+CONFIG_EXYNOS4412
 CONFIG_EXYNOS5
 CONFIG_EXYNOS5250
 CONFIG_EXYNOS5420

7, Compiling U-Boot

In the Ubuntu terminal, enter:

ARCH=arm && CROSS_COMPILE=arm-none-linux-gnueabihf- && export ARCH CROSS_COMPILE
make distclean && make cbt4412_defconfig && make

Cross here_ Compile is configured to your own cross compiler name.
If displayed

./spl/board/samsung/cbt4412/tools/mkcbt4412spl  spl/u-boot-spl.bin spl/cbt4412-spl.bin
  COPY    u-boot.dtb

Indicates that the compilation was successful. Note that this is all about cbt4412. If it is not the previously configured core board model, it indicates that there is a macro definition CONFIG_XXX_XXX is not configured correctly.

8, SD card burning

1,sd_ fusing. Analysis of SH script

Since I don't have the mkbl2 provided by Samsung, I use it It's a three week script sd_fusing.sh, pro test available.3
Beginners can put / SD directly_ Fuse / copy out.
Open / sd_fuse/tiny4412/sd_fusing.sh, you can see that MKBL2 sets... /... / SPL / u-boot-spl After the bin is verified, bl2.0 is generated bin.

####################################
# check files

E4412_UBOOT=../../u-boot.bin
E4412_UBOOT_SPL=../../spl/u-boot-spl.bin
MKBL2=../mkbl2

if [ ! -f ${E4412_UBOOT} ]; then
	echo "Error: u-boot.bin NOT found, please build it & try again."
	exit -1
fi

if [ ! -f ${MKBL2} ]; then
	echo "Error: can not find host tool - mkbl2, stop."
	exit -1
fi

#<make bl2>
${MKBL2} ${E4412_UBOOT_SPL} bl2.bin 14336

####################################

The following code shows that the address of BL1 is in the first block and the address of BL2 is in the 17th block. bl2.bin is written from the position of the 17th block.

####################################
# fusing images

signed_bl1_position=1
bl2_position=17
uboot_position=49
#tzsw_position=705
#tzsw_position=1649

#<BL1 fusing>
echo "---------------------------------------"
echo "BL1 fusing"
dd iflag=dsync oflag=dsync if=./E4412_N.bl1.bin of=$1 seek=$signed_bl1_position

#<BL2 fusing>
echo "---------------------------------------"
echo "BL2 fusing"
dd iflag=dsync oflag=dsync if=./bl2.bin of=$1 seek=$bl2_position

#<u-boot fusing>
echo "---------------------------------------"
echo "u-boot fusing"
dd iflag=dsync oflag=dsync if=${E4412_UBOOT} of=$1 seek=$uboot_position

2. SD card burning steps

For specific steps, please refer to Part 4 of another blog post.2

9, Open the serial port tool to check the startup of uboot

In win10 system, I set the parameters of COM6 port as baud rate 115200, 8-bit data bit, 1-bit stop bit and no parity bit.
Open xshell and connect COM6 port, which is connected to serial port 0 of cbt4412 core board.

U-Boot 2022.01-rc4 (Jan 08 2022 - 15:40:53 +0800) for CBT4412

CPU:   Exynos4412 @ 1.4 GHz
Model: CBt4412 board based on Exynos4412
DRAM:  1 GiB
WARNING: Caches not enabled
MMC:   
Loading Environment from MMC... MMC Device 2 not found
*** Warning - No MMC card found, using default environment

Hit any key to stop autoboot:  0 
No MMC device available
Couldn't find partition mmc 0
Can't set block device
Wrong Image Format for bootm command
ERROR: can't get kernel image!
CBT4412 #

Remaining work:

The migration work described here is only the beginning. There are still many work to be done later. For example, uart cannot be used without debug mode, uboot cannot be started in eMMC, USB function is not supported, network function is not available, and so on. It needs to be further improved.
Throw a brick and attract jade for everyone to discuss. Please comment on any mistakes. I hope bloggers can share the method of U-Boot supporting DM9000 network card.

  1. Different versions of U-Boot have different migration steps ↩︎

  2. Ubuntu18.04 format SD card file type when burning U-Boot ↩︎ ↩︎

  3. tiny4412 uboot 2020.10 version migration ↩︎ ↩︎

Topics: Linux U-boot