This document contains a detailed procedure to describe detailed procedure of
flashing multiple Jetson devices simultaneously. Supported Jetson devices are
jetson-tx1, jetson-nano-emmc, jetson-tx2, and jetson-xavier.


###############################################################################
# A: Preparation (Actions on the master host: takes <15min)                   #
###############################################################################
1. Assumption:
   - Linux host machine is running either Ubuntu 14.04, 16.04, or
     18.04 LTS
   - User downloaded and extracted the L4T BSP by following the
     "L4T_quick_start_guide.txt"

2. Prepare redundancy:
   - If and only if BFS redundancy is required for jetson-tx1 or
     jetson-nano-emmc, then follow extra steps as specified in
     ``TX1_boot-firmware-redundancy.txt''.
   - The A/B redundancy is pre-populated by default for jetson-tx2
     and jetson-xavier, and no extra steps are required.

3. Prepare secureboot:
   - If and only if secureboot is required, then follow extra steps
     specified in ``READM_secureboot.txt.''

4. Generate mass flash image:

   - Enter the command `cd Linux_for_Tegra`.
   - connect one target Jetson device, and put it into RCM mode.
   - run nvmassflashgen.sh:

     For non-secureboot (including flashing with redundancy):
       sudo ./nvmassflashgen.sh <jetson device name> mmcblk0p1

     For secureboot (including +redundancy):
       sudo ./nvmassflashgen.sh -x <TegraID> -y PKC -u <PKC keyfile> <jetson device name> mmcblk0p1
       sudo ./nvmassflashgen.sh -x <TegraID> -y SBKPKC -u <PKC keyfile> -v <SBK keyfile> <jetson device name> mmcblk0p1

     NOTE: nvmassflashgen.sh generates massflash images named as:
           mfi_<jetson_device>.tbz2 for non-secureboot,
           mfi_<jetson_device>_signed.tbz2 for PKC secureboot,
           mfi_<jetson_device>_encrypt_signed.tbz2 for SBKPKC secureboot.

     Where `<jetson_device>` is the name of the Jetson device.
 
     NOTE: SBKPKC mode is only supported by jetson-tx2 and jetson-xavier.

###############################################################################
# B: Mass Flash (Actions on each of manufacturing hosts: takes < min)         #
###############################################################################
1. Download mfi_<jetson_device>[[_encrypt]_signed].tbz2

   You must download mfi_<jetson_device>[[_encrypt]_signed].tbz2 to
   each manufacturing host.

   Example:
   ubuntu@ahost:~$ scp loginname@<master host ipaddr>:Linux_for_Tegra/mfi_jetson_tx1.tbz2
   loginname@<master host ipaddr?'s password:
   mfi_jetson_tx1.tbz2              100% 1024KB   1.0MB/s   00:00

2. Untar mfi_<jetson_device>[[_encrypt]_signed].tbz2 image (takes less than three minutes):

   - tar xvjf mfi_<jetson_device>[[_encrypt]_signed].tbz2
   - cd mfi_<jetson_device>[[_encrypt]_signed]

3. Flash multiple TX1s simultaneously:

   - Connect the Jetson devices to the manufacturing hosts.
     (Make sure all devices are in exactly the same hardware revision as prepared in
      section A: Especially SKU, FAB, BOARDREV, etc... )
   - Put all of connected Jetsons into RCM mode.
   - Enter: `sudo ./nvmflash.sh [--showlogs]`

     NOTE: nvmflash.sh saves all massflashing logs in bootloader/mfilogs
           directory. Each log name has following format:
           ``<hostname>_<timestamp>_<pid>_flash_<USB_path>.log''

4. Performance with full Ubuntu Desktop (both Jetson devices on same USB bridge):

   +===============+==============+=============+===========+=============+
   | No of Jetsons | DeskTop cler | +redundancy | +PKC      | +SBK        |
   +===============+==============+=============+===========+=============+
   | 1             |  < 4min      | < 4min      | < 4min    | < 4min      |
   +---------------+--------------+-------------+-----------+-------------+
   | 2             |  < 4min      | < 4min      | < 4min    | < 4min      |
   +---------------+--------------+-------------+-----------+-------------+
     ....
   +---------------+--------------+-------------+-----------+-------------+
   | n             |  TBF         |  TBF        |  TBF      | TBF         |
   +---------------+--------------+-------------+-----------+-------------+

   NOTE: The final performance (i.e. how many simultaneous flashing
         each host PC can take) is solely depending on USB configuration
         of host PC.
