Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provision.sh.in: accept STM32_Programmer -otp displ failure #1048

Merged

Conversation

olheureu
Copy link
Contributor

@olheureu olheureu commented Feb 20, 2023

The "provision.sh" script was made more robust by commit a9b949c [1] that introduced a "set -e" command in the Bash script [2], which:

  set -e Exit immediately if a pipeline (...), exits with a
         non-zero status.

The script is more robust in the sense that it will exit immediately in case a subcommand fails. The purpose is to avoid to close an STM32MP15x from which the OTP is not fully burned.

When testing commit a9b949c [1] on a closed STM32MP15x device, "provision.sh" stopped with an error message:

  Flashing service completed successfully
  + stm32prog_otp_refresh_values ++ STM32_Programmer_CLI -c port=USB1 -otp displ
  + otp_displ='      -------------------------------------------------------------------
                          STM32CubeProgrammer v2.12.0
        -------------------------------------------------------------------
  [...]
  Uploading OTP data:
  Error: Read OTP Partition failed

  Error: Uploading the OTP structure failed
  Error: Initializing the OTP structure failed
  '

The diagnostic is easy: on a closed STM32MP15x, the "STM32_Programmer_CLI -c port=USB1 -otp displ" command embedded in line 105:
otp_displ=$(STM32_Programmer_CLI -c port=USB1 -otp displ)
fails and return an error code 1, because the OTP is not accessible on closed STM32MP15x. With "set -e", this failure aborts the script.

Fixed: accept an error on that particular command, by appending a "|| echo ..." to the command.

References:

The "provision.sh" script was made more robust by commit a9b949c
[1] that introduced a "set -e" command in the Bash script [2], which:

  set -e Exit immediately if a pipeline (...), exits with a
         non-zero status.

The script is more robust in the sense that it will exit immediately
in case a subcommand fails. The purpose is to avoid to close an
STM32MP15x from which the OTP is not fully burned.

When testing commit a9b949c [1] on a closed STM32MP15x device,
"provision.sh" stopped with an error message:

  Flashing service completed successfully
  + stm32prog_otp_refresh_values
  ++ STM32_Programmer_CLI -c port=USB1 -otp displ
  + otp_displ='      -------------------------------------------------------------------
                          STM32CubeProgrammer v2.12.0
        -------------------------------------------------------------------
  [...]
  Uploading OTP data:
  Error: Read OTP Partition failed

  Error: Uploading the OTP structure failed
  Error: Initializing the OTP structure failed
  '

The diagnostic is easy: on a closed STM32MP15x, the
"STM32_Programmer_CLI -c port=USB1 -otp displ" command embedded in
line 105:

  otp_displ=$(STM32_Programmer_CLI -c port=USB1 -otp displ)

fails and return an error code 1, because the OTP is not accessible on
closed STM32MP15x. With "set -e", this failure aborts the script.

Fixed: accept an error on that particular command, by appending a "||
echo ..." to the command.

References:
- [1]       commit a9b949c (recipes-support: provision.sh.in: add
            error exit handling) from Tim Anderson
            <tim.anderson@foundries.io>, 2023-02-09 10:26:32 -0700
- [2]       "bash(1) — Linux manual page"
            <https://www.man7.org/linux/man-pages/man1/bash.1.html>

Signed-off-by: Olivier L'Heureux <olivier.lheureux@fortrobotics.com>
Copy link
Contributor

@Tim-Anderson Tim-Anderson left a comment

Choose a reason for hiding this comment

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

Yes that will output a message but still continue. then at line 120 it should be an Error_exit since it should not progress if not OTP data is read.

It will then exit with an error at line 236 since the grep will exit with an error.

I suggest a graceful error_exit at line 120

@olheureu
Copy link
Contributor Author

Yes that will output a message but still continue. then at line 120 it should be an Error_exit since it should not progress if not OTP data is read.

It will then exit with an error at line 236 since the grep will exit with an error.

I suggest a graceful error_exit at line 120

It depends on the provision.sh use. At FORT Robotics, being able to re-provision an already-produced device is a requirement.
But as the already-provisioned devices will have a closed STM32MP15x, the OTP will be inaccessible.
If you add an error_exit in case the OTP is inaccessible, you forbids re-provisioning.

Reprovisioning a closed device was tested: it works perfectly, with a warning message that the OTP can't be accessed.

@olheureu
Copy link
Contributor Author

It will then exit with an error at line 236 since the grep will exit with an error.

In line 236, the grep (part of stm32prog_state_is_open) is embedded in an if test
if stm32prog_state_is_open; then
and consequently does not force a script exit, even with set -e.

@olheureu
Copy link
Contributor Author

olheureu commented Feb 20, 2023

To be completely clear: reprovisioning a closed device where the OTP is inaccessible is a feature.

Copy link
Contributor

@Tim-Anderson Tim-Anderson left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -94,7 +94,7 @@ function usage {
# [...]

stm32prog_otp_refresh_values () {
otp_displ=$(STM32_Programmer_CLI -c port=USB1 -otp displ)
otp_displ=$(STM32_Programmer_CLI -c port=USB1 -otp displ || echo "STM32_Programmer_CLI -otp displ returned an error")
Copy link
Contributor

Choose a reason for hiding this comment

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

I would change it to

otp_displ=$(STM32_Programmer_CLI -c port=USB1 -otp displ) || echo "STM32_Programmer_CLI -otp displ returned an error"

So that the error is shown to a user instead of appending to otp_displ variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have tested your proposal: it works with bash and dash. But I am not so sure it is want we want.

The purpose of the otp_displ=$(...) assignment is, in my view, to retrieve the information once, so that we can parse it and know the OTP state. In my view, a closed STM32MP15x with an unreadable OTP is something perfectly normal and supported. So I wanted something that just negates the code 1 returned by STM32_Programmer_CLI. I could have written something as || /usr/bin/true, but I think we could be more explicit with a sort of comment that would be written in the $otp_displ content. Those who inspect it will know more about the OTP state.
My intention was not to issue a warning, nothing is malfunctioning.
Your proposal will generate a visible warning when the STM32MP15x is closed. My code consider a closed STM32MP15x as a feature.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, it looks reasonable.

Copy link
Member

@ricardosalveti ricardosalveti left a comment

Choose a reason for hiding this comment

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

LGTM

@ricardosalveti ricardosalveti merged commit e2807be into foundriesio:main Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants