【 Intel/Altera FPGA技术实战 】Stratix 10 SOC U-Boot & ATF (Arm Trusted Firmware) Build(六)

一、前言

上节我们已经大致介绍了Stratix 10 SOC的Boot机制,在此基础上提出了Boot方式的选择方法,Boot系统架构的设计建议,软件开发、调试的所需文件/依赖等。

而我们GHRD(Golden Hardware Reference Design)工程自定义设计的开发调试是通过JTAG加载实现的,就需要软件生成JTAG加载所需的文件/依赖,那么我们就先来准备软件开发、调试的所需文件/依赖。

我们之前通过Quartus工具综合 + 实现已生成sof(1)文件,这里还需要HPS FSBL(2)文件,然后再把sof(1)文件和HPS FSBL(2)文件打包成HPS SOF(3)文件,HPS SOF(3)文件才能用于JTAG加载启动。

由上图可知,需要通过HPS Bootloader源码编译生成HPS FSBL(2)文件,这里与之前的FPGA器件通过Quartus工具的BSP Generator生成FSBL的方式不同,优势在于:之前的生成FSBL的方式需要依托于EDA工具高度定制,每板需要一个镜像;而Stratix 10和Agilex器件使用开源的U-boot源码,一个镜像可以适配多个板。

接下来向大家step by step的展示HPS FSBL的编译过程,编译过程中会遇到一些问题,让我们一起来解决,希望对大家后续的开发有帮助。

二、准备
1. EDA工具:Quartus Prime Pro 25.1(或其他版本,建议25.1以上)
2. Linux 操作系统:建议 ubuntu 22.04
3. 或者 Windows 操作系统:建议 Windows 11 安装 WSL,具体搭建方式请参考:【 Intel/Altera FPGA技术实战 】Stratix 10 SOC GHRD工程搭建(一)_altera fpga windows开发 平台搭建-ZEEKLOG博客
三、U-Boot编译
1. U-Boot Build流程具体请参考:Building Bootloader for Stratix10 | Documentation | RocketBoards.org,大致如下图所示;
2. 在GitHub下载U-Boot源码;

U-Boot源码下载链接:GitHub - altera-fpga/u-boot-socfpga: Official Intel SOCFPGA U-Boot repository. Note: (1) A "RC" labeled branch is for internal active development use and customer early access without official customer support. (2) Latest stable branch (no RC labeled) is strongly recommended for development and production use outside of Intel. (3) See doc/README.socfpga for Quartus and Device support.

3. 使用下面命令下载 & Setup 交叉编译工具链,注意此时aarch64-none-linux-gnu-安装在linux根目录下:
wget https://developer.arm.com/-/media/Files/downloads/gnu/11.2-2022.02/binrel\ /gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu.tar.xz tar xf gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu.tar.xz rm -f gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu.tar.xz export PATH=`pwd`/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin:$PATH
4. 解压后切换到U-Boot源码路径,并设置编译工具链环境变量:
cd /mnt/g/Stratix10_uboot/u-boot-socfpga-socfpga_v2025.07/ export PATH=/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin:$PATH export CROSS_COMPILE=aarch64-none-linux-gnu-
5. 配置Stratix 10通用defconfig;
make socfpga_stratix10_defconfig

其实就是把./configs/socfpga_stratix10_defconfig文件内的配置信息刷到U-Boot根目录下的generated_defconfig文件,请查看下图中,执行make socfpga_stratix10_defconfig命令后,两个config文件完全相同;

6. 使用下面命令编译U-Boot,可以自动生成SPL和U-Boot;
make -j
7. 编译过程可能会提示没有gcc或者python等依赖,使用下面命令安装;
sudo apt update sudo apt install build-essential sudo apt install python3
8. 编译过程出现make[1]: warning: Clock skew detected. Your build may be incomplete,是因为Makefile的修改时间大于系统的当前时间,这里是WSL系统时间同步问题,如果是Vmware虚拟机运行Linux应该不会出现该问题;
9. 查询WSL系统的当前时间,比Windows系统时间慢了2分钟;
10. 安装后台同步时间的服务chrony,并查询系统控制状态确认chrony已激活 & 运行;
sudo apt update sudo apt install chrony sudo systemctl status chrony
11. 再次查询WSL系统的当前时间,与Windows系统时间相同;
12. 重新编译U-Boot,warning已经消除,但是又报错提示:Image 'u-boot' is missing external blobs and is non-functional: blob-ext,Image 'u-boot' has faked external blobs and is non-functional: bl31.bin;

