【Tiny4412】从0移植uboot(三) _编译最小可用uboot

本文介绍如何定制U-Boot源码以适应特定硬件,并详细讲解了编译及烧录过程,包括使用三星提供的工具进行打包。

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

前两篇介绍了uboot-2013.01的配置原理以及大体的运行流程,本文将讨论如何对uboot源码进行配置,将一个可用的uboot烧录到SD卡中。

定制自己的core board

市面上能买到的开发板的核心板基本都是基于官方参考板制作的,所以虽然标准操作是”定制”自己的core board,但鉴于我的板子的核心板是基于三星的参考板做的,所以我们做的主要工作就是按照(一)中的原理,编写(山寨)我们”自己的”核心板配置。我们需要的目录是“board/samsung/origen/”,这部分的主要功能就是将其中的文件”改名字”。首先来认识一下原版以示尊重

board/samsung/origen/

$ls board/samsung/origen/
lowlevel_init.S Makefile mem_setup.S mmc_boot.c origen.c origen_setup.h tools
接下来就开始我们的山寨工作

//山寨参考板目录
$cp -arf ./board/samsung/origen ./board/samsung/xboot

//山寨关键文件
$mv ./board/samsung/xboot/origen.c ./board/samsung/xboot/xboot.c
uboot的编译系统和内核的类似,所以Makefile也得改(./board/samsung/xboot/Makefile)
from

30 ifndef CONFIG_SPL_BUILD
31 COBJS += origen.o
32 endif
to

30 ifndef CONFIG_SPL_BUILD
31 COBJS += xboot.o
32 endif
include/configs/origen.h

用于配置整个板子的头文件也不能放过

$cp include/configs/origen.h include/configs/xboot.h
from

104 #define CONFIG_SYS_PROMPT “ORIGEN # ”
133 #define CONFIG_IDENT_STRING ” for ORIGEN”
to

104 #define CONFIG_SYS_PROMPT “xboot # ”
133 #define CONFIG_IDENT_STRING ” for xboot”
boards.cfg

最后,别忘了我在上文提到的boards.cfg文件,如果这里面不动手脚,我们的板子是不会被Makefile找到的,So,

284 origen arm armv7 origen samsung exynos
285 xboot arm armv7 xboot samsung exynos
和之前一样,至此,我们就可以先编译一下过过手瘾(顺便检查一下配置^-^),

1 #!/bin/bash
2 CPU_NUM= (grepprocessor/proc/cpuinfo|awkfield=$NF;ENDprintfield+1)3exportARCH=arm4exportCROSSCOMPILE=/opt/armcrosscompile/arm2014.05/bin/armnonelinuxgnueabi5newName=xboot6makedistclean7make ( g r e p p r o c e s s o r / p r o c / c p u i n f o | a w k ′ f i e l d = $ N F ; E N D p r i n t f i e l d + 1 ′ ) 3 e x p o r t A R C H = a r m 4 e x p o r t C R O S S C O M P I L E = / o p t / a r m − c r o s s − c o m p i l e / a r m − 2014.05 / b i n / a r m − n o n e − l i n u x − g n u e a b i − 5 n e w N a m e = ” x b o o t ” 6 m a k e d i s t c l e a n 7 m a k e {newName}_config
8 make -j${CPU_NUM}
上面是编译的小脚本,下面是编译的输出。
这里写图片描述

编译and烧录

按照(一)中介绍的,此时已经可以”make xboot_config;make -8”并得到uboot.bin,但此时这个uboot.bin是不能直接烧录的。但无论如何,请暂且记住它的大小:176568byte。接下来,我们需要对uboot.bin进行一系列处理使它能够在exynos4412上运行,这其中要用到下面的几个命令或三星提供的工具软件,这些操作的目的就是根据三星的芯片的启动要求对uboot.bin 进行一些处理,包括在特定长度的位置加上和校验信息以及插入一些文件段。

修改地方

这里对原文中的uboot.bin打包动作,进行修改,使用三星的提供的源码对其进行打包。一步到位,更加简单:

源码如下:

