diff --git a/tools/resources/bake_tools.sh b/tools/resources/bake_tools.sh new file mode 100755 index 00000000..3541866f --- /dev/null +++ b/tools/resources/bake_tools.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash + +# @file merge common helpers and script into a single script without dependencies +# +# +# + +set -e + +# find script resources directory +if [ -z "$TBD_PROJECT_DIR" ]; then + scripts_srcs_dir="$(realpath -- $(dirname -- ${BASH_SOURCE[0]}))" +else + scripts_srcs_dir="$TBD_PROJECT_DIR/tools/resources" +fi + +source "$scripts_srcs_dir/common_header.sh" + +# @brief parameter defaults +# +# +tbd_logging_tag="bake_tools" +script_files="$scripts_srcs_dir"/src/*.sh +process_only=false +header_file=$scripts_srcs_dir/common_header.sh + +# @brief parse command line options +# +# +parse_args() { + while [ $# -gt 0 ]; do + arg=$1 + + case $arg in + -o|--out-dir) + out_dir=$2 + shift + ;; + -p|--process-ony) + process_only=true + ;; + *) + break + ;; + esac + shift + done + + if [ $# -gt 0 ]; then + script_files=$@ + fi + + + if [ -z "$out_dir" ]; then + out_dir=$(dirname -- "$scripts_srcs_dir")/bin + fi +} + + +parse_args $@ + +tbd_logi "writing baked script files to $out_dir" + +if ! [ -d "$out_dir" ]; then + mkdir -p "$out_dir" +fi + +for script_file in $script_files; do + if ! [ -f "$script_file" ]; then + tbd_loge "$script_file: input file not found" + continue + fi + + # remove .sh extension from final tool name + out_file=$out_dir/$(basename -- ${script_file%.sh}) + + num_header_lines=$(awk '/-- END OF HEADER --/{ print NR; exit }' "$script_file") + if [ -z "$num_header_lines" ]; then + if $process_only; then + continue + fi + + if cp "$script_file" "$out_file"; then + tbd_logi "$script_file: copied" + else + tbd_loge "$script_file: failed to copy" + fi + else + if cat "$header_file" > "$out_file" \ + && tail -n +$num_header_lines "$script_file" >> $out_file + then + tbd_logi "$script_file: baked" + else + tbd_loge "$script_file: failed to bake" + fi + fi +done diff --git a/tools/resources/helpers.sh b/tools/resources/common_header.sh similarity index 82% rename from tools/resources/helpers.sh rename to tools/resources/common_header.sh index 7bbecdc5..d85f4e0d 100644 --- a/tools/resources/helpers.sh +++ b/tools/resources/common_header.sh @@ -1,3 +1,9 @@ +#!/usr/bin/env bash + +set -e + +#### logging utils #### + c_none="0" c_black="0;30" c_red="0;31" @@ -55,6 +61,8 @@ tbd_abort() { exit 1 } +#### script execution utils #### + # @brief run a bash command with output # # @arg 1 [enum] display or hide stdout of command (SILENT/VERBOSE) @@ -72,6 +80,8 @@ tbd_run() { fi } +#### TBD project utils #### + # @brief quick check if the given directory looks like a TBD project root # # A tbd, ports and apps folder and CMakeLists.txt file should be present. @@ -126,3 +136,21 @@ tbd_project_root() { return 1 } + +tbd_get_platforms() { + local project_dir=$1 + if [ -z "$project_dir" ]; then + project_dir=$(tbd_project_root) + fi + + if [ -z "$project_dir" ]; then + return 1 + fi + + for platform_file in "$project_dir"/config/platforms/platform.*.json; do + platform=$(basename -- ${platform_file%.json}) + platform=${platform#platform.} + echo $platform + done + +} diff --git a/tools/resources/src/gdb-device.sh b/tools/resources/src/gdb-device.sh new file mode 100755 index 00000000..5297ec90 --- /dev/null +++ b/tools/resources/src/gdb-device.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -e + +tbd_logging_tag="tbd_gbd_emu" + +resource_path=$(dirname -- $(dirname -- ${BASH_SOURCE[0]}))/resources +source "$resource_path/helpers.sh" + +project_dir=$(tbd_project_root) +if [ -z "$project_dir" ]; then + tbd_abort "could not find TBD project in path" +fi + +if ! which xtensa-esp32s3-elf-gdb; then + tbd_abort "debugger 'xtensa-esp32s3-elf-gdb' not in PATH, please activate ESP IDF using '. /export.sh'" +fi + +symbols_file=${project_dir}/build/$1/ctag-tbd.elf +if ! [ -f "$symbols_file" ]; then + tbd_abort "symbols file does not exist, no file ${symbols_file}" +fi + +exec xtensa-esp32s3-elf-gdb \ + -x "$resource_path/device.gdb" \ + "$symbols_file" \ + $@ diff --git a/tools/resources/src/gdb-emu.sh b/tools/resources/src/gdb-emu.sh new file mode 100755 index 00000000..70588a39 --- /dev/null +++ b/tools/resources/src/gdb-emu.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -e + +tbd_logging_tag="tbd_gbd_emu" + +resource_path=$(dirname -- $(dirname -- ${BASH_SOURCE[0]}))/resources +source "$resource_path/helpers.sh" + +project_dir=$(tbd_project_root) +if [ -z "$project_dir" ]; then + tbd_abort "could not find TBD project in path" +fi + +if ! which xtensa-esp32s3-elf-gdb; then + tbd_abort "debugger 'xtensa-esp32s3-elf-gdb' not in PATH, please activate ESP IDF using '. /export.sh'" +fi + +symbols_file=$project_dir/build/emu/ctag-tbd.elf +if ! [ -f "$symbols_file" ]; then + tbd_abort "symbols file does not exist, no file ${symbols_file}" +fi + +exec xtensa-esp32s3-elf-gdb \ + -x "$resource_path/emu.gdb" \ + "$symbols_file" \ + $@ diff --git a/tools/resources/src/tbb.sh b/tools/resources/src/tbb.sh new file mode 100755 index 00000000..ae942480 --- /dev/null +++ b/tools/resources/src/tbb.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash + +resource_path=$(dirname -- $(dirname -- ${BASH_SOURCE[0]})) +source "$resource_path/common_header.sh" + +# -- END OF HEADER -- + +tbd_logging_tag="tbd build" + +project_dir=$(tbd_project_root) +if [ -z "$project_dir" ]; then + tbd_abort "could not find TBD project in path" +fi + +cmake_args= + +# @brief parse command line options +# +# All options unknown to tbb are passed on to CMake +# +parse_args() { + while [ $# -gt 0 ]; do + arg=$1 + case $arg in + --refresh) + refresh=true + ;; + --silent) + tbd_cmd_verbosity="SILENT" + ;; + *) + break + ;; + esac + shift + done + + if [ $# -lt 1 ]; then + tbd_abort "no platform specified" + fi + platform=$1 + shift + + cmake_args=$@ +} + +parse_args $@ +tbd_get_platforms "$project_dir" + + + +# if [ -z "$ESP_IDF_VERSION" ] && [ $TBD_IN_CONTAINER -eq 1 ]; then +# source "$TBD_IDF_ACTIVATE" +# fi + +# if [ -z "$TBD_PROJECT_DIR" ]; then +# TBD_TOOL_MAIN="$(dirname -- $(dirname -- ${BASH_SOURCE[0]}))/tbdtools/__main__.py" +# else +# cd "$TBD_PROJECT_DIR" +# TBD_TOOL_MAIN="$TBD_PROJECT_DIR/tools/tbdtools/__main__.py" +# fi + +# export + +# export LOGURU_LEVEL=DEBUG +# platform="$1" +# shift + +# exec python "$TBD_TOOL_MAIN" -p "${platform}" firmware $@ diff --git a/tools/resources/src/tbd.sh b/tools/resources/src/tbd.sh new file mode 100755 index 00000000..63b1df3c --- /dev/null +++ b/tools/resources/src/tbd.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +TBD_TOOL_MAIN="$(dirname -- $(dirname -- ${BASH_SOURCE[0]}))/tbdtools/__main__.py" +export LOGURU_LEVEL=WARNING +exec python "$TBD_TOOL_MAIN" $@ diff --git a/tools/resources/src/tbd_deps.sh b/tools/resources/src/tbd_deps.sh new file mode 100755 index 00000000..071fdfd2 --- /dev/null +++ b/tools/resources/src/tbd_deps.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +if [ -z "$ESP_IDF_VERSION" ] || [ -z "$IDF_PYTHON_ENV_PATH" ]; then + echo "no esp idf python env seems to be active, make sure to source export.sh from idf dir before running this script" + exit 1 +fi + +if ! echo pip install \ + sphinx \ + pydata-sphinx-theme \ + sphinxcontrib-youtube \ + breathe \ + typer \ + cxxheaderparser \ + jinja2 \ + GitPython \ + loguru \ + pyhumps \ + pydantic \ + pyyaml +then + echo "an error occurred during installation of TBD python dependencies" +fi \ No newline at end of file diff --git a/tools/resources/src/tbe.sh b/tools/resources/src/tbe.sh new file mode 100755 index 00000000..de671da1 --- /dev/null +++ b/tools/resources/src/tbe.sh @@ -0,0 +1,111 @@ +#!/usr/bin/env bash + +resource_path=$(dirname -- $(dirname -- ${BASH_SOURCE[0]})) +source "$resource_path/common_header.sh" + +# -- END OF HEADER -- + +tbd_logging_tag="tbd emu" + +project_dir=$(tbd_project_root) +if [ -z "$project_dir" ]; then + tbd_abort "could not find TBD project in path" +fi + +bin_dir=${project_dir}/build/emu +qemu_dir=/opt/qemu/build + +build_only=false +qemu_args=() +qemu_extra_args=() +refresh=false +tbd_cmd_verbosity="VERBOSE" + + +# @brief parse command line options +# +# All options unknown to tbe are passed on to qemu +# +parse_args() { + for arg in "$@"; do + case $arg in + --refresh) + refresh=true + ;; + --silent) + tbd_cmd_verbosity="SILENT" + ;; + --debug) + qemu_extra_args+=(-s) + qemu_extra_args+=(-S) + ;; + --build-only) + refresh=true + build_only=true + ;; + *) + qemu_args+=("$arg") + ;; + esac + done +} + + +refresh_build() { + tbd_run pushd ${project_dir} + + tbd_logi "refreshing target build" + # -drive file="${bin_dir}/qemu_efuse.bin,if=none,format=raw,id=efuse" \ + + if ! [ -f "${bin_dir}/project_description.json" ]; then + tbd_logi "updating build config" + cmake -Bbuild/emu -G Ninja -DTBD_PLATFORM=emu + fi + + tbd_logi "rebuilding executable" + tbd_run cmake --build "${bin_dir}" -j $(nproc --all) + + tbd_run pushd ${bin_dir} + + tbd_logi "creating firmware binary" + tbd_run esptool.py --chip=esp32s3 merge_bin \ + --output=${bin_dir}/qemu_flash.bin \ + --fill-flash-size=16MB --flash_mode dio --flash_freq 80m --flash_size 16MB \ + @flash_args + + if ! [ -f qemu_efuse.bin ]; then + tbd_logi "creating efuse binary" + tbd_run dd if=/dev/zero bs=1KiB count=1 of=qemu_efuse.bin + fi + + tbd_run popd + tbd_run popd +} + + +run_emulator() { + tbd_logi "starting emulator" + + exec "${qemu_dir}/qemu-system-xtensa" -M esp32s3 \ + -m 8M \ + -drive file="${bin_dir}/qemu_flash.bin,if=mtd,format=raw" \ + -drive file="${bin_dir}/qemu_efuse.bin,if=none,format=raw,id=efuse" \ + -global driver=nvram.esp32s3.efuse,property=drive,value=efuse \ + -global driver=timer.esp32c3.timg,property=wdt_disable,value=true \ + -nic user,model=open_eth \ + -nographic \ + -serial mon:stdio \ + ${qemu_extra_args[@]} \ + ${qemu_args[@]} +} + +parse_args $@ + +if $refresh; then + refresh_build +fi + +if ! $build_only; then + run_emulator +fi + diff --git a/tools/resources/src/tbr.sh b/tools/resources/src/tbr.sh new file mode 100755 index 00000000..18e3db37 --- /dev/null +++ b/tools/resources/src/tbr.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +docs_makefile=$PWD/docs/config/Makefile + +make -f "$docs_makefile" diff --git a/tools/resources/src/tbx.sh b/tools/resources/src/tbx.sh new file mode 100755 index 00000000..d0e48c59 --- /dev/null +++ b/tools/resources/src/tbx.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +set +e + +tbd_logging_tag=tbx + +load_includes() { + resource_path=$(dirname -- $(dirname -- ${BASH_SOURCE[0]}))/resources + source "$resource_path/helpers.sh" +} + +load_includes + +var=$(tbd_project_root) +echo $var