从零移植uboot 2017 到nuc970(第一天)

来源:互联网 发布:php curl 编码 编辑:程序博客网 时间:2024/05/18 02:42

前言:

         完成第一阶段,基本的移植之后,重新整理下,改善排版,修改部分言辞。

         明确移植目的,为了引导操作系统。

首先readme里面有这样的描述

There are two classes of configuration variables:* Configuration _OPTIONS_:These are selectable by the user and have names beginning with"CONFIG_".* Configuration _SETTINGS_:These depend on the hardware etc. and should not be meddled with ifyou don't know what you're doing; they have names beginning with"CONFIG_SYS_".Previously, all configuration was done by hand, which involved creatingsymbolic links and editing configuration files manually. More recently,U-Boot has added the Kbuild infrastructure used by the Linux kernel,allowing you to use the "make menuconfig" command to configure yourbuild.

实际上新的uboot加入了kconfig机制,当然是从内核移植过来的。新的编译框架

采用makeflie和kconfig共同作用机制。

For all supported boards there are ready-to-use defaultconfigurations available; just type "make <board_name>_defconfig".Example: For a TQM823L module type:cd u-bootmake TQM823L_defconfigNote: If you're looking for the default configuration file for a boardyou're sure used to be there but is now missing, check the filedoc/README.scrapyard for a list of no longer supported boards.
如果你的单板有默认的配置文件,这里让你修改的就比较少了。
Execution typically starts with an architecture-specific (and possiblyCPU-specific) start.S file, such as:- arch/arm/cpu/armv7/start.S- arch/powerpc/cpu/mpc83xx/start.S- arch/mips/cpu/start.S

不管是从makeflie,还是Lds,还是readme都会告诉你,程序刚开始的部分位于start.S

但是这里刚开始指的是上电复位后第一个执行的语句。

and so on. From there, three functions are called; the purpose andlimitations of each of these functions are described below.lowlevel_init():- purpose: essential init to permit execution to reach board_init_f()- no global_data or BSS- there is no stack (ARMv7 may have one but it will soon be removed)- must not set up SDRAM or use console- must only do the bare minimum to allow execution to continue toboard_init_f()- this is almost never needed- return normally from this function//lowlevel在不同的单板,所执行的工作可能有所区别,但至少保证关闭中断。
board_init_f():- purpose: set up the machine ready for running board_init_r():i.e. SDRAM and serial UART- global_data is available- stack is in SRAM- BSS is not available, so you cannot use global/static variables,only stack variables and global_data//在spl,和非spl两个同样的函数名,链接的文件不同。spl的b_i_f做的工作
//实际上更少,或者完全可以是空函数Non-SPL-specific notes:- dram_init() is called to set up DRAM. If already done in SPL thiscan do nothing//这里只是赋值了些结构体成员SPL-specific notes:- you can override the entire board_init_f() function with your ownversion as needed.- preloader_console_init() can be called here in extremis- should set up SDRAM, and anything needed to make the UART work- these is no need to clear BSS, it will be done by crt0.S- must return normally from this function (don't call board_init_r()directly)//Note: "SPL" stands for "Secondary Program Loader,"这里分成两个模式,一个有spl,一个没有很显然其functionality具有不同的特性。Here the BSS is cleared. For SPL, if CONFIG_SPL_STACK_R is defined, then atthis point the stack and global_data are relocated to belowCONFIG_SPL_STACK_R_ADDR. For non-SPL, U-Boot is relocated to run at the top ofmemory.//spl具体和non区别在哪里,只有看具体代码和之后的介绍才清楚,姑且先略过,刚开始没必要过分纠结,以后解析代码会告诉
//到底区别在哪里。
board_init_r():- purpose: main execution, common code- global_data is available- SDRAM is available- BSS is available, all static/global variables can be used- execution eventually continues to main_loop()Non-SPL-specific notes:- U-Boot is relocated to the top of memory and is now running fromthere.SPL-specific notes:- stack is optionally in SDRAM, if CONFIG_SPL_STACK_R is defined andCONFIG_SPL_STACK_R_ADDR points into SDRAM- preloader_console_init() can be called here - typically this isdone by defining CONFIG_SPL_BOARD_INIT and then supplying aspl_board_init() function containing this call- loads U-Boot or (in falcon mode) Linux