/*
 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
 *              http://www.samsung.com/
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main (int argc, char *argv[])
{
    FILE        *fp;
    unsigned char   src;
    char        *Buf, *a;
    int     BufLen;
    int     nbytes, fileLen;
    unsigned int    checksum = 0;
    int     i;

    if (argc != 4)
    {
        printf("Usage: mkbl1 <source file> <destination file> <size> \n");
        return -1;
    }

    BufLen = atoi(argv[3]);
    Buf = (char *)malloc(BufLen);
    memset(Buf, 0x00, BufLen);

    fp = fopen(argv[1], "rb");
    if( fp == NULL)
    {
        printf("source file open error\n");
        free(Buf);
        return -1;
    }

    fseek(fp, 0L, SEEK_END);
    fileLen = ftell(fp);
    fseek(fp, 0L, SEEK_SET);

    if ( BufLen > fileLen )
    {
        printf("Usage: unsupported size\n");
        free(Buf);
        fclose(fp);
        return -1;
    }

    nbytes = fread(Buf, 1, BufLen, fp);

    if ( nbytes != BufLen )
    {
        printf("source file read error\n");
        free(Buf);
        fclose(fp);
        return -1;
    }

    fclose(fp);

    for(i = 0;i < (14 * 1024) - 4;i++)
    {
        checksum += (unsigned char)(Buf[i]);
    }
    *(unsigned int*)(Buf+i) = checksum;

    fp = fopen(argv[2], "wb");
    if (fp == NULL)
    {
        printf("destination file open error\n");
        free(Buf);
        return -1;
    }

    a   = Buf;
    nbytes  = fwrite( a, 1, BufLen, fp);

    if ( nbytes != BufLen )
    {
        printf("destination file write error\n");
        free(Buf);
        fclose(fp);
        return -1;
    }

    free(Buf);
    fclose(fp);

    return 0;
}

对其进行编译,生成一个可执行文件 mkbl2, 在脚本中使用如下命令,就可以完成bin文件的打包任务:

####################################
# check files

E4412_UBOOT=../../u-boot.bin
MKBL2=../mkbl2

if [ ! -f ${E4412_UBOOT} ]; then
    echo "Error: u-boot.bin NOT found, please build it & try again."
    exit -1
fi

if [ ! -f ${MKBL2} ]; then
    echo "Error: can not find host tool - mkbl2, stop."
    exit -1
fi

#<make bl2> 对可执行文件(mkbl2)传入参数
${MKBL2} ${E4412_UBOOT} bl2.bin 14336

最后,使用命令 ./sd_fusing.sh /dev/your_SD_device 即可完成烧写的任务。
主要分为 BL1BL2u-bootTrustZone S/W 这四个区域的烧写。

# the file for tiny4412 development board.
# file name: sd_fusing.sh
#
# Copyright (C) 2011 Samsung Electronics Co., Ltd.
#              http://www.samsung.com/
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
####################################

if [ -z $1 ]
then
    echo "usage: ./sd_fusing.sh <SD Reader's device file>"
    exit 0
fi

if [ -b $1 ]
then
    echo "$1 reader is identified."
else
    echo "$1 is NOT identified."
    exit 0
fi

####################################
#<verify device>

BDEV_NAME=`basename $1`
BDEV_SIZE=`cat /sys/block/${BDEV_NAME}/size`

if [ ${BDEV_SIZE} -le 0 ]; then
    echo "Error: NO media found in card reader."
    exit 1
fi

if [ ${BDEV_SIZE} -gt 32000000 ]; then
    echo "Error: Block device size (${BDEV_SIZE}) is too large"
    exit 1
fi

####################################
# check files

E4412_UBOOT=../../u-boot.bin
MKBL2=../mkbl2

if [ ! -f ${E4412_UBOOT} ]; then
    echo "Error: u-boot.bin NOT found, please build it & try again."
    exit -1
fi

if [ ! -f ${MKBL2} ]; then
    echo "Error: can not find host tool - mkbl2, stop."
    exit -1
fi

#<make bl2>
${MKBL2} ${E4412_UBOOT} bl2.bin 14336

####################################
# fusing images

signed_bl1_position=1
bl2_position=17
uboot_position=49
tzsw_position=705

#<BL1 fusing>
echo "---------------------------------------"
echo "BL1 fusing"
dd iflag=dsync oflag=dsync if=./E4412_N.bl1.bin of=$1 seek=$signed_bl1_position

#<BL2 fusing>
echo "---------------------------------------"
echo "BL2 fusing"
dd iflag=dsync oflag=dsync if=./bl2.bin of=$1 seek=$bl2_position

#<u-boot fusing>
echo "---------------------------------------"
echo "u-boot fusing"
dd iflag=dsync oflag=dsync if=${E4412_UBOOT} of=$1 seek=$uboot_position

#<TrustZone S/W fusing>
echo "---------------------------------------"
echo "TrustZone S/W fusing"
dd iflag=dsync oflag=dsync if=./E4412_tzsw.bin of=$1 seek=$tzsw_position

#<flush to disk>
sync

####################################
#<Message Display>
echo "---------------------------------------"
echo "U-boot image is fused successfully."
echo "Eject SD card and insert it again."

致敬社区大神:原文链接

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值