Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Make use of standalone uboot driver in flasher#346

Merged
mangelajo merged 2 commits intomainfrom
uboot
Mar 17, 2025
Merged

Make use of standalone uboot driver in flasher#346
mangelajo merged 2 commits intomainfrom
uboot

Conversation

@NickCao
Copy link
Copy Markdown
Collaborator

@NickCao NickCao commented Mar 14, 2025

Summary by CodeRabbit

  • New Features

    • Integrated an external bootloader support package to enhance device flashing reliability.
  • Refactor

    • Streamlined device interaction and console management for improved robustness.
    • Consolidated configuration setups and thread initialization for clarity.
  • Style

    • Standardized formatting and spacing across components and tests to boost consistency and maintainability.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 14, 2025

Walkthrough

The pull request refactors several components in the flashing driver packages. In the flashers package, code formatting has been streamlined by condensing multiline declarations, adjusting blank lines, and updating method calls. The U-Boot console handling is modified to remove redundant object creation and to instantiate it if absent. In addition, tests have been reformatted and a standalone U-Boot module was removed. The opendal package also sees minor formatting updates. A new dependency on jumpstarter-driver-uboot has been added to the project configuration.

Changes

File(s) Change Summary
packages/jumpstarter-driver-flashers/.../bundle.py Reformatted the login field declaration in FlashBundleSpecV1Alpha1 and adjusted blank lines between class definitions.
packages/jumpstarter-driver-flashers/.../client.py Simplified U-Boot console handling by calling self.uboot.reboot_to_console() directly; adjusted thread creation, regex patterns, and removed unused debug lines.
packages/jumpstarter-driver-flashers/.../driver.py Added an import for UbootConsole and logic to initialize it if missing in the children dictionary; tidied up docstrings and formatting.
packages/jumpstarter-driver-flashers/.../driver_test.py Reformatted test fixtures and class instantiation into single lines for improved readability.
packages/jumpstarter-driver-flashers/.../test_bundle.py Removed two extra blank lines in the test_bundle_read function.
packages/jumpstarter-driver-flashers/.../uboot.py Removed the file that contained the UbootConsole and DhcpInfo classes.
packages/jumpstarter-driver-flashers/pyproject.toml Added the new dependency "jumpstarter-driver-uboot" and configured it as a workspace source.
packages/jumpstarter-driver-opendal/.../client.py Updated docstring formatting and simplified the formatting of the dump method signature.
packages/jumpstarter-driver-opendal/.../driver.py Added a blank line after the copy_exporter_file method for formatting consistency.

Sequence Diagram(s)

sequenceDiagram
    participant Flasher as BaseFlasher
    participant Children as Device Children
    participant Uboot as UbootConsole
    Flasher->>Children: Check for "uboot" key
    alt "uboot exists"
        Children-->>Flasher: Return existing UbootConsole
    else "uboot missing"
        Flasher->>Uboot: Instantiate UbootConsole with power & serial
        Uboot-->>Children: Assign as "uboot"
    end
    Flasher->>Uboot: Call reboot_to_console()
    Uboot-->>Flasher: Reboot acknowledged
Loading

Suggested reviewers

  • mangelajo

Poem

Hop, hop, the code aligns,
Fields and threads in tidy lines.
U-Boot whispers its soft command,
Tests and drivers now so grand.
I, a bunny, cheer the flow—
A hoppin’ code delight to show!
(_/)(✿ °‿°)

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 14, 2025

Deploy Preview for jumpstarter-docs ready!

Name Link
🔨 Latest commit 28308bb
🔍 Latest deploy log https://app.netlify.com/sites/jumpstarter-docs/deploys/67d81d215d08c00008d750cd
😎 Deploy Preview https://deploy-preview-346--jumpstarter-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mangelajo
Copy link
Copy Markdown
Member

I verified that it works, although I guess you want to go for the better uboot :)

