上一篇博文中我们已经编译出了裸板程序led.bin
接着就是制作sd卡启动,将裸板程序跑起来。
首先需要将sdcard插入PC,让ubuntu系统识别到sdcard,目前来说没有windows工具,因此只能使用真实的linux机器或者虚拟机。
sc@sc-System-Product-Name:~/work/tiny4412/sd_fuse$ df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 3990428 0 3990428 0% /dev
tmpfs 803368 9980 793388 2% /run
/dev/sda4 98299524 6071976 87211180 7% /
tmpfs 4016832 216 4016616 1% /dev/shm
tmpfs 5120 4 5116 1% /run/lock
tmpfs 4016832 0 4016832 0% /sys/fs/cgroup
/dev/sda2 7743632 147204 7180020 3% /boot
/dev/sda1 997456 3492 993964 1% /boot/efi
/dev/sda5 1807565100 161443956 1554279096 10% /home
tmpfs 803368 56 803312 1% /run/user/1000
/dev/sdb1 7590912 4 7590908 1% /media/sc/FRIENDLYARM
上面的/dev/sdb1就是我们的sdcard设备。
接着在友善之臂提供的uboot文件目录下有个sd_fuse文件夹,里面是打包脚本、源文件和一些工具。我们就 是利用这里面的文件和工具制作卡启动的。
其中V310-EVT1-mkbl2.c是让我们编译mkbl2工具的。需要执行gcc -o mkbl2 V310-EVT1-mkbl2.c,编译出mkbl2工具,这个工具在tiny4412/sd_fusing.sh 脚本中会被调用到。
tiny4412文件夹下有如下文件
其中E4412_N.bl1.bin (BL1)是由三星原厂提供,没有源码。
E4412_tzsw.bin也是由三星原厂提供的。
sd_fusing.sh就是要使用是烧写脚本。
在tiny4412目录下执行 sudo ./sd_fusing.sh /dev/sdb ../led.bin // (led.bin拷贝到了,tiny4412的上级目录下。/dev/sdb是ubuntu识别到的我们的sdcard)
报错: Usage: unsupported size
这里主要是在执行mkbl2文件的时候出错,在sd_fuse.sh文件中调用到了mkbl2
即执行了./mkbl2 led.bin bl2.bin 14336后出错。
查看mkbl2的源码V310-EVT1-mkbl2.c
/*
* 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
#include
#include
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
它做的主要工作是:
1.从源文件中读取13k的数据到buf中,
2.处理buf中的前14332字节的数据,得到4字节的checksum
3.组装buf中的钱14332字节的数据和4字节的checksum,得到一个新的14k的buf数据。
4.将3中构建的buf数据写到bl2.bin文件中。
问题是当我们的源文件小于14k时,就直接返回错误了,因此我们需要修改源文件,让其支持小于14k的文件。
修改:
/*
* 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
#include
#include
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
这样就不在报错了。也正常生成bl2.bin文件。
接着还需要修改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 "
exit 0
fi
if [ -b $1 ]
then
echo "$1 reader is identified."
else
echo "$1 is NOT identified."
exit 0
fi
####################################
#
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 //原文件中是直接指定了u-boot.bin文件,
E4412_UBOOT=$2 //需要修改成传入的第二个参数,也就是led.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
#
${MKBL2} ${E4412_UBOOT} bl2.bin 14336
####################################
# fusing images
signed_bl1_position=1
bl2_position=17
uboot_position=49
tzsw_position=705
#
echo "---------------------------------------"
echo "BL1 fusing"
dd iflag=dsync oflag=dsync if=./E4412_N.bl1.bin of=$1 seek=$signed_bl1_position
#
echo "---------------------------------------"
echo "BL2 fusing"
dd iflag=dsync oflag=dsync if=./bl2.bin of=$1 seek=$bl2_position
#
echo "---------------------------------------"
echo "u-boot fusing"
dd iflag=dsync oflag=dsync if=${E4412_UBOOT} of=$1 seek=$uboot_position
#
echo "---------------------------------------"
echo "TrustZone S/W fusing"
dd iflag=dsync oflag=dsync if=./E4412_tzsw.bin of=$1 seek=$tzsw_position
#
sync
####################################
#
echo "---------------------------------------"
echo "U-boot image is fused successfully."
echo "Eject SD card and insert it again."
如果想看sd_fusing.sh的代码注释可以参考:https://blog.csdn.net/z961968549/article/details/78041839 写的很详细。
现在准备工作完成:
插上sdcard,执行:
sc@sc-System-Product-Name:~/work/tiny4412/sd_fuse/tiny4412$ sudo ./sd_fusing.sh /dev/sdb ../led.bin
/dev/sdb reader is identified.
---------------------------------------
BL1 fusing
16+0 records in
16+0 records out
8192 bytes (8.2 kB, 8.0 KiB) copied, 0.0271815 s, 301 kB/s
---------------------------------------
BL2 fusing
28+0 records in
28+0 records out
14336 bytes (14 kB, 14 KiB) copied, 0.0450742 s, 318 kB/s
---------------------------------------
u-boot fusing
0+1 records in
0+1 records out
176 bytes copied, 0.00129791 s, 136 kB/s
---------------------------------------
TrustZone S/W fusing
184+0 records in
184+0 records out
94208 bytes (94 kB, 92 KiB) copied, 0.287752 s, 327 kB/s
---------------------------------------
U-boot image is fused successfully.
Eject SD card and insert it again.
这样就烧写成功。
将sdcard插入开发板,把启动开关拨到sdcard启动,复位系统,就可以看到led灯轮流亮起。