99
1010# Nuvoton MA35D1 SoC family - ARM Cortex-A35 dual-core + Cortex-M4
1111# Boot flow: Mask ROM (IBR) -> BL2 (TF-A) -> BL31 -> BL32 (OP-TEE) -> BL33 (U-Boot) -> Linux
12- ARCH="arm64"
12+ declare -g ARCH="arm64"
1313
1414# Disable BTF - 5.10.y kernel has issues with newer pahole/toolchain
1515declare -g KERNEL_BTF="no"
1616
1717# Use NetworkManager for network configuration
1818declare -g NETWORKING_STACK="network-manager"
19- ATF_PLAT="ma35d1"
20- BOOTDELAY=1
21- BOOTPATCHDIR="u-boot-nuvoton-ma35d1"
19+
20+ declare -g ATF_PLAT="ma35d1"
21+ declare -g BOOTDELAY=1
22+ declare -g BOOTPATCHDIR="u-boot-nuvoton-ma35d1"
2223
2324# U-Boot source from Nuvoton
24- BOOTSOURCE='https://github.com/OpenNuvoton/MA35D1_u-boot-v2020.07.git'
25- BOOTBRANCH='branch:master'
26- BOOTDIR='u-boot-nuvoton-ma35d1'
27- UBOOT_TARGET_MAP=";;u-boot.bin header.bin fip.bin bl2.bin bl31.bin bl2-ma35d1.dtb tee-header_v2.bin tee-pager_v2.bin"
25+ declare -g BOOTSOURCE='https://github.com/OpenNuvoton/MA35D1_u-boot-v2020.07.git'
26+ declare -g BOOTBRANCH='branch:master'
27+ declare -g BOOTDIR='u-boot-nuvoton-ma35d1'
28+ declare -g UBOOT_TARGET_MAP=";;u-boot.bin header.bin fip.bin bl2.bin bl31.bin bl2-ma35d1.dtb tee-header_v2.bin tee-pager_v2.bin"
2829
2930# TF-A source from Nuvoton
3031declare -g ATF_USE_GCC="> 8.0"
@@ -40,27 +41,27 @@ MA35D1_DDR_DTB="${MA35D1_DDR_DTB:-ma35d1-cpu800-wb-512m}"
4041# TF-A build: BL2 + BL31 + DTB (FIP is created later in uboot_custom_postprocess)
4142declare -g ATF_TARGET_MAP="PLAT=ma35d1 DEBUG=1 DTB_FILE_NAME=${MA35D1_DDR_DTB}.dtb bl2 bl31 dtbs;;build/ma35d1/debug/bl2.bin build/ma35d1/debug/bl31.bin build/ma35d1/debug/fdts/${MA35D1_DDR_DTB}.dtb:bl2-ma35d1.dtb"
4243
43- LINUXFAMILY="nuvoton-ma35d1"
44- IMAGE_PARTITION_TABLE="msdos"
44+ declare -g LINUXFAMILY="nuvoton-ma35d1"
45+ declare -g IMAGE_PARTITION_TABLE="msdos"
4546
4647# Boot script for loading kernel/initrd/dtb from partition
47- BOOTSCRIPT="boot-nuvoton-ma35d1.cmd:boot.cmd"
48- BOOTENV_FILE="nuvoton-ma35d1.txt"
48+ declare -g BOOTSCRIPT="boot-nuvoton-ma35d1.cmd:boot.cmd"
49+ declare -g BOOTENV_FILE="nuvoton-ma35d1.txt"
4950
5051case "${BRANCH}" in
5152 vendor)
5253 declare -g KERNEL_MAJOR_MINOR="5.10"
53- KERNELSOURCE='https://github.com/OpenNuvoton/MA35D1_linux-5.10.y.git'
54- KERNELBRANCH="branch:master"
55- KERNELPATCHDIR="nuvoton-ma35d1-${BRANCH}"
56- LINUXCONFIG="linux-nuvoton-ma35d1-${BRANCH}"
54+ declare -g KERNELSOURCE='https://github.com/OpenNuvoton/MA35D1_linux-5.10.y.git'
55+ declare -g KERNELBRANCH="branch:master"
56+ declare -g KERNELPATCHDIR="nuvoton-ma35d1-${BRANCH}"
57+ declare -g LINUXCONFIG="linux-nuvoton-ma35d1-${BRANCH}"
5758 ;;
5859esac
5960
60- KERNEL_TARGET="vendor"
61- CPUMIN=180000
62- CPUMAX=800000
63- GOVERNOR="ondemand"
61+ declare -g KERNEL_TARGET="vendor"
62+ declare -g CPUMIN=180000
63+ declare -g CPUMAX=800000
64+ declare -g GOVERNOR="ondemand"
6465
6566# Host dependencies for OP-TEE build
6667function add_host_dependencies__ma35d1_optee_deps() {
@@ -79,7 +80,7 @@ function fetch_sources_tools__ma35d1_fetch_optee() {
7980}
8081
8182# ATF post-processing: verify build outputs and build fiptool
82- atf_custom_postprocess() {
83+ function atf_custom_postprocess() {
8384 display_alert "Post-processing ATF" "MA35D1" "info"
8485
8586 local atf_src_dir="$(pwd)"
@@ -102,38 +103,38 @@ atf_custom_postprocess() {
102103 display_alert "ATF post-processing complete" "bl2.bin + bl31.bin + fiptool ready" "info"
103104}
104105
105- # Compile OP-TEE for MA35D1
106- compile_optee_ma35d1() {
107- local optee_src_dir="${SRC}/cache/sources/optee-os-ma35d1"
108- local optee_out_dir="${optee_src_dir}/out/arm-plat-nuvoton/core"
106+ # Post-process U-Boot: create FIP and Nuvoton boot header
107+ function uboot_custom_postprocess() {
108+ # Compile OP-TEE for MA35D1 (defined inside for correct hashing)
109+ function compile_optee_ma35d1() {
110+ local optee_src_dir="${SRC}/cache/sources/optee-os-ma35d1"
111+ local optee_out_dir="${optee_src_dir}/out/arm-plat-nuvoton/core"
109112
110- display_alert "Compiling OP-TEE" "MA35D1" "info"
113+ display_alert "Compiling OP-TEE" "MA35D1" "info"
111114
112- [[ -d "${optee_src_dir}" ]] || exit_with_error "OP-TEE source not found at ${optee_src_dir}"
115+ [[ -d "${optee_src_dir}" ]] || exit_with_error "OP-TEE source not found at ${optee_src_dir}"
113116
114- local cross_compile="aarch64-linux-gnu-"
117+ local cross_compile="aarch64-linux-gnu-"
115118
116- run_host_command_logged make -C "${optee_src_dir}" clean PLATFORM=nuvoton-MA35D1 2>/dev/null || true
119+ run_host_command_logged make -C "${optee_src_dir}" clean PLATFORM=nuvoton-MA35D1 2>/dev/null || true
117120
118- display_alert "Building OP-TEE" "PLATFORM=nuvoton-MA35D1" "info"
119- run_host_command_logged make -C "${optee_src_dir}" \
120- CROSS_COMPILE_core="${cross_compile}" \
121- CROSS_COMPILE_ta_arm64="${cross_compile}" \
122- PLATFORM=nuvoton-MA35D1 \
123- CFG_ARM64_core=y \
124- CFG_TEE_CORE_LOG_LEVEL=1 \
125- LDFLAGS="--no-warn-rwx-segments" \
126- NOWERROR=1 \
127- -j$(nproc)
121+ display_alert "Building OP-TEE" "PLATFORM=nuvoton-MA35D1" "info"
122+ run_host_command_logged make -C "${optee_src_dir}" \
123+ CROSS_COMPILE_core="${cross_compile}" \
124+ CROSS_COMPILE_ta_arm64="${cross_compile}" \
125+ PLATFORM=nuvoton-MA35D1 \
126+ CFG_ARM64_core=y \
127+ CFG_TEE_CORE_LOG_LEVEL=1 \
128+ LDFLAGS="--no-warn-rwx-segments" \
129+ NOWERROR=1 \
130+ -j$(nproc)
128131
129- [[ -f "${optee_out_dir}/tee-header_v2.bin" ]] || exit_with_error "OP-TEE build failed: tee-header_v2.bin not found"
130- [[ -f "${optee_out_dir}/tee-pager_v2.bin" ]] || exit_with_error "OP-TEE build failed: tee-pager_v2.bin not found"
132+ [[ -f "${optee_out_dir}/tee-header_v2.bin" ]] || exit_with_error "OP-TEE build failed: tee-header_v2.bin not found"
133+ [[ -f "${optee_out_dir}/tee-pager_v2.bin" ]] || exit_with_error "OP-TEE build failed: tee-pager_v2.bin not found"
131134
132- display_alert "OP-TEE built successfully" "MA35D1" "info"
133- }
135+ display_alert "OP-TEE built successfully" "MA35D1" "info"
136+ }
134137
135- # Post-process U-Boot: create FIP and Nuvoton boot header
136- uboot_custom_postprocess() {
137138 display_alert "Creating MA35D1 boot images" "BL2 + OP-TEE + FIP + Header" "info"
138139
139140 local atf_dir="${SRC}/cache/sources/${ATFDIR}/${ATFBRANCH##*:}"
@@ -247,28 +248,29 @@ uboot_custom_postprocess() {
247248
248249# Write bootloader to SD card/image
249250# Note: This only works during image creation, not on target board
250- write_uboot_platform() {
251+ function write_uboot_platform() {
251252 local src_dir="$1"
252253 local target_dev="$2"
253254
254- display_alert "Writing MA35D1 bootloader" "${target_dev}" "info"
255-
256255 local header_bin="${src_dir}/header.bin"
257256 local bl2_dtb_bin="${src_dir}/bl2-ma35d1.dtb"
258257 local bl2_bin="${src_dir}/bl2.bin"
259258 local fip_bin="${src_dir}/fip.bin"
260259
261- [[ -f "${header_bin}" ]] || { display_alert "Missing" " header.bin" "err "; return 1; }
262- [[ -f "${bl2_bin}" ]] || { display_alert "Missing" " bl2.bin" "err "; return 1; }
263- [[ -f "${fip_bin}" ]] || { display_alert "Missing" " fip.bin" "err "; return 1; }
260+ [[ -f "${header_bin}" ]] || { echo "Missing header.bin"; return 1; }
261+ [[ -f "${bl2_bin}" ]] || { echo "Missing bl2.bin"; return 1; }
262+ [[ -f "${fip_bin}" ]] || { echo "Missing fip.bin"; return 1; }
264263
264+ # Write header at 1KB and 1.5KB offsets (sectors 2 and 3)
265265 dd if="${header_bin}" of="${target_dev}" bs=512 seek=2 conv=notrunc status=none
266266 dd if="${header_bin}" of="${target_dev}" bs=512 seek=3 conv=notrunc status=none
267267
268+ # Write DTB at 128KB offset (0x20000)
268269 [[ -f "${bl2_dtb_bin}" ]] && dd if="${bl2_dtb_bin}" of="${target_dev}" bs=1024 seek=128 conv=notrunc status=none
269270
271+ # Write BL2 at 192KB offset (0x30000)
270272 dd if="${bl2_bin}" of="${target_dev}" bs=1024 seek=192 conv=notrunc status=none
271- dd if="${fip_bin}" of="${target_dev}" bs=1024 seek=768 conv=notrunc status=none
272273
273- display_alert "Bootloader written" "header + bl2 + fip" "info"
274+ # Write FIP at 768KB offset (0xC0000)
275+ dd if="${fip_bin}" of="${target_dev}" bs=1024 seek=768 conv=notrunc status=none
274276}
0 commit comments