# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: MIT
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

# Build the FSKP Blob for BMC

This section explains how to build a BMC FSKP blob and subsequent tarball.
These steps must be completed using a X64_64 linux build machine. The usb
connection to IGX is not required for this process.

0. Prepare the following fuse files:
    - fuse.xml
    - fskp_conf.txt
    - <AK_KEY>
    - <EK_KEY>

1. Download the following packages under the same path:
    - fskp_t234_<VERSION>_aarch64.tbz2
    - Jetson_Linux_<VERSION>_aarch64.tbz2
    - arm_tegraflash_<VERSION>_aarch64.tbz2

2. Install the BSP package

3. Follow the steps to untar the packages:
    a. `cd Linux_for_Tegra/`
    b. `tar xvjf ../fskp_t234_<VERSION>_aarch64.tbz2`
    c. `cp /path/to/arm_tegraflash_<VERSION>_aarch64.tbz2 ../`

4. Run the FSKP Blob generation script
    - For testing:
        `sudo ./l4t/tools/flashtools/fuseburn/bmc_fuse/package_bmc_fskp.sh -f <FUSE_CONFIG> --fskpcfg <EXP_KEY_CONFIG> -k <AK> <EK> -t`
    - For burning fuses:
        `sudo ./l4t/tools/flashtools/fuseburn/bmc_fuse/package_bmc_fskp.sh -f <FUSE_CONFIG> --fskpcfg <EXP_KEY_CONFIG> -k <AK> <EK> -b`


    The script will create bmc_fuse_<VERSION>.tbz2 under Linux_for_Tegra/

# Burn Tegra's fuse from IGX's BMC

This section explains how to copy the built tarball from the Linux build machine to the IGX's BMC
and run the BMC script to burn Tegra's fuse.

1. Copy the tarball to the BMC
    `scp bmc_fuse_<VERSION>.tbz2 root@<bmc_ip>:/run/initramfs`

2. Log into the BMC with its credentials
    `ssh root@<bmc_ip>`

3. Untar the tarball as following
    a. `cd /run/initramfs`
    b. `tar -xvf bmc_fuse_<VERSION>.tbz2`

4. Flash the Tegra QSPI image from the BMC
    `bash bmcfuse/bmcfuse.sh`

Note:
1. Please replace <bmc_ip> with the IP address actually assigned to BMC(For example,192.168.1.110).
2. Replace <VERSION> with the actual version number of the L4T BSP release(for exmaple, R36.3.0).

