Skip to content

Commit 62b6f53

Browse files
projectgusigrr
authored andcommitted
esp32/esp108: Add "permissive mode"
Running command "esp32.cpuX set_permissive 1" will disable memory type checks (can be extended to disable other client-side checks in future.)
1 parent 49d9086 commit 62b6f53

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

src/target/esp108.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ static int xtensa_read_memory(struct target *target,
448448
int res;
449449
uint8_t *albuff;
450450

451-
if (esp108_get_addr_type(address) == INVALID) {
451+
if (esp108_get_addr_type(address) == INVALID && !esp108_permissive_mode) {
452452
LOG_DEBUG("%s: address 0x%08x not readable", __func__, address);
453453
return ERROR_FAIL;
454454
}
@@ -522,7 +522,7 @@ static int xtensa_write_memory(struct target *target,
522522
int res;
523523
uint8_t *albuff;
524524

525-
if (esp108_get_addr_type(address) != READWRITE) {
525+
if (esp108_get_addr_type(address) != READWRITE && !esp108_permissive_mode) {
526526
LOG_DEBUG("%s: address 0x%08x not writable", __func__, address);
527527
return ERROR_FAIL;
528528
}
@@ -1449,6 +1449,8 @@ static const struct command_registration esp108_any_command_handlers[] = {
14491449
COMMAND_REGISTRATION_DONE
14501450
};
14511451

1452+
extern const struct command_registration esp108_common_command_handlers[];
1453+
14521454
static const struct command_registration esp108_command_handlers[] = {
14531455
{
14541456
.name = "esp108",
@@ -1457,6 +1459,9 @@ static const struct command_registration esp108_command_handlers[] = {
14571459
.usage = "",
14581460
.chain = esp108_any_command_handlers,
14591461
},
1462+
{
1463+
.chain = esp108_common_command_handlers,
1464+
},
14601465
COMMAND_REGISTRATION_DONE
14611466
};
14621467

src/target/esp108_common.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "esp108_common.h"
2626
#include "esp108_dbg_regs.h"
2727

28+
bool esp108_permissive_mode;
29+
2830
//Convert a register index that's indexed relative to windowbase, to the real address.
2931
enum xtensa_reg_idx windowbase_offset_to_canonical(const enum xtensa_reg_idx reg, const int windowbase)
3032
{
@@ -677,3 +679,30 @@ inline uint32_t intfromchars(uint8_t *c)
677679
{
678680
return c[0] + (c[1] << 8) + (c[2] << 16) + (c[3] << 24);
679681
}
682+
683+
684+
COMMAND_HANDLER(handle_set_esp108_permissive_mode)
685+
{
686+
if (CMD_ARGC != 1) {
687+
return ERROR_COMMAND_SYNTAX_ERROR;
688+
}
689+
bool is_one = strcmp(CMD_ARGV[0], "1") == 0;
690+
if (!is_one && strcmp(CMD_ARGV[0], "0") != 0) {
691+
return ERROR_COMMAND_SYNTAX_ERROR; // 0 or 1 only
692+
}
693+
esp108_permissive_mode = is_one;
694+
return ERROR_OK;
695+
}
696+
697+
const struct command_registration esp108_common_command_handlers[] = {
698+
{
699+
.name = "set_permissive",
700+
.handler = handle_set_esp108_permissive_mode,
701+
.mode = COMMAND_ANY,
702+
.help = "When set to 1, enable ESP108 permissive mode (less client-side checks)",
703+
.usage = "[0|1]",
704+
},
705+
COMMAND_REGISTRATION_DONE
706+
};
707+
708+

src/target/esp108_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "breakpoints.h"
4545
#include "algorithm.h"
4646

47+
extern bool esp108_permissive_mode;
4748

4849
#define XT_INS_NUM_BITS 24
4950
#define XT_DEBUGLEVEL 6 /* XCHAL_DEBUGLEVEL in xtensa-config.h */

src/target/esp32.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ static int xtensa_read_memory(struct target *target,
552552
int res;
553553
uint8_t *albuff;
554554

555-
if (esp108_get_addr_type(address) == INVALID) {
555+
if (esp108_get_addr_type(address) == INVALID && !esp108_permissive_mode) {
556556
LOG_DEBUG("%s: address 0x%08x not readable", __func__, address);
557557
return ERROR_FAIL;
558558
}
@@ -635,7 +635,7 @@ static int xtensa_write_memory(struct target *target,
635635
int res;
636636
uint8_t *albuff;
637637

638-
if (esp108_get_addr_type(address) != READWRITE) {
638+
if (esp108_get_addr_type(address) != READWRITE && !esp108_permissive_mode) {
639639
LOG_DEBUG("%s: address 0x%08x not writable", __func__, address);
640640
return ERROR_FAIL;
641641
}
@@ -1853,6 +1853,8 @@ static const struct command_registration esp32_any_command_handlers[] = {
18531853
COMMAND_REGISTRATION_DONE
18541854
};
18551855

1856+
extern const struct command_registration esp108_common_command_handlers[];
1857+
18561858
static const struct command_registration esp32_command_handlers[] = {
18571859
{
18581860
.name = "esp32",
@@ -1861,6 +1863,9 @@ static const struct command_registration esp32_command_handlers[] = {
18611863
.usage = "",
18621864
.chain = esp32_any_command_handlers,
18631865
},
1866+
{
1867+
.chain = esp108_common_command_handlers,
1868+
},
18641869
COMMAND_REGISTRATION_DONE
18651870
};
18661871

0 commit comments

Comments
 (0)