Skip to content

Commit bbf4847

Browse files
committed
feat: enhance signature display and add config area CRC
Extended signature display now shows TYP code alongside device group name and interprets NOA value (4=linear, >4=dual bank mode). Config area CRC command now enforces exact area boundaries per spec section 6.21, warning if -a/-s options are provided. Signed-off-by: Vincent Jardin <vjardin@free.fr>
1 parent f75ae56 commit bbf4847

File tree

3 files changed

+51
-34
lines changed

3 files changed

+51
-34
lines changed

src/main.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ main(int argc, char *argv[]) {
446446
bool bnd_srs1_set = false, bnd_srs2_set = false;
447447
const char *boundary_file = NULL;
448448
int8_t area_koa = -1; /* -1 = not set, 0/1/2 = code/data/config */
449+
bool addr_explicit = false, size_explicit = false;
449450
write_entry_t write_entries[MAX_WRITE_FILES];
450451
int write_count = 0;
451452
enum command cmd = CMD_NONE;
@@ -458,9 +459,11 @@ main(int argc, char *argv[]) {
458459
break;
459460
case 'a':
460461
address = parse_hex(optarg);
462+
addr_explicit = true;
461463
break;
462464
case 's':
463465
size = parse_hex(optarg);
466+
size_explicit = true;
464467
break;
465468
case 'b':
466469
baudrate = (uint32_t)strtoul(optarg, NULL, 10);
@@ -734,11 +737,19 @@ main(int argc, char *argv[]) {
734737
ra_close(&dev);
735738
errx(EXIT_FAILURE, "area not found");
736739
}
737-
/* --area sets defaults, -a/-s can still override */
738-
if (address == 0)
740+
/* Config area CRC requires exact boundaries per spec 6.21 */
741+
if (cmd == CMD_CRC && area_koa == KOA_TYPE_CONFIG) {
742+
if (addr_explicit || size_explicit)
743+
warnx("config area CRC requires exact boundaries, -a/-s ignored");
739744
address = area_sad;
740-
if (size == 0)
741745
size = area_ead - area_sad + 1;
746+
} else {
747+
/* --area sets defaults, -a/-s can still override */
748+
if (address == 0)
749+
address = area_sad;
750+
if (size == 0)
751+
size = area_ead - area_sad + 1;
752+
}
742753
}
743754

744755
/* Note: IDA with all-0xFF fails with 0xC1 on unlocked devices

src/radfu.c

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -342,19 +342,47 @@ get_area_type_koa(uint8_t koa) {
342342
}
343343

344344
/*
345-
* Get device group name from TYP field per spec 6.15.2.2
345+
* Print device group info from TYP field per spec 6.15.2.2
346346
*/
347-
STATIC const char *
348-
get_device_group(uint8_t typ) {
347+
STATIC void
348+
print_device_group(uint8_t typ) {
349+
const char *name;
350+
const char *devices;
349351
switch (typ) {
350352
case TYP_GRP_AB:
351-
return "GrpA/GrpB (RA4M2/3, RA6M4/5, RA4E1, RA6E1)";
353+
name = "GrpA/GrpB";
354+
devices = "RA4M2/3, RA6M4/5, RA4E1, RA6E1";
355+
break;
352356
case TYP_GRP_C:
353-
return "GrpC (RA6T2)";
357+
name = "GrpC";
358+
devices = "RA6T2";
359+
break;
354360
case TYP_GRP_D:
355-
return "GrpD (RA4E2, RA6E2, RA4T1, RA6T3)";
361+
name = "GrpD";
362+
devices = "RA4E2, RA6E2, RA4T1, RA6T3";
363+
break;
356364
default:
357-
return "Unknown";
365+
printf("Device Group: Unknown (TYP=0x%02X)\n", typ);
366+
return;
367+
}
368+
printf("Device Group: %s (TYP=0x%02X)\n", name, typ);
369+
printf(" Devices: %s\n", devices);
370+
}
371+
372+
/*
373+
* Print NOA (Number of Areas) with mode interpretation
374+
* Standard: 4 areas (User, Data, Config, + reserved)
375+
* Dual bank: 5+ areas (User0, User1, Data, Config, etc.)
376+
*/
377+
STATIC void
378+
print_noa_info(uint8_t noa) {
379+
printf("Number of Areas: %d", noa);
380+
if (noa == 4) {
381+
printf(" (linear mode)\n");
382+
} else if (noa > 4) {
383+
printf(" (dual bank mode)\n");
384+
} else {
385+
printf("\n");
358386
}
359387
}
360388

@@ -526,15 +554,15 @@ ra_get_dev_info(ra_device_t *dev) {
526554
uint8_t bfv_minor = data[7];
527555
uint8_t bfv_build = data[8];
528556

529-
printf("Device Group: %s\n", get_device_group(typ));
557+
print_device_group(typ);
530558
printf("Boot Firmware: v%d.%d.%d\n", bfv_major, bfv_minor, bfv_build);
531559
if (rmb >= 1000000)
532560
printf("Max UART Baudrate: %u bps (%.1f Mbps)\n", rmb, rmb / 1000000.0);
533561
else if (rmb >= 1000)
534562
printf("Max UART Baudrate: %u bps (%.1f Kbps)\n", rmb, rmb / 1000.0);
535563
else
536564
printf("Max UART Baudrate: %u bps\n", rmb);
537-
printf("Number of Areas: %d\n", noa);
565+
print_noa_info(noa);
538566

539567
/* Parse Device ID if available (16 bytes starting at offset 9) */
540568
if (data_len >= 25) {

tests/test_radfu.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -147,25 +147,6 @@ test_get_area_type_koa(void **state) {
147147
assert_string_equal(get_area_type_koa(0xFF), "Unknown");
148148
}
149149

150-
/*
151-
* Device group tests
152-
*/
153-
154-
static void
155-
test_get_device_group(void **state) {
156-
(void)state;
157-
158-
/* Test known device groups per spec 6.15.2.2 */
159-
assert_string_equal(get_device_group(TYP_GRP_AB), "GrpA/GrpB (RA4M2/3, RA6M4/5, RA4E1, RA6E1)");
160-
assert_string_equal(get_device_group(TYP_GRP_C), "GrpC (RA6T2)");
161-
assert_string_equal(get_device_group(TYP_GRP_D), "GrpD (RA4E2, RA6E2, RA4T1, RA6T3)");
162-
163-
/* Unknown types */
164-
assert_string_equal(get_device_group(0x00), "Unknown");
165-
assert_string_equal(get_device_group(0x03), "Unknown");
166-
assert_string_equal(get_device_group(0xFF), "Unknown");
167-
}
168-
169150
/*
170151
* Area lookup tests
171152
*/
@@ -424,9 +405,6 @@ main(void) {
424405
cmocka_unit_test(test_get_area_type),
425406
cmocka_unit_test(test_get_area_type_koa),
426407

427-
/* Device group tests */
428-
cmocka_unit_test(test_get_device_group),
429-
430408
/* Area lookup tests */
431409
cmocka_unit_test(test_find_area_for_address),
432410

0 commit comments

Comments
 (0)