Skip to content

fix(v3.8.x): rpi_boot.update_firmware: ensure /tmp folder exists when doing flash-kernel #498

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

Merged
merged 5 commits into from
Mar 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/otaclient/boot_control/_rpi_boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import logging
import os
import subprocess
import time
from pathlib import Path
from string import Template
from typing import Any, Generator, Literal
Expand Down Expand Up @@ -298,6 +299,13 @@ def _prepare_flash_kernel(target_slot_mp: StrOrPath) -> Generator[None, Any, Non
sys_mp = target_slot_mp / "sys"
mounts[str(sys_mp)] = "/sys"

# NOTE(20250314): ensure that tmp folder exists on standby slot
_tmp_on_standby = target_slot_mp / "tmp"
# also handle the case when /tmp is a symlink
if _tmp_on_standby.is_symlink():
_tmp_on_standby = _tmp_on_standby.resolve()
_tmp_on_standby.mkdir(exist_ok=True, parents=True)

try:
for _mp, _src in mounts.items():
CMDHelperFuncs.mount(
Expand Down Expand Up @@ -332,6 +340,7 @@ def update_firmware(self, *, target_slot: SlotID, target_slot_mp: StrOrPath):
env={"FK_FORCE": "yes"},
)
os.sync()
logger.info("flash-kernel succeeded!")
except subprocess.CalledProcessError as e:
_err_msg = f"flash-kernel failed: {e!r}\nstderr: {e.stderr.decode()}\nstdout: {e.stdout.decode()}"
logger.error(_err_msg)
Expand Down Expand Up @@ -410,11 +419,15 @@ def prepare_tryboot_txt(self):
logger.error(_err_msg)
raise _RPIBootControllerError(_err_msg) from e

def reboot_tryboot(self):
def reboot_tryboot(self, *, reboot_wait: int = 6):
"""Reboot with tryboot flag."""
logger.info(f"tryboot reboot to standby slot({self.standby_slot})...")
logger.info(
f"tryboot reboot to standby slot({self.standby_slot}) in {reboot_wait=}s ..."
)
time.sleep(reboot_wait)
Copy link
Collaborator

Choose a reason for hiding this comment

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

(nits) I wonder, if we can use flush instead of waiting for constant time like the following code.

for handler in logger.handlers:
    handler.flush()

Copy link
Member Author

Choose a reason for hiding this comment

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

Emmm currently our _LogTeeHandler at otaclient._logging in otaclient v3.8.x doesn't implement the flush API.

Copy link
Member Author

Choose a reason for hiding this comment

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

So for v3.8.x, let's make the thing easier, just wait for 6 seconds.

And in the main branch, let's implement the flush API in the otaclient LogHandler 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, this is nits comment. Please feel free to ignore as necessary. And I agree with waiting for constant value for this hot-fix.

Emmm currently our _LogTeeHandler at otaclient._logging in otaclient v3.8.x doesn't implement the flush API.

Oh..., I understood we need to implement it by ourselves. the original logging.Handler.flush() just pass the function...

try:
# NOTE: "0 tryboot" is a single param.
logger.info("system will reboot now!")
CMDHelperFuncs.reboot(args=["0 tryboot"])
except Exception as e:
_err_msg = "failed to reboot"
Expand Down
Loading