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# tpl don't need replace MAGIC 67if grep -q '^NEWIDB=true' ${INI} ; then 68 ARG_NEWIDB="y" 69fi 70 71# replace 72if [ "${TPL_BIN}" != "" -a "${SPL_BIN}" != "" ]; then 73 if [ "${ARG_NEWIDB}" == "y" ]; then 74 cp ${TPL_BIN} tmp/tpl.bin 75 else 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 fi 80 81 cp ${SPL_BIN} tmp/u-boot-spl.bin 82 sed -i "s/FlashData=.*$/FlashData=.\/tmp\/tpl.bin/" ${TMP_INI} 83 sed -i "0,/Path1=.*/s/Path1=.*$/Path1=.\/tmp\/tpl.bin/" ${TMP_INI} 84 sed -i "s/FlashBoot=.*$/FlashBoot=.\/tmp\/u-boot-spl.bin/" ${TMP_INI} 85 LABEL="TPL+SPL" 86elif [ "${TPL_BIN}" != "" ]; then 87 if [ "${ARG_NEWIDB}" == "y" ]; then 88 cp ${TPL_BIN} tmp/tpl.bin 89 else 90 cp ${TPL_BIN} tmp/u-boot-tpl.bin 91 dd if=tmp/u-boot-tpl.bin of=tmp/tpl.bin bs=1 skip=4 92 sed -i "1s/^/${MAGIC:0:4}/" tmp/tpl.bin 93 fi 94 sed -i "s/FlashData=.*$/FlashData=.\/tmp\/tpl.bin/" ${TMP_INI} 95 sed -i "0,/Path1=.*/s/Path1=.*$/Path1=.\/tmp\/tpl.bin/" ${TMP_INI} 96 LABEL="TPL" 97else 98 cp ${SPL_BIN} tmp/u-boot-spl.bin 99 sed -i "s/FlashBoot=.*$/FlashBoot=.\/tmp\/u-boot-spl.bin/" ${TMP_INI} 100 LABEL="SPL" 101fi 102 103./tools/boot_merger ${TMP_INI} 104rm tmp/ -rf 105 106echo "pack loader(${LABEL}) okay! Input: ${INI}" 107echo 108