jumpstarter ⚡remote ➤ j storage flash auto-osbuild-am69sk-autosd9-qa-regular-aarch64-1716106242.66b4d866.raw.xz
BaseFlasherClient - INFO - Writing image to storage in the background: /Users/majopela/work/jumpstarter/auto-osbuild-am69sk-autosd9-qa-regular-aarch64-1716106242.66b4d866.raw.xz
BaseFlasherClient - INFO - Setting up flasher bundle files in exporter
BaseFlasherClient - INFO - Image /Users/majopela/work/jumpstarter/auto-osbuild-am69sk-autosd9-qa-regular-aarch64-1716106242.66b4d866.raw.xz already exists in storage with matching hash, skipping
SNMPServerClient - INFO - Starting power cycle sequence
SNMPServerClient - INFO - Waiting 2 seconds...
SNMPServerClient - INFO - Power cycle sequence complete
UbootConsoleClient - INFO - Waiting for U-Boot prompt...
UbootConsoleClient - INFO - Running DHCP to obtain network configuration...
UbootConsoleClient - INFO - Running command: dhcp
UbootConsoleClient - INFO - Running command: printenv netmask
BaseFlasherClient - INFO - discovered dhcp details: ip_address='10.26.28.138' gateway='10.26.28.254' netmask='255.255.255.0'
UbootConsoleClient - INFO - Running command: setenv serverip '10.26.28.62'
UbootConsoleClient - INFO - Running command: tftpboot 0x82000000 J784S4XEVM.flasher.img
UbootConsoleClient - INFO - Running command: tftpboot 0x84000000 k3-j784s4-evm.dtb
BaseFlasherClient - INFO - Running boot command: booti 0x82000000 - 0x84000000
BaseFlasherClient - INFO - Using target block device: /dev/mmcblk1
BaseFlasherClient - INFO - Running preflash command: dd if=/dev/zero of=/dev/mmcblk0 bs=512 count=34
BaseFlasherClient - INFO - Running preflash command: dd if=/dev/zero of=/dev/mmcblk1 bs=512 count=34
BaseFlasherClient - INFO - Waiting until the http image preparation in storage is completed
BaseFlasherClient - INFO - Flash progress: 22.44 MB, Speed: 13.90 MB/s
BaseFlasherClient - INFO - Flash progress: 33.56 MB, Speed: 8.59 MB/s
BaseFlasherClient - INFO - Flash progress: 41.31 MB, Speed: 5.97 MB/s
BaseFlasherClient - INFO - Flash progress: 53.19 MB, Speed: 9.17 MB/s
BaseFlasherClient - INFO - Flash progress: 65.44 MB, Speed: 9.44 MB/s
BaseFlasherClient - INFO - Flash progress: 80.50 MB, Speed: 11.48 MB/s

@NickCao
Copy link
Copy Markdown
Collaborator Author

NickCao commented Mar 15, 2025

I verified that it works, although I guess you want to go for the better uboot :)

Indeed, especially around console handling. Right now the same pexpect instance is passed around, and it can cause problems especially with builtin serial adapters that's powered by the board.

@NickCao
Copy link
Copy Markdown
Collaborator Author

NickCao commented Mar 15, 2025

Rebased.

TODO:

  • Support set_console_debug on uboot client.

bytes_diff = current_bytes - last_pos
speed_mb = (bytes_diff / (1024*1024)) / elapsed
total_mb = current_bytes/(1024*1024)
speed_mb = (bytes_diff / (1024 * 1024)) / elapsed
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what do you pass to reformat those files? should we set it in ruff linting?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Nothing, just uv run ruff format && uv run ruff check --fix --unsafe-fixes

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ah uv run ruff format thanks! :)

@mangelajo
Copy link
Copy Markdown
Member

mangelajo commented Mar 15, 2025

@NickCao this also works!,

But one note, as all the execution in uboot now requires opening streams all the time with .pexpect() ... it's noticeably slower (like 1-2 seconds per uboot command).

Can we make it accept an open stream instead?

@NickCao
Copy link
Copy Markdown
Collaborator Author

NickCao commented Mar 15, 2025

Can we make it accept an open stream instead?

Yet we should recreate the pexpect instance everytime, since we make extensive use of the before attribute and we never knows what could be remaining in that.

I think a good design is to make reboot_to_console a context manager managing the stream?

@mangelajo
Copy link
Copy Markdown
Member

Can we make it accept an open stream instead?

Yet we should recreate the pexpect instance everytime, since we make extensive use of the before attribute and we never knows what could be remaining in that.

I think a good design is to make reboot_to_console a context manager managing the stream?
Ahh wait

I tried with this change and it performs much better:

def run_command(self, cmd: str, timeout: int = 60) -> bytes:
    self.logger.info(f"Running command: {cmd}")
    with self.serial.pexpect() as p:
        #p.sendline("")
        #p.expect_exact(self.prompt, timeout=timeout)
        p.sendline(cmd)
        p.expect_exact(self.prompt, timeout=timeout)
        return p.before

Could we do that?

I understand that if something has sent command or something that will output a prompt, it could get confused... but there is a very noticeable change in environments with latency...

@mangelajo
Copy link
Copy Markdown
Member

Also, another request,

