Skip to content

Commit 413789a

Browse files
Daniel Newtonjgriffiths
authored andcommitted
switch_to.sh: support noradio/qemu variants from base config, add --skip-reconfigure
Allows removing more largely redundant config files.
1 parent ec9b990 commit 413789a

File tree

1 file changed

+170
-25
lines changed

1 file changed

+170
-25
lines changed

tools/switch_to.sh

Lines changed: 170 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,39 @@ CI=""
1010
LOG=""
1111
DEBUG=""
1212
JTAG=""
13+
PSRAM=""
14+
UNAMALGAMATED=""
15+
WEBDISPLAY=""
16+
WEBDISPLAY_LARGER=""
17+
SKIP_RECONFIGURE=""
1318

1419
function usage {
15-
echo "THIS SCRIPT IS FOR JADE DEVELOPMENT ONLY";
16-
echo "${0} jade|jade_v1_1|jade_v2 [--dev] [--noradio] [--ci] [--log|--log-cbor|--log-wifi] [--debug] [--jtag]";
20+
if [ -n "$1" ]; then
21+
echo "error: $1" >&2
22+
fi
23+
echo "${0} jade|jade_v1_1|jade_v2|qemu [OPTIONS]"
24+
echo "WARNING: THIS SCRIPT IS FOR JADE DEVELOPMENT ONLY";
25+
echo "JADE OPTIONS:"
26+
echo " --noradio Disable Bluetooth support"
27+
echo " --log Enable logging"
28+
echo " --log-cbor Enable CBOR logging messages over the serial API"
29+
echo " --log-wifi Enable text logging over WiFi"
30+
echo "JADE V2 OPTIONS:"
31+
echo " --jtag Enable JTAG debugging support"
32+
echo "QEMU OPTIONS:"
33+
echo " --psram Emulate a device with PSRAM support"
34+
echo " --webdisplay Provide a device display using a web browser"
35+
echo " --webdisplay-larger Provide a larger device display for --webdisplay"
36+
echo "COMMON OPTIONS:"
37+
echo " --dev Development (non-production) device (mandatory for qemu)"
38+
echo " --ci Automatically execute the default UX action for CI testing"
39+
echo " --debug Enable debug message handlers for testing"
40+
echo " --unamalgamated Disable amalgamation of source files when building"
41+
echo " --skip-reconfigure Make config changes but do not reconfigure the build"
42+
if [ -n "$1" ]; then
43+
exit 1
44+
fi
45+
exit 0
1746
}
1847

1948
function have_cmd()
@@ -23,60 +52,131 @@ function have_cmd()
2352

2453
function set_config()
2554
{
26-
sed -i "/^$1=/d" sdkconfig.defaults # Remove any old value
55+
sed -i "/^$1=/d" sdkconfig.defaults # Remove old value: ignore if missing
2756
if [ -n "$2" ]; then
2857
echo "$1=$2" >>sdkconfig.defaults # Add the new value
2958
fi
3059
}
3160

61+
function remove_config()
62+
{
63+
# Remove config value: error if missing
64+
REGEX="$1="
65+
if ! grep -q "$REGEX" "sdkconfig.defaults"; then
66+
echo "error: '$REGEX' not found in sdkconfig.defaults" >&2
67+
exit 1
68+
fi
69+
sed -i "/^$REGEX/d" sdkconfig.defaults
70+
}
71+
3272
while true; do
3373
case "$1" in
3474
jade) CONFIG=$1; ARCH="esp32"; shift ;;
3575
jade_v1_1) CONFIG=$1; ARCH="esp32"; shift ;;
3676
jade_v2) CONFIG=$1; ARCH="esp32s3"; shift ;;
77+
qemu) CONFIG=$1; ARCH="esp32"; shift ;;
3778
--dev) DEVELOPMENT="y"; shift ;;
38-
--noradio) NORADIO="_noradio"; shift ;;
79+
--noradio) NORADIO=1; shift ;;
3980
--ci) CI="1"; shift ;;
4081
--log) LOG=uart; shift ;;
4182
--log-cbor) LOG=cbor; shift ;;
4283
--log-wifi) LOG=wifi; shift ;;
4384
--debug) DEBUG=1; shift ;;
4485
--jtag) JTAG=1; shift ;;
45-
-h | --help) usage;
46-
exit 0 ;;
86+
--psram) PSRAM=1; shift ;;
87+
--unamalgamated) UNAMALGAMATED=1; shift ;;
88+
--webdisplay) WEBDISPLAY=1; shift ;;
89+
--webdisplay-larger) WEBDISPLAY=1; WEBDISPLAY_LARGER=1; shift ;;
90+
--skip-reconfigure) SKIP_RECONFIGURE=1; shift ;;
91+
-h | --help) usage ;;
4792
"") break ;;
48-
*) echo "error: unknown option ${1}"; usage; exit 1
93+
*) usage "unknown option ${1}" ;;
4994
esac
5095
done
5196

