Uboot 板级初始化流程and so on

本文详细解析了U-Boot的启动过程,从mips mt7621架构的SPL(Secondary Program Loader)到board_init_f()和board_init_r()函数的执行。SPL负责基本初始化,包括DRAM和UART,而board_init_r()标志着U-Boot第二阶段的开始,允许使用全局变量和BSS段。在board_init_r()之后,系统进入main_loop,准备加载内核或进行命令交互。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

--------------------------

本文以U-boot 2018.09源码 mips mt7621进行举例说明。

        此预期的理论初始化流程适用于全U-boot和SPL(Secondary Program Loader)

这里解释下SPL,SPL是一种U-Boot功能。它将原始u-boot镜像分为两个独立的部分。第一部分用于初始化DRAM(动态随机存取存储器)和其他必要的外围设备,然后将第二部分加载到内存中,然后运行它。第二部分包含u-boot所有剩余的功能。第二部分称为"辅助程序”,第一部分称为"辅助程序加载器"。

所以uboot的启动是分为两级加载的。

        目前,SPL部分大多使用单独的代码路径,但函数名和函数的功能都是相同的。某些板级或架构可能与此不符。至少大多数ARM框架的板级使用CONFIG_SPL_FRAMEWORK这个宏来控制这一点。

uboot的目录层次结构:

Directory Hierarchy:
====================

/arch			Architecture specific files
  /arc			Files generic to ARC architecture
  /arm			Files generic to ARM architecture
  /m68k			Files generic to m68k architecture
  /microblaze		Files generic to microblaze architecture
  /mips			Files generic to MIPS architecture
  /nds32		Files generic to NDS32 architecture
  /nios2		Files generic to Altera NIOS2 architecture
  /openrisc		Files generic to OpenRISC architecture
  /powerpc		Files generic to PowerPC architecture
  /riscv		Files generic to RISC-V architecture
  /sandbox		Files generic to HW-independent "sandbox"
  /sh			Files generic to SH architecture
  /x86			Files generic to x86 architecture
