UnboundLocalError: local variable 'bpmp_dtb' referenced before assignment

Dear Forum,

I followed the instruction in Jetson Orin NX and Nano Series — Jetson Linux Developer Guide documentation
to update the pinmux for my custom carrier board with Jetson Orin NX 8GB on top:

<SDK_install>/JetPack_5.1.2_Linux_JETSON_ORIN_NX_TARGETS/Linux_for_Tegra/bootloader/t186ref/BCT/tegra234-l4es-orin-nx-mb1-bct–padvoltage-default-camera-nx.dtsi
<SDK_install>/JetPack_5.1.2_Linux_JETSON_ORIN_NX_TARGETS/Linux_for_Tegra/bootloader/t186ref/BCT/tegra234-l4es-orin-nx-mb1-bct-pinmux-camera-nx.dtsi
<SDK_install>/JetPack_5.1.2_Linux_JETSON_ORIN_NX_TARGETS/Linux_for_Tegra/bootloader/tegra234-l4es-orin-nx-mb1-bct-gpio-default-camera-nx.dtsi

<SDK_install>/JetPack_5.1.2_Linux_JETSON_ORIN_NX_TARGETS/Linux_for_Tegra/bootloader//tegra234-l4es-orin-nx-mb2-bct-misc-p3767-0001-camera-nx.dts :

/dts-v1/;

#include "tegra234-mb2-bct-common.dtsi"

/ {
        mb2-misc {
                eeprom {
                        cvm_eeprom_i2c_instance = <0>;
                        cvm_eeprom_i2c_slave_address = <0xa0>;
                        cvm_eeprom_read_size = <0x100>;
                        cvb_eeprom_i2c_instance = <0x0>;
                        cvb_eeprom_i2c_slave_address = <0xae>;
                        cvb_eeprom_read_size = <0x0>;
                };
        };
};

And :
<SDK_install>/JetPack_5.1.2_Linux_JETSON_ORIN_NX_TARGETS/Linux_for_Tegra/l4es-camera-nx+p3767.conf

# Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#  * Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#  * 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.
#  * Neither the name of NVIDIA CORPORATION 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 ``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 OWNER 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.

source "${LDK_DIR}/p3767.conf.common";

# update_flash_args_common:
update_flash_args_common()
{
        local emcfuse_bin="${1}";
        local emcpredefvalue="${2}"

        if [ ${EMC_OPT_DISABLE_FUSE_OVERRIDE} -eq 0 ]; then
                return;
        fi

        # EMCFUSE_VALUE can be passed by user
        emc_opt_disable_fuse="${DEFAULT_EMC_FUSE}";

        if [ -n "${emcpredefvalue}" ]; then
                emc_opt_disable_fuse="${emcpredefvalue}";
        elif [ -f "${emcfuse_bin}" ]; then
                emc_opt_disable_fuse=`xxd -ps "${emcfuse_bin}" | xxd -p -r | grep "OptEmcDisable" | awk '{print $2}' | sed 's/.*\(.\)/\1/'`;
        fi

        echo "emc_opt_disable_fuse:(${emc_opt_disable_fuse})"

        # For the first 

        if [ "${board_sku}" = "0000" ]; then
                # use default DTB and CFG files except for TS1 & EB1 revisions
                if [ "${board_FAB}" = "TS1" ] || [ "${board_FAB}" = "EB1" ]; then
                        PINMUX_CONFIG="tegra234-mb1-bct-pinmux-p3767-hdmi-a01.dtsi";
                        PMC_CONFIG="tegra234-mb1-bct-padvoltage-p3767-hdmi-a01.dtsi";
                        BPFDTB_FILE="tegra234-bpmp-3767-0000-a00-3509-a02.dtb";
                fi
        elif [ "${board_sku}" = "0001" ]; then
                BPFDTB_FILE="tegra234-bpmp-3767-0001-3509-a02.dtb";
                DTB_FILE="tegra234-p3767-0001-p3768-0000-a0.dtb";
        elif [ -n "${board_sku}" ]; then
                echo "Error: Orin NX SKU '${board_sku}' is not supported by L4es Camera BSP yet" 1>&2
                exit 1
        fi
}

# update_flash_args:
update_flash_args()
{
        # All updates should go into update_flash_args_common to allow
        # for other files to include this file and override variables.
        update_flash_args_common
}

DEFAULT_EMC_FUSE="0";
#PINMUX_CONFIG="tegra234-mb1-bct-pinmux-p3767-hdmi-a03.dtsi";
#PMC_CONFIG="tegra234-mb1-bct-padvoltage-p3767-hdmi-a03.dtsi";

# Customized for CAMERA-NX
PINMUX_CONFIG="tegra234-l4es-orin-nx-mb1-bct-pinmux-camera-nx.dtsi";
PMC_CONFIG="tegra234-l4es-orin-nx-mb1-bct--padvoltage-default-camera-nx.dtsi";
# NOTE: BPFDTB file name sounds like it has something to do with carrier board (Xavier NX Carrier - 3509),
# and clearly our carrier board is different, but since BPMP is undocumented and DTB is provided only as a binary,
# the only option is to reuse this as-is.
# End of customization for CAMERA-NX

BPFDTB_FILE="tegra234-bpmp-3767-0001-a02-3509-a02.dtb";
DTB_FILE="tegra234-p3767-0001-p3768-0000-a0.dtb";
TBCDTB_FILE="${DTB_FILE}";
EMMC_CFG="flash_t234_qspi.xml";