出现该错误的原因是U-Boot编译需要ATF支持,但缺少关键的二进制blob文件(bl31.bin),bl31.bin是ATF的Stage 3-1镜像,负责提供安全监控调用(SMC)、PSCI电源管理等服务,U-Boot 的FIT(Flattened Image Tree)镜像在build时需要把 bl31.bin打包进去,但找不到该文件,故Binman(U-Boot 的镜像打包工具)报错并中止编译;

四、ATF编译
1. 由上面log可知需要编译ATF生成bl31.bin,在GitHub下载ATF源码;

ATF源码下载链接:GitHub - altera-fpga/arm-trusted-firmware: Official Intel SOCFPGA Arm-TF repository. Note: (1) A "RC" labeled branch is for internal active development use and customer early access without official customer support. (2) Latest stable branch (no RC labeled) is strongly recommended for development and production use outside of Intel. (3) See README for Quartus and Device support.

2. 解压后切换到ATF源码路径,设置编译工具链环境变量,并检查交叉编译工具链是否ok;
cd /mnt/g/Stratix10_uboot/arm-trusted-firmware-socfpga_v2.13.0/ export PATH=/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin:$PATH export CROSS_COMPILE=aarch64-none-linux-gnu- aarch64-none-linux-gnu-gcc --version
3. 使用下面命令编译ATF;
make PLAT=stratix10 clean make PLAT=stratix10 all
4. 在./build/stratix10/release路径下成功编译bl2.bin,bl31.bin;
五、U-Boot & bl31.bin编译
1. 切换到U-Boot源码路径,把刚才编译好的bl31.bin复制到U-Boot根目录;
cp /mnt/g/Stratix10_uboot/arm-trusted-firmware-socfpga_v2.13.0/build/stratix10/release/bl31.bin /
2. 使用下面命令重新编译U-Boot;
PATH=/gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu/bin:$PATH export CROSS_COMPILE=aarch64-none-linux-gnu- aarch64-none-linux-gnu-gcc --version make distclean make -j
3. 下图中可以看到在spl/路径下生成u-boot-spl.bin,u-boot-spl-dtb.bin和u-boot-spl-dtb.hex文件,最后OFCHK .config检查配置并正常退出,说明U-Boot编译成功;
4. 使用下面命令查看,U-Boot根目录下FIT镜像u-boot.itb是否包含bl31.bin和u-boot,Image 1 (atf)子镜像就是bl31.bin,说明bl31.bin已打包ok;
./tools/dumpimage -l u-boot.itb
5. 查看生成的u-boot文件;
  1. U-Boot根目录下:u-boot文件是ELF(Executable and Linkable Format)格式的u-boot,是一种可执行文件格式,主要用于开发调试;而u-boot.itb文件是FIT格式的u-boot,是把内核、设备树等封装在一起的镜像,主要用于固化部署,u-boot.itb就是上节中我们提到的HPS SSBL文件;
  2. spl/路径下:u-boot-spl.bin就是上节中我们提到的HPS FSBL文件,该BIN格式文件用于烧录到flash;
6. 我们再来回忆一下Stratix 10 SoC中HPS的Boot流程(为简化流程,这里省掉了FPGA配置),其中HPS FSBL文件主要用于初始化,具体请参考:【 Intel/Altera FPGA技术实战 】Stratix 10 SOC 系统 Boot 概述(五)-ZEEKLOG博客
  1. Power On;
  2. SDM先加载HPS EMIF IO,再加载HPS FSBL(u-boot-spl.bin)到HPS的片上RAM的0x00000000地址,最后释放HPS的复位;
  3. HPS执行FSBL(初始化DRAM、时钟、外设等),再从启动介质加载SSBL(u-boot.itb)到HPS侧DRAM;
  4. HPS跳转执行SSBL;
  5. SSBL加载Linux Kernel/Application;
