Uboot学习笔记①---(文件目录结构、README摘要、uImage的64字节头信息)

时间:2023-01-18 16:30:48

uboot下载地址ftp://ftp.denx.de/pub/u-boot/

1、查看uboot文件目录结构

[objc] view plain copy
  1. Directory Hierarchy:  
  2. ====================  
  3.   
  4. /arch           Architecture specific files  
  5.   /arm          Files generic to ARM architecture  
  6.     /cpu        CPU specific files  
  7.       /arm720t      Files specific to ARM 720 CPUs  
  8.       /arm920t      Files specific to ARM 920 CPUs  
  9.       /at91         Files specific to Atmel AT91RM9200 CPU  
  10.       /imx          Files specific to Freescale MC9328 i.MX CPUs  
  11.       /s3c24x0      Files specific to Samsung S3C24X0 CPUs  
  12.     /lib        Architecture specific library files  
  13.   /x86          Files generic to x86 architecture  
  14.     /cpu        CPU specific files  
  15.     /lib        Architecture specific library files  
  16.   /mips         Files generic to MIPS architecture  
  17.     /cpu        CPU specific files  
  18.       /mips32       Files specific to MIPS32 CPUs  
  19.       /xburst       Files specific to Ingenic XBurst CPUs  
  20.     /lib        Architecture specific library files  
  21.   /powerpc      Files generic to PowerPC architecture  
  22.     /cpu        CPU specific files  
  23.       /74xx_7xx     Files specific to Freescale MPC74xx and 7xx CPUs  
  24.       /mpc5xx       Files specific to Freescale MPC5xx CPUs  
  25.       /mpc5xxx      Files specific to Freescale MPC5xxx CPUs  
  26.     /lib        Architecture specific library files  
  27. /api            Machine/arch independent API for external apps  
  28. /board          Board dependent files  
  29. /common         Misc architecture independent functions  
  30. /disk           Code for disk drive partition handling  
  31. /doc            Documentation (don't expect too much)  
  32. /drivers        Commonly used device drivers  
  33. /dts                    Contains Makefile for building internal U-Boot fdt.  
  34. /examples       Example code for standalone applications, etc.  
  35. /fs             Filesystem code (cramfs, ext2, jffs2, etc.)  
  36. /include        Header Files  
  37. /lib            Files generic to all architectures  
  38.   /libfdt       Library files to support flattened device trees  
  39.   /lzma         Library files to support LZMA decompression  
  40.   /lzo          Library files to support LZO decompression  
  41. /net            Networking code  
  42. /post           Power On Self Test  
  43. /rtc            Real Time Clock drivers  
  44. /tools          Tools to build S-Record or U-Boot images, etc.  

uboot层次结构和调用关系

Uboot学习笔记①---(文件目录结构、README摘要、uImage的64字节头信息)

2、查看解压目录中的README文件

Software Configuration:
=======================
Configuration is usually done using C preprocessor defines; the
rationale behind that is to avoid dead code whenever possible.

There are two classes of configuration variables:

# README文件中说明了很多“CONFIG_”和“CONFIG_SYS_”的作用,在看makefile时不懂的话可以查询一下
* 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 if
  you don't know what you're doing; they have names beginning with
  "CONFIG_SYS_".

编译uboot

Selection of Processor Architecture and Board Type:
--------------------------------------------------
For all supported boards there are ready-to-use default
configurations available; just type "make <board_name>_config".

Example: For a TQM823L module type:

    cd u-boot
    make TQM823L_config

For the Cogent platform, you need to specify the CPU type as well;
e.g. "make cogent_mpc8xx_config". And also configure the cogent
directory according to the instructions in cogent/README.

make NAME_config

where "NAME_config" is the name of one of the existing configu-
rations; see boards.cfg for supported names.(NAME_config在uboot根目录中)

Finally, type "make all", and you should get some working U-Boot
images 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 format

#使用命令改变make编译输出uboot.bin的目录 etc.

By default the build is performed locally and the objects are saved
in the source directory. One of the two methods can be used to change
this behavior and build U-Boot to some external directory:
1. Add O= to the make command line invocations:
    make O=/tmp/build distclean
    make O=/tmp/build NAME_config
    make O=/tmp/build all

2. Set environment variable BUILD_DIR to point to the desired location:
    export BUILD_DIR=/tmp/build
    make distclean
    make NAME_config
    make all
Note that the command line "O=" setting overrides the BUILD_DIR environment
variable.

#以下这段话还不知道什么时候用的上,先记录一下

Please be aware that the Makefiles assume you are using GNU make, so
for instance on NetBSD you might need to use "gmake" instead of
native "make".

#uboot命令汇总

[objc] view plain copy
  1. Monitor Commands - Overview:  
  2. ============================  
  3. go    - start application at address 'addr'  
  4. run    - run commands in an environment variable  
  5. bootm    - boot application image from memory  
  6. bootp    - boot image via network using BootP/TFTP protocol  
  7. bootz   - boot zImage from memory  
  8. tftpboot- boot image via network using TFTP protocol  
  9.            and env variables "ipaddr" and "serverip"  
  10.            (and eventually "gatewayip")  
  11. tftpput - upload a file via network using TFTP protocol  
  12. rarpboot- boot image via network using RARP/TFTP protocol  
  13. diskboot- boot from IDE devicebootd   - boot default, i.e., run 'bootcmd'  
  14. loads    - load S-Record file over serial line  
  15. loadb    - load binary file over serial line (kermit mode)  
  16. md    - memory display  
  17. mm    - memory modify (auto-incrementing)  
  18. nm    - memory modify (constant address)  
  19. mw    - memory write (fill)  
  20. cp    - memory copy  
  21. cmp    - memory compare  
  22. crc32    - checksum calculation  
  23. i2c    - I2C sub-system  
  24. sspi    - SPI utility commands  
  25. base    - print or set address offset  
  26. printenv- print environment variables  
  27. setenv    - set environment variables  
  28. saveenv - save environment variables to persistent storage  
  29. protect - enable or disable FLASH write protection  
  30. erase    - erase FLASH memory  
  31. flinfo    - print FLASH memory information  
  32. bdinfo    - print Board Info structure  
  33. iminfo    - print header information for application image  
  34. coninfo - print console devices and informations  
  35. ide    - IDE sub-system  
  36. loop    - infinite loop on address range  
  37. loopw    - infinite write loop on address range  
  38. mtest    - simple RAM test  
  39. icache    - enable or disable instruction cache  
  40. dcache    - enable or disable data cache  
  41. reset    - Perform RESET of the CPU  
  42. echo    - echo args to console  
  43. version - print monitor version  
  44. help    - print online help  
  45. ?    - alias for 'help'  

3、uImage的64字节头信息

Image uImage与zImage的区别

这里就解释了uImage比zImage多的64字节是哪些

在include/image.h中的源码为

[objc] view plain copy
  1. #define IH_NMLEN        32    /* Image Name Length        */  
  2.   
  3. /* 
  4.  * Legacy format image header, 
  5.  * all data in network byte order (aka natural aka bigendian). 
  6.  */  
  7. typedef struct image_header {  
  8.     uint32_t    ih_magic;    /* Image Header Magic Number    */  
  9.     uint32_t    ih_hcrc;    /* Image Header CRC Checksum    */  
  10.     uint32_t    ih_time;    /* Image Creation Timestamp    */  
  11.     uint32_t    ih_size;    /* Image Data Size        */  
  12.     uint32_t    ih_load;    /* Data     Load  Address        */  
  13.     uint32_t    ih_ep;        /* Entry Point Address        */  
  14.     uint32_t    ih_dcrc;    /* Image Data CRC Checksum    */  
  15.     uint8_t        ih_os;        /* Operating System        */  
  16.     uint8_t        ih_arch;    /* CPU architecture        */  
  17.     uint8_t        ih_type;    /* Image Type            */  
  18.     uint8_t        ih_comp;    /* Compression Type        */  
  19.     uint8_t        ih_name[IH_NMLEN];    /* Image Name        */  
  20. } image_header_t;  
  21. <span style="color:#CC0000;">  
  22. </span>  

#寄存器使用情况

On ARM, the following registers are used:

    R0:    function argument word/integer result
    R1-R3:    function argument word
    R9:    GOT pointer
    R10:    stack limit (used only if stack checking if enabled)
    R11:    argument (frame) pointer
    R12:    temporary workspace
    R13:    stack pointer
    R14:    link register
    R15:    program counter

    ==> U-Boot will use R8 to hold a pointer to the global data