Linux内核编译——Uboot

    1、概述

            最近在做linux内核移植,内核是编译好了,只是内核导进EMMC后启动不了,移植卡在Starting kernel ...所以有必要把启动梳理一遍,看卡在那个地方。

    2、Uboot介绍

            U-Boot是Das U-Boot的简称,其含义是Universal Boot Loader,是遵循GPL条款的开放源码项目。一开始德国DENX软件工程中心的Wolfgang Denk基于8xxROM和FADSROM的源码创建了PPCBoot工程项目,此后不断添加处理器的支持。后来,Sysgo Gmbh把PPCBoot移植到ARM平台上,创建了ARMBoot工程项目。然后以PPCBoot工程和ARMBoot工程为基础,创建了U-Boot工程,2002年12月17日第一个版本U-Boot-0.2.0发布,同时PPCBoot和ARMboot停止维护。而今,U-Boot作为一个主流、通用的Bootloader,成功地被移植到包括主流的PowerPC、ARM、X86 、MIPS、NIOS、XScale等体系结构的上百种开发板,成为功能最多、灵活性最强,并且开发最积极的开源BootLoader。目前。U-Boot仍然由DENX的Wolfgang Denk维护。

    3、Uboot 下载

       下载:  点击打开链接

        介绍:点击打开链接

    4、Uboot 编译

            1)下载后解压
                  tar -xjvf u-boot-2017.09.tar.bz2      
            2)编译
                参考文档     点击打开链接
    

                具体步骤:

                            》uboot也支持menuconfig,先调用设置处理器jiagou

            

                            》选择打印串口编号,迅为的开发板为 串口3

            

                            》设置 交叉编译器

                                export CROSS_COMPILE=/home/cjx/Linux/Linux/LinuxTool/CompileTool/arm-2014.05/bin/arm-none-linux-gnueabi- 

                            》设置处理器
                                export ARCH=arm

                            》设置板子类型

                                make am335x_evm_config

                            》开始编译

                                make


    5、Uboot menuconfig 认识

            

            >   Architecture select (ARM architecture)  --->  处理器架构选择

                >

            >    ARM architecture  ---> ARM 架构子选项

                >[ ] Support for ARM SMC Calling Convention (SMCCC) 支持SMCCC,这是一个开源的

Minecraft启动器核心库,SMCCC介绍点击打开链接

                >[ ] support boot from semihosting     支持半主控,用于调试

                >[*] Build U-Boot using the Thumb instruction set    用thumb指令建立uboot

                >[*] Build SPL using the Thumb instruction set    用thumb指令建立SPL

                >[ ] L2cache off     

                >[*] Use an assembly optimized implementation of memcpy    memcpy用汇编优化执行
                >
                >[ ] ARM64 system support AArch32 execution state  32位执行支持
                  Target select (Samsung EXYNOS)  ---> 目标芯片选择
                >[ ] EXYNOS architecture type select 
                >[ ] Use LPAE page table format    页表格式
                >[ ] Support the 'dek_blob' command    

                >    ARM debug  --->    调试

            >  General setup  ---> 

                >()  Local version - append to U-Boot release    版本号

                >[*] Automatically append version information to the version strin    

                >[*] Optimize for size  优化大小

                >[*] Select defaults suitable for booting general purpose Linux di│    选择何时的启动

                >[*] Enable malloc() pool before relocation   使能malloc池在引导之前

                >(0x400) Size of malloc() pool before relocation    malloc大小

                >[*] Configure standard U-Boot features (expert users)  --->    配置标准的uboot特性

                >[ ] 64bit physical address support     64位物理地址支持

          >    Boot images  --->    镜像

                >[*] Enable support for Android Boot Images    使能安卓引导

                >[*] Support Flattened Image Tree 支持扁平镜像树

                >[*]   Support SHA256 checksum of FIT image contents     支持FIT镜像校验和

                >[ ]   Enable signature verification of FIT uImages    FIT uimage签名验证

                >[ ]   Show verbose messages when FIT images fail    打印信息当FIT镜像失败

                [ ]   Select the best match for the kernel device tree    选择最好的匹配到设备树

                >-*-   Support Flattened Image Tree within SPL

                 >[ ]   Enable signature verification of FIT firmware within SPL 

                 >[*]   Enable SPL loading U-Boot as a FIT      

                 >[ ] Set up board-specific details in device tree before boot    

                 >

         > API  ---> 

                >[ ] Enable U-Boot API 使能uboot api

         >    Boot timing  --->  开机时序

                >[ ] Boot timing and reporting     开机报告

                >(20) Number of boot ID numbers available for user use    引导ID给 user

                >(30) Number of boot stage records to store    引导记录数

                >(0) Address to stash boot timing information     开机时序记录存储地址

                >(0x1000) Size of boot timing stash region     存储区大小

       >Boot media  ---> 引导媒介

                >

       >(2) delay in seconds before automatically booting     自动引导延时

       >[ ] Enable boot arguments 启动参数

                >()    Boot arguments 

       >    Console  --->  控制台

                >[ ] Console recording  控制台记录

                >()  Board specific string to be added to uboot version string    

                >[ ] Support a silent console 支持无信息控制台

                >[ ] Buffer characters before the console is available    控制台之前有效的

字符缓冲

                >[ ] Enable console multiplexing    使能控制台复用

                >[ ] Select console devices from the environment      选择控制台设备根据

环境

                >[ ] Allow board control over console overwriting    允许控制台覆盖板控制

                >[ ] Update environment variables during console init   更新环境变量在控

