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