/api			Machine/arch independent API for external apps
/board			Board dependent files
/cmd			U-Boot commands functions
/common			Misc architecture independent functions
/configs		Board default configuration files
/disk			Code for disk drive partition handling
/doc			Documentation (don't expect too much)
/drivers		Commonly used device drivers
/dts			Contains Makefile for building internal U-Boot fdt.
/examples		Example code for standalone applications, etc.
/fs			Filesystem code (cramfs, ext2, jffs2, etc.)
/include		Header Files
/lib			Library routines generic to all architectures
/Licenses		Various license files
/net			Networking code
/post			Power On Self Test
/scripts		Various build scripts and Makefiles
/test			Various unit test files
/tools			Tools to build S-Record or U-Boot images, etc.

常用比较重要的几个目录:

DTS配置文件:/arch/your_architecture/dts/xxxx.dts

板级实现/board/xxx

板子默认配置/configs/xxx_defconfig   各种功能宏

板级常规配置/include/configs/xxx.h

uboot固件编译的链接配置文件为u-boot.lds和u-boot-spl.lds,路径如下

suvine@ubuntu:~/workspace/source_code/mtk-openwrt-lede-4.2.1.0/bootloader/u-boot-mt7621-2018.09-gitb178829-20200526$ find ./ -name "u-boot.lds"
./arch/m68k/cpu/u-boot.lds
./arch/nds32/cpu/n1213/u-boot.lds
./arch/arm/cpu/armv8/u-boot.lds
./arch/arm/cpu/u-boot.lds
./arch/arm/mach-zynq/u-boot.lds
./arch/microblaze/cpu/u-boot.lds
./arch/powerpc/cpu/mpc83xx/u-boot.lds
./arch/powerpc/cpu/mpc85xx/u-boot.lds
./arch/powerpc/cpu/mpc86xx/u-boot.lds
./arch/sandbox/cpu/u-boot.lds
./arch/x86/cpu/u-boot.lds
./arch/nios2/cpu/u-boot.lds
./arch/xtensa/cpu/u-boot.lds
./arch/sh/cpu/u-boot.lds
./arch/arc/cpu/u-boot.lds
./arch/riscv/cpu/ax25/u-boot.lds
./arch/mips/cpu/u-boot.lds
./board/birdland/bav335x/u-boot.lds
./board/cssi/MCR3000/u-boot.lds
./board/cirrus/edb93xx/u-boot.lds
./board/compulab/cm_t335/u-boot.lds
./board/vscom/baltos/u-boot.lds
./board/qualcomm/dragonboard410c/u-boot.lds
./board/qualcomm/dragonboard820c/u-boot.lds
./board/ti/am335x/u-boot.lds
./u-boot.lds
suvine@ubuntu:~/workspace/source_code/mtk-openwrt-lede-4.2.1.0/bootloader/u-boot-mt7621-2018.09-gitb178829-20200526$ find ./ -name "u-boot-spl.lds"
./arch/arm/cpu/armv7/sunxi/u-boot-spl.lds
./arch/arm/cpu/armv8/u-boot-spl.lds
./arch/arm/cpu/arm926ejs/spear/u-boot-spl.lds
./arch/arm/cpu/arm926ejs/orion5x/u-boot-spl.lds
./arch/arm/cpu/arm926ejs/mxs/u-boot-spl.lds
./arch/arm/cpu/u-boot-spl.lds
./arch/arm/cpu/arm1136/u-boot-spl.lds
./arch/arm/mach-at91/armv7/u-boot-spl.lds
./arch/arm/mach-at91/arm926ejs/u-boot-spl.lds
./arch/arm/mach-zynq/u-boot-spl.lds
./arch/arm/mach-omap2/u-boot-spl.lds
./arch/microblaze/cpu/u-boot-spl.lds
./arch/powerpc/cpu/mpc83xx/u-boot-spl.lds
./arch/powerpc/cpu/mpc85xx/u-boot-spl.lds
./arch/sandbox/cpu/u-boot-spl.lds
./arch/x86/cpu/u-boot-spl.lds
./arch/mips/cpu/u-boot-spl.lds
./tpl/u-boot-spl.lds
./spl/u-boot-spl.lds

U-boot的执行通常从特定于体系架构(可能是

特定于CPU的)start.S文件开始,例如:

-arch/arm/cpu/armv7/start.S

-arch/powerpc/cpu/mpc83xx/start.S

-arch/mips/cpu/start.S 

我们例举arch/mips/cpu/start.S源码:


#ifndef CONFIG_SYS_INIT_SP_ADDR
#define CONFIG_SYS_INIT_SP_ADDR	(CONFIG_SYS_SDRAM_BASE + \
				CONFIG_SYS_INIT_SP_OFFSET)
#endif

#ifdef CONFIG_32BIT
# define MIPS_RELOC	3
# define STATUS_SET	0
#endif

#ifdef CONFIG_64BIT
# ifdef CONFIG_SYS_LITTLE_ENDIAN
#  define MIPS64_R_INFO(ssym, r_type3, r_type2, r_type) \
	(((r_type) << 24) | ((r_type2) << 16) | ((r_type3) << 8) | (ssym))
# else
#  define MIPS64_R_INFO(ssym, r_type3, r_type2, r_type) \
	((r_type) | ((r_type2) << 8) | ((r_type3) << 16) | (ssym) << 24)
# endif
# define MIPS_RELOC	MIPS64_R_INFO(0x00, 0x00, 0x12, 0x03)
# define STATUS_SET	ST0_KX
#endif

	.set noreorder

	.macro init_wr sel
	MTC0	zero, CP0_WATCHLO,\sel
	mtc0	t1, CP0_WATCHHI,\sel
	mfc0	t0, CP0_WATCHHI,\sel
	bgez	t0, wr_done
	 nop
	.endm

	.macro uhi_mips_exception
	move	k0, t9		# preserve t9 in k0
	move	k1, a0		# preserve a0 in k1
	li	t9, 15		# UHI exception operation
	li	a0, 0		# Use hard register context
	sdbbp	1		# Invoke UHI operation
	.endm

	.macro setup_stack_gd
	li	t0, -16
	PTR_LI	t1, CONFIG_SYS_INIT_SP_ADDR
	and	sp, t1, t0		# force 16 byte alignment
	PTR_SUBU \
		sp, sp, GD_SIZE		# reserve space for gd
	and	sp, sp, t0		# force 16 byte alignment
	move	k0, sp			# save gd pointer
