1#!/bin/bash 2# 3# Copyright (c) 2020 Rockchip Electronics Co., Ltd 4# 5# SPDX-License-Identifier: GPL-2.0 6# 7 8if [ $# -eq 0 ]; then 9 echo "ERROR: No args of $0" 10 exit 1 11fi 12 13while [ $# -gt 0 ]; do 14 case $1 in 15 --ini) 16 INI=$2 17 shift 2 18 ;; 19 --spl) 20 SPL_BIN=$2 21 if [ ! -f ${SPL_BIN} ]; then 22 echo "ERROR: No ${SPL_BIN}" 23 exit 1 24 fi 25 shift 2 26 ;; 27 --tpl) 28 TPL_BIN=$2 29 if [ ! -f ${TPL_BIN} ]; then 30 echo "ERROR: No ${TPL_BIN}" 31 exit 1 32 fi 33 shift 2 34 ;; 35 *) 36 echo "ERROR: Unknown arg: $1" 37 exit 1 38 ;; 39 esac 40done 41 42if [ ! -f ${INI} ]; then 43 echo "ERROR: No ${INI}" 44 exit 0 45fi 46 47if [ "${TPL_BIN}" == "" -a "${SPL_BIN}" == "" ]; then 48 echo "ERROR: No SPL and TPL file" 49 exit 0 50fi 51 52rm tmp -rf && mkdir tmp -p 53TMP_INI="tmp/MINIALL.ini" 54cp ${INI} ${TMP_INI} 55 56# magic 57MAGIC=`sed -n '/NAME=/s/NAME=//p' ${INI}` 58if [ "${MAGIC}" == "RV1126" ]; then 59 MAGIC="110B" 60elif [ "${MAGIC}" == "RKPX30" ]; then 61 MAGIC="RK33" 62fi 63 64# replace 65if [ "${TPL_BIN}" != "" -a "${SPL_BIN}" != "" ]; then 66 cp ${TPL_BIN} tmp/u-boot-tpl.bin 67 cp ${SPL_BIN} tmp/u-boot-spl.bin 68 dd if=tmp/u-boot-tpl.bin of=tmp/tpl.bin bs=1 skip=4 69 70 sed -i "1s/^/${MAGIC:0:4}/" tmp/tpl.bin 71 sed -i "s/FlashData=.*$/FlashData=.\/tmp\/tpl.bin/" ${TMP_INI} 72 sed -i "0,/Path1=.*/s/Path1=.*$/Path1=.\/tmp\/tpl.bin/" ${TMP_INI} 73 sed -i "s/FlashBoot=.*$/FlashBoot=.\/tmp\/u-boot-spl.bin/" ${TMP_INI} 74 LABEL="TPL+SPL" 75elif [ "${TPL_BIN}" != "" ]; then 76 cp ${TPL_BIN} tmp/u-boot-tpl.bin 77 dd if=tmp/u-boot-tpl.bin of=tmp/tpl.bin bs=1 skip=4 78 sed -i "1s/^/${MAGIC:0:4}/" tmp/tpl.bin 79 sed -i "s/FlashData=.*$/FlashData=.\/tmp\/tpl.bin/" ${TMP_INI} 80 sed -i "0,/Path1=.*/s/Path1=.*$/Path1=.\/tmp\/tpl.bin/" ${TMP_INI} 81 LABEL="TPL" 82else 83 cp ${SPL_BIN} tmp/u-boot-spl.bin 84 sed -i "s/FlashBoot=.*$/FlashBoot=.\/tmp\/u-boot-spl.bin/" ${TMP_INI} 85 LABEL="SPL" 86fi 87 88rm *_loader_*.bin -f 89./tools/boot_merger ${TMP_INI} 90 91FNAME=`basename *_loader_*.bin` 92if [[ ${FNAME} != *spl* ]]; then 93 rename 's/loader_/spl_loader_/' *_loader_*.bin 94fi 95rm tmp/ -rf 96 97echo "pack loader(${LABEL}) okay! Input: ${INI}" 98echo 99