i will send the flash.sh code script in two reply while it not support to upload flash.sh file and text limit here.
code 1 to 1997
#!/bin/bash
# SPDX-FileCopyrightText: Copyright (c) 2011-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# flash.sh: Flash the target board.
# flash.sh performs the best in LDK release environment.
#
# Usage: Place the board in recovery mode and run:
#
# flash.sh [options] <target_board> <root_device>
#
# for more detail enter 'flash.sh -h'
#
# Examples:
# ./flash.sh <target_board> internal - boot <target_board> from on-board device (eMMC/SDCARD)
# ./flash.sh <target_board> external - boot <target_board> from external device
# ./flash.sh <target_board> mmcblk0p1 - boot <target_board> from eMMC
# ./flash.sh <target_board> mmcblk1p1 - boot <target_board> from SDCARD
# ./flash.sh <target_board> sda1 - boot <target_board> from USB device
# ./flash.sh <target_board> nvme0n1 - boot <target_board> from NVME storage device
# ./flash.sh -N <IPaddr>:/nfsroot <target_board> eth0 - boot <target_board> from NFS
# ./flash.sh -k LNX <target_board> mmcblk1p1 - update <target_board> kernel
# ./flash.sh -k EBT <target_board> mmcblk1p1 - update <target_board> bootloader
#
# Optional Environment Variables:
# BCTFILE ---------------- Boot control table configuration file to be used.
# BOARDID ---------------- Pass boardid to override EEPROM value
# BOARDREV --------------- Pass board_revision to override EEPROM value
# BOARDSKU --------------- Pass board_sku to override EEPROM value
# BOOTLOADER ------------- Bootloader binary to be flashed
# BOOTPARTLIMIT ---------- GPT data limit. (== Max BCT size + PPT size)
# BOOTPARTSIZE ----------- Total eMMC HW boot partition size.
# CFGFILE ---------------- Partition table configuration file to be used.
# CMDLINE ---------------- Target cmdline. See help for more information.
# DEVSECTSIZE ------------ Device Sector size. (default = 512Byte).
# DTBFILE ---------------- Device Tree file to be used.
# EMMCSIZE --------------- Size of target device eMMC (boot0+boot1+user).
# FLASHAPP --------------- Flash application running in host machine.
# FLASHER ---------------- Flash server running in target machine.
# INITRD ----------------- Initrd image file to be flashed.
# KERNEL_IMAGE ----------- Linux kernel zImage file to be flashed.
# MTS -------------------- MTS file name such as mts_si.
# MTSPREBOOT ------------- MTS preboot file name such as mts_preboot_si.
# NFSARGS ---------------- Static Network assignments.
# <C-ipa>:<S-ipa>:<G-ipa>:<netmask>
# NFSROOT ---------------- NFSROOT i.e. <my IP addr>:/exported/rootfs_dir.
# NO_RECOVERY_IMG -------- Do not create or re-create recovery.img
# NO_ROOTFS -------------- Do not create or re-create system.img
# ODMDATA ---------------- Odmdata to be used.
# PKCKEY ----------------- RSA key file to used to sign bootloader images.
# ROOTFSSIZE ------------- Linux RootFS size (internal emmc/nand only).
# ROOTFS_DIR ------------- Linux RootFS directory name.
# POWEROFF --------------- Set to 1 to power off the target device after the flashing is done.
# Example: $ POWEROFF=1 ./flash.sh <target_board> <rootdev>
# SBKKEY ----------------- SBK key file to used to encrypt bootloader images.
# SCEFILE ---------------- SCE firmware file such as camera-rtcpu-sce.img.
# SPEFILE ---------------- SPE firmware file path such as bootloader/spe.bin.
# FAB -------------------- Target board's FAB ID.
# TEGRABOOT -------------- lowerlayer bootloader such as nvtboot.bin.
# WB0BOOT ---------------- Warmboot code such as nvtbootwb0.bin
#
INFODIVIDER="\
###############################################################################\
";
chkerr ()
{
if [ $? -ne 0 ]; then
if [ "$1" != "" ]; then
echo "$1" >&2;
else
echo "failed." >&2;
fi;
exit 1;
fi;
if [ "$1" = "" ]; then
echo "done.";
fi;
}
pr_conf()
{
echo "target_board=${target_board}";
echo "target_rootdev=${target_rootdev}";
echo "rootdev_type=${rootdev_type}";
echo "rootfssize=${rootfssize}";
echo "odmdata=${odmdata}";
echo "flashapp=${flashapp}";
echo "flasher=${flasher}";
echo "bootloader=${bootloader}";
echo "tegraboot=${tegraboot}";
echo "wb0boot=${wb0boot}";
echo "mtspreboot=${mtspreboot}";
echo "mts=${mts}";
echo "bctfile=${bctfile}";
echo "cfgfile=${cfgfile}";
echo "kernel_fs=${kernel_fs}";
echo "kernel_image=${kernel_image}";
echo "dtbfile=${dtbfile}"
echo "rootfs_dir=${rootfs_dir}";
echo "nfsroot=${nfsroot}";
echo "nfsargs=${nfsargs}";
echo "kernelinitrd=${kernelinitrd}";
echo "cmdline=${cmdline}";
echo "boardid=${boardid}";
}
validateIP ()
{
local ip=$1;
local ret=1;
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=${IFS};
IFS='.';
ip=($ip);
IFS=${OIFS};
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && \
${ip[2]} -le 255 && ${ip[3]} -le 255 ]];
ret=$?;
fi;
if [ ${ret} -ne 0 ]; then
echo "Invalid IP address: $1" >&2;
exit 2;
fi;
}
netmasktbl=(\
"255.255.255.252" \
"255.255.255.248" \
"255.255.255.240" \
"255.255.255.224" \
"255.255.255.192" \
"255.255.255.128" \
"255.255.255.0" \
"255.255.254.0" \
"255.255.252.0" \
"255.255.248.0" \
"255.255.240.0" \
"255.255.224.0" \
"255.255.192.0" \
"255.255.128.0" \
"255.255.0.0" \
"255.254.0.0" \
"255.252.0.0" \
"255.248.0.0" \
"255.240.0.0" \
"255.224.0.0" \
"255.192.0.0" \
"255.128.0.0" \
"255.0.0.0" \
);
validateNETMASK ()
{
local i;
local nm=$1;
for (( i=0; i<${#netmasktbl[@]}; i++ )); do
if [ "${nm}" = ${netmasktbl[$i]} ]; then
return 0;
fi;
done;
echo "Error: Invalid netmask($1)" >&2;
exit 3;
}
validateNFSargs ()
{
local a=$2;
OIFS=${IFS};
IFS=':';
a=($a);
IFS=${OIFS};
if [ ${#a[@]} -ne 4 ]; then
echo "Error: Invalid nfsargs($2)" >&2;
exit 4;
fi;
validateIP ${a[0]};
if [ "${serverip}" = "" ]; then
validateIP ${a[1]};
fi;
validateIP ${a[2]};
validateNETMASK ${a[3]};
if [ "$1" != "" ]; then
eval "$1=$2";
fi;
return 0;
}
validateNFSroot ()
{
if [ "$2" = "" ]; then
return 1;
fi;
OIFS=${IFS};
IFS=':';
local var=$1;
local a=($2);
IFS=${OIFS};
if [ ${#a[@]} -ne 2 ]; then
echo "Error: Invalid nfsroot($2)" >&2;
exit 5;
fi;
validateIP ${a[0]};
if [[ "${a[1]}" != /* ]]; then
echo "Error: Invalid nfsroot($2)" >&2;
exit 6;
fi;
eval "${var}=$2";
return 0;
}
usage ()
{
state=$1;
retval=$2;
if [[ $state == allunknown ]]; then
echo -e "
Usage: sudo ./flash.sh [options] <target_board> <rootdev>
Where,
target board: Valid target board name.
rootdev: Proper root device.";
elif [[ $state == rootdevunknown ]]; then
echo -e "
Usage: sudo ./flash.sh [options] ${target_board} <rootdev>
Where,
rootdev for ${target_board}:
${ROOT_DEV}";
else
echo "
Usage: sudo ./flash.sh [options] ${target_board} ${target_rootdev}";
fi;
cat << EOF
options:
-b <bctfile> --------- Boot control table config file.
-c <cfgfile> --------- Flash partition table config file.
-d <dtbfile> --------- device tree file.
-e <emmc size> ------- Target device's eMMC size.
-f <flashapp> -------- Path to flash application (tegraflash.py)
-h ------------------- print this message.
-i <enc rfs key file>- key for disk encryption support.
-k <partition id> ---- partition name or number specified in flash.cfg.
-m <mts preboot> ----- MTS preboot such as mts_preboot_si.
-n <nfs args> -------- Static nfs network assignments
<Client IP>:<Server IP>:<Gateway IP>:<Netmask>
-o <odmdata> --------- ODM data.
-p <bp size> --------- Total eMMC HW boot partition size.
-r ------------------- skip building and reuse existing system.img.
-s <PKC key file>----- PKC key used for signing and building bl_update_payload.
(obsolete)
-t <tegraboot> ------- tegraboot binary such as nvtboot.bin
-u <PKC key file>----- PKC key used for odm fused board.
-v <SBK key file>----- Secure Boot Key (SBK) key used for ODM fused board.
-w <wb0boot> --------- warm boot binary such as nvtbootwb0.bin
-x <tegraid> --------- Tegra CHIPID. default = 0x18(jetson-tx2)
0x21(jetson-tx1).
-z <sn> -------------- Serial Number of target board.
-B <boardid> --------- BoardId.
-C <cmdline> --------- Kernel commandline arguments.
WARNING:
Each option in this kernel commandline gets
higher preference over the values set by
flash.sh. In case of NFS booting, this script
adds NFS booting related arguments, if -i option
is omitted.
-F <flasher> --------- Flash server such as cboot.bin.
-G <file name> ------- Read partition and save image to file.
-I <initrd> ---------- initrd file. Null initrd is default.
-K <kernel> ---------- Kernel image file such as zImage or Image.
-L <bootloader> ------ Bootloader such as cboot.bin or u-boot-dtb.bin.
-M <mts boot> -------- MTS boot file such as mts_si.
-N <nfsroot> --------- i.e. <my IP addr>:/my/exported/nfs/rootfs.
-P <end of PPT + 1> -- Primary GPT start address + size of PPT + 1.
-R <rootfs dir> ------ Sample rootfs directory.
-S <size> ------------ Rootfs size in bytes. Valid only for internal
rootdev. KiB, MiB, GiB short hands are allowed,
for example, 1GiB means 1024 * 1024 * 1024 bytes.
-Z ------------------- Print configurations and then exit.
--no-flash ----------- perform all steps except physically flashing the board.
This will create a system.img.
--external-device----- Generate flash images for external devices
--no-systemimg ------- Do not create or re-create system.img.
--bup ---------------- Generate bootloader update payload(BUP).
--multi-spec---------- Enable support for building multi-spec BUP.
--clean-up------------ Clean up BUP buffer when multi-spec is enabled.
--rapid-boot-----------Rapid-boot support on Jetson-Nano.
--usb-instance <id> -- Specify the USB instance to connect to;
<id> = USB port path (e.g. 3-14).
--no-root-check ------ Typical usage of this script require root permissions.
Pass this option to allow running the script as a
regular user, in which case only specific combinations
of command-line options will be functional.
--user_key <key_file> User provided key file (16-byte) to encrypt user images,
like kernel, kernel-dtb and initrd.
If user_key is specified, SBK key (-v) has to be specified.
--rcm-boot ----------- Do RCM boot instead of physically flashing the board.
--sign --------------- Sign images and store them under "bootloader/signed"
directory. The board will not be physically flashed.
--image -------------- Specify the image to be written into board.
EOF
exit $retval;
}
setdflt ()
{
local var="$1";
if [ "${!var}" = "" ]; then
eval "${var}=\"$2\"";
fi;
}
setval ()
{
local var="$1";
local val="$2";
if [ "${!val}" = "" ]; then
echo "Error: missing $val not defined." >&2;
exit 8;
fi;
eval "${var}=\"${!val}\"";
}
mkfilesoft ()
{
local var="$1";
local varname="$1name";
eval "${var}=\"$2\"";
if [ "${!var}" = "" -o ! -f "${!var}" ]; then
if [ "$3" != "" -a -f "$3" ]; then
eval "${var}=\"$3\"";
fi;
fi;
if [ "${!var}" != "" ]; then
if [ ! -f "${!var}" ]; then
eval "${var}=\"\"";
eval "${varname}=\"\"";
return 1;
fi;
eval "${var}=\"$(readlink -f "${!var}")\"";
eval "${varname}=\"$(basename "${!var}")\"";
fi;
return 0;
}
mkfilepath ()
{
local var="$1";
local varname="$1name";
eval "${var}=\"$2\"";
setdflt "${var}" "$3";
if [ "${!var}" != "" ]; then
eval "${var}=\"$(readlink -f "${!var}")\"";
if [ ! -f "${!var}" ]; then
echo "Error: missing $var (${!var}).";
usage allknown 1;
fi;
eval "${varname}=\"$(basename "${!var}")\"";
fi;
}
mkdirpath ()
{
local var="$1";
eval "${var}=$2";
setdflt "$1" "$3";
if [ "${!var}" != "" ]; then
eval "${var}=\"$(readlink -f "${!var}")\"";
if [ ! -d "${!var}" ]; then
echo "Error: missing $var (${!var}).";
usage allknown 1;
fi;
fi;
}
getsize ()
{
local var="$1";
local val="$2";
if [[ ${!val} != *[!0-9]* ]]; then
eval "${var}=${!val}";
elif [[ (${!val} == *KiB) && (${!val} != *[!0-9]*KiB) ]]; then
eval "${var}=$(( ${!val%KiB} * 1024 ))";
elif [[ (${!val} == *MiB) && (${!val} != *[!0-9]*MiB) ]]; then
eval "${var}=$(( ${!val%MiB} * 1024 * 1024 ))";
elif [[ (${!val} == *GiB) && (${!val} != *[!0-9]*GiB) ]]; then
eval "${var}=$(( ${!val%GiB} * 1024 * 1024 * 1024))";
else
echo "Error: Invalid $1: ${!val}" >&2;
exit 9;
fi;
}
validatePartID ()
{
local idx=0;
declare -A cf;
while read aline; do
if [ "$aline" != "" ]; then
arr=( $(echo $aline | tr '=' ' ') );
if [ "${arr[1]}" == "name" ]; then
if [ "${arr[3]}" == "id" ]; then
cf[$idx,1]="${arr[2]}";
cf[$idx,0]="${arr[4]}";
else
cf[$idx,0]="${arr[2]}";
fi
idx=$((idx+1));
fi
fi;
done < $4;
if [ "${arr[3]}" == "id" ]; then
for ((i = 0; i < idx; i++)) do
if [ "\"$3\"" = "${cf[$i,0]}" -o \
"\"$3\"" = "${cf[$i,1]}" ]; then
eval "$1=${cf[$i,0]}";
eval "$2=${cf[$i,1]}";
return 0;
fi;
done;
echo "Error: invalid partition id ($3)" >&2;
exit 10;
else
return 0;
fi;
}
cp2local ()
{
local src=$1;
if [ "${!src}" = "" ]; then return 1; fi;
if [ ! -f "${!src}" ]; then return 1; fi;
if [ "$2" = "" ]; then return 1; fi;
if [ -f "$2" -a "${!src}" = "$2" ]; then
local sum1=$(sum "${!src}");
local sum2=$(sum "$2");
if [ "$sum1" = "$sum2" ]; then
echo "Existing ${src}($2) reused.";
return 0;
fi;
fi;
echo -n "copying ${src}(${!src})... ";
cp -f "${!src}" "$2";
chkerr;
return 0;
}
chsuffix ()
{
local var="$1";
local fname=`basename "$2"`;
local OIFS=${IFS};
IFS='.';
na=($fname);
IFS=${OIFS};
eval "${var}=${na[0]}.${3}";
}
pad_file_aligned ()
{
local __file="$1";
local __alignment="$2";
local __padvalue="$3";
local __padstring="";
filesize=$(stat --format=%s "${__file}");
rem=$(( filesize % __alignment ));
if (( rem > 0 )); then
rem=$(( __alignment - rem ));
for ((i = 0 ; i < rem ; i++)); do
__padstring+=${__padvalue};
done;
echo -e -n "${__padstring}" >> "${__file}";
fi;
}
build_fsimg ()
{
local __localsysfile="$1";
local __fillpat="$2";
local __rootfssize="$3";
local __rootfs_type="$4";
local __rootfs_dir="$5";
local __cmdline="$6";
local __do_sign="$7";
local _extlinux_conf="extlinux/extlinux.conf"
echo "Making ${__localsysfile}... ";
local bcnt=$(( ${__rootfssize} / 512 ));
local bcntdiv=$(( ${__rootfssize} % 512 ));
if [ ${bcnt} -eq 0 -o ${bcntdiv} -ne 0 ]; then
echo "Error: ${__rootfs_type} file system size has to be 512 bytes allign." >&2;
exit 11;
fi
if [ "${__rootfs_type}" != "FAT32" ] && [ ! -f "${__rootfs_dir}/boot/${_extlinux_conf}" ]; then
echo "${__rootfs_dir}/boot/${_extlinux_conf} is not found, exiting..." >&2;
exit 11
fi
if [ "${__fillpat}" != "" -a "${__fillpat}" != "0" ]; then
local fc=`printf '%d' ${__fillpat}`;
local fillc=`printf \\\\$(printf '%02o' $fc)`;
< /dev/zero head -c ${__rootfssize} | tr '\000' ${fillc} > ${__localsysfile};
chkerr "making ${__localsysfile} with fillpattern($fillc}) failed.";
else
truncate --size ${__rootfssize} ${__localsysfile};
chkerr "making ${__localsysfile} with zero fillpattern failed.";
fi;
loop_dev="$(losetup --show -f "${__localsysfile}")";
chkerr "mapping ${__localsysfile} to loop device failed.";
if [ "${__rootfs_type}" = "FAT32" ]; then
mkfs.msdos -I -F 32 "${loop_dev}" > /dev/null 2>&1;
else
mkfs -t ${__rootfs_type} "${loop_dev}" > /dev/null 2>&1;
fi;
chkerr "formating ${__rootfs_type} filesystem on ${__localsysfile} failed.";
mkdir -p mnt; chkerr "make $4 mount point failed.";
mount "${loop_dev}" mnt; chkerr "mount ${__localsysfile} failed.";
mkdir -p mnt/boot/dtb; chkerr "make ${__localsysfile}/boot/dtb failed.";
cp -f "${kernel_fs}" mnt/boot;
chkerr "Copying ${kernel_fs} failed.";
_dtbfile=${__rootfs_dir}/boot/${dtbfilename};
if [ -f "${_dtbfile}" ]; then
cp -f "${_dtbfile}" "mnt/boot/dtb/${dtbfilename}";
chkerr "populating ${_dtbfile} to ${__localsysfile}/boot/dtb failed.";
fi;
if [ "${__rootfs_type}" = "FAT32" ]; then
touch -f mnt/boot/cmdline.txt > /dev/null 2>&1;
chkerr "Creating cmdline.txt failed.";
echo -n -e "${__cmdline}" >mnt/boot/cmdline.txt;
chkerr "Writing cmdline.txt failed.";
else
pushd mnt > /dev/null 2>&1;
echo -n -e "\tpopulating rootfs from ${__rootfs_dir} ... ";
(cd "${__rootfs_dir}"; tar cf - *) | tar xf - ;
chkerr "Failed. Your APPSIZE might be too small.";
# Populate extlinux.conf if "$cmdline" exists
if [ "${__cmdline}" != "" ]; then
# Add the "$cmdline" at the APPEND line if it does not exist.
echo -n -e "\tpopulating /boot/${_extlinux_conf} ... ";
rootfs_found=$(grep -cE "${__cmdline}" "./boot/${_extlinux_conf}");
if [ "${rootfs_found}" == "0" ];then
sed -i "/^[ \t]*APPEND/s|\$| ${__cmdline}|" "./boot/${_extlinux_conf}";
chkerr;
fi;
fi;
if [ "${__do_sign}" = "True" ]; then
local kernel_fs_basename;
kernel_fs_basename=$(basename "${kernel_fs}");
echo -n -e "\tgenerating sig file of ${kernel_fs_basename} ... ";
signimage "./boot/${kernel_fs_basename}" "True" "kernel" "${minratchet_configname}"; chkerr;
echo -n -e "\tgenerating sig file of ${dtbfilename} ... ";
signimage "./boot/dtb/${dtbfilename}" "True" "kernel_dtb" "${minratchet_configname}"; chkerr;
echo -n -e "\tgenerating sig file of initrd ... ";
signimage "./boot/initrd" "True" "data"; chkerr;
echo -n -e "\tgenerating sig file of extlinux.conf ... ";
# Signing tool will pad extlinux.conf with 0x80 to be 16-byte aligned.
# This pad byte of 0x80 may cause some utilities fail to read the entire
# extlinux.conf.
# So, pad extlinux.conf to 16-byte aligned with linefeed.
pad_file_aligned "./boot/${_extlinux_conf}" 16 "\x0a";
signimage "./boot/${_extlinux_conf}" "True" "data"; chkerr;
fi
popd > /dev/null 2>&1;
fi;
echo -e -n "\tSync'ing ${__localsysfile} ... ";
sync; sync; sleep 5; # Give FileBrowser time to terminate gracefully.
echo "done.";
umount mnt > /dev/null 2>&1;
losetup -d "${loop_dev}" > /dev/null 2>&1;
rmdir mnt > /dev/null 2>&1;
if [ "${__fillpat}" != "" -a -x mksparse ]; then
echo -e -n "\tConverting RAW image to Sparse image... ";
mv -f ${__localsysfile} ${__localsysfile}.raw;
if [ "${BLBlockSize}" != "" ]; then
blblksizeoption="-b $BLBlockSize";
fi;
./mksparse ${blblksizeoption} --fillpattern=${__fillpat} ${__localsysfile}.raw ${__localsysfile}; chkerr;
fi;
echo "${__localsysfile} built successfully. ";
}
get_fuse_level ()
{
local rcmcmd;
local inst_args="";
local idval_1="";
local idval_2="";
local flval="";
local baval="None";
local flvar="$1";
local hivar="$2";
local bavar="$3";
if [ -f "${BL_DIR}/tegrarcm_v2" ]; then
rcmcmd="tegrarcm_v2";
elif [ -f "${BL_DIR}/tegrarcm" ]; then
rcmcmd="tegrarcm";
else
echo "Error: tegrarcm is missing." >&2;
exit 12;
fi;
if [ -n "${usb_instance}" ]; then
inst_args="--instance ${usb_instance}";
fi;
pushd "${BL_DIR}" > /dev/null 2>&1;
ECID=$(./${rcmcmd} ${inst_args} --uid | grep BR_CID | cut -d' ' -f2);
popd > /dev/null 2>&1;
if [ "${ECID}" != "" ]; then
idval_1="0x${ECID:3:2}";
eval "${hivar}=\"${idval_1}\"";
idval_2="0x${ECID:6:2}";
flval="${ECID:2:1}";
baval="";
if [ "${idval_1}" = "0x21" -o "${idval_1}" = "0x12" -o \
"${idval_1}" = "0x00" -a "${idval_2}" = "0x21" ]; then
case ${flval} in
0|1|2) flval="fuselevel_nofuse"; ;;
3) flval="fuselevel_production"; ;;
4) flval="fuselevel_production"; baval="NS"; ;;
5) flval="fuselevel_production"; baval="SBK"; ;;
6) flval="fuselevel_production"; baval="PKC"; ;;
*) flval="fuselevel_unknown"; ;;
esac;
SKIPUID="--skipuid";
if [ "${idval_1}" = "0x00" ]; then
eval "${hivar}=\"${idval_2}\"";
fi;
elif [ "${idval_1}" = "0x80" ]; then
if [ "${idval_2}" = "0x19" ]; then
case ${flval} in
0|1|2) flval="fuselevel_nofuse"; ;;
8) flval="fuselevel_production"; baval="NS"; ;;
# 9: 2K RSA, a: 3K RSA
9|a) flval="fuselevel_production"; baval="PKC"; ;;
# d: 2K RSA + SBK, e: 3K RSA + SBK
d|e) flval="fuselevel_production"; baval="SBKPKC"; ;;
esac;
SKIPUID="--skipuid";
hwchipid="0x19";
hwchiprev="${ECID:5:1}";
fi
else
case ${flval} in
0|1|2) flval="fuselevel_nofuse"; ;;
8|c) flval="fuselevel_production"; baval="NS"; ;;
9|d) flval="fuselevel_production"; baval="SBK"; ;;
a) flval="fuselevel_production"; baval="PKC"; ;;
e) flval="fuselevel_production"; baval="SBKPKC"; ;;
*) flval="fuselevel_unknown"; ;;
esac;
fi;
eval "${flvar}=\"${flval}\"";
eval "${bavar}=\"${baval}\"";
fi;
}
function get_full_path ()
{
local val="$1";
local result="$2";
local fullpath;
fullpath=$(readlink -f ${val}); # null if path is invalid
if [ "${fullpath}" == "" ]; then
echo "Invalid path/filename ${val}" >&2;
exit 13;
fi;
eval "${result}=${fullpath}";
}
#
# XXX: This EEPROM read shall be replaced with new FAB agnostic function.
#
get_board_version ()
{
local args="";
local __board_id=$1;
local __board_version=$2;
local __board_sku=$3;
local __board_revision=$4;
local command="dump eeprom boardinfo cvm.bin"
local boardid;
local boardversion;
local boardsku;
local boardrevision;
if [ -n "${usb_instance}" ]; then
args+="--instance ${usb_instance} ";
fi;
if [ "${CHIPMAJOR}" != "" ]; then
args+="--chip \"${CHIPID} ${CHIPMAJOR}\" ";
else
args+="--chip ${CHIPID} ";
fi;
args+="--applet \"${LDK_DIR}/${SOSFILE}\" ";
args+="${SKIPUID} ";
SKIPUID="";
if [ "${CHIPID}" = "0x19" ]; then
mkfilesoft soft_fuses "${TARGET_DIR}/BCT/${SOFT_FUSES}";
cp2local soft_fuses "${BL_DIR}/${soft_fusesname}";
args+="--soft_fuses ${soft_fusesname} "
args+="--bins \"mb2_applet ${MB2APPLET}\" ";
command+=";reboot recovery"
fi
args+="--cmd \"${command}\" ";
local cmd="./tegraflash.py ${args}";
pushd "${BL_DIR}" > /dev/null 2>&1;
if [ "${keyfile}" != "" ]; then
cmd+="--key \"${keyfile}\" ";
fi;
if [ "${sbk_keyfile}" != "" ]; then
cmd+="--encrypt_key \"${sbk_keyfile}\" ";
fi;
echo "${cmd}";
eval "${cmd}";
chkerr "Reading board information failed.";
if [ "${SKIP_EEPROM_CHECK}" = "" ]; then
boardid=`./chkbdinfo -i cvm.bin`;
boardversion=`./chkbdinfo -f cvm.bin`;
boardsku=`./chkbdinfo -k cvm.bin`;
boardrevision=`./chkbdinfo -r cvm.bin`;
chkerr "Parsing board information failed.";
fi;
popd > /dev/null 2>&1;
eval ${__board_id}="${boardid}";
eval ${__board_version}="${boardversion}";
eval ${__board_sku}="${boardsku}";
eval ${__board_revision}="${boardrevision}";
}
#
# EEPROM get board S/N .
#
boardinfo_trk ()
{
local boardinforom;
local boardpartnu;
if [[ -e "${LDK_DIR}/nv_internal_trk.sh" &&
-e "${BL_DIR}/chkbdinfo" &&
-e "${BL_DIR}/cvm.bin" ]]; then
pushd "${BL_DIR}" > /dev/null 2>&1;
boardinforom=$(./chkbdinfo -a cvm.bin);
boardpartnu=$(./chkbdinfo -p cvm.bin);
if [[ "${boardinforom}" != "" ]] && [[ "${boardpartnu}" != "" ]]; then
eval "PRODUCT_OUT=\"${LDK_DIR}\" \"${LDK_DIR}/nv_internal_trk.sh\" \"${boardinforom}\" \"${boardpartnu}\"";
fi
popd > /dev/null 2>&1;
fi
}
#
# SoC Sanity Check:
#
chk_soc_sanity ()
{
local mach_dir="";
local socname="Unknown";
local opmode="Unknown";
local disk_enc="";
if [ "${hwchipid}" = "" ]; then
# Nothing to check against. Just let it go.
echo "Error: probing the target board failed." >&2;
echo " Make sure the target board is connected through " >&2;
echo " USB port and is in recovery mode." >&2;
exit 14;
fi;
#
# Print Target Board Information:
# NOTE: The list of board listed here may or may not be
# supported by the version of BSP(Board Support Package)
# that provides this copy of the script. This lists all
# of the publicly available Jetson developer platforms.
#
case ${hwchipid} in
0x21) socname="Tegra 210"; mach_dir="t210ref"; ;;
0x18) socname="Tegra 186"; mach_dir="t186ref"; ;;
0x19) socname="Tegra 194"; mach_dir="t186ref"; ;;
esac;
case ${fuselevel} in
fuselevel_nofuse) opmode="pre-production"; ;;
fuselevel_production) opmode="production"; ;;
esac;
if [ ${disk_enc_enable} -eq 1 ]; then
disk_enc="enabled";
else
disk_enc="disabled";
fi;
echo "# Target Board Information:";
echo -n "# Name: ${ext_target_board}, Board Family: ${target_board}, ";
echo "SoC: ${socname}, ";
echo "# OpMode: ${opmode}, Boot Authentication: ${bootauth}, ";
echo "# Disk encryption: ${disk_enc} ,";
echo "${INFODIVIDER}";
if [ "${CHIPID}" != "" -a "${CHIPID}" != "${hwchipid}" ]; then
echo -n "Error: The Actual SoC ID(${hwchipid}) " >&2;
echo -n "mismatches intended ${ext_target_board} " >&2;
echo "SoC ID(${CHIPID})." >&2;
exit 14;
fi;
if [ "${target_board}" != "${mach_dir}" ]; then
echo -n "Error: The Actual board family (${mach_dir}) " >&2;
echo -n "mismatches intended ${ext_target_board} " >&2;
echo "board family(${target_board})." >&2;
exit 14;
fi;
case ${bootauth} in
PKC)
if [ "${keyfile}" = "" ] || [ "${sbk_keyfile}" != "" ]; then
echo -n "Error: Either RSA key file is not provided or SBK key " >&2;
echo "file is provided for PKC protected target board." >&2;
exit 14;
fi;
;;
SBKPKC)
if [ "${keyfile}" = "" ] || [ "${sbk_keyfile}" = "" ]; then
echo -n "Error: Either RSA key file and/or SBK key file " >&2;
echo "is not provided for SBK and PKC protected target board." >&2;
exit 14;
fi;
;;
SBK)
echo "Error: L4T does not support SBK protected target board." >&2;
exit 14;
;;
NS)
if [ "${keyfile}" != "" ] || [ "${sbk_keyfile}" != "" ]; then
echo -n "Error: either RSA key file and/or SBK key file " >&2;
echo "are provided for none SBK and PKC protected target board." >&2;
exit 14;
fi;
;;
*)
if [ "${dbmaster}" != "" ]; then
echo -n "Error: The RSA key file is provided for " >&2;
echo "non-PKC protected target board." >&2;
exit 14;
fi;
;;
esac;
}
function rootuuid_gen() {
local root_id=$1
local uuid=""
local uuidgen_installed="$(which uuidgen || true)"
if [ "${uuidgen_installed}" == "" ]; then
echo "Error: uuidgen not installed! Please provide the UUID or install"
echo "uuidgen. For example, to install uuidgen for Ubuntu distributions,"
echo "execute the command 'sudo apt install uuid-runtime'. Otherwise a"
echo "UUID can be provided by storing a UUID to the file"
echo "${rootfsuuidfile} or ${rootfsuuidfile}_b if neabled ROOTFS_AB"
usage allunknown 1;
fi
uuid="$(uuidgen)"
setval "rootfsuuid${root_id}" uuid;
echo "${uuid}" > "${rootfsuuidfile}${root_id}"
echo "Generated UUID ${uuid} for mounting root APP${root_id} partition."
}
function rootuuid_chk_and_gen() {
local root_id=$1
local uuid=""
local uuid_regex="([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})"
# For external device, if you want to generate a new uuid every time you flash,
# uncomment the below lines
# if [ "${external_device}" = "1" ] && [ -f "${rootfsuuidfile}${root_id}" ]; then
# rm "${rootfsuuidfile}${root_id}"
# fi
# read UUID which stored in the file ${rootfsuuidfile} if the file exist
if [ -f "${rootfsuuidfile}${root_id}" ]; then
uuid="$(sed -nr "s/^${uuid_regex}$/\1/p" "${rootfsuuidfile}${root_id}")"
if [ "${#uuid}" != "36" ]; then
echo "File ${rootfsuuidfile}${root_id} contains invalid UUID!"
usage allunknown 1;
fi
setval "rootfsuuid${root_id}" uuid;
echo "Using UUID ${uuid} for mounting root APP${root_id} partition."
fi
# generate UUID if ${rootfsuuidfile} isn't present
eval uuid='$'{"rootfsuuid${root_id}"}
if [ "${uuid}" == "" ] && [ "${target_partname}" == "" ]; then
rootuuid_gen "${root_id}"
fi
}
function rootuuid_restore {
local ext="${1}"
local _rootfsuuid="rootfsuuid${ext}"
local _rootfsuuid_b
rootuuid_chk_and_gen "${ext}"
if [[ "${rootfs_ab}" == 1 ]]; then
# get UUID for APP_b
_rootfsuuid_b="rootfsuuid_b${ext}"
rootuuid_chk_and_gen "_b${ext}"
fi
if [[ "${!_rootfsuuid}" == "" ]] || \
[[ "${rootfs_ab}" == 1 && "${!_rootfsuuid_b}" == "" ]]; then
echo "No UUID found for root partition! If the root partition"
echo "is not currently being mounted using a partition UUID,"
echo "then flash the device by specifying the root device that"
echo "was specified when previously flashing the entire system"
echo "(eg. /dev/mmcblk0p1). Otherwise, to mount the root"
echo "partition using a partition UUID please either:"
echo "1. If you know the UUID for the root partition save it"
echo " to the file ${rootfsuuidfile},"
echo " or for root B partition save it"
echo " to the file ${rootfsuuidfile}_b"
echo "2. Re-flash entire system to generate a new UUID."
usage allunknown 1;
fi
}
function sysfile_exist {
if [ ${disk_enc_enable} -eq 0 ]; then
echo "Reusing existing ${localsysfile}... ";
if [ ! -e "${localsysfile}" ]; then
echo "file does not exist." >&2;
exit 15;
fi;
if [[ "${rootfs_ab}" == 1 ]]; then
echo "Reusing existing ${localsysfile}.b... ";
if [ ! -e "${localsysfile}_b" ]; then
echo "file does not exist." >&2;
exit 15;
fi;
fi;
else
echo "Reusing existing ${localsysbootfile} & ${localsysencrootfile}... ";
if [ ! -e "${localsysbootfile}" ] || [ ! -e "${localsysencrootfile}" ]; then
echo "file does not exist." >&2;
exit 15;
fi;
if [[ "${rootfs_ab}" == 1 ]]; then
echo "Reusing existing ${localsysbootfile_b} & ${localsysencrootfile_b}... ";
if [ ! -e "${localsysbootfile_b}" ] || [ ! -e "${localsysencrootfile_b}" ]; then
echo "file does not exist." >&2;
exit 15;
fi;
fi;
fi;
echo "done.";
}
function make_boot_image() {
if [ -n "${BOOTIMG}" ]; then
if ! [ -f "${BOOTIMG}" ]; then
echo "Error: ${BOOTIMG} not found" >&2
exit 16;
fi
cp "${BOOTIMG}" "${localbootfile}"
if [[ "${rootfs_ab}" == 1 ]]; then
cp "${BOOTIMG}" "${localbootfile}_b"
fi
return
fi
echo -n "Making Boot image... ";
./mkbootimg \
--kernel "${kernel_image}" \
--ramdisk "${ramdisk}" \
--board "${target_rootdev}" \
--output "${localbootfile}" \
--cmdline "${cmdline}" > /dev/null 2>&1;
chkerr;
if [[ "${rootfs_ab}" == 1 ]]; then
if [[ "${disk_enc_enable}" == 1 ]]; then
./mkbootimg \
--kernel "${kernel_image}" \
--ramdisk "${ramdisk_b}" \
--board "${target_rootdev}" \
--output "${localbootfile}_b" \
--cmdline "${cmdline_b}" > /dev/null 2>&1;
chkerr;
else
./mkbootimg \
--kernel "${kernel_image}" \
--ramdisk "${ramdisk}" \
--board "${target_rootdev}" \
--output "${localbootfile}_b" \
--cmdline "${cmdline_b}" > /dev/null 2>&1;
chkerr;
fi
fi
}
function check_xmllint() {
# Usage:
# check_xmllint {__ret_value}
local __ret_value="${1}"
if [ -f "/usr/bin/xmllint" ]; then
eval "${__ret_value}=\"/usr/bin/xmllint\""
else
if [ -z "${__XMLLINT_BIN}" ]; then
echo "ERROR xmllint not found! To install - please run: " \
"\"sudo apt-get install libxml2-utils\"" >&2
exit 17
fi;
fi;
}
function get_value_from_PT_table() {
# Usage:
# get_value_from_PT_table {__pt_name} \
# {__pt_node} \
# {__pt_file} \
# {__ret_value}
local __XMLLINT_BIN="";
local __pt_name="${1}";
local __pt_node="${2}";
local __pt_file="${3}";
local __ret_value="${4}";
local __node_val="";
# Check xmllint
check_xmllint __XMLLINT_BIN
# Get node value
__node_val="$(${__XMLLINT_BIN} --xpath "/partition_layout/device/partition[@name='${__pt_name}']/${__pt_node}/text()" ${__pt_file})";
__node_val=$(echo ${__node_val} | sed -e 's/^[[:space:]]*//');
eval "${__ret_value}=\"${__node_val}\"";
}
function partition_exists_in_PT_table() {
# Usage:
# partition_exists_in_PT_table {__pt_name} {__pt_file}
local __XMLLINT_BIN="";
local __pt_name="${1}";
local __pt_file="${2}";
# Check xmllint
check_xmllint __XMLLINT_BIN
# Check whether node exists
${__XMLLINT_BIN} --xpath "/partition_layout/device/partition[@name='${__pt_name}']" ${__pt_file} >/dev/null 2>&1
return $?
}
#
# Get attribuate from partition table
#
function get_attr_from_PT_table() {
# Usage:
# get_attr_from_PT_table {__pt_name} \
# {__pt_attr} \
# {__pt_file} \
# {__ret_value}
local __XMLLINT_BIN="";
local __pt_name="${1}";
local __pt_attr="${2}";
local __pt_file="${3}";
local __ret_value="${4}";
local __attr_val="";
# Check xmllint
if [ -f "/usr/bin/xmllint" ]; then
__XMLLINT_BIN="/usr/bin/xmllint";
else
if [ -z "${__XMLLINT_BIN}" ]; then
echo "ERROR xmllint not found! To install - please run: " \
"\"sudo apt-get install libxml2-utils\"" >&2
exit 17
fi;
fi;
# Get attr value
__attr_val="$(${__XMLLINT_BIN} --xpath "string(/partition_layout/device/partition[@name='${__pt_name}']/@${__pt_attr})" "${__pt_file}")";
eval "${__ret_value}=\"${__attr_val}\"";
}
function create_fsimg {
local do_sign="${2}";
if [ ${disk_enc_enable} -eq 0 ]; then
local source_folder="${1}"
APP_TAG+="-e s/APPFILE/${localsysfile}/ ";
# this is set at a setval function
if [ "${target_partname}" = "" ] || [ "${target_partname}" = "APP" ]; then
build_fsimg "${localsysfile}" "${fillpat}" \
"${rootfssize}" "${rootfs_type}" \
"${source_folder}" "${cmdline}" "${do_sign}";
fi;
if [[ "${rootfs_ab}" == 1 ]]; then
# build fsimage for APP_b
local sysfile=""
# check if APP_b exist in layout file
get_value_from_PT_table "APP_b" "filename" "${cfgfile}" sysfile
if [ "${sysfile}" != "" ]; then
if [ "${target_partname}" = "" ] || \
[ "${target_partname}" = "APP_b" ]; then
build_fsimg "${localsysfile}_b" "${fillpat}" \
"${rootfssize}" "${rootfs_type}" \
"${source_folder}" "${cmdline_b}" "${do_sign}";
fi;
fi;
fi;
else
if [ "${target_partname}" = "" ] || [ "${target_partname}" = "APP" ]; then
build_boot_fsimg "${localsysbootfile}" "${fillpat}" \
"${bootfssize}" "${rootfs_type}" \
"${rootfs_dir}/boot" "${cmdline}" "${do_sign}";
fi;
if [ "${target_partname}" = "" ] || [ "${target_partname}" = "APP_ENC" ]; then
build_enc_root_fsimg "${localsysencrootfile}" "${fillpat}" \
"${encrootfssize}" "${rootfs_type}" \
"${rootfs_dir}" "${rootfsuuid_enc}" \
"${bootpartuuid}" "${ECID}" "${rootfsuuid_b_enc}";
fi;
if [[ "${rootfs_ab}" == 1 ]]; then
if [ "${target_partname}" = "" ] || [ "${target_partname}" = "APP_b" ]; then
echo -e -n "\tpopulating initrd_b to rootfs... ";
cp -f initrd_b "${rootfs_dir}/boot/initrd"; chkerr;
build_boot_fsimg "${localsysbootfile_b}" "${fillpat}" \
"${bootfssize}" "${rootfs_type}" \
"${rootfs_dir}/boot" "${cmdline_b}" "${do_sign}";
fi;
if [ "${target_partname}" = "" ] || [ "${target_partname}" = "APP_ENC_b" ]; then
build_enc_root_fsimg "${localsysencrootfile_b}" "${fillpat}" \
"${encrootfssize}" "${rootfs_type}" \
"${rootfs_dir}" "${rootfsuuid_b_enc}" \
"${bootpartuuid_b}" "${ECID}" "${rootfsuuid_enc}";
fi;
fi;
fi;
}
# Use compression to allow bpmp-fw-dtb to support more than 4 ram codes
function compress_bpmp_fw_dtb() {
local bpmp_fw_dtb_file="${1}";
local bpmp_fw_dtb_filename="${2}";
local bpmp_fw_dtb_filename_base;
local bpmp_fw_dtb_filename_ext;
local lz4c_bin="lz4c";
# Check for lz4c installation
local lz4c_check=$(which "${lz4c_bin}");
if [ -z "${lz4c_check}" ]; then
echo "error: lz4c not found";
echo "To install please run:";
SYSTEM_VER="$(grep "DISTRIB_RELEASE" </etc/lsb-release | cut -d= -f 2 | sed 's/\.//')"
if [ "${SYSTEM_VER}" -lt 2004 ]; then
echo " sudo apt-get install -y liblz4-tool";
else
echo " sudo apt-get install -y lz4";
fi
exit 1;
else
echo "lz4c installed at ${lz4c_check}";
fi
# Compress bpmp-fw-dtb
bpmp_fw_dtb_filename_base="${bpmp_fw_dtb_filename%%.*}";
bpmp_fw_dtb_filename_ext="${bpmp_fw_dtb_filename#*.}";
echo -e -n "Compressing ${bpmp_fw_dtb_file} ...\n";
"${lz4c_bin}" -f "${bpmp_fw_dtb_file}" \
"${BL_DIR}/${bpmp_fw_dtb_filename_base}_lz4.${bpmp_fw_dtb_filename_ext}" \
1>/dev/null 2>&1;
chkerr "Failed to compress ${bpmp_fw_dtb_file} with ${lz4c_bin}.";
mkfilesoft bpfdtbfile "${BPFDTBFILE}" \
"${BL_DIR}/${bpmp_fw_dtb_filename_base}_lz4.${bpmp_fw_dtb_filename_ext}";
}
function signimage() {
# l4t_sign_image.sh generates signature file (with .sig extension)
# in the same folder of file path specified in --file
local image="$1";
local split="$2";
local ftype="$3";
local ratchet_config="$4";
if [ -n "${ratchet_config}" ]; then
cp -f "${BL_DIR}"/"${ratchet_config}" .
"${LDK_DIR}"/l4t_sign_image.sh \
--file "$image" --type "$ftype" \
--key "${keyfile}" --encrypt_key "${user_keyfile}" --chip "${tegraid}" --split "${split}" \
--minratchet_config "${ratchet_config}";
else
"${LDK_DIR}"/l4t_sign_image.sh \
--file "$image" --type "$ftype" \
--key "${keyfile}" --encrypt_key "${user_keyfile}" --chip "${tegraid}" --split "${split}";
fi;
chkerr;
}
function assign_string() {
# Usage:
# assign_string {filename} \
# {string} # string to assign \
# {offset} # offset in decimal \
# {size} # number of chars to assign
local filename="${1}";
local string="${2}";
local offset="${3}";
local size="${4}";
echo "assign_string: ${filename} ${string} ${offset} ${size}"
# example dd comand: echo ${string} | dd of=foo bs=1 seek=131064 count=4 conv=notrunc
dd_cmd="echo ${string} "
dd_cmd+="| dd of=${filename} bs=1 seek=${offset} count=${size} conv=notrunc"
echo "${dd_cmd}"
eval "${dd_cmd}"
}
function assign_value() {
# Usage:
# assign_value {filename} \
# {value} # value in decimal to assign \
# {offset} # offset in decimal \
# {size} # number of bytes to assign
local filename="${1}";
local value="${2}";
local offset="${3}";
local size="${4}";
echo "assign_value: ${filename} ${value} ${offset} ${size}"
# example dd comand: printf '\xab\xcd\xef\x65' | dd of=foo bs=1 seek=131068 count=4 conv=notrunc
# printf '\x09\x38\xc5\x33' | dd of=crc-flash.xml.bin bs=1 seek=131068 count=4 conv=notrunc
# value is in little-endian
dd_cmd="printf '"
for ((i = 0 ; i < size ; i++)); do
byte=$(( value & 0xff ))
value=$(( value >> 8 ))
dd_cmd+="\x"
dd_cmd+=$( printf "%x" ${byte} )
done;
dd_cmd+="' | dd of=${filename} bs=1 seek=${offset} count=${size} conv=notrunc"
echo "${dd_cmd}"
eval "${dd_cmd}"
}
# function: generate_pt_header
#
# This function generates pt header and stores the pt header to the end of
# the PT partition.
# flash.xml.bin contains the partition table, and is flashed to PT partition.
# So the size of flash.xml.bin will be expanded to the size of PT partition.
#
# The pt header consists of :
# o version (2 bytes):
# * major = 0x01
# * minor = 0x00
# o reserved (6 bytes)
# o magic (4 bytes) = 'PTHD'
# o crc32 (4 bytes)
#
# The flash.xml.bin is created later during the actual flashing procedures
# by tegraparser.
#
# So flash.xml.bin cannot be created here (will be overwritten by tegraparser).
# Use new name of "crc-flash.xml.bin for this reason, and populate the new name
# to crc-flash.xml and flash.xml too.
#
# Notes: ${localcfgfile}=flash.xml
# These procedures assume that the ptfile (filename spcecified in PT partition)
# is ${localcfgfile}.bin (or flash.xml.bin)
#
function generate_pt_header()
{
ptfile=""
ptsize=""
PT_VER_MAJOR=$((0x01))
PT_VER_MINOR=$((0x00))
PT_MAGIC='PTHD'
get_value_from_PT_table "PT" "filename" "${localcfgfile}" ptfile
get_value_from_PT_table "PT" "size" "${localcfgfile}" ptsize
# use a new name of crc-flash.xml.tmp
cp "${localcfgfile}" crc-"${localcfgfile}".tmp
# replace old flash.xml.bin with new crc-flash.xml.bin
sed -i -e "s/${ptfile}/crc-${ptfile}/" crc-"${localcfgfile}".tmp
# call tegraparser, it will generate crc-flash.xml.bin
./tegraparser --pt crc-"${localcfgfile}".tmp
# copy the new crc-${localcfgfile}.tmp to ${localcfgfile}
cp crc-"${localcfgfile}".tmp "${localcfgfile}"
# expand the file to the PT partition size
truncate -s "${ptsize}" "crc-${ptfile}"
offset=$((ptsize-16))
assign_value "crc-${ptfile}" ${PT_VER_MAJOR} $offset 1
offset=$((ptsize-15))
assign_value "crc-${ptfile}" ${PT_VER_MINOR} $offset 1
offset=$((ptsize-8))
assign_string "crc-${ptfile}" ${PT_MAGIC} $offset 4
# call tegrahost to fill crc32 to the last 4 bytes of crc-${ptfile}
./tegrahost --fillcrc32 "crc-${ptfile}"
}
if [ $# -lt 2 ]; then
usage allunknown 1;
fi;
nargs=$#;
target_rootdev=${!nargs};
nargs=$(($nargs-1));
ext_target_board=${!nargs};
# NV internal
_nvbrd_trk=0
if [ ! -r ${ext_target_board}.conf ]; then
echo "Error: Invalid target board - ${ext_target_board}.";
usage allunknown 1;
fi
# set up LDK_DIR path
LDK_DIR=$(cd "$(dirname "$0")" && pwd);
LDK_DIR=$(readlink -f "${LDK_DIR}");
# set common print message for process_board_version()
print_board_version()
{
local board_id="${1}";
local board_version="${2}";
local board_sku="${3}";
local board_revision="${4}";
local chiprev="${5}";
echo "Board ID(${board_id}) version(${board_version}) sku(${board_sku}) revision(${board_revision})" >/dev/stderr;
}
ext_target_board_canonical=`readlink -e "${ext_target_board}".conf`
ext_target_board_canonical=`basename "${ext_target_board_canonical}" .conf`
disk_enc_enable=0;
rootfs_ab=0;
source ${ext_target_board}.conf
# set up path variables
BL_DIR="${LDK_DIR}/bootloader";
TARGET_DIR="${BL_DIR}/${target_board}";
KERNEL_DIR="${LDK_DIR}/kernel";
export PATH="${KERNEL_DIR}:${PATH}:${BL_DIR}"; # preference on our DTC
DTB_DIR="${KERNEL_DIR}/dtb";
DTC="${KERNEL_DIR}/dtc";
if [ "${BINSARGS}" = "" -a "${BINS}" != "" ]; then #COMPAT
BINARGS="--bins \""; #COMPAT
fi; #COMPAT
if [ "${BINSARGS}" != "" ]; then
SKIPUID="--skipuid";
fi;
# Print BSP Info:
#
echo "${INFODIVIDER}";
echo "# L4T BSP Information:";
if [ -f "${LDK_DIR}/nv_tegra/bsp_version" ]; then
source "${LDK_DIR}/nv_tegra/bsp_version"
echo "# R${BSP_BRANCH} , REVISION: ${BSP_MAJOR}.${BSP_MINOR}"
elif [ -f "${LDK_DIR}/rootfs/etc/nv_tegra_release" ]; then
head -n1 "${LDK_DIR}/rootfs/etc/nv_tegra_release" | \
sed -e s/DATE:/\\n\#\ DATE:/;
else
echo "# Unknown Release";
fi;
echo "${INFODIVIDER}";
# Determine rootdev_type
#
rootdev_type="external";
if [[ "${target_rootdev}" == "internal" || "${target_rootdev}" == mmcblk0p* || \
"${target_rootdev}" == ${BOOTDEV} ]]; then
rootdev_type="internal";
INITRD="";
if [ ${disk_enc_enable} -eq 1 ] && [ "${target_rootdev}" != "internal" ]; then
echo "Change device boot from ${target_rootdev} to internal"
target_rootdev="internal";
fi
elif [ "${target_rootdev}" = "eth0" -o "${target_rootdev}" = "eth1" ]; then
rootdev_type="network";
disk_enc_enable=0;
elif [[ "${target_rootdev}" != "external" && "${target_rootdev}" != mmcblk1p* && \
"${target_rootdev}" != sd* && "${target_rootdev}" != nvme* ]]; then
echo "Error: Invalid target rootdev($target_rootdev).";
usage rootdevunknown 1;
fi;
if [[ "${rootdev_type}" == "external" && "${disk_enc_enable}" -eq 1 ]]; then
echo "Error: When disk encryption is enabled, root device cannot be ${target_rootdev}" >&2
exit 18;
fi;
# Import disk encryption helper function
#
if [ ${disk_enc_enable} -eq 1 ]; then
disk_encryption_helper_dir="${LDK_DIR}/tools/disk_encryption";
if [ ! -f "${disk_encryption_helper_dir}/disk_encryption_helper.func" ]; then
echo "Error: disk encryption is not supported." >&2
exit 19
fi
source "${disk_encryption_helper_dir}/disk_encryption_helper.func"
fi;
rootfsuuid="";
rootfsuuid_enc="";
rootfsuuid_ext="";
rootfsuuid_ext_enc="";
rootfsuuid_b="";
rootfsuuid_b_enc="";
rootfsuuid_b_ext=""
rootfsuuid_b_ext_enc="";
cmdline_b="";
rootfsuuidfile="${BL_DIR}/l4t-rootfs-uuid.txt"
read_part_name="";
rcm_boot=0;
no_root_check=0;
no_flash=0;
rapid_boot=0
external_device=0;
no_systemimg=0;
bup_blob=0;
to_sign=0;
support_multi_spec=0;
clean_up=0;
PKCKEY="";
_ODMDATA="";
opstr+="b:c:d:e:f:h:i:k:m:n:o:p:rs:t:u:v:w:x:z:B:C:F:G:I:K:L:M:N:P:R:S:Z:-:";
while getopts "${opstr}" OPTION; do
case $OPTION in
b) BCTFILE=${OPTARG}; ;;
c) CFGFILE=${OPTARG}; ;;
d) DTBFILE=${OPTARG}; ;;
e) EMMCSIZE=${OPTARG}; ;;
f) FLASHAPP=${OPTARG}; ;;
h) usage allunknown 0; ;;
i) ENC_RFS_KEY=${OPTARG}; ;;
k) target_partname=${OPTARG}; ;; # cmdline only
m) MTSPREBOOT=${OPTARG}; ;;
n) NFSARGS=${OPTARG}; ;;
o) _ODMDATA=${OPTARG}; ;;
p) BOOTPARTSIZE=${OPTARG}; ;;
r) reuse_systemimg="true"; ;; # cmdline only
s) PKCKEY=${OPTARG}; ;;
t) TEGRABOOT=${OPTARG}; ;;
u) dbmaster="${OPTARG}"; ;;
v) SBKKEY=${OPTARG}; ;;
w) WB0BOOT=${OPTARG}; ;;
x) tegraid=${OPTARG}; ;;
z) sn=${OPTARG}; ;;
B) BOARDID=${OPTARG}; ;;
C) CMDLINE="${OPTARG}"; ;;
F) FLASHER=${OPTARG}; ;;
G) read_part_name=${OPTARG}; ;;
I) INITRD=${OPTARG}; ;;
K) KERNEL_IMAGE=${OPTARG}; ;;
L) BOOTLOADER=${OPTARG}; ;;
M) MTS=${OPTARG}; ;;
N) NFSROOT=${OPTARG}; ;;
P) BOOTPARTLIMIT=${OPTARG}; ;;
R) ROOTFS_DIR=${OPTARG}; ;;
S) ROOTFSSIZE=${OPTARG}; ;;
Z) zflag="true"; ;; # cmdline only
-) case ${OPTARG} in
no-root-check) no_root_check=1; ;;
no-flash) no_flash=1; ;;
no-systemimg) no_systemimg=1; ;;
external-device) external_device=1; ;;
rcm-boot) rcm_boot=1; ;;
bup) bup_blob=1; ;;
sign) to_sign=1; ;;
multi-spec) support_multi_spec=1; ;;
clean-up) clean_up=1; ;;
rapid-boot) rapid_boot=1; ;;
usb-instance)
usb_instance="${!OPTIND}";
OPTIND=$(($OPTIND + 1));
;;
image)
write_image_name="${!OPTIND}";
OPTIND=$(($OPTIND + 1));
;;
user_key)
USERKEY="${!OPTIND}";
OPTIND=$(($OPTIND + 1));
;;
esac;;
*) usage allunknown 1; ;;
esac;
done
if [[ "${BUILD_SD_IMAGE}" == 1 && "${no_flash}" == 0 ]]; then
echo "*** The option BUILD_SD_IMAGE must work with --no-flash flag. ***" >&2
echo "Exiting now..." >&2;
exit 20;
fi;
# allow payload generation to happen without sudo option
if [ ${bup_blob} -eq 0 ]; then
# if the user is not root, there is not point in going forward unless
# the user knows what he's doing.
if [ "${no_root_check}" != "1" ] && [ "${USER}" != "root" ]; then
echo "flash.sh requires root privilege" >&2;
exit 21;
fi
fi
#
# -s option is obsolete and is repleced by -u option.
# However, to be compatible with earlier release, -s should still be handled
#
# If -u is present, simply ignore -s
# If -u is absent, assign value from -s to -u
#
if [ "${PKCKEY}" != "" ] && [ "${dbmaster}" = "" ]; then
dbmaster="${PKCKEY}";
fi;
# get key file if -u option provided
keyfile="";
if [ "${dbmaster}" != "" ]; then
if [[ ${dbmaster} =~ ^/ ]]; then
keyfile="${dbmaster}";
else
keyfile=`readlink -f "${dbmaster}"`;
fi;
if [ ! -f "${keyfile}" ]; then
echo "Error: keyfile ${keyfile} not found" >&2;
exit 22;
fi;
fi;
# get sbk key file if -v option provided
sbk_keyfile="";
if [ "${SBKKEY}" != "" ]; then
# when sbk key is present, pkc key must be present
if [ "${keyfile}" = "" ]; then
echo "Error: missing PKC key; try -u" >&2;
exit 23;
fi;
sbk_keyfile=`readlink -f "${SBKKEY}"`;
if [ ! -f "${sbk_keyfile}" ]; then
echo "Error: keyfile ${sbk_keyfile} not found" >&2;
exit 24;
fi;
fi;
# get user_key file if --user_key option provided
user_keyfile="";
zero_keyfile=".zero_.key";
if [ "${USERKEY}" != "" ]; then
# when user key is present, sbk key must be present
if [ "${sbk_keyfile}" = "" ]; then
echo "Error: missing SBK key; try -v" >&2;
exit 25;
fi;
user_keyfile=`readlink -f "${USERKEY}"`;
if [ ! -f "${user_keyfile}" ]; then
echo "Error: keyfile ${user_keyfile} not found" >&2;
exit 26;
fi;
else
if [ "${sbk_keyfile}" != "" ]; then
# there is sbk_key, but no user_key
echo "sbk_keyfile is present, but no user_keyfile; set user_keyfile to zero keyfile";
echo "0x00000000 0x00000000 0x00000000 0x00000000" > "${zero_keyfile}";
user_keyfile=$(readlink -f "${zero_keyfile}");
fi;
fi;
# get enc rfs key file if -i option provided
enc_rfs_keyfile="";
if [ "${ENC_RFS_KEY}" != "" ]; then
enc_rfs_keyfile=$(readlink -f "${ENC_RFS_KEY}");
if [ ! -f "${enc_rfs_keyfile}" ]; then
echo "Error: keyfile ${enc_rfs_keyfile} not found" >&2;
exit 27;
fi;
fi;
ECID="";
# get the fuse level and update the data accordingly
fuselevel="${FUSELEVEL}";
hwchipid="";
hwchiprev="${CHIPREV}";
if [ "${hwchiprev}" = "" ]; then
if [ "${CHIPID}" = "0x19" ]; then
hwchiprev="2";
else
hwchiprev="0";
fi
fi;
bootauth="";
if [ "${fuselevel}" = "" ]; then
get_fuse_level fuselevel hwchipid bootauth;
# fuselevel_unknown or empty will be handled as fuselevel_production
if [ "${fuselevel}" = "fuselevel_unknown" ] || [ "${fuselevel}" = "" ]; then
fuselevel="fuselevel_production";
fi;
else
# can not "--skipuid" when function get_fuse_level is skipped.
SKIPUID="";
fi;
declare -F -f process_fuse_level > /dev/null 2>&1;
if [ $? -eq 0 ]; then
process_fuse_level "${fuselevel}";
fi;
#
# Handle -G option for reading partition image to file
#
if [ "${read_part_name}" != "" ]; then
# Exit if no -k option
if [ "${target_partname}" = "" ]; then
echo "Error: missing -k option to specify partition name" >&2;
exit 28;
fi
# Exit if --image option is provided for write partition
if [ "${write_image_name}" != "" ]; then
echo "Error: not support to write partition while reading partition" >&2;
exit 29;
fi
# Exit if path is invalid
get_full_path ${read_part_name} read_part_name;
fi;
#
# Handle --image option for writing image to specified partition
#
if [ "${write_image_name}" != "" ]; then
# Exit if no -k option
if [ "${target_partname}" = "" ]; then
echo "Error: missing -k option to specify partition name" >&2;
exit 30;
fi
# Exit if file does not exist
if [ ! -f "${write_image_name}" ]; then
echo "Error: ${write_image_name} does not exist" >&2;
exit 31;
fi;
# Exit if path is invalid
get_full_path ${write_image_name} write_image_name;
fi;
# SoC Sanity Check
if [ ${no_flash} -eq 0 ]; then
chk_soc_sanity;
fi;
if [ ${rapid_boot} -ne 0 ]; then
declare -F -f rapid_boot_functionality > /dev/null 2>&1;
rapid_boot_functionality;
fi;
# get the board version and update the data accordingly
declare -F -f process_board_version > /dev/null 2>&1;
if [ $? -eq 0 ]; then
board_version="${FAB}";
board_id="${BOARDID}";
board_sku="${BOARDSKU}";
board_revision="${BOARDREV}";
if [ "${board_version}" == "" ]; then
if [ "${hwchipid}" != "" ]; then
get_board_version board_id board_version board_sku board_revision;
_nvbrd_trk=1;
BOARDID="${board_id}";
BOARDSKU="${board_sku}";
FAB="${board_version}";
BOARDREV="${board_revision}";
fi;
fi;
process_board_version "${board_id}" "${board_version}" "${board_sku}" "${board_revision}" "${hwchiprev}";
fi;
# convert fuselevel to digit string
if [ "${fuselevel}" == "fuselevel_nofuse" ]; then
fuselevel_s="0";
else
fuselevel_s="1";
fi;
# Set board spec: BOARD_ID-FAB-BOARDSKU-BOARDREV-NV_PRODUCTION-CHIP_REV-BOARD_NAME-ROOTFS_DEV
spec="${BOARDID}-${FAB}-${BOARDSKU}-${BOARDREV}-${fuselevel_s}-${hwchiprev}-${ext_target_board}-${target_rootdev}";
# Make sure spec length is less than maximum supported by BUP (64)
MAX_SPEC_LEN=64
if ((${#spec} > ${MAX_SPEC_LEN})); then
echo "Error: spec length exceeds ${MAX_SPEC_LEN}, ${spec}(len=${#spec})" >&2
exit 32
fi;
# get board SN and Part
if [ ${_nvbrd_trk} -ne 0 ]; then
timeout 10s cat <(boardinfo_trk);
fi;
###########################################################################
# System default values: should be defined AFTER target_board value.
#
ROOTFS_TYPE="${ROOTFS_TYPE:-ext4}";
DEVSECTSIZE="${DEVSECTSIZE:-512}"; # default sector size = 512
BOOTPARTLIMIT="${BOOTPARTLIMIT:-10485760}"; # 1MiB limit
ACR_TYPE="${ACR_TYPE:-acr-debug}"; # default is acr-debug
fillpat="${FSFILLPATTERN:-0}"; # no cmdline: default=0
no_rootfs="${NO_ROOTFS:-0}" # default is 0
no_recovery_img="${NO_RECOVERY_IMG:-0}"
boardid="${BOARDID}";
if [ "${tegraid}" = "" ]; then
tegraid="${CHIPID}";
fi;
if [ -z "${DFLT_KERNEL}" ]; then
DFLT_KERNEL=${KERNEL_DIR}/Image;
else
basekernel=`basename "${DFLT_KERNEL}"`;
if [ "${DFLT_KERNEL}" = "${basekernel}" ]; then
DFLT_KERNEL="${KERNEL_DIR}/${DFLT_KERNEL}";
fi;
fi;
if [ -z "${DFLT_KERNEL_FS}" ]; then
DFLT_KERNEL_FS=${DFLT_KERNEL};
fi;
if [ -z "${DFLT_KERNEL_IMAGE}" ]; then
DFLT_KERNEL_IMAGE=${DFLT_KERNEL};
fi;
# as ODMDATA can be overwritten by process_board_version, overwrite with user specified option here.
if [ -n "${_ODMDATA}" ]; then
# used by setval function below
ODMDATA=${_ODMDATA};
fi
###########################################################################
# System mandatory vars:
#
setval odmdata ODMDATA; # .conf mandatory
setval rootfs_type ROOTFS_TYPE;
setval devsectsize DEVSECTSIZE;
getsize rootfssize ROOTFSSIZE; # .conf mandatory
getsize emmcsize EMMCSIZE; # .conf mandatory
getsize bootpartsize BOOTPARTSIZE; # .conf mandatory
getsize bootpartlim BOOTPARTLIMIT;
getsize recrootfssize RECROOTFSSIZE;
mkfilepath flashapp "${FLASHAPP}" "${BL_DIR}/tegraflash.py";
mkfilepath flasher "${FLASHER}" "${BL_DIR}/cboot.bin";
mkfilepath bootloader "${BOOTLOADER}" "${BL_DIR}/cboot.bin";
mkdirpath rootfs_dir "${ROOTFS_DIR}" "${LDK_DIR}/rootfs";
mkfilepath kernel_image "$KERNEL_IMAGE" "${DFLT_KERNEL_IMAGE}";
mkfilepath kernel_fs "$KERNEL_IMAGE" "${DFLT_KERNEL_FS}";
mkfilepath bctfile "${BCTFILE}" "${TARGET_DIR}/BCT/${EMMC_BCT}";
if [ "${CHIPID}" = "0x19" ]; then
mkfilepath bctfile1 "${BCTFILE1}" "${TARGET_DIR}/BCT/${EMMC_BCT1}";
fi;
mkfilepath cfgfile "${CFGFILE}" "${TARGET_DIR}/cfg/${EMMC_CFG}";
mkfilepath dtbfile "${DTBFILE}" "${DTB_DIR}/${DTB_FILE}";
mkfilesoft kernelinitrd "${INITRD}" "${BL_DIR}/l4t_initrd.img";
mkfilesoft tegraboot "${TEGRABOOT}" "${TARGET_DIR}/nvtboot.bin";
mkfilesoft wb0boot "${WB0BOOT}" "${TARGET_DIR}/nvtbootwb0.bin";
mkfilesoft cpu_bootloader "${BOOTLOADER}" "";
mkfilesoft mtspreboot "${MTSPREBOOT}" "${BL_DIR}/mts_preboot_si";
mkfilesoft ist_ucode "${IST_UCODE}" "";
mkfilesoft mcepreboot "${MTS_MCE}" "${BL_DIR}/${MTS_MCE}";
mkfilesoft mtsproper "${MTSPROPER}" "${BL_DIR}/${MTSPROPER}";
mkfilesoft mts "${MTS}" "${BL_DIR}/mts_si";
mkfilesoft mb1file "${MB1FILE}" "${BL_DIR}/mb1_prod.bin";
if [ "${BPFFILE}" != "" -a \
"${BPFBASEFILE}" != "" -a "${BPFBASEDTBFILE}" != "" -a \
-f "${BPFBASEFILE}" -a -f "${BPFBASEDTBFILE}" ]; then
cat "${BPFBASEFILE}" "${BPFBASEDTBFILE}" > "${BPFFILE}";
fi;
mkfilesoft bpffile "${BPFFILE}" "${BL_DIR}/bpmp.bin";
mkfilesoft bpfdtbfile "${BPFDTBFILE}" "${TARGET_DIR}/${BPFDTB_FILE}";
if [ "${bpfdtbfile}" = "" -a "${BPMPDTB_FILE}" != "" ]; then #COMPAT
mkfilesoft bpfdtbfile "${BL_DIR}/${BPMPDTB_FILE}" ""; #COMPAT
fi; #COMPAT
# Compress bpmp-fw-dtb for t19x devices if COMP_BPMP_FW_DTB is set to 1
if [ "${CHIPID}" = "0x19" ] && [ "${COMP_BPMP_FW_DTB}" = 1 ]; then
if [ "${TRIM_BPMP_DTB}" = "true" ]; then
echo "Error: Trim and compression cannot be used together.";
exit 1;
fi;
compress_bpmp_fw_dtb "${bpfdtbfile}" "${bpfdtbfilename}"
fi
mkfilesoft nctfile "${NCTFILE}" "${TARGET_DIR}/cfg/${NCT_FILE}";
mkfilesoft tosfile "${TOSFILE}" "${TARGET_DIR}/tos.img";
mkfilesoft eksfile "${EKSFILE}" "${TARGET_DIR}/eks.img";
mkfilesoft fbfile "${FBFILE}" "${BL_DIR}/${FBFILE}";
mkfilesoft bcffile "${BCFFILE}" "";
mkfilesoft sosfile "${SOSFILE}" "";
mkfilesoft mb2blfile "${MB2BLFILE}" "";
mkfilesoft scefile "${SCEFILE}" "${BL_DIR}/camera-rtcpu-sce.img";
mkfilesoft camerafw "${CAMERAFW}" "";
mkfilesoft apefile "${APEFILE}" "${BL_DIR}/adsp-fw.bin";
mkfilesoft spefile "${SPEFILE}" "${BL_DIR}/spe.bin";
mkfilesoft drameccfile "${DRAMECCFILE}" "";
if [ "${BADPAGEFILE}" != "" ]; then
if [ ! -f "${BL_DIR}/badpage.bin" ]; then
echo "creating dummy ${BL_DIR}/badpage.bin"
dd if=/dev/zero of="${BL_DIR}/badpage.bin" bs=4096 count=1;
fi;
mkfilesoft badpagefile "${BADPAGEFILE}" "${BL_DIR}/badpage.bin";
fi;
mkfilesoft uphy_config "${TARGET_DIR}/BCT/${UPHY_CONFIG}" "";
mkfilesoft minratchet_config "${TARGET_DIR}/BCT/${MINRATCHET_CONFIG}" "";
mkfilesoft device_config "${TARGET_DIR}/BCT/${DEVICE_CONFIG}" "";
mkfilesoft misc_cold_boot_config "${TARGET_DIR}/BCT/${MISC_COLD_BOOT_CONFIG}" "";
mkfilesoft misc_config "${TARGET_DIR}/BCT/${MISC_CONFIG}" "";
mkfilesoft pinmux_config "${TARGET_DIR}/BCT/${PINMUX_CONFIG}" "";
mkfilesoft gpioint_config "${TARGET_DIR}/BCT/${GPIOINT_CONFIG}" "";
mkfilesoft pmic_config "${TARGET_DIR}/BCT/${PMIC_CONFIG}" "";
mkfilesoft pmc_config "${TARGET_DIR}/BCT/${PMC_CONFIG}" "";
mkfilesoft prod_config "${TARGET_DIR}/BCT/${PROD_CONFIG}" "";
mkfilesoft scr_config "${TARGET_DIR}/BCT/${SCR_CONFIG}" "";
mkfilesoft scr_cold_boot_config "${TARGET_DIR}/BCT/${SCR_COLD_BOOT_CONFIG}" "";
mkfilesoft dev_params "${TARGET_DIR}/BCT/${DEV_PARAMS}" "";
mkfilesoft bootrom_config "${TARGET_DIR}/BCT/${BOOTROM_CONFIG}" "";
mkfilesoft soft_fuses "${TARGET_DIR}/BCT/${SOFT_FUSES}" "";
mkfilesoft tbcfile "${TBCFILE}" "";
mkfilesoft tbcdtbfile "${TBCDTB_FILE}" "${DTB_DIR}/${DTB_FILE}";
mkfilesoft cbootoptionfile "${CBOOTOPTION_FILE}" "${TARGET_DIR}/cbo.dtb";
mkfilesoft varstorefile "${VARSTORE_FILE}" "";
if [ "${tegraid}" = "0x18" ] || [ "${tegraid}" = "0x19" ] \
&& { [ "${target_partname}" == "" ] || [ "${target_partname}" == "recovery-dtb" ]; } \
&& [ ${bup_blob} -eq 0 ]; then
if [ -f "${DTB_DIR}/${DTB_FILE}" ]; then
echo "Copy "${DTB_DIR}/${DTB_FILE} to "${DTB_DIR}/${DTB_FILE}.rec"
cp "${DTB_DIR}/${DTB_FILE}" "${DTB_DIR}/${DTB_FILE}.rec"
fi
mkfilepath recdtbfile "${RECDTB_FILE}" "${DTB_DIR}/${DTB_FILE}.rec";
fi
if [ "${rootdev_type}" = "network" ]; then
if [ "${NFSROOT}" = "" -a "${NFSARGS}" = "" ]; then
echo "Error: network argument(s) missing.";
usage allknown 1;
fi;
if [ "${NFSROOT}" != "" ]; then
validateNFSroot nfsroot "${NFSROOT}";
fi;
if [ "${NFSARGS}" != "" ]; then
validateNFSargs nfsargs "${NFSARGS}";
fi;
if [ "${nfsroot}" != "" ]; then
nfsdargs="root=/dev/nfs rw netdevwait";
cmdline+="${nfsdargs} ";
if [ "${nfsargs}" != "" ]; then
nfsiargs="ip=${nfsargs}";
nfsiargs+="::${target_rootdev}:off";
else
nfsiargs="ip=:::::${target_rootdev}:on";
fi;
cmdline+="${nfsiargs} ";
cmdline+="nfsroot=${nfsroot} ";
fi;
elif [ "${target_rootdev}" = "cloning_root" ]; then
if [ "${tegraid}" = "0x21" ]; then
# Nano
CMDLINE_ADD="console=ttyS0,115200n8 sdhci_tegra.en_boot_part_access=1";
elif [ "${tegraid}" = "0x18" ]; then
# TX2
CMDLINE_ADD="console=ttyS0,115200n8";
elif [ "${tegraid}" = "0x19" ]; then
# Xavier
CMDLINE_ADD="console=ttyTCU0,115200n8";
else
echo "Unknown tegraid/board,exiting.." >&2;
exit 33
fi;
elif [ "${target_rootdev}" == "internal" ] || \
[ "${target_rootdev}" == "external" ] || \
[[ "${rootfs_ab}" == 1 ]]; then
# For 'internal' and 'external' target root devices,
# or enabled ROOTFS_AB=1, always use the UUID stored in the file
# ${rootfsuuidfile} or ${rootfsuuidfile}_b if present.
# If this file is not present, then try to generate one.
_tmp_uuid="";
if [ "${target_rootdev}" == "external" ] || \
[ "${external_device}" -eq 1 ]; then
rootuuid_restore "_ext"
_tmp_uuid="${rootfsuuid_ext}";
else
rootuuid_restore ""
_tmp_uuid="${rootfsuuid}";
fi
if [ ${disk_enc_enable} -eq 1 ]; then
# The encrypted fs UUID of the rootdev.
if [ "${external_device}" -eq 1 ]; then
rootuuid_restore "_ext_enc"
_tmp_uuid="${rootfsuuid_ext_enc}";
bootpartuuid_restore "_ext"
rootfsuuid_enc="${rootfsuuid_ext_enc}"
rootfsuuid_b_enc="${rootfsuuid_b_ext_enc}"
# These variables are set in disk_encryption_helper.func
bootpartuuid="${bootpartuuid_ext}"
# These variables are set in disk_encryption_helper.func
bootpartuuid_b="${bootpartuuid_b_ext}"
else
rootuuid_restore "_enc";
_tmp_uuid="${rootfsuuid_enc}";
bootpartuuid_restore;
fi
cmdline+="root=UUID=${_tmp_uuid} rw rootwait rootfstype=ext4 "
else
cmdline+="root=PARTUUID=${_tmp_uuid} rw rootwait rootfstype=ext4 "
fi;
else
cmdline+="root=/dev/${target_rootdev} rw rootwait rootfstype=ext4 "
fi;
if [ "${CMDLINE_ADD}" != "" ]; then
cmdline+="${CMDLINE_ADD} ";
fi;
if [ "${CMDLINE}" != "" ]; then
for string in ${CMDLINE}; do
lcl_str=`echo $string | sed "s|\(.*\)=.*|\1|"`
if [[ "${cmdline}" =~ $lcl_str ]]; then
cmdline=`echo "$cmdline" | sed "s|$lcl_str=[0-9a-zA-Z:/]*|$string|"`
else
cmdline+="${string} ";
fi
done
fi;
##########################################################################
if [ "${zflag}" == "true" ]; then
pr_conf;
exit 0;
fi;
##########################################################################