#if CONFIG_VAL(SYS_MALLOC_F_LEN)
	li	t2, CONFIG_VAL(SYS_MALLOC_F_LEN)
	PTR_SUBU \
		sp, sp, t2		# reserve space for early malloc
	and	sp, sp, t0		# force 16 byte alignment
#endif
	move	fp, sp

	/* Clear gd */
	move	t0, k0
1:
	PTR_S	zero, 0(t0)
	blt	t0, t1, 1b
	 PTR_ADDIU t0, PTRSIZE

#if CONFIG_VAL(SYS_MALLOC_F_LEN)
	PTR_S	sp, GD_MALLOC_BASE(k0)	# gd->malloc_base offset
#endif
	.endm

ENTRY(_start)
	/* U-Boot entry point */
	b	reset
	 mtc0	zero, CP0_COUNT	# clear cp0 count for most accurate boot timing

#if defined(CONFIG_SYS_XWAY_EBU_BOOTCFG)
	/*
	 * Almost all Lantiq XWAY SoC devices have an external bus unit (EBU) to
	 * access external NOR flashes. If the board boots from NOR flash the
	 * internal BootROM does a blind read at address 0xB0000010 to read the
	 * initial configuration for that EBU in order to access the flash
	 * device with correct parameters. This config option is board-specific.
	 */
	.org 0x10
	.word CONFIG_SYS_XWAY_EBU_BOOTCFG
	.word 0x0
#endif
#if defined(CONFIG_MALTA)
	/*
	 * Linux expects the Board ID here.
	 */
	.org 0x10
	.word 0x00000420	# 0x420 (Malta Board with CoreLV)
	.word 0x00000000
#endif

#if defined(CONFIG_ROM_EXCEPTION_VECTORS)
	/*
	 * Exception vector entry points. When running from ROM, an exception
	 * cannot be handled. Halt execution and transfer control to debugger,
	 * if one is attached.
	 */
	.org 0x200
	/* TLB refill, 32 bit task */
	uhi_mips_exception

	.org 0x280
	/* XTLB refill, 64 bit task */
	uhi_mips_exception

	.org 0x300
	/* Cache error exception */
	uhi_mips_exception

	.org 0x380
	/* General exception */
	uhi_mips_exception

	.org 0x400
	/* Catch interrupt exceptions */
	uhi_mips_exception

	.org 0x480
	/* EJTAG debug exception */
