背景:
最近在學習uboot,其中有一步很重要的任務就是需要實現uboot 的驗證,沒有辦法驗證uboot是不是自己做的,那么整個開發就會收到阻礙。另外,從公司現在開發的板子來看,uboot從sd卡啟動是一個很常用的手法。苦於身邊的開發板沒有提供這個手段,這里也要吐槽一下供應商連這么簡單的手段都不公開出來。
好在最近參考了有關的文檔,實現了出來。
平台 :Ubuntu 18.04
arm-gcc :4.8
arm-gcc :4.8
$ ./arm-eabi-gcc --version
arm-eabi-gcc (GCC) 4.8
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
准備:
編譯好的 uboot (具體的uboot是從 供應商手上提供的uboot編譯而來的)
一張sd卡,讀卡器
Linux制作sd啟動卡:
安裝以下工具
sudo apt-get install gparted
確定sd卡插入的設備節點
*為了確保萬無一失,可以 檢查插入sd前后 cat /proc/partitions 的區別,有新增的設備就是sd卡所在的設備節點。*
$ cat /proc/partitions major minor #blocks name 7 7 2300 loop7 8 0 104857600 sda 8 16 15298560 sdb 8 17 15036416 sdb1
顯然,這里是 sdb ,我們也可以看到有 /dev/sdb 設備存在。
刪除sd卡原有的分區
* 如果想刪除sd卡原有的隱藏分區也可以通過這一部實現 *
$ sudo fdisk /dev/sdb Welcome to fdisk (util-linux 2.31.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
輸入d 按下回車 :刪除所有分區
Command (m for help): d Selected partition 1 Partition 1 has been deleted.
再輸入w 按下回車:保存修改
Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
此時,如果再使用 cat /proc/partitions 會發現 sdb1 消失
給sd卡分區
輸入:
sudo gparted /dev/sdb
根據界面上面的指示進行操作:(共5步)
1: 添加分區
2:輸入分區大小
3:選擇fat32格式
4:確定添加
5:點擊打勾以保存修改
至此,sd卡制作完畢。
制作燒寫腳本
#!/bin/sh # s5p6818 irom sd/mmc boot fusing tool. # Author: Jianjun Jiang <8192542@qq.com> # display usage message USAGE() { echo Usage: $(basename "$0") '<device> <bootloader>' echo ' device = disk device name for SD card.' echo ' bootloader = /path/to/uboot.bin' echo 'e.g. '$(basename "$0")' /dev/sdc uboot.bin' } #[ `id -u` == 0 ] || { echo "you must be root user"; exit 1; } [ -z "$1" -o -z "$2" ] && { USAGE; exit 1; } dev="$1" xboot="$2" # validate parameters [ -b "${dev}" ] || { echo "${dev} is not a valid block device"; exit 1; } [ X"${dev}" = X"${dev%%[0-9]}" ] || { echo "${dev} is a partition, please use device, perhaps ${dev%%[0-9]}"; exit 1; } [ -f ${xboot} ] || { echo "${xboot} is not a bootloader binary file."; exit 1; } # copy the full bootloader image to block device dd if="${xboot}" of="${dev}" bs=512 seek=1 conv=sync sync; echo "OK"
執行腳本
sudo ./6818-sdmmc.sh /dev/sdb uboot.bin
插入支持sd卡啟動的開發板上,即可完成從sd卡啟動uboot
以下是改動后的uboot的效果。