|
18 | 18 | * @} |
19 | 19 | */ |
20 | 20 |
|
| 21 | +#include <assert.h> |
21 | 22 | #include <inttypes.h> |
22 | 23 | #include <stdio.h> |
23 | 24 | #include <string.h> |
@@ -55,7 +56,19 @@ static char raw_buf[RAW_BUF_SIZE] ALIGNMENT_ATTR; |
55 | 56 | * requires 64 bit alignment. |
56 | 57 | */ |
57 | 58 | static uint8_t page_mem[FLASHPAGE_SIZE] ALIGNMENT_ATTR; |
58 | | -#endif |
| 59 | + |
| 60 | +#ifdef MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE |
| 61 | +/** |
| 62 | + * @brief Reserve 1 page of flash memory |
| 63 | + */ |
| 64 | +FLASH_WRITABLE_INIT(_backing_memory, 0x1); |
| 65 | + |
| 66 | +/* |
| 67 | +* @brief Created to test the sorting of symbols in .flash_writable section |
| 68 | +*/ |
| 69 | +FLASH_WRITABLE_INIT(_abacking_memory, 0x1); |
| 70 | +#endif /* MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE */ |
| 71 | +#endif /* MODULE_PERIPH_FLASHPAGE_PAGEWISE */ |
59 | 72 |
|
60 | 73 | static int getpage(const char *str) |
61 | 74 | { |
@@ -363,7 +376,63 @@ static int cmd_test_last(int argc, char **argv) |
363 | 376 | puts("wrote local page buffer to last flash page"); |
364 | 377 | return 0; |
365 | 378 | } |
366 | | -#endif |
| 379 | + |
| 380 | +#ifdef MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE |
| 381 | +/** |
| 382 | + * @brief Does a write and verify test on reserved page |
| 383 | + */ |
| 384 | +static int cmd_test_reserved(int argc, char **argv) |
| 385 | +{ |
| 386 | + (void) argc; |
| 387 | + (void) argv; |
| 388 | + |
| 389 | + /** |
| 390 | + * Arrays created by the FLASH_WRITABLE_INIT macro should be sorted in |
| 391 | + * ascending order by name. |
| 392 | + */ |
| 393 | + assert(&_abacking_memory < &_backing_memory); |
| 394 | + |
| 395 | + char fill = 'a'; |
| 396 | + const char sig[] = {"RIOT"}; |
| 397 | + unsigned page = flashpage_page((void *)_backing_memory); |
| 398 | + |
| 399 | + printf("Reserved page num: %u \n", page); |
| 400 | + |
| 401 | + flashpage_read(page, page_mem); |
| 402 | + |
| 403 | + /* test is running for the first time so initialize flash */ |
| 404 | + if (memcmp(sig, &page_mem[1], sizeof(sig)) != 0) { |
| 405 | + page_mem[0] = 0; |
| 406 | + memcpy(&page_mem[1], sig, sizeof(sig)); |
| 407 | + } |
| 408 | + else { |
| 409 | + page_mem[0]++; |
| 410 | + } |
| 411 | + |
| 412 | + printf("Since the last firmware update this test has been run " |
| 413 | + "%u times \n", page_mem[0]); |
| 414 | + |
| 415 | + /* fill memory after counter and signature */ |
| 416 | + for (unsigned i = 0x1 + sizeof(sig); i < sizeof(page_mem); i++) { |
| 417 | + page_mem[i] = (uint8_t)fill++; |
| 418 | + if (fill > 'z') { |
| 419 | + fill = 'a'; |
| 420 | + } |
| 421 | + } |
| 422 | + |
| 423 | + if (flashpage_write_and_verify(page, page_mem) != FLASHPAGE_OK) { |
| 424 | + puts("error verifying the content of reserved page"); |
| 425 | + return 1; |
| 426 | + } |
| 427 | + |
| 428 | + puts("wrote local page buffer to reserved flash page"); |
| 429 | + puts("\nWhen running on a bootloader, as an extra check, try restarting " |
| 430 | + "the board and check whether this application still comes up."); |
| 431 | + |
| 432 | + return 0; |
| 433 | +} |
| 434 | +#endif /* MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE */ |
| 435 | +#endif /* MODULE_PERIPH_FLASHPAGE_PAGEWISE */ |
367 | 436 |
|
368 | 437 | /** |
369 | 438 | * @brief Does a short raw write on last page available |
@@ -643,6 +712,9 @@ static const shell_command_t shell_commands[] = { |
643 | 712 | { "edit", "Write bytes to the local page buffer", cmd_edit }, |
644 | 713 | { "test", "Write and verify test pattern", cmd_test }, |
645 | 714 | { "test_last_pagewise", "Write and verify test pattern on last page available", cmd_test_last }, |
| 715 | +#endif |
| 716 | +#ifdef MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE |
| 717 | + { "test_reserved_pagewise", "Write and verify short write on reserved page", cmd_test_reserved}, |
646 | 718 | #endif |
647 | 719 | { "test_last_raw", "Write and verify raw short write on last page available", cmd_test_last_raw }, |
648 | 720 | #ifdef FLASHPAGE_RWWEE_NUMOF |
|
0 commit comments