5297
if [ -z "${ARCH}" ]; then
53-
usage
54-
exit 1
98+
usage "No target architecture selected"
99+
fi
100+
101+
if [ "$CONFIG" = "qemu" ]; then
102+
# QEMU
103+
if [ -n "$NORADIO" ] || [ -n "$LOG" ] || [ -n "$DEBUG" ] || [ -n "$JTAG" ]; then
104+
usage "--[noradio|log|log-cbor|log-wifi|debug|jtag] must not be given for qemu"
105+
elif [ -n "$WEBDISPLAY" ] && [ -z "$PSRAM" ]; then
106+
usage "--[webdisplay|webdisplay-larger] require --psram"
107+
fi
108+
else
109+
# Jade v1.0, 1.1, or 2.0
110+
if [ -n "$PSRAM" ] || [ -n "$WEBDISPLAY" ]; then
111+
usage "--[psram|webdisplay|webdisplay-larger] must not be given for non-qemu"
112+
fi
55113
fi
56114

57115
# TODO: standardize the naming convention for prod/dev configs
58116
if [ -n "${DEVELOPMENT}" ]; then
59-
CONFIG_FILE="./configs/sdkconfig_dev_${CONFIG}${NORADIO}.defaults"
117+
if [ "$CONFIG" = "qemu" ]; then
118+
CONFIG_FILE="./configs/sdkconfig_${CONFIG}.defaults"
119+
else
120+
CONFIG_FILE="./configs/sdkconfig_dev_${CONFIG}.defaults"
121+
fi
60122
else
61-
CONFIG_FILE="./production/sdkconfig_${CONFIG}${NORADIO}_prod.defaults"
123+
if [ "$CONFIG" = "qemu" ]; then
124+
usage "--dev must be given for qemu"
125+
fi
126+
CONFIG_FILE="./production/sdkconfig_${CONFIG}_prod.defaults"
62127
fi
63-
if [ ! -f $CONFIG_FILE ]; then
64-
echo "error: config file $CONFIG_FILE does not exist"
128+
if [ ! -f "$CONFIG_FILE" ]; then
129+
echo "error: config file $CONFIG_FILE does not exist" >&2
65130
exit 1
66131
fi
67132

68133
if ! have_cmd idf.py; then
69-
echo "error: idf.py not found. Please install idf"
70-
echo "(or run export.sh from the idf install) and try again"
134+
echo "error: idf.py not found. Please install idf" >&2
135+
echo "\(or run export.sh from the idf install\) and try again" >&2
71136
exit 1
72137
fi
73138

74139
idf.py clean && \
75-
rm -rf sdkconfig build && \
76-
cp $CONFIG_FILE sdkconfig.defaults
140+
rm -rf sdkconfig build
77141

