common: shell: Add shell flash commands#559
Conversation
|
@GoldenBug has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
|
||
| void cmd_flash_sfdp_read(const struct shell *shell, size_t argc, char **argv) | ||
| { | ||
| if (argc != 2 && argc != 3 && argc != 4) { |
There was a problem hiding this comment.
got it, thanks.
| return; | ||
| } | ||
|
|
||
| uint8_t *raw = malloc(read_bytes * sizeof(uint8_t)); |
There was a problem hiding this comment.
We should probably define some max number we will allow.
There was a problem hiding this comment.
got it, thanks.
| goto exit; | ||
| } | ||
|
|
||
| printf("sfdp raw read from ofst %xh with %d bytes:", offset, read_bytes); |
There was a problem hiding this comment.
shell_print(...)
|
|
||
| printf("sfdp raw read from ofst %xh with %d bytes:", offset, read_bytes); | ||
| if ((offset % 4)) { | ||
| printf("\n[%-3x] ", 0); |
There was a problem hiding this comment.
shell_print(...)
| for (int i = 0; i < read_bytes; i++) { | ||
| if (!((offset + i) % 4)) { | ||
| printf("\n[%-3x] ", (offset + i)); | ||
| } | ||
| printf("%.2x ", raw[i]); | ||
| } | ||
| printf("\n"); |
There was a problem hiding this comment.
There's a shell_hexdump() function which might be useful here.
There was a problem hiding this comment.
Hi @GoldenBug
But according to SFPD raw format, it's better look if using 4/8 bytes aligned. The default aligned bytes is 16.
| if (entry == NULL) { | ||
| printf("%s passed null entry\n", __func__); | ||
| return; | ||
| } |
There was a problem hiding this comment.
We added a utility macro for checking if input parameters are NULL.
Would probably be useful here.
We might need a new one for printing to shell instead of debug log though.
There was a problem hiding this comment.
Hi @GoldenBug ,
In new commit, I have added check-null macros to libutil.h for shell command function use.
But in this case, there's no given shell variable in function device_spi_name_get(), it might not be okay to use it.
GoldenBug
left a comment
There was a problem hiding this comment.
Could you also add the Meta Copyright header to these new files.
You'll find it in the other files now as well.
|
@MouchenHung-QUANTA has updated the pull request. You must reimport the pull request before landing. |
|
@GoldenBug has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
got it, thanks. |
|
@MouchenHung-QUANTA has updated the pull request. You must reimport the pull request before landing. |
|
@GoldenBug has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Summary:
platform flash re_init <spi_device>
platform flash sfdp_read <spi_device> <offset(optional, default 0h)> <read_bytes(optional, default 256)>
Test Plan:
Log: