~aleteoryx/muditaos

ref: sign_test muditaos/run.sh -rwxr-xr-x 3.5 KiB
a217eeb3 — Dawid Wojtas [BH-2024] Fix lack of alarm directory after updating software 1 year, 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash -e
# Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

source config/common.sh

BIN_DIR="build-rt1051-Debug"

help() 
{
cat<<EOF
Script accepts two parameters: 
    - build* 
        build catalog, it will accept any catalog with "build" in name
    default: ${BIN_DIR} is taken

    --gdb PARAM
        parameter to full gdb path, for gcc9 you can pass i.e.
        ~/gcc-arm-none-eabi-8-2019-q3-update/bin/arm-none-eabi-gdb-py
    default: gdb from your PATH

    --product PARAM
        product to run [PurePhone|BellHybrid]

examples:
./run.sh --product PurePhone  build-purephone-rt1051-RelWithDebInfo/ --gdb ~/gcc-arm-none-eabi-8-2019-q3-update/bin/arm-none-eabi-gdb-py // full specification
./run.sh --product BellHybrid build-bell-rt1051-RelWithDebInfo                                                                           // binary for gdb specified
./run.sh --product BellHybrid --gdb ~/gcc-arm-none-eabi-8-2019-q3-update/bin/arm-none-eabi-gdb-py                                        // gdb binary specified
./run.sh --help                                                                                                                          // help
EOF
}

while [[ $# -gt 0 ]]; do
    echo "PARAM: $1"
    case $1 in
        build*)
            BIN_DIR="$1"
            ;;
        --gdb)
            GDB_ARM="$2"
            echo "Loaded $GDB_ARM"
            shift
            ;;
        --product)
            PRODUCT_NAME="$2"
            echo "Product $PRODUCT_NAME"
            shift
            ;;
        --help)
            echo "HELP!"
            help
            exit 0
            ;;
        *)
            echo "Bad param! $1"
            help
            exit 1
            ;;
    esac;
    shift
done

if [ -z ${GDB_ARM+x} ]; then # if GDB_ARM unset, check which GDB binaries are present and choose one
    ALL_GDB_VERSIONS=( $(compgen -A command arm-none-eabi-gdb | sort -n) )
    PY_VER=()

    # check python version for all present GDB binaries
    for GDB_VERSION in "${ALL_GDB_VERSIONS[@]}"; do
        PY_VER+=( "$($GDB_VERSION --batch -iex 'python import sys; print(sys.version)' 2> /dev/null || echo "no python")" )
    done

    # check for GDB versions with python 3
    for i in "${!PY_VER[@]}"; do
        if [[ "${PY_VER[$i]}" == "3."* ]]; then 
            GDB_ARM=${ALL_GDB_VERSIONS[$i]}
            echo "GDB with python 3 found"
            break
        fi 
    done

    if [ -z ${GDB_ARM+x} ]; then # if GDB_ARM still unset check for GDB versions with python 2 
        for i in "${!PY_VER[@]}"; do
            if [[ "${PY_VER[$i]}" == "2."* ]]; then 
                GDB_ARM=${ALL_GDB_VERSIONS[$i]}
                echo "GDB with python 2 found. For the best debugging experience update your GDB binaries from the most recent toolchain release"
                break
            fi 
        done
    fi

    if [ -z ${GDB_ARM+x} ]; then 
        if command -v arm-none-eabi-gdb &> /dev/null; then
            echo "No GDB with python found. If you want to use debugging tools please install a GDB version that supports python."
            GDB_ARM="arm-none-eabi-gdb"
        else 
            echo "looks like you don't have any compatible GDB versions installed. Use the bootstrap.sh script to download and configure the ARM toolchain."
        fi
    fi
fi

if [ -z "${PRODUCT_NAME}" ]; then
    echo "ERROR! Product param not provided"
    help
    exit 1
fi

check_target_rt1051 "${BIN_DIR}" "${PRODUCT_NAME}"

${GDB_ARM} "${BIN_DIR}"/"${PRODUCT_NAME}".elf -x .gdbinit-1051