78142
echo "============================================"
79143
echo "using config file $CONFIG_FILE ..."
144+
cp "$CONFIG_FILE" sdkconfig.defaults
145+
if [ -n "$NORADIO" ]; then
146+
echo "updating config file for noradio ..."
147+
# remove settings (all)
148+
remove_config CONFIG_BT_ENABLED
149+
remove_config CONFIG_BT_NIMBLE_ATT_PREFERRED_MTU
150+
remove_config CONFIG_BT_NIMBLE_ENABLED
151+
remove_config CONFIG_BT_NIMBLE_GAP_DEVICE_NAME_MAX_LEN
152+
remove_config CONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE
153+
remove_config CONFIG_BT_NIMBLE_MAX_CONNECTIONS
154+
remove_config CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL
155+
remove_config CONFIG_BT_NIMBLE_NVS_PERSIST
156+
remove_config CONFIG_BT_NIMBLE_ROLE_BROADCASTER
157+
remove_config CONFIG_BT_NIMBLE_ROLE_CENTRAL
158+
remove_config CONFIG_BT_NIMBLE_ROLE_OBSERVER
159+
remove_config CONFIG_BT_NIMBLE_SM_LEGACY
160+
remove_config CONFIG_BT_NIMBLE_SVC_GAP_DEVICE_NAME
161+
# add settings (all)
162+
set_config CONFIG_APP_NO_BLOBS y
163+
set_config CONFIG_MBEDTLS_ECP_RESTARTABLE y
164+
if [ "$CONFIG" = "jade" ] || [ "$CONFIG" = "jade_v1_1" ]; then
165+
# remove settings (Jade v1.x)
166+
remove_config CONFIG_BTDM_CTRL_BLE_MAX_CONN
167+
remove_config CONFIG_BTDM_CTRL_FULL_SCAN_SUPPORTED
168+
remove_config CONFIG_ESP_COEX_SW_COEXIST_ENABLE
169+
# add settings (Jade v1.x)
170+
set_config CONFIG_ESP_WIFI_IRAM_OPT n
171+
set_config CONFIG_ESP_WIFI_RX_IRAM_OPT n
172+
elif [ "$CONFIG" = "jade_v2" ]; then
173+
# remove settings (Jade v2)
174+
remove_config CONFIG_BT_NIMBLE_LOG_LEVEL_NONE
175+
else
176+
echo "error: unknown CONFIG: $CONFIG" >&2
177+
exit 1
178+
fi
179+
fi
80180
if [ -n "$CI" ]; then
81181
echo "updating config file for CI build ..."
82182
set_config CONFIG_DEBUG_UNATTENDED_CI y
@@ -95,13 +195,13 @@ elif [ "$LOG" = "wifi" ]; then
95195
DEFAULT_IP="${DEFAULT_IP}.100"
96196
fi
97197
set_config CONFIG_LOG_WIFI y
98-
read -p "Enter WIFI SSID: " SSID
198+
read -r -p "Enter WIFI SSID: " SSID
99199
set_config CONFIG_WIFI_SSID "\"$SSID\""
100-
read -p "Enter WIFI Password: " PASSWORD
200+
read -r -p "Enter WIFI Password: " PASSWORD
101201
set_config CONFIG_WIFI_PASSWORD "\"$PASSWORD\""
102-
read -p "Enter socket server IP [${DEFAULT_IP}]: " IP
202+
read -r -p "Enter socket server IP [${DEFAULT_IP}]: " IP
103203
set_config CONFIG_WIFI_LOGGER_IP "\"${IP:-${DEFAULT_IP}}\""
104-
read -p "Enter socket server PORT [8888]: " PORT
204+
read -r -p "Enter socket server PORT [8888]: " PORT
105205
set_config CONFIG_WIFI_LOGGER_PORT ${PORT:-8888}
106206
LOG="uart" # Enable UART logging below
107207
fi
@@ -115,16 +215,61 @@ if [ -n "$DEBUG" ]; then
115215
fi
116216
if [ -n "$JTAG" ]; then
117217
if [[ "$CONFIG" != *"jade_v2"* ]]; then
118-
echo "error: JTAG can only be enabled for jade_v2 variants"
218+
echo "error: JTAG can only be enabled for jade_v2 variants" >&2
119219
exit 1
120220
fi
121221
echo "updating config file for JTAG support ..."
122222
set_config CONFIG_JADE_USE_USB_JTAG_SERIAL y
123223
set_config CONFIG_NEWLIB_STDIN_LINE_ENDING_LF y
124224
set_config CONFIG_NEWLIB_STDOUT_LINE_ENDING_LF y
125225
fi
226+
if [ -n "$PSRAM" ]; then
227+
echo "updating config file for PSRAM support ..."
228+
# remove settings
229+
remove_config CONFIG_ESP_WIFI_STATIC_TX_BUFFER
230+
remove_config CONFIG_ESP_WIFI_STATIC_TX_BUFFER_NUM
231+
# add settings
232+
set_config CONFIG_ESP_INT_WDT_TIMEOUT_MS 300
233+
set_config CONFIG_SPIRAM y
234+
set_config CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY y
235+
set_config CONFIG_SPIRAM_BANKSWITCH_ENABLE n
236+
set_config CONFIG_SPIRAM_MEMTEST n
237+
if [ -n "$WEBDISPLAY" ]; then
238+
echo "updating config file for webdisplay build ..."
239+
# remove settings
240+
remove_config CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT
241+
remove_config CONFIG_DEBUG_UNATTENDED_CI
242+
remove_config CONFIG_ESP_ERR_TO_NAME_LOOKUP
243+
remove_config CONFIG_ESP_INT_WDT_TIMEOUT_MS
244+
remove_config CONFIG_ESP_SYSTEM_CHECK_INT_LEVEL_5
245+
remove_config CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT
246+
remove_config CONFIG_LWIP_IPV6
247+
remove_config CONFIG_LWIP_NETIF_LOOPBACK
248+
remove_config CONFIG_UART_ISR_IN_IRAM
249+
# add settings
250+
set_config CONFIG_ESP_BROWNOUT_DET n
251+
set_config CONFIG_ESP_INT_WDT n
252+
set_config CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT y
253+
set_config CONFIG_HAS_CAMERA y
254+
set_config CONFIG_HTTPD_MAX_REQ_HDR_LEN 4096
255+
set_config CONFIG_HTTPD_WS_SUPPORT y
256+
fi
257+
if [ -n "$WEBDISPLAY_LARGER" ]; then
258+
echo "updating config file for larger webdisplay build ..."
259+
# add settings
260+
set_config CONFIG_BOARD_TYPE_QEMU_LARGER y
261+
# remove settings
262+
remove_config CONFIG_BOARD_TYPE_QEMU
263+
fi
264+
fi
265+
if [ -n "$UNAMALGAMATED" ]; then
266+
echo "updating config file for unamalgamated build ..."
267+
set_config CONFIG_AMALGAMATED_BUILD n
268+
fi
126269
echo "============================================"
127270

128-
idf.py set-target $ARCH && \
129-
idf.py reconfigure && \
130-
echo "run idf.py all to build the firmware"
271+
if [ -z "$SKIP_RECONFIGURE" ]; then
272+
idf.py set-target $ARCH && \
273+
idf.py reconfigure && \
274+
echo "run idf.py all to build the firmware"
275+
fi

0 commit comments

Comments
 (0)