Skip to content

Commit a038683

Browse files
committed
Fix encode_for_define for Windows compatibility
Use C array initializer syntax instead of escaped string literal to avoid shell escaping differences between Windows and Unix.
1 parent 47404de commit a038683

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

builder/family/realtek-ambz2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def get_public_key(private: bytes) -> bytes:
2626

2727

2828
def encode_for_define(data: bytes) -> str:
29-
# we need to escape both shell and the C string
30-
return '\\"' + "".join(f"\\\\x{byte:02x}" for byte in data) + '\\"'
29+
# use C array initializer syntax to avoid shell escaping issues on Windows
30+
return "{" + ",".join(f"0x{byte:02x}" for byte in data) + "}"
3131

3232

3333
public_key_bytes = get_public_key(ImageConfig(**board.get("image")).keys.decryption)

cores/realtek-ambz2/base/api/lt_ota.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
extern uint32_t sys_update_ota_get_curr_fw_idx(void);
1010

1111
#define FLASH_SECTOR_SIZE 0x1000
12-
// IMAGE_PUBLIC_KEY is defined by the build script
12+
// IMAGE_PUBLIC_KEY is defined by the build script as an array initializer
1313
#define IMAGE_PUBLIC_KEY_OFFSET 32
1414
#define IMAGE_PUBLIC_KEY_LENGTH 32
1515

16+
static const uint8_t lt_image_public_key[] = IMAGE_PUBLIC_KEY;
17+
1618
typedef enum {
1719
INVALID = 0,
1820
DISABLED = 1,
@@ -47,11 +49,11 @@ static lt_ota_image_state_t lt_ota_get_image_state(uint8_t index) {
4749
if (num_read != sizeof(public_key))
4850
return INVALID;
4951

50-
if (memcmp(public_key, IMAGE_PUBLIC_KEY, sizeof(public_key)) == 0)
52+
if (memcmp(public_key, lt_image_public_key, sizeof(public_key)) == 0)
5153
return ENABLED;
5254

5355
public_key[0] = ~(public_key[0]);
54-
if (memcmp(public_key, IMAGE_PUBLIC_KEY, sizeof(public_key)) == 0)
56+
if (memcmp(public_key, lt_image_public_key, sizeof(public_key)) == 0)
5557
return DISABLED;
5658

5759
return INVALID;
@@ -69,7 +71,7 @@ static bool lt_ota_set_image_enabled(uint8_t index, bool new_enabled) {
6971
device_mutex_lock(RT_DEV_LOCK_FLASH);
7072
flash_stream_read(&lt_flash_obj, offset, FLASH_SECTOR_SIZE, header);
7173

72-
bool enabled = header[IMAGE_PUBLIC_KEY_OFFSET] == IMAGE_PUBLIC_KEY[0];
74+
bool enabled = header[IMAGE_PUBLIC_KEY_OFFSET] == lt_image_public_key[0];
7375
if (enabled != new_enabled) {
7476
// negate first byte of OTA signature
7577
header[0] = ~(header[0]);

0 commit comments

Comments
 (0)