switch_to.sh: support noradio/qemu variants from base config, add --skip-reconfigure
What changed, and why it matters
This is a developer-only build helper script update. It adds support for QEMU emulator builds, a few new build options, and a flag to skip reconfiguring the build. There is no change to the actual Jade firmware or wallet security logic, and nothing in the commit suggests a security fix or vulnerability.
No security action required. Treat as routine build-system maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
tools/switch_to.sh is a shell script that selects an ESP-IDF sdkconfig.defaults file and applies build-time configuration overrides. The commit refactors option handling, adds qemu as a target, introduces –psram, –webdisplay, –webdisplay-larger, –unamalgamated, and –skip-reconfigure flags, and moves Bluetooth-disable logic from separate config files into the script. It also improves usage/error output and adds read -r safety. No cryptographic, protocol, or runtime firmware code is modified.
Changed components
tools/switch_to.shInspect captured patch +170 / −25
diff --git a/tools/switch_to.sh b/tools/switch_to.sh
index b617da3..f3819f7 100755
--- a/tools/switch_to.sh
+++ b/tools/switch_to.sh
@@ -10,10 +10,39 @@ CI=""
LOG=""
DEBUG=""
JTAG=""
+PSRAM=""
+UNAMALGAMATED=""
+WEBDISPLAY=""
+WEBDISPLAY_LARGER=""
+SKIP_RECONFIGURE=""
function usage {
- echo "THIS SCRIPT IS FOR JADE DEVELOPMENT ONLY";
- echo "${0} jade|jade_v1_1|jade_v2 [--dev] [--noradio] [--ci] [--log|--log-cbor|--log-wifi] [--debug] [--jtag]";
+ if [ -n "$1" ]; then
+ echo "error: $1" >&2
+ fi
+ echo "${0} jade|jade_v1_1|jade_v2|qemu [OPTIONS]"
+ echo "WARNING: THIS SCRIPT IS FOR JADE DEVELOPMENT ONLY";
+ echo "JADE OPTIONS:"
+ echo " --noradio Disable Bluetooth support"
+ echo " --log Enable logging"
+ echo " --log-cbor Enable CBOR logging messages over the serial API"
+ echo " --log-wifi Enable text logging over WiFi"
+ echo "JADE V2 OPTIONS:"
+ echo " --jtag Enable JTAG debugging support"
+ echo "QEMU OPTIONS:"
+ echo " --psram Emulate a device with PSRAM support"
+ echo " --webdisplay Provide a device display using a web browser"
+ echo " --webdisplay-larger Provide a larger device display for --webdisplay"
+ echo "COMMON OPTIONS:"
+ echo " --dev Development (non-production) device (mandatory for qemu)"
+ echo " --ci Automatically execute the default UX action for CI testing"
+ echo " --debug Enable debug message handlers for testing"
+ echo " --unamalgamated Disable amalgamation of source files when building"
+ echo " --skip-reconfigure Make config changes but do not reconfigure the build"
+ if [ -n "$1" ]; then
+ exit 1
+ fi
+ exit 0
}
function have_cmd()
@@ -23,60 +52,131 @@ function have_cmd()
function set_config()
{
- sed -i "/^$1=/d" sdkconfig.defaults # Remove any old value
+ sed -i "/^$1=/d" sdkconfig.defaults # Remove old value: ignore if missing
if [ -n "$2" ]; then
echo "$1=$2" >>sdkconfig.defaults # Add the new value
fi
}
+function remove_config()
+{
+ # Remove config value: error if missing
+ REGEX="$1="
+ if ! grep -q "$REGEX" "sdkconfig.defaults"; then
+ echo "error: '$REGEX' not found in sdkconfig.defaults" >&2
+ exit 1
+ fi
+ sed -i "/^$REGEX/d" sdkconfig.defaults
+}
+
while true; do
case "$1" in
jade) CONFIG=$1; ARCH="esp32"; shift ;;
jade_v1_1) CONFIG=$1; ARCH="esp32"; shift ;;
jade_v2) CONFIG=$1; ARCH="esp32s3"; shift ;;
+ qemu) CONFIG=$1; ARCH="esp32"; shift ;;
--dev) DEVELOPMENT="y"; shift ;;
- --noradio) NORADIO="_noradio"; shift ;;
+ --noradio) NORADIO=1; shift ;;
--ci) CI="1"; shift ;;
--log) LOG=uart; shift ;;
--log-cbor) LOG=cbor; shift ;;
--log-wifi) LOG=wifi; shift ;;
--debug) DEBUG=1; shift ;;
--jtag) JTAG=1; shift ;;
- -h | --help) usage;
- exit 0 ;;
+ --psram) PSRAM=1; shift ;;
+ --unamalgamated) UNAMALGAMATED=1; shift ;;
+ --webdisplay) WEBDISPLAY=1; shift ;;
+ --webdisplay-larger) WEBDISPLAY=1; WEBDISPLAY_LARGER=1; shift ;;
+ --skip-reconfigure) SKIP_RECONFIGURE=1; shift ;;
+ -h | --help) usage ;;
"") break ;;
- *) echo "error: unknown option ${1}"; usage; exit 1
+ *) usage "unknown option ${1}" ;;
esac
done
if [ -z "${ARCH}" ]; then
- usage
- exit 1
+ usage "No target architecture selected"
+fi
+
+if [ "$CONFIG" = "qemu" ]; then
+ # QEMU
+ if [ -n "$NORADIO" ] || [ -n "$LOG" ] || [ -n "$DEBUG" ] || [ -n "$JTAG" ]; then
+ usage "--[noradio|log|log-cbor|log-wifi|debug|jtag] must not be given for qemu"
+ elif [ -n "$WEBDISPLAY" ] && [ -z "$PSRAM" ]; then
+ usage "--[webdisplay|webdisplay-larger] require --psram"
+ fi
+else
+ # Jade v1.0, 1.1, or 2.0
+ if [ -n "$PSRAM" ] || [ -n "$WEBDISPLAY" ]; then
+ usage "--[psram|webdisplay|webdisplay-larger] must not be given for non-qemu"
+ fi
fi
# TODO: standardize the naming convention for prod/dev configs
if [ -n "${DEVELOPMENT}" ]; then
- CONFIG_FILE="./configs/sdkconfig_dev_${CONFIG}${NORADIO}.defaults"
+ if [ "$CONFIG" = "qemu" ]; then
+ CONFIG_FILE="./configs/sdkconfig_${CONFIG}.defaults"
+ else
+ CONFIG_FILE="./configs/sdkconfig_dev_${CONFIG}.defaults"
+ fi
else
- CONFIG_FILE="./production/sdkconfig_${CONFIG}${NORADIO}_prod.defaults"
+ if [ "$CONFIG" = "qemu" ]; then
+ usage "--dev must be given for qemu"
+ fi
+ CONFIG_FILE="./production/sdkconfig_${CONFIG}_prod.defaults"
fi
-if [ ! -f $CONFIG_FILE ]; then
- echo "error: config file $CONFIG_FILE does not exist"
+if [ ! -f "$CONFIG_FILE" ]; then
+ echo "error: config file $CONFIG_FILE does not exist" >&2
exit 1
fi
if ! have_cmd idf.py; then
- echo "error: idf.py not found. Please install idf"
- echo "(or run export.sh from the idf install) and try again"
+ echo "error: idf.py not found. Please install idf" >&2
+ echo "\(or run export.sh from the idf install\) and try again" >&2
exit 1
fi
idf.py clean && \
- rm -rf sdkconfig build && \
- cp $CONFIG_FILE sdkconfig.defaults
+ rm -rf sdkconfig build
echo "============================================"
echo "using config file $CONFIG_FILE ..."
+cp "$CONFIG_FILE" sdkconfig.defaults
+if [ -n "$NORADIO" ]; then
+ echo "updating config file for noradio ..."
+ # remove settings (all)
+ remove_config CONFIG_BT_ENABLED
+ remove_config CONFIG_BT_NIMBLE_ATT_PREFERRED_MTU
+ remove_config CONFIG_BT_NIMBLE_ENABLED
+ remove_config CONFIG_BT_NIMBLE_GAP_DEVICE_NAME_MAX_LEN
+ remove_config CONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE
+ remove_config CONFIG_BT_NIMBLE_MAX_CONNECTIONS
+ remove_config CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL
+ remove_config CONFIG_BT_NIMBLE_NVS_PERSIST
+ remove_config CONFIG_BT_NIMBLE_ROLE_BROADCASTER
+ remove_config CONFIG_BT_NIMBLE_ROLE_CENTRAL
+ remove_config CONFIG_BT_NIMBLE_ROLE_OBSERVER
+ remove_config CONFIG_BT_NIMBLE_SM_LEGACY
+ remove_config CONFIG_BT_NIMBLE_SVC_GAP_DEVICE_NAME
+ # add settings (all)
+ set_config CONFIG_APP_NO_BLOBS y
+ set_config CONFIG_MBEDTLS_ECP_RESTARTABLE y
+ if [ "$CONFIG" = "jade" ] || [ "$CONFIG" = "jade_v1_1" ]; then
+ # remove settings (Jade v1.x)
+ remove_config CONFIG_BTDM_CTRL_BLE_MAX_CONN
+ remove_config CONFIG_BTDM_CTRL_FULL_SCAN_SUPPORTED
+ remove_config CONFIG_ESP_COEX_SW_COEXIST_ENABLE
+ # add settings (Jade v1.x)
+ set_config CONFIG_ESP_WIFI_IRAM_OPT n
+ set_config CONFIG_ESP_WIFI_RX_IRAM_OPT n
+ elif [ "$CONFIG" = "jade_v2" ]; then
+ # remove settings (Jade v2)
+ remove_config CONFIG_BT_NIMBLE_LOG_LEVEL_NONE
+ else
+ echo "error: unknown CONFIG: $CONFIG" >&2
+ exit 1
+ fi
+fi
if [ -n "$CI" ]; then
echo "updating config file for CI build ..."
set_config CONFIG_DEBUG_UNATTENDED_CI y
@@ -95,13 +195,13 @@ elif [ "$LOG" = "wifi" ]; then
DEFAULT_IP="${DEFAULT_IP}.100"
fi
set_config CONFIG_LOG_WIFI y
- read -p "Enter WIFI SSID: " SSID
+ read -r -p "Enter WIFI SSID: " SSID
set_config CONFIG_WIFI_SSID "\"$SSID\""
- read -p "Enter WIFI Password: " PASSWORD
+ read -r -p "Enter WIFI Password: " PASSWORD
set_config CONFIG_WIFI_PASSWORD "\"$PASSWORD\""
- read -p "Enter socket server IP [${DEFAULT_IP}]: " IP
+ read -r -p "Enter socket server IP [${DEFAULT_IP}]: " IP
set_config CONFIG_WIFI_LOGGER_IP "\"${IP:-${DEFAULT_IP}}\""
- read -p "Enter socket server PORT [8888]: " PORT
+ read -r -p "Enter socket server PORT [8888]: " PORT
set_config CONFIG_WIFI_LOGGER_PORT ${PORT:-8888}
LOG="uart" # Enable UART logging below
fi
@@ -115,7 +215,7 @@ if [ -n "$DEBUG" ]; then
fi
if [ -n "$JTAG" ]; then
if [[ "$CONFIG" != *"jade_v2"* ]]; then
- echo "error: JTAG can only be enabled for jade_v2 variants"
+ echo "error: JTAG can only be enabled for jade_v2 variants" >&2
exit 1
fi
echo "updating config file for JTAG support ..."
@@ -123,8 +223,53 @@ if [ -n "$JTAG" ]; then
set_config CONFIG_NEWLIB_STDIN_LINE_ENDING_LF y
set_config CONFIG_NEWLIB_STDOUT_LINE_ENDING_LF y
fi
+if [ -n "$PSRAM" ]; then
+ echo "updating config file for PSRAM support ..."
+ # remove settings
+ remove_config CONFIG_ESP_WIFI_STATIC_TX_BUFFER
+ remove_config CONFIG_ESP_WIFI_STATIC_TX_BUFFER_NUM
+ # add settings
+ set_config CONFIG_ESP_INT_WDT_TIMEOUT_MS 300
+ set_config CONFIG_SPIRAM y
+ set_config CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY y
+ set_config CONFIG_SPIRAM_BANKSWITCH_ENABLE n
+ set_config CONFIG_SPIRAM_MEMTEST n
+ if [ -n "$WEBDISPLAY" ]; then
+ echo "updating config file for webdisplay build ..."
+ # remove settings
+ remove_config CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT
+ remove_config CONFIG_DEBUG_UNATTENDED_CI
+ remove_config CONFIG_ESP_ERR_TO_NAME_LOOKUP
+ remove_config CONFIG_ESP_INT_WDT_TIMEOUT_MS
+ remove_config CONFIG_ESP_SYSTEM_CHECK_INT_LEVEL_5
+ remove_config CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT
+ remove_config CONFIG_LWIP_IPV6
+ remove_config CONFIG_LWIP_NETIF_LOOPBACK
+ remove_config CONFIG_UART_ISR_IN_IRAM
+ # add settings
+ set_config CONFIG_ESP_BROWNOUT_DET n
+ set_config CONFIG_ESP_INT_WDT n
+ set_config CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT y
+ set_config CONFIG_HAS_CAMERA y
+ set_config CONFIG_HTTPD_MAX_REQ_HDR_LEN 4096
+ set_config CONFIG_HTTPD_WS_SUPPORT y
+ fi
+ if [ -n "$WEBDISPLAY_LARGER" ]; then
+ echo "updating config file for larger webdisplay build ..."
+ # add settings
+ set_config CONFIG_BOARD_TYPE_QEMU_LARGER y
+ # remove settings
+ remove_config CONFIG_BOARD_TYPE_QEMU
+ fi
+fi
+if [ -n "$UNAMALGAMATED" ]; then
+ echo "updating config file for unamalgamated build ..."
+ set_config CONFIG_AMALGAMATED_BUILD n
+fi
echo "============================================"
-idf.py set-target $ARCH && \
- idf.py reconfigure && \
- echo "run idf.py all to build the firmware"
+if [ -z "$SKIP_RECONFIGURE" ]; then
+ idf.py set-target $ARCH && \
+ idf.py reconfigure && \
+ echo "run idf.py all to build the firmware"
+fi
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.