Skip to content

Commit fd48828

Browse files
authored
C2 Fix/aes PR espressif#9228 (#328)
1 parent b037c4b commit fd48828

File tree

10 files changed

+143
-156
lines changed

10 files changed

+143
-156
lines changed

Diff for: .github/scripts/on-release.sh

+36-13
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ echo "Event: $GITHUB_EVENT_NAME, Repo: $GITHUB_REPOSITORY, Path: $GITHUB_WORKSPA
3535
echo "Action: $action, Branch: $RELEASE_BRANCH, ID: $RELEASE_ID"
3636
echo "Tag: $RELEASE_TAG, Draft: $draft, Pre-Release: $RELEASE_PRE"
3737

38+
# Try extracting something like a JSON with a "boards" array/element and "vendor" fields
39+
BOARDS=`echo $RELEASE_BODY | grep -Pzo '(?s){.*}' | jq -r '.boards[]? // .boards? // empty' | xargs echo -n 2>/dev/null`
40+
VENDOR=`echo $RELEASE_BODY | grep -Pzo '(?s){.*}' | jq -r '.vendor? // empty' | xargs echo -n 2>/dev/null`
41+
if ! [ -z "${BOARDS}" ]; then echo "Releasing board(s): $BOARDS" ; fi
42+
if ! [ -z "${VENDOR}" ]; then echo "Setting packager: $VENDOR" ; fi
43+
3844
function get_file_size(){
3945
local file="$1"
4046
if [[ "$OSTYPE" == "darwin"* ]]; then
@@ -170,12 +176,26 @@ mkdir -p "$PKG_DIR/tools"
170176

171177
# Copy all core files to the package folder
172178
echo "Copying files for packaging ..."
173-
cp -f "$GITHUB_WORKSPACE/boards.txt" "$PKG_DIR/"
179+
if [ -z "${BOARDS}" ]; then
180+
# Copy all variants
181+
cp -f "$GITHUB_WORKSPACE/boards.txt" "$PKG_DIR/"
182+
cp -Rf "$GITHUB_WORKSPACE/variants" "$PKG_DIR/"
183+
else
184+
# Remove all entries not starting with any board code or "menu." from boards.txt
185+
cat "$GITHUB_WORKSPACE/boards.txt" | grep "^menu\." > "$PKG_DIR/boards.txt"
186+
for board in ${BOARDS} ; do
187+
cat "$GITHUB_WORKSPACE/boards.txt" | grep "^${board}\." >> "$PKG_DIR/boards.txt"
188+
done
189+
# Copy only relevant variant files
190+
mkdir "$PKG_DIR/variants/"
191+
for variant in `cat ${PKG_DIR}/boards.txt | grep "\.variant=" | cut -d= -f2` ; do
192+
cp -Rf "$GITHUB_WORKSPACE/variants/${variant}" "$PKG_DIR/variants/"
193+
done
194+
fi
174195
cp -f "$GITHUB_WORKSPACE/package.json" "$PKG_DIR/"
175196
cp -f "$GITHUB_WORKSPACE/programmers.txt" "$PKG_DIR/"
176197
cp -Rf "$GITHUB_WORKSPACE/cores" "$PKG_DIR/"
177198
cp -Rf "$GITHUB_WORKSPACE/libraries" "$PKG_DIR/"
178-
cp -Rf "$GITHUB_WORKSPACE/variants" "$PKG_DIR/"
179199
cp -f "$GITHUB_WORKSPACE/tools/espota.exe" "$PKG_DIR/tools/"
180200
cp -f "$GITHUB_WORKSPACE/tools/espota.py" "$PKG_DIR/tools/"
181201
cp -f "$GITHUB_WORKSPACE/tools/gen_esp32part.py" "$PKG_DIR/tools/"
@@ -201,19 +221,22 @@ RVTC_NEW_NAME="esp-rv32"
201221
echo "Generating platform.txt..."
202222
cat "$GITHUB_WORKSPACE/platform.txt" | \
203223
sed "s/version=.*/version=$RELEASE_TAG/g" | \
204-
sed 's/tools.esp32-arduino-libs.path={runtime.platform.path}\/tools\/esp32-arduino-libs/tools.esp32-arduino-libs.path=\{runtime.tools.esp32-arduino-libs.path\}/g' | \
205-
sed 's/tools.xtensa-esp32-elf-gcc.path={runtime.platform.path}\/tools\/xtensa-esp32-elf/tools.xtensa-esp32-elf-gcc.path=\{runtime.tools.xtensa-esp32-elf-gcc.path\}/g' | \
206-
sed 's/tools.xtensa-esp32s2-elf-gcc.path={runtime.platform.path}\/tools\/xtensa-esp32s2-elf/tools.xtensa-esp32s2-elf-gcc.path=\{runtime.tools.xtensa-esp32s2-elf-gcc.path\}/g' | \
207-
sed 's/tools.xtensa-esp32s3-elf-gcc.path={runtime.platform.path}\/tools\/xtensa-esp32s3-elf/tools.xtensa-esp32s3-elf-gcc.path=\{runtime.tools.xtensa-esp32s3-elf-gcc.path\}/g' | \
208-
sed 's/tools.xtensa-esp-elf-gdb.path={runtime.platform.path}\/tools\/xtensa-esp-elf-gdb/tools.xtensa-esp-elf-gdb.path=\{runtime.tools.xtensa-esp-elf-gdb.path\}/g' | \
209-
sed "s/tools.riscv32-esp-elf-gcc.path={runtime.platform.path}\\/tools\\/riscv32-esp-elf/tools.riscv32-esp-elf-gcc.path=\\{runtime.tools.$RVTC_NEW_NAME.path\\}/g" | \
210-
sed 's/tools.riscv32-esp-elf-gdb.path={runtime.platform.path}\/tools\/riscv32-esp-elf-gdb/tools.riscv32-esp-elf-gdb.path=\{runtime.tools.riscv32-esp-elf-gdb.path\}/g' | \
211-
sed 's/tools.esptool_py.path={runtime.platform.path}\/tools\/esptool/tools.esptool_py.path=\{runtime.tools.esptool_py.path\}/g' | \
212-
sed 's/debug.server.openocd.path={runtime.platform.path}\/tools\/openocd-esp32\/bin\/openocd/debug.server.openocd.path=\{runtime.tools.openocd-esp32.path\}\/bin\/openocd/g' | \
213-
sed 's/debug.server.openocd.scripts_dir={runtime.platform.path}\/tools\/openocd-esp32\/share\/openocd\/scripts\//debug.server.openocd.scripts_dir=\{runtime.tools.openocd-esp32.path\}\/share\/openocd\/scripts\//g' | \
214-
sed 's/debug.server.openocd.scripts_dir.windows={runtime.platform.path}\\tools\\openocd-esp32\\share\\openocd\\scripts\\/debug.server.openocd.scripts_dir.windows=\{runtime.tools.openocd-esp32.path\}\\share\\openocd\\scripts\\/g' \
224+
sed 's/{runtime\.platform\.path}.tools.esp32-arduino-libs/\{runtime.tools.esp32-arduino-libs.path\}/g' | \
225+
sed 's/{runtime\.platform\.path}.tools.xtensa-esp-elf-gdb/\{runtime.tools.xtensa-esp-elf-gdb.path\}/g' | \
226+
sed 's/{runtime\.platform\.path}.tools.xtensa-esp32-elf/\{runtime.tools.xtensa-esp32-elf-gcc.path\}/g' | \
227+
sed 's/{runtime\.platform\.path}.tools.xtensa-esp32s2-elf/\{runtime.tools.xtensa-esp32s2-elf-gcc.path\}/g' | \
228+
sed 's/{runtime\.platform\.path}.tools.xtensa-esp32s3-elf/\{runtime.tools.xtensa-esp32s3-elf-gcc.path\}/g' | \
229+
sed 's/{runtime\.platform\.path}.tools.riscv32-esp-elf-gdb/\{runtime.tools.riscv32-esp-elf-gdb.path\}/g' | \
230+
sed "s/{runtime\.platform\.path}.tools.riscv32-esp-elf/\\{runtime.tools.$RVTC_NEW_NAME.path\\}/g" | \
231+
sed 's/{runtime\.platform\.path}.tools.esptool/\{runtime.tools.esptool_py.path\}/g' | \
232+
sed 's/{runtime\.platform\.path}.tools.openocd-esp32/\{runtime.tools.openocd-esp32.path\}/g' \
215233
> "$PKG_DIR/platform.txt"
216234

235+
if ! [ -z ${VENDOR} ]; then
236+
# Append vendor name to platform.txt to create a separate section
237+
sed -i "/^name=.*/s/$/ ($VENDOR)/" "$PKG_DIR/platform.txt"
238+
fi
239+
217240
# Add header with version information
218241
echo "Generating core_version.h ..."
219242
ver_define=`echo $RELEASE_TAG | tr "[:lower:].\055" "[:upper:]_"`

Diff for: boards.txt

+14-3
Original file line numberDiff line numberDiff line change
@@ -33459,9 +33459,22 @@ nano_nora.build.psram_type=opi
3345933459
nano_nora.build.memory_type={build.boot}_{build.psram_type}
3346033460
nano_nora.build.disable_pin_remap=
3346133461

33462+
nano_nora.debug_config.nano_nora.cortex-debug.custom.name=Arduino on Nano ESP32
33463+
nano_nora.debug_config.nano_nora.cortex-debug.custom.overrideAttachCommands.0=set remote hardware-watchpoint-limit 2
33464+
nano_nora.debug_config.nano_nora.cortex-debug.custom.overrideAttachCommands.1=monitor reset halt
33465+
nano_nora.debug_config.nano_nora.cortex-debug.custom.overrideAttachCommands.2=monitor gdb_sync
33466+
nano_nora.debug_config.nano_nora.cortex-debug.custom.overrideAttachCommands.3=interrupt
33467+
nano_nora.debug_config.nano_nora.cortex-debug.custom.overrideRestartCommands.0=monitor reset halt
33468+
nano_nora.debug_config.nano_nora.cortex-debug.custom.overrideRestartCommands.1=monitor gdb_sync
33469+
nano_nora.debug_config.nano_nora.cortex-debug.custom.overrideRestartCommands.2=interrupt
33470+
nano_nora.debug.additional_config=debug_config.nano_nora
33471+
3346233472
nano_nora.tools.esptool_py.program.pattern_args=--chip {build.mcu} --port "{serial.port}" --before default_reset --after hard_reset write_flash -z --flash_mode {build.flash_mode} --flash_freq {build.flash_freq} --flash_size {build.flash_size} {build.bootloader_addr} "{build.path}/{build.project_name}.bootloader.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin" 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0xf70000 "{build.variant.path}/extra/nora_recovery/nora_recovery.ino.bin" 0x10000 "{build.path}/{build.project_name}.bin"
3346333473
nano_nora.tools.esptool_py.erase.pattern_args=--chip {build.mcu} --port "{serial.port}" --before default_reset --after hard_reset erase_flash
3346433474

33475+
nano_nora.programmer.default=esptool
33476+
nano_nora.debug.executable=
33477+
3346533478
nano_nora.menu.PartitionScheme.default=With FAT partition (default)
3346633479
nano_nora.menu.PartitionScheme.spiffs=With SPIFFS partition (advanced)
3346733480
nano_nora.menu.PartitionScheme.spiffs.build.partitions=app3M_spiffs9M_fact512k_16MB
@@ -33473,9 +33486,7 @@ nano_nora.menu.PinNumbers.byGPIONumber.build.disable_pin_remap=-DBOARD_USES_HW_G
3347333486
nano_nora.menu.USBMode.default=Normal mode (TinyUSB)
3347433487
nano_nora.menu.USBMode.hwcdc=Debug mode (Hardware CDC)
3347533488
nano_nora.menu.USBMode.hwcdc.build.usb_mode=1
33476-
nano_nora.menu.USBMode.hwcdc.build.copy_jtag_files=1
33477-
nano_nora.menu.USBMode.hwcdc.build.openocdscript=esp32s3-builtin.cfg
33478-
nano_nora.menu.USBMode.hwcdc.build.debugconfig=esp32s3-arduino.json
33489+
nano_nora.menu.USBMode.hwcdc.debug.executable={build.path}/{build.project_name}.elf
3347933490

3348033491
##############################################################
3348133492

Diff for: libraries/Update/src/Update.h

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <MD5Builder.h>
66
#include <functional>
77
#include "esp_partition.h"
8-
#include "aes/esp_aes.h"
98

109
#define UPDATE_ERROR_OK (0)
1110
#define UPDATE_ERROR_WRITE (1)

Diff for: libraries/Update/src/Updater.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "spi_flash_mmap.h"
44
#include "esp_ota_ops.h"
55
#include "esp_image_format.h"
6+
#include "mbedtls/aes.h"
67

78
static const char * _err2str(uint8_t _error){
89
if(_error == UPDATE_ERROR_OK){
@@ -312,17 +313,27 @@ bool UpdateClass::_decryptBuffer(){
312313
uint8_t tweaked_key[ENCRYPTED_KEY_SIZE]; //tweaked crypt key
313314
int done = 0;
314315

315-
esp_aes_context ctx; //initialize AES
316-
esp_aes_init( &ctx );
316+
/*
317+
Mbedtls functions will be replaced with esp_aes functions when hardware acceleration is available
318+
319+
To Do:
320+
Replace mbedtls for the cases where there's no hardware acceleration
321+
*/
322+
323+
mbedtls_aes_context ctx; //initialize AES
324+
mbedtls_aes_init( &ctx );
317325
while((_bufferLen - done) >= ENCRYPTED_BLOCK_SIZE){
318326
for(int i=0; i < ENCRYPTED_BLOCK_SIZE; i++) _cryptBuffer[(ENCRYPTED_BLOCK_SIZE - 1) - i] = _buffer[i + done]; //reverse order 16 bytes to decrypt
319327
if( ((_cryptAddress + _progress + done) % ENCRYPTED_TWEAK_BLOCK_SIZE) == 0 || done == 0 ){
320328
_cryptKeyTweak(_cryptAddress + _progress + done, tweaked_key); //update tweaked crypt key
321-
if( esp_aes_setkey( &ctx, tweaked_key, 256 ) ){
329+
if( mbedtls_aes_setkey_enc( &ctx, tweaked_key, 256 ) ){
330+
return false;
331+
}
332+
if( mbedtls_aes_setkey_dec( &ctx, tweaked_key, 256 ) ){
322333
return false;
323334
}
324335
}
325-
if( esp_aes_crypt_ecb( &ctx, ESP_AES_ENCRYPT, _cryptBuffer, _cryptBuffer ) ){ //use ESP_AES_ENCRYPT to decrypt flash code
336+
if( mbedtls_aes_crypt_ecb( &ctx, MBEDTLS_AES_ENCRYPT, _cryptBuffer, _cryptBuffer ) ){ //use MBEDTLS_AES_ENCRYPT to decrypt flash code
326337
return false;
327338
}
328339
for(int i=0; i < ENCRYPTED_BLOCK_SIZE; i++) _buffer[i + done] = _cryptBuffer[(ENCRYPTED_BLOCK_SIZE - 1) - i]; //reverse order 16 bytes from decrypt

0 commit comments

Comments
 (0)