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

bootloader: detect boot #1191

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jremmet
Copy link
Contributor

@jremmet jremmet commented May 30, 2023

The boot_expression feature for u-boot was deprecated to sync barebox with features and to allow to connect to a running bootloader.

Readd the feature for both bootloaders and use the check only to set the boot_detected flag.
So after getting a prompt we can check if the bootloader runs trough a reboot.
Show this in the 'reset' method.

Checklist

  • Documentation for the feature
  • Tests for the feature
  • The arguments and description in doc/configuration.rst have been updated
  • Add a section on how to use the feature to doc/usage.rst
  • Add a section on how to use the feature to doc/development.rst
  • PR has been tested on uboot
  • PR has been tested on barebox
  • Man pages have been regenerated

@codecov
Copy link

codecov bot commented May 30, 2023

Codecov Report

Attention: Patch coverage is 88.88889% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 62.3%. Comparing base (d8835d5) to head (226b3eb).
Report is 12 commits behind head on master.

Files Patch % Lines
labgrid/driver/bareboxdriver.py 88.8% 1 Missing ⚠️
labgrid/driver/ubootdriver.py 88.8% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1191     +/-   ##
========================================
- Coverage    62.7%   62.3%   -0.5%     
========================================
  Files         163     164      +1     
  Lines       12025   12203    +178     
========================================
+ Hits         7550    7611     +61     
- Misses       4475    4592    +117     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jremmet
Copy link
Contributor Author

jremmet commented Jun 5, 2023

@Bastian-Krause We want to do some Watchdog tests and rely on the bootloader driver to detect the reboot. We could do this in the test but we like the idea of having this beside the other bootloader configs like the prompt.
A 2nd use case is that we have switchable powersupply which has a manual overwrite for always on. So it happens that we don't power on the board via labgrid. Before the deprecation this runs into a bootloader timeout. Now it starts the tests.

So short having the feature back and only disable the check if we force a state would be good for out use cases. Not sure If this acceptable for the project. This PR tries to solve it without changing too much. (Without addressing accidentally running boards)

@jremmet jremmet changed the title Wip/detect boot RFC: detect boot Jun 7, 2023
@Bastian-Krause
Copy link
Member

Bastian-Krause commented Jul 12, 2023

I'd probably implement the self.console.expect() directly in reset() and drop self.check_boot altogether.

I'm torn between having boot_expression as a driver attribute and passing it as a kwarg to reset() (or await_boot()?): I think boot_expression does not make it clear that it's only used on reset(). Then there's the previous functionality (before #259), then the deprecation (#965) and now we reintroduce it with a subtly different meaning, that's not ideal. I am unsure if a driver argument is justified for this very specific use case.
If we allow passing it as a kwarg to reset() or await_boot(), we'd need to change the LinuxBootProtocol.

@Emantor What do you think?

@jremmet
Copy link
Contributor Author

jremmet commented Jul 13, 2023

We also have trouble if we accidentally connect to a running bootloader. Before deprecation we run into a timeout in this case. (Our power switch has a manual "always on" overwrite...)

Would this a acceptable solution?:
Like the old behavior check the boot_expression in _await_prompt as default, but add a flag to skip it for the "force" from the strategies

@Emantor
Copy link
Member

Emantor commented Jul 14, 2023

The decision to remove this support was to let drivers be deactivated and activated even if the bootloader is already running, which is necessary to support reusing the current state of the board within a labgrid client state transition.

In my opionion testing a watchdog reset belongs to the testcase and using labgrid functionality for this is not the correct approach. What you want to do for watchdog testing anway is to set a global variable inside the bootloader, deactivate the driver, wait for the watchdog reset and reactivate the driver. Than the test can check whether the variable is not there any longer and this is a new running instance of the bootloader and even check the reset reason if this is possible with the board.

I don't have a solution for the case where you have a manual override on the power switch. Can this be queried by software? I think this is more of an organizational problem than something that can be solved with a technical solution inside of labgrid.

@jremmet
Copy link
Contributor Author

jremmet commented Jul 17, 2023

