Skip to content

Commit

Permalink
Merge branch 'master' into esp_insights
Browse files Browse the repository at this point in the history
  • Loading branch information
me-no-dev authored Dec 12, 2022
2 parents 5605430 + 165d624 commit 6b88ede
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/install-platformio-esp32.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export PLATFORMIO_ESP32_PATH="$HOME/.platformio/packages/framework-arduinoespres
PLATFORMIO_ESP32_URL="https://github.com/platformio/platform-espressif32.git"

TOOLCHAIN_VERSION="8.4.0+2021r2-patch3"
ESPTOOLPY_VERSION="~1.30100.0"
ESPTOOLPY_VERSION="~1.40201.0"
ESPRESSIF_ORGANIZATION_NAME="espressif"

echo "Installing Python Wheel ..."
Expand Down
25 changes: 5 additions & 20 deletions .github/scripts/on-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,11 @@ else
build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/BLE/examples/BLE_server/BLE_server.ino" && \
build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/ESP32/examples/Camera/CameraWebServer/CameraWebServer.ino"

# PlatformIO ESP32 Test
# OPTIONS="board_build.mcu = esp32s2"
# build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/WiFi/examples/WiFiClient/WiFiClient.ino" && \
# build_pio_sketch "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries/WiFiClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino"

python -m platformio ci --board "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/WiFi/examples/WiFiClient" --project-option="board_build.mcu = esp32s2" --project-option="board_build.partitions = huge_app.csv"
python -m platformio ci --board "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/WiFi/examples/WiFiClient" --project-option="board_build.mcu = esp32c3" --project-option="board_build.partitions = huge_app.csv"

echo "Hacking in S3 support ..."
replace_script="import json; import os;"
replace_script+="fp=open(os.path.expanduser('~/.platformio/platforms/espressif32/platform.json'), 'r+');"
replace_script+="data=json.load(fp);"
replace_script+="data['packages']['toolchain-xtensa-esp32']['optional']=True;"
replace_script+="data['packages']['toolchain-xtensa-esp32s3']['optional']=False;"
replace_script+="data['packages']['tool-esptoolpy']['owner']='tasmota';"
replace_script+="data['packages']['tool-esptoolpy']['version']='https://github.com/tasmota/esptool/releases/download/v4.2.1/esptool-4.2.1.zip';"
replace_script+="fp.seek(0);fp.truncate();json.dump(data, fp, indent=2);fp.close()"
python -c "$replace_script"

python -m platformio ci --board "$BOARD" "$PLATFORMIO_ESP32_PATH/libraries/WiFi/examples/WiFiClient" --project-option="board_build.mcu = esp32s3" --project-option="board_build.partitions = huge_app.csv"
# Basic sanity testing for other series
for board in "esp32-c3-devkitm-1" "esp32-s2-saola-1" "esp32-s3-devkitc-1"
do
python -m platformio ci --board "$board" "$PLATFORMIO_ESP32_PATH/libraries/WiFi/examples/WiFiClient" --project-option="board_build.partitions = huge_app.csv"
done

#build_pio_sketches "$BOARD" "$OPTIONS" "$PLATFORMIO_ESP32_PATH/libraries"
fi
16 changes: 11 additions & 5 deletions cores/esp32/esp32-hal-uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,21 +496,18 @@ int uartGetDebug()
return s_uart_debug_nr;
}

int log_printf(const char *format, ...)
int log_printfv(const char *format, va_list arg)
{
static char loc_buf[64];
char * temp = loc_buf;
int len;
va_list arg;
va_list copy;
va_start(arg, format);
va_copy(copy, arg);
len = vsnprintf(NULL, 0, format, copy);
va_end(copy);
if(len >= sizeof(loc_buf)){
temp = (char*)malloc(len+1);
if(temp == NULL) {
va_end(arg);
return 0;
}
}
Expand All @@ -528,13 +525,22 @@ int log_printf(const char *format, ...)
xSemaphoreGive(_uart_bus_array[s_uart_debug_nr].lock);
}
#endif
va_end(arg);
if(len >= sizeof(loc_buf)){
free(temp);
}
return len;
}

int log_printf(const char *format, ...)
{
int len;
va_list arg;
va_start(arg, format);
len = log_printfv(format, arg);
va_end(arg);
return len;
}


static void log_print_buf_line(const uint8_t *b, size_t len, size_t total_len){
for(size_t i = 0; i<len; i++){
Expand Down
4 changes: 2 additions & 2 deletions libraries/WiFiClientSecure/src/WiFiClientSecure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ void WiFiClientSecure::setCACert (const char *rootCA)
{
if (bundle != NULL)
{
esp_crt_bundle_set(bundle);
arduino_esp_crt_bundle_set(bundle);
_use_ca_bundle = true;
} else {
esp_crt_bundle_detach(NULL);
arduino_esp_crt_bundle_detach(NULL);
_use_ca_bundle = false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions libraries/WiFiClientSecure/src/esp_crt_bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static esp_err_t esp_crt_bundle_init(const uint8_t *x509_bundle)
return ESP_OK;
}

esp_err_t esp_crt_bundle_attach(void *conf)
esp_err_t arduino_esp_crt_bundle_attach(void *conf)
{
esp_err_t ret = ESP_OK;
// If no bundle has been set by the user then use the bundle embedded in the binary
Expand All @@ -199,7 +199,7 @@ esp_err_t esp_crt_bundle_attach(void *conf)
return ret;
}

void esp_crt_bundle_detach(mbedtls_ssl_config *conf)
void arduino_esp_crt_bundle_detach(mbedtls_ssl_config *conf)
{
free(s_crt_bundle.crts);
s_crt_bundle.crts = NULL;
Expand All @@ -208,7 +208,7 @@ void esp_crt_bundle_detach(mbedtls_ssl_config *conf)
}
}

void esp_crt_bundle_set(const uint8_t *x509_bundle)
void arduino_esp_crt_bundle_set(const uint8_t *x509_bundle)
{
// Free any previously used bundle
free(s_crt_bundle.crts);
Expand Down
6 changes: 3 additions & 3 deletions libraries/WiFiClientSecure/src/esp_crt_bundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extern "C" {
* - ESP_OK if adding certificates was successful.
* - Other if an error occured or an action must be taken by the calling process.
*/
esp_err_t esp_crt_bundle_attach(void *conf);
esp_err_t arduino_esp_crt_bundle_attach(void *conf);


/**
Expand All @@ -46,7 +46,7 @@ esp_err_t esp_crt_bundle_attach(void *conf);
*
* @param[in] conf The config struct for the SSL connection.
*/
void esp_crt_bundle_detach(mbedtls_ssl_config *conf);
void arduino_esp_crt_bundle_detach(mbedtls_ssl_config *conf);


/**
Expand All @@ -58,7 +58,7 @@ void esp_crt_bundle_detach(mbedtls_ssl_config *conf);
*
* @param[in] x509_bundle A pointer to the certificate bundle.
*/
void esp_crt_bundle_set(const uint8_t *x509_bundle);
void arduino_esp_crt_bundle_set(const uint8_t *x509_bundle);


#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFiClientSecure/src/ssl_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p
}
} else if (useRootCABundle) {
log_v("Attaching root CA cert bundle");
ret = esp_crt_bundle_attach(&ssl_client->ssl_conf);
ret = arduino_esp_crt_bundle_attach(&ssl_client->ssl_conf);

if (ret < 0) {
return handle_error(ret);
Expand Down
94 changes: 31 additions & 63 deletions tools/platformio-build.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,52 +82,41 @@ def get_bootloader_image(variants_dir):
return (
variant_bootloader
if isfile(variant_bootloader)
else join(
FRAMEWORK_DIR,
"tools",
"sdk",
build_mcu,
"bin",
"bootloader_${__get_board_boot_mode(__env__)}_${__get_board_f_flash(__env__)}.bin",
else generate_bootloader_image(
join(
FRAMEWORK_DIR,
"tools",
"sdk",
build_mcu,
"bin",
"bootloader_${__get_board_boot_mode(__env__)}_${__get_board_f_flash(__env__)}.elf",
)
)
)


def get_patched_bootloader_image(original_bootloader_image, bootloader_offset):
patched_bootloader_image = join(env.subst("$BUILD_DIR"), "patched_bootloader.bin")
def generate_bootloader_image(bootloader_elf):
bootloader_cmd = env.Command(
patched_bootloader_image,
original_bootloader_image,
env.VerboseAction(
" ".join(
[
'"$PYTHONEXE"',
join(
platform.get_package_dir("tool-esptoolpy") or "", "esptool.py"
),
"--chip",
build_mcu,
"merge_bin",
"-o",
"$TARGET",
"--flash_mode",
"${__get_board_flash_mode(__env__)}",
"--flash_freq",
"${__get_board_f_flash(__env__)}",
"--flash_size",
board_config.get("upload.flash_size", "4MB"),
"--target-offset",
bootloader_offset,
bootloader_offset,
"$SOURCE",
]
),
"Updating bootloader headers",
),
join("$BUILD_DIR", "bootloader.bin"),
bootloader_elf,
env.VerboseAction(" ".join([
'"$PYTHONEXE" "$OBJCOPY"',
"--chip", build_mcu, "elf2image",
"--flash_mode", "${__get_board_flash_mode(__env__)}",
"--flash_freq", "${__get_board_f_flash(__env__)}",
"--flash_size", board_config.get("upload.flash_size", "4MB"),
"-o", "$TARGET", "$SOURCES"
]), "Building $TARGET"),
)

env.Depends("$BUILD_DIR/$PROGNAME$PROGSUFFIX", bootloader_cmd)

return patched_bootloader_image
# Because the Command always returns a NodeList, we have to
# access the first element in the list to get the Node object
# that actually represents the bootloader image.
# Also, this file is later used in generic Python code, so the
# Node object in converted to a generic string
return str(bootloader_cmd[0])


def add_tinyuf2_extra_image():
Expand Down Expand Up @@ -210,34 +199,13 @@ def add_tinyuf2_extra_image():
# Process framework extra images
#

# Starting with v2.0.4 the Arduino core contains updated bootloader images that have
# innacurate default headers. This results in bootloops if firmware is flashed via
# OpenOCD (e.g. debugging or uploading via debug tools). For this reason, before
# uploading or debugging we need to adjust the bootloader binary according to
# the values of the --flash-size and --flash-mode arguments.
# Note: This behavior doesn't occur if uploading is done via esptoolpy, as esptoolpy
# overrides the binary image headers before flashing.

bootloader_patch_required = bool(
env.get("PIOFRAMEWORK", []) == ["arduino"]
and (
"debug" in env.GetBuildType()
or env.subst("$UPLOAD_PROTOCOL") in board_config.get("debug.tools", {})
or env.IsIntegrationDump()
)
)

bootloader_image_path = get_bootloader_image(variants_dir)
bootloader_offset = "0x1000" if build_mcu in ("esp32", "esp32s2") else "0x0000"
if bootloader_patch_required:
bootloader_image_path = get_patched_bootloader_image(
bootloader_image_path, bootloader_offset
)

env.Append(
LIBSOURCE_DIRS=[join(FRAMEWORK_DIR, "libraries")],
FLASH_EXTRA_IMAGES=[
(bootloader_offset, bootloader_image_path),
(
"0x1000" if build_mcu in ("esp32", "esp32s2") else "0x0000",
get_bootloader_image(variants_dir),
),
("0x8000", join(env.subst("$BUILD_DIR"), "partitions.bin")),
("0xe000", join(FRAMEWORK_DIR, "tools", "partitions", "boot_app0.bin")),
]
Expand Down

0 comments on commit 6b88ede

Please sign in to comment.