diff --git a/config/sources/families/nuvoton-ma35d1.conf b/config/sources/families/nuvoton-ma35d1.conf index 3d081ba73b..3898f019f9 100644 --- a/config/sources/families/nuvoton-ma35d1.conf +++ b/config/sources/families/nuvoton-ma35d1.conf @@ -9,22 +9,23 @@ # Nuvoton MA35D1 SoC family - ARM Cortex-A35 dual-core + Cortex-M4 # Boot flow: Mask ROM (IBR) -> BL2 (TF-A) -> BL31 -> BL32 (OP-TEE) -> BL33 (U-Boot) -> Linux -ARCH="arm64" +declare -g ARCH="arm64" # Disable BTF - 5.10.y kernel has issues with newer pahole/toolchain declare -g KERNEL_BTF="no" # Use NetworkManager for network configuration declare -g NETWORKING_STACK="network-manager" -ATF_PLAT="ma35d1" -BOOTDELAY=1 -BOOTPATCHDIR="u-boot-nuvoton-ma35d1" + +declare -g ATF_PLAT="ma35d1" +declare -g BOOTDELAY=1 +declare -g BOOTPATCHDIR="u-boot-nuvoton-ma35d1" # U-Boot source from Nuvoton -BOOTSOURCE='https://github.com/OpenNuvoton/MA35D1_u-boot-v2020.07.git' -BOOTBRANCH='branch:master' -BOOTDIR='u-boot-nuvoton-ma35d1' -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" +declare -g BOOTSOURCE='https://github.com/OpenNuvoton/MA35D1_u-boot-v2020.07.git' +declare -g BOOTBRANCH='branch:master' +declare -g BOOTDIR='u-boot-nuvoton-ma35d1' +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" # TF-A source from Nuvoton declare -g ATF_USE_GCC="> 8.0" @@ -40,27 +41,27 @@ MA35D1_DDR_DTB="${MA35D1_DDR_DTB:-ma35d1-cpu800-wb-512m}" # TF-A build: BL2 + BL31 + DTB (FIP is created later in uboot_custom_postprocess) declare -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" -LINUXFAMILY="nuvoton-ma35d1" -IMAGE_PARTITION_TABLE="msdos" +declare -g LINUXFAMILY="nuvoton-ma35d1" +declare -g IMAGE_PARTITION_TABLE="msdos" # Boot script for loading kernel/initrd/dtb from partition -BOOTSCRIPT="boot-nuvoton-ma35d1.cmd:boot.cmd" -BOOTENV_FILE="nuvoton-ma35d1.txt" +declare -g BOOTSCRIPT="boot-nuvoton-ma35d1.cmd:boot.cmd" +declare -g BOOTENV_FILE="nuvoton-ma35d1.txt" case "${BRANCH}" in vendor) declare -g KERNEL_MAJOR_MINOR="5.10" - KERNELSOURCE='https://github.com/OpenNuvoton/MA35D1_linux-5.10.y.git' - KERNELBRANCH="branch:master" - KERNELPATCHDIR="nuvoton-ma35d1-${BRANCH}" - LINUXCONFIG="linux-nuvoton-ma35d1-${BRANCH}" + declare -g KERNELSOURCE='https://github.com/OpenNuvoton/MA35D1_linux-5.10.y.git' + declare -g KERNELBRANCH="branch:master" + declare -g KERNELPATCHDIR="nuvoton-ma35d1-${BRANCH}" + declare -g LINUXCONFIG="linux-nuvoton-ma35d1-${BRANCH}" ;; esac -KERNEL_TARGET="vendor" -CPUMIN=180000 -CPUMAX=800000 -GOVERNOR="ondemand" +declare -g KERNEL_TARGET="vendor" +declare -g CPUMIN=180000 +declare -g CPUMAX=800000 +declare -g GOVERNOR="ondemand" # Host dependencies for OP-TEE build function add_host_dependencies__ma35d1_optee_deps() { @@ -79,7 +80,7 @@ function fetch_sources_tools__ma35d1_fetch_optee() { } # ATF post-processing: verify build outputs and build fiptool -atf_custom_postprocess() { +function atf_custom_postprocess() { display_alert "Post-processing ATF" "MA35D1" "info" local atf_src_dir="$(pwd)" @@ -102,38 +103,38 @@ atf_custom_postprocess() { display_alert "ATF post-processing complete" "bl2.bin + bl31.bin + fiptool ready" "info" } -# Compile OP-TEE for MA35D1 -compile_optee_ma35d1() { - local optee_src_dir="${SRC}/cache/sources/optee-os-ma35d1" - local optee_out_dir="${optee_src_dir}/out/arm-plat-nuvoton/core" - - display_alert "Compiling OP-TEE" "MA35D1" "info" - - [[ -d "${optee_src_dir}" ]] || exit_with_error "OP-TEE source not found at ${optee_src_dir}" - - local cross_compile="aarch64-linux-gnu-" - - run_host_command_logged make -C "${optee_src_dir}" clean PLATFORM=nuvoton-MA35D1 2>/dev/null || true - - display_alert "Building OP-TEE" "PLATFORM=nuvoton-MA35D1" "info" - run_host_command_logged make -C "${optee_src_dir}" \ - CROSS_COMPILE_core="${cross_compile}" \ - CROSS_COMPILE_ta_arm64="${cross_compile}" \ - PLATFORM=nuvoton-MA35D1 \ - CFG_ARM64_core=y \ - CFG_TEE_CORE_LOG_LEVEL=1 \ - LDFLAGS="--no-warn-rwx-segments" \ - NOWERROR=1 \ - -j$(nproc) - - [[ -f "${optee_out_dir}/tee-header_v2.bin" ]] || exit_with_error "OP-TEE build failed: tee-header_v2.bin not found" - [[ -f "${optee_out_dir}/tee-pager_v2.bin" ]] || exit_with_error "OP-TEE build failed: tee-pager_v2.bin not found" - - display_alert "OP-TEE built successfully" "MA35D1" "info" -} - # Post-process U-Boot: create FIP and Nuvoton boot header -uboot_custom_postprocess() { +function uboot_custom_postprocess() { + # Compile OP-TEE for MA35D1 (defined inside for correct hashing) + function compile_optee_ma35d1() { + local optee_src_dir="${SRC}/cache/sources/optee-os-ma35d1" + local optee_out_dir="${optee_src_dir}/out/arm-plat-nuvoton/core" + + display_alert "Compiling OP-TEE" "MA35D1" "info" + + [[ -d "${optee_src_dir}" ]] || exit_with_error "OP-TEE source not found at ${optee_src_dir}" + + local cross_compile="aarch64-linux-gnu-" + + run_host_command_logged make -C "${optee_src_dir}" clean PLATFORM=nuvoton-MA35D1 2>/dev/null || true + + display_alert "Building OP-TEE" "PLATFORM=nuvoton-MA35D1" "info" + run_host_command_logged make -C "${optee_src_dir}" \ + CROSS_COMPILE_core="${cross_compile}" \ + CROSS_COMPILE_ta_arm64="${cross_compile}" \ + PLATFORM=nuvoton-MA35D1 \ + CFG_ARM64_core=y \ + CFG_TEE_CORE_LOG_LEVEL=1 \ + LDFLAGS="--no-warn-rwx-segments" \ + NOWERROR=1 \ + -j$(nproc) + + [[ -f "${optee_out_dir}/tee-header_v2.bin" ]] || exit_with_error "OP-TEE build failed: tee-header_v2.bin not found" + [[ -f "${optee_out_dir}/tee-pager_v2.bin" ]] || exit_with_error "OP-TEE build failed: tee-pager_v2.bin not found" + + display_alert "OP-TEE built successfully" "MA35D1" "info" + } + display_alert "Creating MA35D1 boot images" "BL2 + OP-TEE + FIP + Header" "info" local atf_dir="${SRC}/cache/sources/${ATFDIR}/${ATFBRANCH##*:}" @@ -247,28 +248,29 @@ uboot_custom_postprocess() { # Write bootloader to SD card/image # Note: This only works during image creation, not on target board -write_uboot_platform() { +function write_uboot_platform() { local src_dir="$1" local target_dev="$2" - display_alert "Writing MA35D1 bootloader" "${target_dev}" "info" - local header_bin="${src_dir}/header.bin" local bl2_dtb_bin="${src_dir}/bl2-ma35d1.dtb" local bl2_bin="${src_dir}/bl2.bin" local fip_bin="${src_dir}/fip.bin" - [[ -f "${header_bin}" ]] || { display_alert "Missing" "header.bin" "err"; return 1; } - [[ -f "${bl2_bin}" ]] || { display_alert "Missing" "bl2.bin" "err"; return 1; } - [[ -f "${fip_bin}" ]] || { display_alert "Missing" "fip.bin" "err"; return 1; } + [[ -f "${header_bin}" ]] || { echo "Missing header.bin"; return 1; } + [[ -f "${bl2_bin}" ]] || { echo "Missing bl2.bin"; return 1; } + [[ -f "${fip_bin}" ]] || { echo "Missing fip.bin"; return 1; } + # Write header at 1KB and 1.5KB offsets (sectors 2 and 3) dd if="${header_bin}" of="${target_dev}" bs=512 seek=2 conv=notrunc status=none dd if="${header_bin}" of="${target_dev}" bs=512 seek=3 conv=notrunc status=none + # Write DTB at 128KB offset (0x20000) [[ -f "${bl2_dtb_bin}" ]] && dd if="${bl2_dtb_bin}" of="${target_dev}" bs=1024 seek=128 conv=notrunc status=none + # Write BL2 at 192KB offset (0x30000) dd if="${bl2_bin}" of="${target_dev}" bs=1024 seek=192 conv=notrunc status=none - dd if="${fip_bin}" of="${target_dev}" bs=1024 seek=768 conv=notrunc status=none - display_alert "Bootloader written" "header + bl2 + fip" "info" + # Write FIP at 768KB offset (0xC0000) + dd if="${fip_bin}" of="${target_dev}" bs=1024 seek=768 conv=notrunc status=none }