The decision to remove this support was to let drivers be deactivated and activated even if the bootloader is already running, which is necessary to support reusing the current state of the board within a labgrid client state transition.

In my opionion testing a watchdog reset belongs to the testcase and using labgrid functionality for this is not the correct approach. What you want to do for watchdog testing anway is to set a global variable inside the bootloader, deactivate the driver, wait for the watchdog reset and reactivate the driver. Than the test can check whether the variable is not there any longer and this is a new running instance of the bootloader and even check the reset reason if this is possible with the board.

I don't have a solution for the case where you have a manual override on the power switch. Can this be queried by software? I think this is more of an organizational problem than something that can be solved with a technical solution inside of labgrid.

Yes I agree. Would adding "boot_expression" to the driver again and adding a check for it to

expectations = [self.prompt, self.autoboot, "Password: ", TIMEOUT]
while True:
index, before, _, _ = self.console.expect(
expectations,
timeout=2
)
if index == 0:
# we got a prompt. no need for any further action to activate
# this driver.
self._status = 1
break
elif index == 1:
# we need to interrupt autoboot
self.console.write(self.interrupt.encode('ASCII'))
elif index == 2:
# we need to enter the password
if not self.password:
raise Exception("Password entry needed but no password set")
if password_entered:
# we already sent the password, but got the pw prompt again
raise Exception("Password was not correct")
self.console.sendline(self.password)
password_entered = True
elif index == 3:
# expect hit a timeout while waiting for a match
if before == last_before:
# we did not receive anything during the previous expect cycle
# let's assume the target is idle and we can safely issue a
# newline to check the state
self.console.sendline("")
if timeout.expired:
raise TIMEOUT(
f"Timeout of {self.login_timeout} seconds exceeded during waiting for login"
)
last_before = before
ok?
We can set the "boot_detected" flag there and use it in strategies and tests.

@jremmet jremmet changed the title RFC: detect boot bootloader: detect boot Mar 5, 2024
@jremmet
Copy link
Contributor Author

jremmet commented Mar 5, 2024

@Emantor I added the flag to driver as discussed.

labgrid/driver/ubootdriver.py Outdated Show resolved Hide resolved
labgrid/driver/bareboxdriver.py Outdated Show resolved Hide resolved
bootstring = attr.ib(default=r"Linux version \d", validator=attr.validators.instance_of(str))
password = attr.ib(default="", validator=attr.validators.instance_of(str))
login_timeout = attr.ib(default=60, validator=attr.validators.instance_of(int))

def __attrs_post_init__(self):
super().__attrs_post_init__()
self._status = 0
self.boot_detected = False
Copy link
Member

Choose a reason for hiding this comment

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

please use an attr.ib for this as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, sure here because it makes this also an Argument. Added it and a note to configuration.rst

if self.boot_expression:
import warnings
warnings.warn("boot_expression is deprecated and will be ignored", DeprecationWarning)
self.boot_detected = False
Copy link
Member

Choose a reason for hiding this comment

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

please use an attr.ib for this as well.

@Emantor Emantor assigned jremmet and unassigned Emantor and Bastian-Krause Mar 25, 2024
@Emantor Emantor added the needs author info Requires more information from the PR/Issue author label Mar 25, 2024
@jremmet jremmet force-pushed the WIP/detect_boot branch 2 times, most recently from 16bbdcd to 23c8e98 Compare March 25, 2024 15:25
@jremmet jremmet requested a review from Emantor March 25, 2024 15:25
Sets self.boot_detected in _await_prompt.
This is used in reset to check if a reboot has occurred.
Can also be used in strategies.

Signed-off-by: Jan Remmet <j.remmet@phytec.de>
Sets self.boot_detected in _await_prompt.
This is used in reset to check if a reboot has occurred.
Can also be used in strategies.

Direct checking was deprecated with:
7b55a19 ("driver/ubootdriver: deprecate boot_expression attribute")

Signed-off-by: Jan Remmet <j.remmet@phytec.de>
@jremmet jremmet removed their assignment Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement needs author info Requires more information from the PR/Issue author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants