From d928305d3a0cb389f2d983b66fb1f02226419570 Mon Sep 17 00:00:00 2001
From: Peter Li <a0220410@ti.com>
Date: Fri, 18 Jun 2021 11:38:46 +0800
Subject: [PATCH 1/2] adapt local environment, run default demo pass

---
 build/build_boot-app-mcu-rtos_release.sh      |   1 +
 .../scripts/hlos/constructappimageshlos.sh    |  22 ++-
 .../scripts/hlos/flash_ospi_boot_main_demo.sh | 158 ++++++++++++++++++
 .../scripts/makemulticore_j721e.sh            |   1 +
 4 files changed, 178 insertions(+), 4 deletions(-)
 create mode 100755 build/build_boot-app-mcu-rtos_release.sh
 create mode 100755 mcuss_demos/boot_app_mcu_rtos/main_domain_apps/scripts/hlos/flash_ospi_boot_main_demo.sh
 create mode 100755 mcuss_demos/boot_app_mcu_rtos/main_domain_apps/scripts/makemulticore_j721e.sh

diff --git a/build/build_boot-app-mcu-rtos_release.sh b/build/build_boot-app-mcu-rtos_release.sh
new file mode 100755
index 0000000..87d687c
--- /dev/null
+++ b/build/build_boot-app-mcu-rtos_release.sh
@@ -0,0 +1 @@
+make -s -j can_boot_app_mcu_rtos HLOSBOOT=linux CANFUNC=none BOARD=j721e_evm SOC=j721e BUILD_PROFILE=release CORE=mcu1_0 BUILD_OS_TYPE=tirtos
diff --git a/mcuss_demos/boot_app_mcu_rtos/main_domain_apps/scripts/hlos/constructappimageshlos.sh b/mcuss_demos/boot_app_mcu_rtos/main_domain_apps/scripts/hlos/constructappimageshlos.sh
index 403ee60..99fa4bc 100755
--- a/mcuss_demos/boot_app_mcu_rtos/main_domain_apps/scripts/hlos/constructappimageshlos.sh
+++ b/mcuss_demos/boot_app_mcu_rtos/main_domain_apps/scripts/hlos/constructappimageshlos.sh
@@ -4,10 +4,12 @@
 ##############################################################
 
 # MY_BOARD options are: j721e_evm or j7200_evm
-MY_BOARD=$1
+#MY_BOARD=$1
+MY_BOARD=j721e_evm
 
 # OS options are: linux or qnx
-OS=qnx
+#OS=qnx
+OS=linux
 
 # Linux-specific paths
 # --------------------
@@ -17,7 +19,15 @@ OS=qnx
 # base-board.dtb (k3-j72*-common-proc-board.dtb), and Image files
 
 # Linux build directory containing all the locally-built Linux-related binaries
-LINUX_BUILD_DIR_PATH=USER_DEFINED_PATH
+if [ $OS == "linux" ]; then
+   SDK_PATH=/home/a0220410local/Public/J721E/SDK_V7.3
+
+   PSDKRA_INSTALL_PATH=$SDK_PATH/ti-processor-sdk-rtos-j721e-evm-07_03_00_07
+   PSDKLA_INSTALL_PATH=$SDK_PATH/ti-processor-sdk-linux-j7-evm-07_03_00_05
+   LINUX_TOOLCHAIN_PATH_GCC_ARCH64=$PSDKRA_INSTALL_PATH/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu/bin
+   LINUX_PREBUILT_DIR=${PSDKLA_INSTALL_PATH}/board-support/prebuilt-images
+   LINUX_BUILD_DIR_PATH=${PSDKLA_INSTALL_PATH}/board-support/u-boot_build/a72/spl
+fi
 
 # QNX-specific paths
 # ------------------
@@ -63,6 +73,10 @@ pushd $PWD > /dev/null
 if [ $OS == "linux" ]; then
     cd $LINUX_BUILD_DIR_PATH
     #cd $LINUX_PREBUILT_DIR_PATH
+    cp $LINUX_PREBUILT_DIR/bl31.bin .
+    cp $LINUX_PREBUILT_DIR/bl32.bin .
+    cp $LINUX_PREBUILT_DIR/Image .
+    cp $LINUX_PREBUILT_DIR/k3-j721e-common-proc-board.dtb base-board.dtb
 fi
 if [ $OS == "qnx" ]; then
     cd $QNX_PREBUILT_DIR_PATH
@@ -73,7 +87,7 @@ for i in "${GenFiles[@]}"
 do
     echo "Generating $i image"
     if [ $OS == "linux" ]; then
-        aarch64-none-linux-gnu-ld -T $LDS_PATH/$i.lds -o $MULTICOREAPP_BIN_PATH/$i.elf
+        ${LINUX_TOOLCHAIN_PATH_GCC_ARCH64}/aarch64-none-linux-gnu-ld -T $LDS_PATH/$i.lds -o $MULTICOREAPP_BIN_PATH/$i.elf
     fi
     if [ $OS == "qnx" ]; then
         ${TOOLCHAIN_PATH_GCC_ARCH64}/aarch64-unknown-nto-qnx7.0.0-ld -T $LDS_PATH/$i.lds -o $MULTICOREAPP_BIN_PATH/$i.elf
diff --git a/mcuss_demos/boot_app_mcu_rtos/main_domain_apps/scripts/hlos/flash_ospi_boot_main_demo.sh b/mcuss_demos/boot_app_mcu_rtos/main_domain_apps/scripts/hlos/flash_ospi_boot_main_demo.sh
new file mode 100755
index 0000000..0bdf1cc
--- /dev/null
+++ b/mcuss_demos/boot_app_mcu_rtos/main_domain_apps/scripts/hlos/flash_ospi_boot_main_demo.sh
@@ -0,0 +1,158 @@
+# Please refer to below link for OSPI image address
+# https://software-dl.ti.com/jacinto7/esd/processor-sdk-rtos-jacinto7/latest/exports/docs/mcusw/mcal_drv/docs/drv_docs/demo_boot_app_mcu_rtos_top.html
+#
+
+#adjust blow PATH according to your own enviroment
+export FLASH_TTY_PORT=/dev/ttyUSB1
+export PSDKRA_PATH=/home/a0220410local/Public/J721E/SDK_V7.3/ti-processor-sdk-rtos-j721e-evm-07_03_00_07
+export DSLITE_PATH=/home/a0220410local/Public/J721E/uniflash_6.2.0
+export MCU_APP_PATH=$PSDKRA_PATH/mcusw/binary
+export MAIN_APP_PATH=$PSDKRA_PATH/mcusw/mcuss_demos/boot_app_mcu_rtos/main_domain_apps/binary/bin/j721e_evm
+
+#path used by utility
+export PDK_PATH=$PSDKRA_PATH/pdk_jacinto_07_03_00_29
+export FLASH_PROGRAMMER_BINARY=$PDK_PATH/packages/ti/board/utils/uniflash/target/bin/j721e_evm/uart_j721e_evm_flash_programmer_release.tiimage
+export FLASH_PROGRAMMER_SYSFW=$PDK_PATH/packages/ti/board/utils/uniflash/target/bin/j721e_evm/sysfw.bin
+export FLASH_PATTERN_BINARY=$PDK_PATH/packages/ti/board/src/flash/nor/ospi/nor_spi_patterns.bin
+export SBL_CUST_BINARY=$PDK_PATH/packages/ti/boot/sbl/binary/j721e_evm/cust/bin/sbl_cust_img_mcu1_0_release.tiimage
+export SBL_PATH=$PDK_PATH/packages/ti/boot/sbl/binary/j721e_evm/ospi/bin
+export TIFS_BINARY=$PDK_PATH/packages/ti/drv/sciclient/soc/V1/tifs.bin
+export MCU1_0_IMAGE=$MCU_APP_PATH/can_boot_app_mcu_rtos/bin/j721e_evm/can_boot_app_mcu_rtos_mcu1_0_release.appimage
+export STAGE1_IMAGE=$MAIN_APP_PATH/multicore_MCU2_0_MCU2_1_stage1.appimage
+export STAGE2_IMAGE=$MAIN_APP_PATH/multicore_DSPs_MCU3_0_MCU3_1_stage2.appimage
+export ATF_OPTEE_IMAGE=$MAIN_APP_PATH/atf_optee.appimage
+export KERNEL_IMAGE=$MAIN_APP_PATH/tikernelimage_linux.appimage
+export DTB_IMAGE=$MAIN_APP_PATH/tidtb_linux.appimage
+export CURRENT_PATH=$PWD
+
+echo "checking $TIFS_BINARY ..."
+if [ ! -f $TIFS_BINARY ]; then
+echo "ERROR!!! $TIFS_BINARY doesn't exist!!!"
+exit 1
+else
+echo "$TIFS_BINARY is in place."
+fi
+
+echo ""
+echo "checking $FLASH_PATTERN_BINARY ..."
+if [ ! -f $FLASH_PATTERN_BINARY ]; then
+echo "ERROR!!! $FLASH_PATTERN_BINARY doesn't exist!!!"
+exit 2
+else
+echo "$FLASH_PATTERN_BINARY is in place."
+fi
+
+echo ""
+echo "checking $FLASH_PROGRAMMER_BINARY ..."
+if [ ! -f $FLASH_PROGRAMMER_BINARY ]; then
+echo "$FLASH_PROGRAMMER_BINARY doesn't exist!!!"
+echo " =============================================================================== "
+echo " Please build flash programmer in $PDK_PATH/packages/ti/build"
+echo " make PLATFORM=j721e_evm board_utils_uart_flash_programmer"
+echo " =============================================================================== "
+exit 3
+fi
+
+echo ""
+echo "checking $SBL_CUST_BINARY ..."
+if [ ! -f $SBL_CUST_BINARY ]; then
+echo "$SBL_CUST_BINARY doesn't exist, ATTENTION!!!"
+echo " =============================================================================== "
+echo " Please build the SBL in $PDK_PATH/package/ti/build "
+echo " step 1: make BOARD=j721e_evm CORE=mcu1_0 BUILD_PROFILE=release pdk_libs_clean"
+echo " step 2: make BOARD=j721e_evm CORE=mcu1_0 BUILD_PROFILE=release pdk_libs"
+echo " step 3: make BOARD=j721e_evm CORE=mcu1_0 BUILD_PROFILE=release sbl_cust_img_clean"
+echo " step 4: make BOARD=j721e_evm CORE=mcu1_0 BUILD_PROFILE=release sbl_cust_img"
+echo " =============================================================================== "
+exit 4
+fi
+
+echo ""
+echo "checking $MCU1_0_IMAGE ..."
+if [ ! -f $MCU1_0_IMAGE ]; then
+echo "$MCU1_0_IMAGE doesn't exist, ATTENTION!!!"
+exit 5
+fi
+
+echo ""
+echo "all the necessary binaries are available, good to go..."
+
+echo ""
+echo "checking $FLASH_PROGRAMMER_SYSFW ..."
+if [ ! -f $FLASH_PROGRAMMER_SYSFW ]; then
+echo "cp $TIFS_BINARY to $FLASH_PROGRAMMER_SYSFW"
+cp $TIFS_BINARY $FLASH_PROGRAMMER_SYSFW
+else
+echo "$FLASH_PROGRAMMER_SYSFW is in place."
+fi
+
+echo ""
+echo "----step 1---- flash $FLASH_PROGRAMMER_BINARY ..."
+$DSLITE_PATH/dslite.sh --mode processors -c $FLASH_TTY_PORT -f $FLASH_PROGRAMMER_BINARY -i 0
+
+echo ""
+echo "----step 2---- erase flash ..."
+#erase flash, only needed once if FLASH layout isn't changed
+$DSLITE_PATH/dslite.sh --mode processors -c $FLASH_TTY_PORT -e 3000000 -d 3 -o 0
+
+echo ""
+echo "----step 3---- flash ospi pattern ..."
+$DSLITE_PATH/dslite.sh --mode processors -c $FLASH_TTY_PORT -f $FLASH_PATTERN_BINARY -d 3 -o 3FE0000
+
+echo ""
+echo "----step 4---- flash SBL ..."
+$DSLITE_PATH/dslite.sh --mode processors -c $FLASH_TTY_PORT -f $SBL_CUST_BINARY -d 3 -o 0
+
+echo ""
+echo "----step 5---- flash TIFS ..."
+$DSLITE_PATH/dslite.sh --mode processors -c $FLASH_TTY_PORT -f $TIFS_BINARY -d 3 -o 80000
+
+echo ""
+echo "----step 6---- flash mcu1_0 image ..."
+$DSLITE_PATH/dslite.sh --mode processors -c $FLASH_TTY_PORT -f $MCU1_0_IMAGE -d 3 -o 100000
+
+echo ""
+echo "----step 7---- flash stage1 image ..."
+if [ ! -f $STAGE1_IMAGE ]; then
+echo "$STAGE1_IMAGE doesn't exist, ATTENTION!!!"
+exit 6
+else
+$DSLITE_PATH/dslite.sh --mode processors -c $FLASH_TTY_PORT -f $STAGE1_IMAGE -d 3 -o 1fc0000
+fi
+
+echo ""
+echo "----step 8---- flash stage2 image ..."
+if [ ! -f $STAGE2_IMAGE ]; then
+echo "$STAGE2_IMAGE doesn't exist, ATTENTION!!!"
+exit 7
+else
+$DSLITE_PATH/dslite.sh --mode processors -c $FLASH_TTY_PORT -f $STAGE2_IMAGE -d 3 -o 27c0000
+fi
+
+echo ""
+echo "----step 9---- flash atf_optee image ..."
+if [ ! -f $ATF_OPTEE_IMAGE ]; then
+echo "$ATF_OPTEE_IMAGE doesn't exist, ATTENTION!!!"
+exit 8
+else
+$DSLITE_PATH/dslite.sh --mode processors -c $FLASH_TTY_PORT -f $ATF_OPTEE_IMAGE -d 3 -o 1c0000
+fi
+	
+echo ""
+echo "----step 10---- flash kernel image ..."
+if [ ! -f $KERNEL_IMAGE ]; then
+echo "$KERNEL_IMAGE doesn't exist, ATTENTION!!!"
+exit 9
+else
+$DSLITE_PATH/dslite.sh --mode processors -c $FLASH_TTY_PORT -f $KERNEL_IMAGE -d 3 -o 7c0000
+fi
+
+echo ""
+echo "----step 11---- flash dtb image ..."
+if [ ! -f $DTB_IMAGE ]; then
+echo "$DTB_IMAGE doesn't exist, ATTENTION!!!"
+exit 10
+else
+$DSLITE_PATH/dslite.sh --mode processors -c $FLASH_TTY_PORT -f $DTB_IMAGE -d 3 -o 1ec0000
+fi
+
diff --git a/mcuss_demos/boot_app_mcu_rtos/main_domain_apps/scripts/makemulticore_j721e.sh b/mcuss_demos/boot_app_mcu_rtos/main_domain_apps/scripts/makemulticore_j721e.sh
new file mode 100755
index 0000000..0ac7543
--- /dev/null
+++ b/mcuss_demos/boot_app_mcu_rtos/main_domain_apps/scripts/makemulticore_j721e.sh
@@ -0,0 +1 @@
+./makemulticore.sh j721e_evm
-- 
2.17.1