# Customized for VIANSIGHT-NX
#DTB_FILE="tegra234-p3767-0000-l4es-camera-nx.dtb";
#TBCDTB_FILE="${DTB_FILE}";
MB2_BCT="tegra234-l4es-orin-nx-mb2-bct-misc-p3767-0001-camera-nx.dts";
# End of customization for CAMERA-NX

However, while running the flash command :
sudo ./tools/kernel_flash/l4t_initrd_flash.sh --external-device nvme0n1p1 -c tools/kernel_flash/flash_l4t_external.xml -p "-c bootloader/t186ref/cfg/flash_t234_qspi.xml" --showlogs --network usb0 l4es-camera-nx+p3767 internal

I got following error :

*** Sign and generate flashing ready partition images... *** 
Welcome to Tegra Flash
version 1.0.0
Type ? or help for help and q or quit to exit
Use ! to execute system commands
 
[   0.0345 ] tegrasign_v3.py --key None --getmode mode.txt
[   0.0347 ] Assuming zero filled SBK key
[   0.0337 ] Parsing partition layout
[   0.0348 ] tegraparser_v2 --pt flash.xml.tmp
Traceback (most recent call last):
  File "/workspace/Ref/Platforms/Nvidia-Jetson/Software/SDK_install/JetPack_5.1.2_Linux_JETSON_ORIN_NX_TARGETS/Linux_for_Tegra/bootloader/tegraflash_impl_t234.py", line 1401, in tegraflash_update_bpmp_dtb
    if bpmp_dtb == None and bpmp_dtb_in_layout == None:
UnboundLocalError: local variable 'bpmp_dtb' referenced before assignment

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./tegraflash.py", line 1383, in <module>
    tegraflash_run_commands()
  File "./tegraflash.py", line 1217, in tegraflash_run_commands
    interpreter.onecmd(command)
  File "/usr/lib/python3.6/cmd.py", line 217, in onecmd
    return func(arg)
  File "./tegraflash.py", line 730, in do_sign
    self.chip_inst.tegraflash_sign(exports)
  File "/workspace/Ref/Platforms/Nvidia-Jetson/Software/SDK_install/JetPack_5.1.2_Linux_JETSON_ORIN_NX_TARGETS/Linux_for_Tegra/bootloader/tegraflash_impl_t234.py", line 2594, in tegraflash_sign
    self.tegraflash_parse_partitionlayout()
  File "/workspace/Ref/Platforms/Nvidia-Jetson/Software/SDK_install/JetPack_5.1.2_Linux_JETSON_ORIN_NX_TARGETS/Linux_for_Tegra/bootloader/tegraflash_impl_t234.py", line 467, in tegraflash_parse_partitionlayout
    self.tegraflash_update_bpmp_dtb()
  File "/workspace/Ref/Platforms/Nvidia-Jetson/Software/SDK_install/JetPack_5.1.2_Linux_JETSON_ORIN_NX_TARGETS/Linux_for_Tegra/bootloader/tegraflash_impl_t234.py", line 1468, in tegraflash_update_bpmp_dtb
    raise tegraflash_exception('Unexpected error in updating: ' + bpmp_dtb + ' ' + str(e))
UnboundLocalError: local variable 'bpmp_dtb' referenced before assignment
Error: /workspace/Ref/Platforms/Nvidia-Jetson/Software/SDK_install/JetPack_5.1.2_Linux_JETSON_ORIN_NX_TARGETS/Linux_for_Tegra/bootloader/signed/flash.idx is not found
Error: failed to relocate images to /workspace/Ref/Platforms/Nvidia-Jetson/Software/SDK_install/JetPack_5.1.2_Linux_JETSON_ORIN_NX_TARGETS/Linux_for_Tegra/tools/kernel_flash/images
Cleaning up...

If I replace

PINMUX_CONFIG="tegra234-l4es-orin-nx-mb1-bct-pinmux-camera-nx.dtsi";
PMC_CONFIG="tegra234-l4es-orin-nx-mb1-bct--padvoltage-default-camera-nx.dtsi";

by

PINMUX_CONFIG="tegra234-mb1-bct-pinmux-p3767-hdmi-a03.dtsi";
PMC_CONFIG="tegra234-mb1-bct-padvoltage-p3767-hdmi-a03.dtsi";

then the flashing goes smoothly but of course my changes will not be applied.

Could you help to identify what is the missing configuration, please ?

Thanks and best regards,
Khang

Dump the full log, please.
Mostly that’s because some files contain spaces in their file names, so argument parsing fails.

1 Like

Hi @DaveYYY,

It turns out that I put the MB2_BCT file (tegra234-l4es-orin-nx-mb2-bct-misc-p3767-0001-camera-nx.dts) in a wrong location : <SDK_install>/JetPack_5.1.2_Linux_JETSON_ORIN_NX_TARGETS/Linux_for_Tegra/bootloader/tegra234-l4es-orin-nx-mb2-bct-misc-p3767-0001-camera-nx.dts , it should be found in
<SDK_install>/JetPack_5.1.2_Linux_JETSON_ORIN_NX_TARGETS/Linux_for_Tegra/bootloader/t186ref/BCT/tegra234-l4es-orin-nx-mb2-bct-misc-p3767-0001-camera-nx.dts

Best Regards,
Khang