Skip to content

common: shell: Add shell flash commands#559

Closed
MouchenHung-QUANTA wants to merge 4 commits into
facebook:mainfrom
MouchenHung-QUANTA:common-Add_shell_flash_command
Closed

common: shell: Add shell flash commands#559
MouchenHung-QUANTA wants to merge 4 commits into
facebook:mainfrom
MouchenHung-QUANTA:common-Add_shell_flash_command

Conversation

@MouchenHung-QUANTA

Copy link
Copy Markdown
Contributor

Summary:

  • Add shell flash commands including spi re-init and sfpd read.
    • spi re-init
      platform flash re_init <spi_device>
    • sfpd read
      platform flash sfdp_read <spi_device> <offset(optional, default 0h)> <read_bytes(optional, default 256)>

Test Plan:

  • Build Code: PASS
  • Check shell command in BIC console: PASS

Log:

  • BIC console:
    uart:~$ platform flash re_init spi1_cs0 
    spi1_cs0 re-init success!
    
    uart:~$ platform flash sfpd_read spi1_cs0 1 16
    sfdp raw read from ofst 1 with 16 bytes:
    [0  ]    46 44 50 
    [4  ] 06 01 02 ff 
    [8  ] 00 06 01 10 
    [c  ] 30 00 00 ff 
    [10 ] c2
    
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 14, 2022
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@GoldenBug has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Comment thread common/shell/commands/flash_shell.c Outdated

void cmd_flash_sfdp_read(const struct shell *shell, size_t argc, char **argv)
{
if (argc != 2 && argc != 3 && argc != 4) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argc < 2 || argc > 4

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, thanks.

return;
}

uint8_t *raw = malloc(read_bytes * sizeof(uint8_t));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably define some max number we will allow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, thanks.

goto exit;
}

printf("sfdp raw read from ofst %xh with %d bytes:", offset, read_bytes);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shell_print(...)

Handy shell APIs'


printf("sfdp raw read from ofst %xh with %d bytes:", offset, read_bytes);
if ((offset % 4)) {
printf("\n[%-3x] ", 0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shell_print(...)

Handy shell APIs'

Comment on lines +84 to +90
for (int i = 0; i < read_bytes; i++) {
if (!((offset + i) % 4)) {
printf("\n[%-3x] ", (offset + i));
}
printf("%.2x ", raw[i]);
}
printf("\n");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a shell_hexdump() function which might be useful here.

Docs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @GoldenBug
But according to SFPD raw format, it's better look if using 4/8 bytes aligned. The default aligned bytes is 16.

Comment on lines +102 to +105
if (entry == NULL) {
printf("%s passed null entry\n", __func__);
return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 GoldenBug left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add the Meta Copyright header to these new files.
You'll find it in the other files now as well.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@MouchenHung-QUANTA has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@GoldenBug has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@MouchenHung-QUANTA

Copy link
Copy Markdown
Contributor Author

Could you also add the Meta Copyright header to these new files. You'll find it in the other files now as well.

got it, thanks.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@MouchenHung-QUANTA has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@GoldenBug has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

3 participants