制台初始化之前

                >[*] Don't display the console devices on boot    在boot里面不显示控制

台设备

                >[ ] Allow deregistering stdio devices     允许注销输入输出设备

        >[ ] Support a FIT image embedded in the U-boot image  支持FIT镜像到

U-boot镜像点击打开链接

        >()  Default fdt file 默认的fdt文件

        >[*] add U-Boot environment variable vers    增加环境矢量

        >[*] Display information about the CPU during start up    启动显示CPU

信息

        >[*] Display information about the board during start up    启动显示板子

信息

        >    Start-up hooks  ---> 启动钩子函数

        > Security support  ---- 安全支持

        >    SPL / TPL  ---> SPL是uboot第一阶段执行的代码. 主要负责搬移uboot第二阶段

的代码到内存中运行. SPL是由固化在芯片内部的ROM引导的. 我们知道很多芯片厂商固化的

ROM支持从nandflash, SDCARD等外部介质启动

            >    Command line interface  ---> 命令行接口

                > [*] Support U-Boot commands  

                >    Autoboot options  ---> 自动引导选项

                        >

                >[*] Fastboot support  ---> fastboot支持,fastboot是一种比recovery更底层的刷

机模式

                         >

                >   Info commands  ---> 

                >   Boot commands  ---> 启动命令

                > Environment commands  --->    环境命令

                    >

                >   Memory commands  --->    内存命令

                >   Compression commands  ---> 压缩命令

                >   Device access commands  ---> 设备控制命令

                >  Shell scripting commands  ---> 脚本命令

                >  Network commands  --->    网络命令

                >   Misc commands  --->    函数命令

                > Power commands  ----    电源控制命令

                >   Security commands  --->    安全命令

                > Firmware commands  ----      固件命令

                >   Filesystem commands  --->     文件系统命令

                >  Debug commands  --->       调试命令

                >[ ] Enable UBI - Unsorted block images commands    是一种用于Raw Flash的

卷管理系统,主要功能是在同一个Flash芯片上管理多个逻辑卷,并且平衡整个Flash读写操作

         > Partition Types  ---> 分区类型

                >

        >   Device Tree Control  ---> 设备树控制

                >

        >   Environment  --->    环境

                >

        >-*- Networking support  ---> 网络支持

                >

        >    Device Drivers  --->    设备驱动

                >

         >   File systems  ---> 文件系统

        >    Library routines  --->    库程序

        > [ ] Unit tests  ----    单元测试


6、平台介绍

        在分析启动流程之前先来看看自己开发板的硬件环境,我购买的是迅为的iTOP-4412开发板,开发板的核心处理器是Exynos4412处理器。芯片有两种封装,POP集成1G内存,SCP外扩1G内存(4个k4b2g),我的是SCP版,存储是eMMC KLM8G。

        Exynos 4412点击打开链接采用了三星32nm HKMG工艺,是三星第一款四核处理器。主频1.4GHz,GPU 400MHz,Cortex-A9内核介绍。Exynos 4412启动点击打开链接是通过固化在iRom里的的固件程序先引导bootloader到iRam,这里的寻找bootloader位置可通过拨码开关来选择启动方式,默认从eMMC,也可选择SD卡等外设存储。引导后接着就是我们自己编译的uboot来引导内核。

7、Uboot启动流程分析

        参考文档:点击打开链接  点击打开链接

        1)概述

              对于CPU来说整个启动分两步,第一步是固化在芯片内部的引导,主要加载uboot.bin。这段固件应该要先判断uboot是在那个存储里面,拷贝完之后进行跳转,执行uboot.bin。第二阶段uboot.bin先初始化外设,然后初始化系统允许环境

        2)初始化外设的代码

            arch/arm/cpu/armv7/start.S
            board/samsung/myboard/lowlevel_init.S
            arch/arm/lib/crt0.S
            arch/arm/lib/board.c
            arch/samsung/myboard/myboard.c

        

            start.S

                    1、设置CPU为SVC模式,uboot需要更多的权限所以需要打开

                    2、关闭MMU,uboot操作的都是实际地址

                    3、关闭Cache,cache主要是做缓存的,因为内存的初始化比CPU初始化慢半拍,上电之初就操作存储可能会导致问题

                    4、跳转到lowerlevel_init.s  low_level_init


            lowlevel_init.S

                    5、初始化时钟

                    6、初始化内存

                    7、初始化串口,看门狗

                    8、跳转到crt0.S _main


            crt0.S

                    9、设置栈

                    10、初始化C运行环境

                    11、调用board_init_f()


            board.c

                    12、board_init_f对全局信息GD结构体进行填充


            crt0.S

                    13、代码重定位

                    

        3)准备环境阶段

            arch/arm/lib/crt0.S

            arch/arm/lib/board.c

           1. board_init_r()是进入定制板目录的入口
common/main.c

           2. main_loop()中关闭中断,执行命令以及加载引导内核


        4)uboot是如何加载内核的

            1.uboot需要先初始化好DRAM,因为要把内核搬运到这里面

            2.初始化一个串口

            3.uboot需要把板子类型传给内核,按照arch/arm/tools/mach-types中的描述,将板子编号存储在r1寄存器,这里板子类型有什么用?

            4.建立内核参数,包含内存位置,内存大小及根文件系统的位置等

            5.加载ramfs文件系统

            6.启动内核镜像

猜你喜欢

转载自blog.csdn.net/cheng401733277/article/details/79982709