嵌入式开发软件环境:uboot、kernel、rootfs、data布局分析

本文详细介绍了UBoot+Linux的整体方案在嵌入式系统中的应用,包括地址空间的逻辑布局、存储空间的物理布局实现及烧录过程。通过JTAG或配套烧写器、专用串口工具等方法完成不同组件的烧写,并讨论了针对批量生产的高效软件烧录流程。

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

uboot+linux的整体方案

开发板的datasheet中都有详细的地址空间的划分,其中比较重要的两块是:DDR地址空间和Flash地址空间。DDR空间是系统和应用的运行空间,一般由linux系统自身进行使用和管理;Flash空间是系统和应用载体的存放空间,一般需要在使用前进行划分,由应用开发者进行管理。

简单的示例和说明。

其中,Flash的整体地址空间为:0x34000000~0x34FFFFFF,共16MB,使用的是Nor Flash芯片。布局需要做的工作是:

  • 确定uboot二进制文件的大小,使用的地址范围
  • 确定linux kernel镜像文件的大小,使用的地址范围
  • 确定rootfs 根文件系统的镜像文件大小,使用的地址范围
  • 估计整体应用方案所需的空间大小,选择可使用的地址范围

完成上述工作后,项目的布局如下:

  • uboot:0x34000000~0x34080000, 512KB
  • kernel : 0x34080000~0x34180000, 1MB, 文件大小为952.8KB
  • rootfs : 0x34180000~0x34700000, 5.5MB, 文件大小为3.85MB
  • data : 0x34700000~0x34FFFFFF, 9MB, 文件大小为3.725MB



到这一步已经完成了地址空间的逻辑布局,接下来就是存储空间的物理布局实现,就是对Flash进行分区,这里可以分成四个区,对应上述四块软件,也可以分成三个区:
mtdparts=phys_mapped_flash:0x180000(boot),0x580000(roofs70),0x900000(data)

烧写镜像文件
如何将上述相应的镜像文件下载到或者烧写到开发板上,也涉及到大批量生成的烧录方式

  • JTAG,或者配套的烧写器,再加上配套的软件套件,如CCS,完成uboot的烧写
  • 专门的串口烧写工具,完成uboot的烧写
  • 在uboot环境下可以使用tftp工具,完成kernel镜像、rootfs文件、app文件的烧写

项目中主要是:烧写器+tftp(uboot一般不修改)



uboot环境中tftp工具的使用
不同的uboot版本命令格式和提供的功能会有所差别,最好是使用前查阅帮助或者参考开发指导手册,主要的功能有从服务器下载文件和上传文件到服务器,常见的格式为:


- 下载文件:tftp <addr> <file>
- 上传文件:tftp <addr> <size> <file>
如果使用的是Nand Flash芯片,下载过程:


- 下载文件到内存地址
- erase Flash上对应的文件存放地址空间
- write 内存地址中的文件内容到Flash上对应的地址空间
如果使用的是Nor Flash芯片,下载过程:


- erase Flash上对应文件的存放地址空间
- 直接下载文件到Flash中对应文件的地址空间中:tftp 0x34180000 rootfs.jffs2
同样的现在也可以直接从Nor Flash中启动内核镜像,而不需要先将其加载到内存再启动:
setenv bootcmd "bootm 0x34080000"



批量生产的软件烧录

进行设备的批量生产阶段,肯定不能按照开发阶段的过程来进行软件环境的烧录,对于大批量来说,这样做效率太低,而且容易出错。越简单、单一的操作效率越高,越不容易出错。最佳的方式是:一步解决。在此推荐的方式是:

    • 按照上面的内容和步骤完成整个软件环境的布局和构建
    • 用tftp工具将整个Flash中的内容全部打包上传到服务器,得到一个整体方案镜像
    • 使用烧片器烧写整体镜像完成批量原始设备的软件烧录构建