7. SPL源码中有详细的FSBL初始化流程(SPL源码绝对路径:./arch/arm/mach-socfpga/spl_s10.c),请参考已注释的SPL源码;
// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2016-2023 Intel Corporation <www.intel.com> * */ #include <hang.h> #include <init.h> #include <log.h> #include <asm/global_data.h> #include <asm/io.h> #include <asm/utils.h> #include <debug_uart.h> #include <image.h> #include <spl.h> #include <asm/arch/clock_manager.h> #include <asm/arch/firewall.h> #include <asm/arch/mailbox_s10.h> #include <asm/arch/misc.h> #include <asm/arch/reset_manager.h> #include <asm/arch/smmu_s10.h> #include <asm/arch/system_manager.h> #include <wdt.h> #include <dm/uclass.h> DECLARE_GLOBAL_DATA_PTR; void board_init_f(ulong dummy) { // 初始化运行环境 const struct cm_config *cm_default_cfg = cm_get_default_config(); int ret; struct udevice *dev; ret = spl_early_init(); // 初始化 SPL 内存池、malloc if (ret) hang(); // 获取Stratix 10外设基地址,包括时钟、复位、系统管理等寄存器 socfpga_get_managers_addr(); /* Ensure watchdog is paused when debugging is happening */ writel(SYSMGR_WDDBG_PAUSE_ALL_CPU, socfpga_get_sysmgr_addr() + SYSMGR_SOC64_WDDBG); // 配置看门狗 /* * Enable watchdog as early as possible before initializing other * component. */ if (CONFIG_IS_ENABLED(WDT)) // 配置看门狗 initr_watchdog(); /* ensure all processors are not released prior Linux boot */ writeq(0, CPU_RELEASE_ADDR); // 清除 CPU 释放寄存器,确保所有核在reset // 初始化定时器 socfpga_per_reset(SOCFPGA_RESET(OSC1TIMER0), 0); timer_init(); // 初始化FSBL和SDM之间通信的Mailbox,FSBL获取SDM侧QSPI flash访问控制权的请求通道 mbox_init(); mbox_hps_stage_notify(HPS_EXECUTION_STATE_FSBL); // 引脚复用初始化,根据Platform Designer中HPS外设IO配置进行初始化 sysmgr_pinmux_init(); /* configuring the HPS clocks */ cm_basic_init(cm_default_cfg); // HPS时钟系统初始化,包括HPS,DRAM和HPS外设等时钟 // 调试UART初始化,建议开发调试阶段开启 #ifdef CONFIG_DEBUG_UART socfpga_per_reset(SOCFPGA_RESET(UART0), 0); debug_uart_init(); #endif preloader_console_init(); // 控制台注册,使用printf/puts函数可以输出log print_reset_info(); // 显示上次复位原因(POR, WDOG, 软件复位等),用于调试 cm_print_clock_quick_summary(); // 打印关键时钟频率(CPU, DDR, OSC1 等),用于调试 // 初始化Security Register & Firewall ret = uclass_get_device_by_name(UCLASS_NOP, "socfpga-secreg", &dev); if (ret) { printf("Firewall & secure settings init failed: %d\n", ret); hang(); } // 初始化DRAM,包括DRAM PHY/controller initial/calibration + tarining #if CONFIG_IS_ENABLED(ALTERA_SDRAM) ret = uclass_get_device(UCLASS_RAM, 0, &dev); if (ret) { debug("DRAM init failed: %d\n", ret); hang(); } #endif // 初始化QSPI #ifdef CONFIG_CADENCE_QSPI mbox_qspi_open(); #endif }
8. 前言中用于JTAG加载启动的HPS SOF文件(3),是由sof(1)文件和HPS FSBL Hex(2)文件打包生成的,而U-Boot编译生成的HPS FSBL(u-boot-spl.bin)文件不能直接用于打包,需要用ELF格式的u-boot-spl文件转换出HEX格式的u-boot-spl.hex;
9. 使用下面命令把HPS FSBL(u-boot-spl.bin)文件转换为HEX文件;
aarch64-none-linux-gnu-objcopy -O ihex spl/u-boot-spl spl/u-boot-spl.hex
10. 查看已生成HPS FSBL HEX文件,接下来我们就可以打包HPS SOF文件(3),再用JTAG愉快的加载启动了。