b_i_r不管是在spl,还是非spl都是非常重要的函数,其实spl的uboot,可以直接引导linux

看你想不想这样做了。

总体来说三个重要的lowlevel_init():board_init_f():board_init_r()
Configuration Options:----------------------Configuration depends on the combination of board and CPU type; allsuch information is kept in a configuration file"include/configs/<board_name>.h".//这里就指出了第二个比较重要的地方,include/configs/xxxx.h
//新的编译框架不xxx_defconfig和board_name.h同时作用。而xxx_defconfig生产.configExample: For a TQM823L module, all configuration settings are in"include/configs/TQM823L.h".Many of the options are named exactly as the corresponding Linuxkernel configuration options. The intention is to make it easier tobuild a config tool - later.The following options need to be configured:- CPU Type: Define exactly one, e.g. CONFIG_MPC85XX.- Board Type: Define exactly one, e.g. CONFIG_MPC8540ADS.- CPU Daughterboard Type: (if CONFIG_ATSTK1000 is defined) Define exactly one, e.g. CONFIG_ATSTK1002- Marvell Family MemberCONFIG_SYS_MVFS - define it if you want to enablemultiple fs option at one timefor marvell soc family- ARM options:CONFIG_SYS_EXCEPTION_VECTORS_HIGHSelect high exception vectors of the ARM core, e.g., do notclear the V bit of the c1 register of CP15.CONFIG_SYS_THUMB_BUILDUse this flag to build U-Boot using the Thumb instructionset for ARM architectures. Thumb instruction set providesbetter code density. For ARM architectures that supportThumb2 this flag will result in Thumb2 code generated byGCC.CONFIG_ARM_ERRATA_716044CONFIG_ARM_ERRATA_742230CONFIG_ARM_ERRATA_743622CONFIG_ARM_ERRATA_751472CONFIG_ARM_ERRATA_761320CONFIG_ARM_ERRATA_773022CONFIG_ARM_ERRATA_774769CONFIG_ARM_ERRATA_794072If set, the workarounds for these ARM errata are applied earlyduring U-Boot startup. Note that these options force theworkarounds to be applied; no CPU-type/version detectionexists, unlike the similar options in the Linux kernel. Do notset these options unless they apply!COUNTER_FREQUENCYGeneric timer clock source frequency.COUNTER_FREQUENCY_REALGeneric timer clock source frequency if the real clock isdifferent from COUNTER_FREQUENCY, and can only be determinedat run time.NOTE: The following can be machine specific errata. Thesedo have ability to provide rudimentary version and machinespecific checks, but expect no product checks.CONFIG_ARM_ERRATA_430973CONFIG_ARM_ERRATA_454179CONFIG_ARM_ERRATA_621766CONFIG_ARM_ERRATA_798870CONFIG_ARM_ERRATA_801819- Generic CPU options:CONFIG_SYS_GENERIC_GLOBAL_DATADefines global data is initialized in generic board board_init_f().If this macro is defined, global data is created and cleared ingeneric board board_init_f(). Without this macro, architecture/boardshould initialize global data before calling board_init_f().前后呼应了下,这里可以看到一个行为的变化CONFIG_SYS_BIG_ENDIAN, CONFIG_SYS_LITTLE_ENDIANDefines the endianess of the CPU. Implementation of thosevalues is arch specific.CONFIG_SYS_FSL_DDRFreescale DDR driver in use. This type of DDR controller isfound in mpc83xx, mpc85xx, mpc86xx as well as some ARM core
。。太多了,就不列举了,现在反而清楚一点官方readme手册足够清楚
当我需要去决定一些UBOOT特性的增加修改,根据这个就很有帮助了。
Board initialization settings:------------------------------During Initialization u-boot calls a number of board specific functionsto allow the preparation of board specific prerequisites, e.g. pin setupbefore drivers are initialized. To enable these callbacks thefollowing configuration macros have to be defined. Currently this isarchitecture specific, so please check arch/your_architecture/lib/board.ctypically in board_init_f() and board_init_r().//注意spl和非spl的b_i_f和b_i_r分别对应着不同的文件。- CONFIG_BOARD_EARLY_INIT_F: Call board_early_init_f()- CONFIG_BOARD_EARLY_INIT_R: Call board_early_init_r()- CONFIG_BOARD_LATE_INIT: Call board_late_init()- CONFIG_BOARD_POSTCLK_INIT: Call board_postclk_init()Building the Software:======================Building U-Boot has been tested in several native build environmentsand in many different cross environments. Of course we cannot supportall possibly existing versions of cross development tools in all(potentially obsolete) versions. In case of tool chain problems werecommend to use the ELDK (see http://www.denx.de/wiki/DULG/ELDK)which is extensively used to build and test U-Boot.If you are not using a native environment, it is assumed that youhave GNU cross compiling tools available in your path. In this case,you must set the environment variable CROSS_COMPILE in your shell.Note that no changes to the Makefile or any other source files arenecessary. For example using the ELDK on a 4xx CPU, please enter:$ CROSS_COMPILE=ppc_4xx-$ export CROSS_COMPILENote: If you wish to generate Windows versions of the utilities inthe tools directory you can use the MinGW toolchain(http://www.mingw.org). Set your HOST tools to the MinGWtoolchain and execute 'make tools'. For example:$ make HOSTCC=i586-mingw32msvc-gcc HOSTSTRIP=i586-mingw32msvc-strip toolsBinaries such as tools/mkimage.exe will be created which canbe executed on computers running Windows.U-Boot is intended to be simple to build. After installing thesources you must configure U-Boot for one specific board type. Thisis done by typing:make NAME_defconfigwhere "NAME_defconfig" is the name of one of the existing configu-rations; see boards.cfg for supported names.Note: for some board special configuration names may exist; check ifadditional information is available from the board vendor; forinstance, the TQM823L systems are available without (standard)or with LCD support. You can select such additional "features"when choosing the configuration, i. e.make TQM823L_defconfig- will configure for a plain TQM823L, i. e. no LCD supportmake TQM823L_LCD_defconfig- will configure for a TQM823L with U-Boot console on LCDetc.Finally, type "make all", and you should get some working U-Bootimages ready for download to / installation on your system:- "u-boot.bin" is a raw binary image- "u-boot" is an image in ELF binary format- "u-boot.srec" is in Motorola S-Record formatBy default the build is performed locally and the objects are savedin the source directory. One of the two methods can be used to changethis behavior and build U-Boot to some external directory:1. Add O= to the make command line invocations:make O=/tmp/build distcleanmake O=/tmp/build NAME_defconfigmake O=/tmp/build all2. Set environment variable KBUILD_OUTPUT to point to the desired location:export KBUILD_OUTPUT=/tmp/buildmake distcleanmake NAME_defconfigmake allNote that the command line "O=" setting overrides the KBUILD_OUTPUT environment
编译uboot比较简单,我忽然想起来曾经的面试,我说自己移植过uboot,他不屑的说,你不会

是光编译了下吧。我觉得也是。看到uboot2009移植到s3c2410面试官就很不屑,貌似市面上太多的移植教程

//官方的一些定制uboot的说明If the system board that you have is not listed, then you will needto port U-Boot to your hardware platform. To do this, follow thesesteps:1. Create a new directory to hold your board specific code. Add anyfiles you need. In your board directory, you will need at leastthe "Makefile" and a "<board>.c".//所以在/board/里面放好自己文件2. Create a new configuration file "include/configs/<board>.h" foryour board.//在/include/configs/xx.h写好自己的配置3. If you're porting U-Boot to a new CPU, then also create a newdirectory to hold your CPU specific code. Add any files you need.4. Run "make <board>_defconfig" with your new name.5. Type "make", and you should get a working "u-boot.srec" fileto be installed on your target system.6. Debug and solve any problems that might arise.[Of course, this last step is much harder than it sounds.]//看起来容易做起来难Testing of U-Boot Modifications, Ports to New Hardware, etc.

.......
看readme也能获取很多有效信息。第一天到此结束,本文是重制版,本着不改变原来记录太多的原则

但是对于一些不适当的措辞,误导的说法要剔除

2 0
原创粉丝点击