### U-Boot Root Filesystem Configuration and Information #### Understanding the Role of U-Boot in Booting a System with RootFS U-Boot (Universal Boot Loader) plays an essential role during system boot-up by initializing hardware components before handing over control to the operating system kernel. For systems that require loading a root file system from various storage devices or network interfaces, configuring U-Boot appropriately is crucial. The NXP-provided version of U-Boot can be obtained through their GitHub repository[^1]. This source code serves as the foundation for customizing U-Boot according to specific needs such as supporting different boards like `s5p_goni` which has been successfully configured using: ```bash make s5p_goni_config ``` This command sets up default configurations suitable for this particular board type[^3]. #### Setting Up Environment Variables for RootFS Loading To configure U-Boot so it knows where to find the root filesystem after starting Linux Kernel, environment variables must be set within U-Boot's configuration space. Commonly used settings include specifying paths related to device trees (`fdt_file`) and root partitions (`bootargs`). An example setup might look like this: ```bash setenv fdt_high 0xffffffff setenv initrd_high 0xffffffff setenv bootcmd 'fatload mmc 0:1 $kernel_addr_r uImage; fatload mmc 0:1 $fdt_addr_r dtb.img; bootm $kernel_addr_r - $fdt_addr_r' setenv bootargs 'console=ttySAC2,115200 root=/dev/mmcblk0p2 rw rootwait' saveenv ``` In this snippet: - The console setting ensures serial output. - The `root=` parameter points to the partition containing the root filesystem on the SD card. - `rw` enables read-write access mode. - `rootwait` delays mounting until the device becomes available. These commands prepare U-Boot to load both the kernel image and device tree binary from FAT-formatted media while passing necessary parameters to initialize the correct block device as the root directory upon startup. #### Handling Different Storage Media Types Depending on whether the target platform uses eMMC, NAND flash, SPI NOR Flash, USB drives, etc., adjustments may need to occur when defining how data should get loaded into memory prior to execution. In some cases, additional drivers could also become required based on chosen peripherals involved in transferring files between external storages and internal RAM buffers. For instance, if working with older versions lacking certain features mentioned earlier regarding unsupported protocols like Kermit, alternative methods involving other supported ones would have to suffice instead[^4]: ```bash loadx 0x05000000 115200 ``` However, more recent releases typically offer broader compatibility across multiple transfer standards including TFTP, NFS, Ymodem among others making integration simpler without requiring manual intervention each time new binaries are introduced onto platforms running customized instances derived from upstream sources provided via repositories similar to what was referenced initially concerning availability channels offered by manufacturers supplying SoCs utilized inside embedded products designed around ARM architectures specifically targeted here today discussing aspects surrounding initialization routines executed early stages preceding full OS takeovers post-power-on sequences initiated either automatically following reset conditions met internally once power rails stabilize sufficiently enough allowing microprocessor cores begin executing instructions stored ROM regions mapped low addresses reserved special purposes outlined technical documentation accompanying chipsets employed throughout design cycles leading final assembly steps completed manufacturing facilities responsible producing units eventually shipped customers worldwide seeking solutions leveraging advanced processing capabilities delivered modern semiconductor technologies implemented silicon wafers fabricated state-of-the-art foundries adhering strict quality assurance practices ensuring reliability performance metrics meet expectations end-users deploying these systems real-world applications ranging consumer electronics industrial automation automotive infotainment medical instrumentation telecommunications infrastructure server farms cloud computing services internet things edge analytics machine learning workloads artificial intelligence research projects educational tools hobbyist experiments maker movements open-source communities collaborative development efforts spanning global networks interconnected researchers developers engineers scientists enthusiasts contributing knowledge sharing innovations accelerating pace discovery pushing boundaries human ingenuity shaping future possibilities emerging tech landscapes continuously evolving digital age characterized rapid advancements unprecedented connectivity pervasive computation transforming societies cultures economies environments globally. --related questions-- 1. How does one modify U-Boot to support newer communication protocols not included out-of-the-box? 2. What considerations exist when choosing between different types of root filesystem implementations for embedded systems? 3. Can you provide examples of common pitfalls encountered during U-Boot customization processes? 4. Is there any difference in handling rootfs configuration between bare metal programming versus using RTOSes? 5. Are there best practices recommended for maintaining secure yet flexible U-Boot setups?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值