<think>好的,我需要帮助用户查找全志芯片上Android系统的开机启动配置和常见问题解决方案。首先,用户提到了使用全志A64芯片的Android 6.0系统,涉及到内网和外网的连接问题。这可能与启动时的网络配置有关。 首先,我应该回顾用户提供的引用内容。引用[2]提到SWUpdate套件依赖U-boot环境变量,配置文件路径是device/config/chips/mr536/configs/evb1/linux-5.15-origin/env-5.15.cfg。这可能涉及到启动加载器的配置,但用户的问题是关于Android系统的,所以可能需要查看类似的路径下的配置文件,比如uboot的环境变量或内核启动参数。 引用[3]提到用户在使用全志A64开发时遇到开机后的网络连接问题。这可能涉及到Android系统启动时的网络服务初始化,或者硬件驱动的加载问题。需要检查启动脚本或init.rc文件中的网络配置部分。 接下来,我需要整理全志Android系统的启动流程。通常Android启动流程包括uboot引导、内核启动、init进程初始化等阶段。全志芯片可能会有特定的配置文件和启动脚本,例如在uboot中的env.cfg或bootargs设置,以及Android的init.rc文件中定义的服务和动作。 对于开机启动配置,用户可能需要关注以下几个部分: 1. **U-Boot配置**:检查uboot的环境变量,如bootcmd、bootargs,确保正确加载内核和设备树。引用[2]中的env-5.15.cfg可能是一个参考,但全志A64的路径可能不同,可能需要查找类似device/config/chips/a64/configs...的路径。 2. **内核启动参数**:在bootargs中设置正确的控制台、内存分配等参数,可能会影响外设初始化。 3. **Android init.rc文件**:位于system/core/rootdir/init.rc,这里定义了系统服务启动顺序,包括网络服务、zygote等。用户提到的网络问题可能需要检查netd服务或wpa_supplicant的配置。 4. **硬件抽象层(HAL)**:检查硬件相关的库文件,确保WiFi和以太网驱动正确加载,可能需要查看device/全志/a64/...下的设备配置。 5. **启动脚本**:在/system/etc/init.d/或vendor/init.d/中的脚本,可能涉及网络配置或服务启动。 关于常见问题,比如开机后网络连接异常,可能的原因包括: - 驱动未正确加载:检查内核日志(dmesg)是否有驱动加载错误。 - 服务启动顺序问题:在init.rc中,网络服务可能依赖其他服务,需要确保依赖关系正确。 - 权限问题:网络相关的服务可能需要特定权限,检查selinux策略或文件权限。 - 配置错误:检查/etc/wifi/wpa_supplicant.conf或类似文件的配置是否正确。 用户可能还需要查看全志提供的开发文档,或者社区论坛,寻找针对A64芯片的Android系统启动配置指南。例如,检查是否有特定的补丁或内核参数需要设置,以确保WiFi和以太网接口正确初始化。 最后,需要提醒用户备份配置文件,修改前进行测试,避免系统无法启动。如果遇到具体错误,可以通过adb logcat或dmesg获取更多信息,帮助诊断问题。</think>### 全志芯片 Android 系统开机启动配置及常见问题解决方案 #### 一、开机启动配置 1. **U-Boot 环境变量配置** 全志芯片的启动流程从 U-Boot 开始,其环境变量配置直接影响内核加载和设备初始化- 配置文件路径通常位于 `device/config/chips/[芯片型号]/configs/[型]/env.cfg`,例如: ```bash # 全志A64的U-Boot环境变量示例 bootcmd=run load_kernel; bootm 0x46000000 bootargs=console=ttyS0,115200 root=/dev/mmcblk0p2 init=/init ``` - 关键参数说明: - `bootcmd`:定义内核加载命令(如从存储设备或网络加载)。 - `bootargs`:传递内核启动参数(控制台、根文件系统路径等)[^2]。 2. **Android init 进程配置** Android 系统的初始化由 `init.rc` 文件控制,路径为 `system/core/rootdir/init.rc`。 - **服务启动顺序**:通过 `on early-init`、`on boot` 等阶段定义服务依赖关系。 - **网络服务配置**:检查以下服务是否正常启动: ```bash service netd /system/bin/netd class main socket netd stream 0660 root system ``` 3. **硬件驱动与设备树** - 设备树文件(`.dts`)位于 `kernel/arch/arm64/boot/dts/[芯片型号]/`,需确认外设(如WiFi、以太网)节点配置正确。 - 驱动模块加载:在 `init.rc` 或启动脚本中添加 `insmod` 命令加载内核模块(如WiFi驱动)。 --- #### 二、常见问题及解决方法 1. **开机后网络无法连接** - **可能原因**: - 驱动未加载:检查内核日志 `dmesg | grep eth0` 或 `dmesg | grep wlan`。 - 服务冲突:若同时启用有线和无线网络,需在 `init.rc` 中调整服务启动顺序。 - **解决方案**: - 在 `init.rc` 中增加网络接口初始化延迟: ```bash on property:sys.boot_completed=1 exec -- /system/bin/sleep 5 start netd ``` 2. **系统启动卡在 U-Boot 阶段** - **可能原因**: - `bootcmd` 错误:内核镜像路径或加载方式不正确。 - 存储设备分区表损坏。 - **解决方案**: - 通过串口调试 U-Boot,使用 `printenv` 验证环境变量。 - 重新烧写分区表:使用 `sunxi-fel` 工具修复[^3]。 3. **外设初始化失败(如触摸屏、传感器)** - **可能原因**: - 设备树节点未启用或配置错误。 - HAL 层库文件缺失。 - **解决方案**: -设备树中启用对应节点: ```bash &i2c1 { touchscreen@38 { compatible = "edt,edt-ft5406"; reg = <0x38>; }; }; ``` - 检查 `vendor/lib/hw/` 下是否存在对应的 `.so` 库文件。 --- #### 三、调试工具与日志 1. **内核日志**: ```bash adb shell dmesg > kernel.log ``` 2. **Android 系统日志**: ```bash adb logcat > system.log ``` 3. **U-Boot 调试**: 通过串口连接开发,使用 `minicom` 或 `screen` 工具查看启动阶段输出。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

suvine

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值