Read more

【AIGC】ChatGPT 实用技巧:文本与数据的结构化方法全解析

【AIGC】ChatGPT 实用技巧:文本与数据的结构化方法全解析

博客主页: [小ᶻ☡꙳ᵃⁱᵍᶜ꙳]本文专栏: AIGC |ChatGPT 文章目录 * 💯前言 * 💯中文排版序号 * 1. 一级标题(First-Level Title) * 2. 二级标题(Second-Level Title) * 3. 三级标题(Third-Level Title) * 4. 四级标题(Fourth-Level Title) * 💯Markdown 语法 * 一级标题(First-Level Heading) * 二级标题(Second-Level Heading) * 子标题(Subheadings) * 列表(Lists) * 无序列表 * 有序列表 * 加粗和斜体(Bold and Italics) * 加粗 * 斜体 * 💯编程语法也是结构化 * YAML 语法结构的例子 * 1. 层级关系(

低成本运行 Claude Code:通过 LiteLLM 接入 GitHub Copilot Chat API 的完整指南

低成本运行 Claude Code:通过 LiteLLM 接入 GitHub Copilot Chat API 的完整指南

阅读原文 一、背景与动机 Claude Code 是 Anthropic 推出的编程 Agent 工具,很多人会用它做 “vibe coding”:一边写代码一边提问,在对话中重构、重组、查 bug,体验非常接近“和聪明同事结对编程”。 但在实际使用中,它有两个比较现实的问题: 1. 成本高:频繁的对话请求,会很快消耗你的 Anthropic API 配额; 2. 网络不稳:在一些网络环境下,直接请求 Anthropic API 可能经常超时或失败。 与此同时,很多开发者已经在使用 GitHub Copilot。GitHub 在 Copilot 背后接入了包括 Claude 在内的多种大模型(具体组合会随时间调整),而你已经为这部分算力付过费了。 于是,一个很自然的问题出现了:

TRAE vs Qoder vs Cursor vs GitHub Copilot:谁才是真正的“AI 工程师”?

引言:工具选择 = 成本 + 效率 + 风险 的综合权衡 2026 年,AI 编程工具已从“玩具”走向“生产主力”。但面对 TRAE、Qoder、Cursor、GitHub Copilot 等选项,开发者不仅要问: * 它能写 Rust 吗?支持中文需求吗? * 更要问:一个月多少钱?团队用得起吗?代码安全有保障吗? 本文将从 五大核心维度 深度剖析四大主流 AI IDE: 1. 核心理念与自主性 2. 多语言与跨生态支持能力 3. 工程化与交付闭环能力 4. 中文本地化与业务适配 5. 收费模式、定价策略与企业成本 帮你做出技术可行、经济合理、风险可控的决策。 一、核心理念:

开源模型应用落地-qwen2.5-7b-instruct-LoRA微调-LLaMA-Factory-单机单卡-V100(十八)

开源模型应用落地-qwen2.5-7b-instruct-LoRA微调-LLaMA-Factory-单机单卡-V100(十八)

一、前言     本篇文章将使用LLaMA-Factory去高效微调(命令和界面方式)QWen2.5系列模型,通过阅读本文,您将能够更好地掌握这些关键技术,理解其中的关键技术要点,并应用于自己的项目中。     QWen2系列模型微调: 开源模型应用落地-qwen2-7b-instruct-LoRA微调-LLaMA-Factory-单机单卡-V100(八)https://charles.blog.ZEEKLOG.net/article/details/141391066 二、术语介绍 2.1. LoRA微调   &nb