将一副图片编译进uboot

时间:2021-11-08 04:51:48

在uboot显示图片的时候可以将jpg图片作为uboot的一段,在程序中访问该段,实现图片。

图片: logo.jpg ,将其拷贝到common下

  • 修改u-boot.lds,添加".log"段。(u-boot.lds的路径:arch/arm/cpu/godnet/u-boot.lds)
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_start)
SECTIONS
{
. = 0x00000000; . = ALIGN();
.text :
{
arch/arm/cpu/godnet/start.o (.text)
*(.text)
} . = ALIGN();
__logo_start = .;
.logo :
{
common/logo.o (.logo);
}
__logo_end = .; . = ALIGN();
.rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) } . = ALIGN();
.data : { *(.data) } . = ALIGN();
.got : { *(.got) } __u_boot_cmd_start = .;
.u_boot_cmd : { *(.u_boot_cmd) }
__u_boot_cmd_end = .; . = ALIGN();
__bss_start = .;
.bss : { *(.bss) }
_end = .;
}
  • 在common下添加logo.S文件,写入如下内容
.section .logo
.incbin "./logo.jpg"
  • 添加common/cmd_logo.c ,内容如下:
    #include <common.h>
    #include <command.h> extern unsigned int __logo_start;
    extern unsigned int __logo_end; int do_logo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
    { volatile char *p = (volatile char *)(&__logo_start);
    int i;
    unsigned int len = ; len = (unsigned int)&__logo_end - (unsigned int)&__logo_start; printf("__logo_start = %p\n", &__logo_start);
    printf("__logo_end = %p\n", &__logo_end);
    printf("logo size is %x\n", len); for (i = ; i < len; i++)
    {
    if(i % == )
    {
    printf("\n");
    } printf("%3x ", *p++&0xff);
    }
    printf("\n"); return ; } U_BOOT_CMD(
    logo, CONFIG_SYS_MAXARGS, , do_logo,
    "minimal test like /bin/sh",
    "[args..]"
    );
  • 修改common/Makefile,添加如下内容:
COBJS-y += cmd_logo.o
AOBJS-y += logo.o COBJS := $(sort $(COBJS-y))
AOBJS := $(sort $(AOBJS-y))
SRCS := $(AOBJS:.o=.S) $(COBJS:.o=.c)
OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS))
  • 编译uboot

本例是将.logo段的图片数据读取并打印出来,显示图片不是重点。