UbootConsoleClient - INFO - Running DHCP to obtain network configuration...
UbootConsoleClient - INFO - Running command: printenv autoload; echo $?
UbootConsoleClient - INFO - Running command: setenv autoload 'no'; echo $?
UbootConsoleClient - INFO - Running command: dhcp; echo $?
UbootConsoleClient - INFO - Running command: setenv autoload; echo $?
UbootConsoleClient - INFO - Running command: printenv ipaddr; echo $?
UbootConsoleClient - INFO - Running command: printenv gatewayip; echo $?
UbootConsoleClient - INFO - Running command: printenv netmask; echo $?

Can we make it not write the "; echo $?" artifact for the checked commands?

it's an implementation detail that only adds noise to the output :)

Anyway, great work, I love the new driver! :)

@NickCao
Copy link
Copy Markdown
Collaborator Author

NickCao commented Mar 15, 2025

Try jumpstarter-dev/jumpstarter#348, this should bring us back to the original speed, also prohibits misuse (like, forgetting to call reboot_to_console)

@mangelajo
Copy link
Copy Markdown
Member

Try #348, this should bring us back to the original speed, also prohibits misuse (like, forgetting to call reboot_to_console)

cherry picked with the changes commented in #348, all good, much better speed :)

@NickCao NickCao changed the title Init jumpstarter-driver-uboot Make use of standalone uboot driver in flasher Mar 17, 2025
@NickCao NickCao marked this pull request as ready for review March 17, 2025 13:01
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
packages/jumpstarter-driver-flashers/pyproject.toml (2)

21-21: Dependency Addition in Dependencies List
The new dependency declaration "jumpstarter-driver-uboot" has been successfully added to the dependencies list as part of the U-Boot driver integration. Consider whether a version constraint should be specified if the package eventually leaves workspace mode, but if the intention is to manage it exclusively via a workspace, this setup is acceptable.


37-39: Workspace Source Configuration for U-Boot Driver
The new [tool.uv.sources] section correctly declares the jumpstarter-driver-uboot as a workspace dependency, aligning with the objective of integrating a standalone U-Boot driver. Please consider either removing or documenting the commented-out line (#asyncio_mode = "auto") so that the configuration remains clean and understandable.

packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/client.py (1)

27-540: Address potential performance concerns mentioned in PR discussion

The PR discussions mentioned by mangelajo highlight a performance issue with the execution of U-Boot commands taking an additional 1-2 seconds per command due to frequent opening of streams with .pexpect(). While the current implementation has improved by using the context manager pattern, additional optimization might be needed.

I notice that a follow-up PR (#348) was mentioned that aims to restore the original speed. Consider implementing a solution where the pexpect instance is reused more efficiently to minimize overhead, while still ensuring any unwanted data from the before attribute is properly cleared.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 860deda and 28308bb.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (9)
  • packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/bundle.py (2 hunks)
  • packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/client.py (13 hunks)
  • packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/driver.py (4 hunks)
  • packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/driver_test.py (3 hunks)
  • packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/test_bundle.py (0 hunks)
  • packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/uboot.py (0 hunks)
  • packages/jumpstarter-driver-flashers/pyproject.toml (2 hunks)
  • packages/jumpstarter-driver-opendal/jumpstarter_driver_opendal/client.py (2 hunks)
  • packages/jumpstarter-driver-opendal/jumpstarter_driver_opendal/driver.py (1 hunks)
💤 Files with no reviewable changes (2)
  • packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/test_bundle.py
  • packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/uboot.py
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: e2e
  • GitHub Check: pytest-matrix (3.13)
  • GitHub Check: pytest-matrix (3.11)
  • GitHub Check: pytest-matrix (3.12)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-dev .devfile/Containerfile)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-devspace .devfile/Containerfile.client)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-utils Dockerfile.utils)
🔇 Additional comments (35)
packages/jumpstarter-driver-opendal/jumpstarter_driver_opendal/driver.py (1)

198-198: Formatting looks good.

Adding a blank line between method definitions enhances code readability and follows good Python style practices.

packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/driver_test.py (4)

24-26: Improved code spacing looks good.

The reformatting of the pytest fixture decorator spacing enhances readability.


42-42: Good code simplification.

Condensing the BaseFlasher instantiation into a single line makes the code more concise while maintaining readability.


48-48: Good code simplification.

Condensing the BaseFlasher instantiation into a single line is consistent with the similar change above.


56-56: Good code simplification.

Condensing the initram variable assignment improves code conciseness.

packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/bundle.py (2)

12-12: Improved readability with consistent blank lines.

Adding blank lines between class definitions improves code organization and readability.

Also applies to: 18-18, 25-25


31-31: Good code simplification.

Condensing the login field declaration into a single line makes the code more concise while maintaining readability.

packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/driver.py (8)

7-7: Good addition of standalone UbootConsole import.

This import aligns with the PR objective of making use of a standalone U-Boot driver in the flasher.


17-18: Consistent docstring formatting.

Removing the space after opening triple quotes maintains consistency in docstring formatting.

Also applies to: 202-203


21-22: Consistent attribute formatting.

Standardizing the formatting of the tftp_dir and http_dir attributes improves code consistency.


30-36: Consistent formatting for conditional checks.

The reformatting of the code for checking and initializing "tftp" and "http" children improves readability.


39-47: Improved error message formatting.

The reformatted error messages for missing "serial" and "power" children enhance readability.


49-55: Excellent implementation of the standalone UbootConsole.

This code automatically initializes the "uboot" child if not present, which is a key part of making use of the standalone U-Boot driver. This approach ensures backward compatibility while integrating the new driver.


59-59: Improved comment formatting.

The reformatted comment about the default dtb improves readability.


101-104: Enhanced error message readability.

The reformatted ValueError message is now more readable with proper line breaks.

packages/jumpstarter-driver-opendal/jumpstarter_driver_opendal/client.py (5)

47-47: Added blank line for separation

The added blank line improves readability by clearly separating functions.


49-50: Improved docstring formatting

The docstring formatting has been standardized by removing the extra space after the opening triple quotes.


55-58: Standardized string quotation style and improved formatting

Changed single quotes to double quotes for string literals and improved the formatting of the URL parsing and operator creation for better readability.


60-60: Enhanced tuple unpacking readability

The return statement uses the star operator for unpacking more clearly, which improves code readability.


529-529: Simplified method signature formatting

The dump method signature has been reformatted from multi-line to single-line, maintaining the same parameters while improving code compactness.

packages/jumpstarter-driver-flashers/jumpstarter_driver_flashers/client.py (15)

44-44: Added TODO comment for future enhancement

Good practice to document the need to set console debug on the uboot client in the future.


64-65: Simplified bootloader shell implementation using standalone uboot driver

The code now directly uses the context manager from the standalone uboot driver instead of a separate UbootConsole class, aligning with the PR objective to "Make use of standalone uboot driver in flasher".


99-103: Improved thread creation readability

The thread creation code has been reformatted to improve readability by spreading the arguments across multiple lines.


198-199: Clarified variable naming with MB units

The variables now consistently use _mb suffix to clearly indicate they represent values in megabytes.


232-240: Enhanced method signature readability

The _transfer_bg_thread method signature has been reformatted to improve readability by placing each parameter on its own line.


301-307: Improved JSON structure readability

The JSON creation code has been reformatted to improve readability by structuring the dictionary across multiple lines.


321-321: Standardized regex pattern with double quotes

Changed single quotes to double quotes for consistency with the rest of the codebase.


376-380: Integrated standalone uboot driver for console handling

The code now uses the context manager pattern with self.uboot.reboot_to_console() and directly calls self.uboot.setup_dhcp() instead of managing these operations manually. This change addresses the performance concerns mentioned in the PR discussions by potentially reducing the frequency of opening streams.


385-385: Simplified environment configuration with uboot driver

Now using the set_env_dict method from the uboot driver to handle environment configuration, which encapsulates the implementation details within the driver.


392-392: Streamlined command execution with uboot driver

Command execution is now handled through the run_command method from the uboot driver, providing a consistent interface and encapsulating implementation details.

Also applies to: 397-397, 402-403


404-409: Enhanced console interaction with pexpect

Improved the console interaction code by directly using the serial's pexpect method and added conditional debug output based on the console_debug flag.


441-441: Standardized operator unpacking

Updated the unpacking to consistently use the pattern seen elsewhere in the codebase, including capturing the operator scheme.


464-481: Improved CLI options readability

The CLI command options have been reformatted for better readability by giving each option its own line, which makes the code easier to maintain and extend.


489-494: Enhanced flash method call readability

The flash method call has been reformatted for better readability by placing each argument on its own line.


535-539: Streamlined decompression command logic

Improved the formatting of the decompression command logic and standardized on double quotes for string literals throughout the code.

@mangelajo mangelajo enabled auto-merge March 17, 2025 13:24
Copy link
Copy Markdown
Member

@mangelajo mangelajo left a comment

Choose a reason for hiding this comment

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

testing in HW : passed!

@mangelajo mangelajo merged commit 268ae9e into main Mar 17, 2025
@NickCao NickCao deleted the uboot branch March 31, 2025 15:44
@mangelajo mangelajo added this to the 0.6.0 milestone May 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants