Skip to content

Commit 8108948

Browse files
authored
Add error message when hitting E15 (#278)
Fixes #266
1 parent 699049f commit 8108948

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

main.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7474,10 +7474,17 @@ bool coprodis_command::execute(device_map &devices) {
74747474
}
74757475

74767476
#if HAS_LIBUSB
7477-
static void check_otp_write_error(picoboot::command_failure &e, bool ecc) {
7477+
static void check_otp_write_error(picoboot::command_failure &e, struct picoboot_otp_cmd *otp_cmd, model_t model) {
74787478
if (e.get_code() == PICOBOOT_UNSUPPORTED_MODIFICATION) {
7479-
if (ecc) fail(ERROR_NOT_POSSIBLE, "Attempted to modify OTP ECC row(s)\n");
7479+
if (otp_cmd->bEcc) fail(ERROR_NOT_POSSIBLE, "Attempted to modify OTP ECC row(s)\n");
74807480
else fail(ERROR_NOT_POSSIBLE, "Attempted to clear bits in OTP row(s)\n");
7481+
} else if (
7482+
e.get_code() == PICOBOOT_NOT_PERMITTED
7483+
&& model->chip() == rp2350
7484+
&& model->chip_revision() == rp2350_a2
7485+
&& otp_cmd->wRow >= OTP_PAGE_COUNT * (OTP_PAGE_ROWS - 1)
7486+
) {
7487+
fail(ERROR_NOT_POSSIBLE, "Cannot write to page locks for pages 32-63 on RP2350 A2 due to errata RP2350-E15 - use otp permissions command instead\n");
74817488
}
74827489
}
74837490

@@ -7954,7 +7961,7 @@ bool otp_load_command::execute(device_map &devices) {
79547961
try {
79557962
con.otp_write(&otp_cmd, buffer, len);
79567963
} catch (picoboot::command_failure &e) {
7957-
check_otp_write_error(e, otp_cmd.bEcc);
7964+
check_otp_write_error(e, &otp_cmd, model);
79587965
throw e;
79597966
}
79607967
});
@@ -7983,7 +7990,7 @@ bool otp_load_command::execute(device_map &devices) {
79837990
try {
79847991
con.otp_write(&otp_cmd, (uint8_t *)file_buffer, file_size);
79857992
} catch (picoboot::command_failure &e) {
7986-
check_otp_write_error(e, otp_cmd.bEcc);
7993+
check_otp_write_error(e, &otp_cmd, model);
79877994
throw e;
79887995
}
79897996

@@ -8091,6 +8098,7 @@ bool otp_set_command::execute(device_map &devices) {
80918098
auto con = get_single_picoboot_cmd_compatible_device_connection("otp set", devices, {PC_OTP_READ, PC_OTP_WRITE});
80928099
hack_init_otp_regs();
80938100
picoboot_memory_access raw_access(con);
8101+
auto model = raw_access.get_model();
80948102
auto matches = filter_otp(settings.otp.selectors, otp_cmd_max_bits(), settings.otp.fuzzy);
80958103
// baing lazy to count
80968104
std::set<uint32_t> unique_rows;
@@ -8225,7 +8233,7 @@ bool otp_set_command::execute(device_map &devices) {
82258233
con.otp_write(&otp_cmd, (uint8_t *)&write_value, sizeof(write_value));
82268234
}
82278235
} catch (picoboot::command_failure &e) {
8228-
check_otp_write_error(e, otp_cmd.bEcc);
8236+
check_otp_write_error(e, &otp_cmd, model);
82298237
throw e;
82308238
}
82318239

@@ -8234,6 +8242,8 @@ bool otp_set_command::execute(device_map &devices) {
82348242

82358243
bool otp_permissions_command::execute(device_map &devices) {
82368244
auto con = get_single_picoboot_cmd_compatible_device_connection("otp permissions", devices, {PC_OTP_READ, PC_OTP_WRITE});
8245+
picoboot_memory_access raw_access(con);
8246+
auto model = raw_access.get_model();
82378247

82388248
json perms_json = json::parse(*get_file(ios::in|ios::binary));
82398249

@@ -8380,6 +8390,8 @@ void wl_do_field(json json_data, vector<uint16_t>& data, uint32_t& flags, const
83808390
bool otp_white_label_command::execute(device_map &devices) {
83818391
auto con = get_single_picoboot_cmd_compatible_device_connection("otp white-label", devices, {PC_OTP_READ, PC_OTP_WRITE});
83828392
hack_init_otp_regs();
8393+
picoboot_memory_access raw_access(con);
8394+
auto model = raw_access.get_model();
83838395
const otp_reg* flags_reg;
83848396
const otp_reg* addr_reg;
83858397
{
@@ -8468,7 +8480,7 @@ bool otp_white_label_command::execute(device_map &devices) {
84688480
try {
84698481
con.otp_write(&otp_cmd, (uint8_t*)data.data(), data.size()*sizeof(data[0]));
84708482
} catch (picoboot::command_failure &e) {
8471-
check_otp_write_error(e, otp_cmd.bEcc);
8483+
check_otp_write_error(e, &otp_cmd, model);
84728484
throw e;
84738485
}
84748486

@@ -8479,7 +8491,7 @@ bool otp_white_label_command::execute(device_map &devices) {
84798491
try {
84808492
con.otp_write(&otp_cmd, (uint8_t*)&struct_row, sizeof(struct_row));
84818493
} catch (picoboot::command_failure &e) {
8482-
check_otp_write_error(e, otp_cmd.bEcc);
8494+
check_otp_write_error(e, &otp_cmd, model);
84838495
throw e;
84848496
}
84858497

@@ -8495,7 +8507,7 @@ bool otp_white_label_command::execute(device_map &devices) {
84958507
try {
84968508
con.otp_write(&otp_cmd, (uint8_t*)tmp_data.data(), tmp_data.size()*sizeof(flags));
84978509
} catch (picoboot::command_failure &e) {
8498-
check_otp_write_error(e, otp_cmd.bEcc);
8510+
check_otp_write_error(e, &otp_cmd, model);
84998511
throw e;
85008512
}
85018513

0 commit comments

Comments
 (0)