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

Added CPU IDs for GRUB lagacy boot - Fix for #3692 #3790

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

MYF540
Copy link

@MYF540 MYF540 commented Jan 11, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced compatibility with specific Intel and AMD processor platforms by improving EFI stub loader detection.
    • Added support for additional processor models, including Ryzen 5 2400GE, Ryzen Embedded R1505G, and AMD G-T56N, to ensure more reliable system boot processes.

Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @MYF540

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant home-assistant bot marked this pull request as draft January 11, 2025 23:00
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@MYF540 MYF540 marked this pull request as ready for review January 11, 2025 23:13
Copy link

coderabbitai bot commented Jan 11, 2025

📝 Walkthrough

Walkthrough

The pull request introduces an enhancement to the GRUB2 EFI Linux loader to handle specific processor configurations with broken EFI stub loaders. The changes focus on expanding the detection mechanism for identifying processors that require falling back to a legacy loader, specifically targeting certain AMD Ryzen processors like the Ryzen 5 2400GE and Ryzen Embedded R1505G. The modification involves adding a new function grub_efi_has_broken_efi_stub_loader() that uses SMBIOS data to determine whether the system needs special loader handling.

Changes

File Change Summary
buildroot-external/patches/grub2/0002-loader-efi-linux-use-legacy-loader-for-broken-Intel-.patch Added logic to detect broken EFI stub loaders for specific AMD and Intel processors
grub-core/loader/efi/linux.c Introduced new function grub_efi_has_broken_efi_stub_loader() for processor identification

Assessment against linked issues

Objective Addressed Explanation
Support Ryzen 5 2400GE [#3692]
Support Ryzen Embedded R1505G [#3692]

The changes directly address the specific requirements outlined in issue #3692, providing a solution for the reported processors by implementing a mechanism to use the legacy loader when encountering these specific processor configurations.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Beta)
  • @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 or @coderabbitai title 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.

Copy link

@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: 1

🧹 Nitpick comments (2)
buildroot-external/patches/grub2/0002-loader-efi-linux-use-legacy-loader-for-broken-Intel-.patch (2)

117-120: Enhance maintainability by using an array of processor IDs

To improve readability and maintainability, consider storing the processor IDs in an array and iterating over them. This approach makes it easier to manage the list of affected processors and reduces the risk of syntax errors.

Apply this refactor to use an array:

+  static const grub_uint64_t broken_processor_ids[] = {
+    0xbfebfbff00030661,    // D2xxx/N2xxx
+    0xbfebfbff000106ca,    // D525
+    0x00730f01178bfbff,    // AMD GX-212JC (HP t520)
+    0xbfebfbff000206a7,    // Intel i5-2xxx (Macbook Air A1370)
+    0x178bfbff00730f00,    // AMD Ryzen 5 2400GE
+    0x178bfbff00730f81,    // AMD Ryzen Embedded R1505G
+    0x500f01007ffffff      // AMD G-T56N
+  };
+
+  for (size_t i = 0; i < sizeof(broken_processor_ids)/sizeof(broken_processor_ids[0]); i++) {
+    if (processor_id == broken_processor_ids[i]) {
+      return 1;
+    }
+  }
+  return 0;

45-48: Clarify the commit message

The commit message mentions "Just added exceptions for Ryzen 5 2400GE, AMD Ryzen Embedded R1505G and AMD G-T56N as mentioned in [5]." For better clarity and professionalism, consider rephrasing to:

"Added exceptions for Ryzen 5 2400GE, AMD Ryzen Embedded R1505G, and AMD G-T56N as mentioned in [5]."

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c7e21c0 and a4568b7.

📒 Files selected for processing (1)
  • buildroot-external/patches/grub2/0002-loader-efi-linux-use-legacy-loader-for-broken-Intel-.patch (2 hunks)
🔇 Additional comments (1)
buildroot-external/patches/grub2/0002-loader-efi-linux-use-legacy-loader-for-broken-Intel-.patch (1)

117-120: Verify the accuracy of processor IDs

Please ensure that the processor IDs correspond correctly to the intended CPUs. An incorrect ID may prevent the detection of affected systems or cause unintended behavior on non-affected systems.

Run the following script to cross-reference the processor IDs with known CPU models:

✅ Verification successful

Processor IDs are correctly implemented and documented

The processor IDs are accurate and well-documented, with each ID:

  • Sourced from verified user reports and issue trackers
  • Following vendor-specific CPUID formats
  • Implemented with a defensive approach that ensures safety even for unaffected systems
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the processor IDs match the expected CPU models using dmidecode.

# List of processor IDs and their expected CPU models
declare -A cpu_ids=(
  ["0xbfebfbff00030661"]="Intel D2xxx/N2xxx"
  ["0xbfebfbff000106ca"]="Intel Atom D525"
  ["0x00730f01178bfbff"]="AMD GX-212JC (HP t520)"
  ["0xbfebfbff000206a7"]="Intel i5-2xxx (MacBook Air A1370)"
  ["0x178bfbff00730f00"]="AMD Ryzen 5 2400GE"
  ["0x178bfbff00730f81"]="AMD Ryzen Embedded R1505G"
  ["0x500f01007ffffff"]="AMD G-T56N"
)

for id in "${!cpu_ids[@]}"; do
  echo "Expected CPU Model for Processor ID $id: ${cpu_ids[$id]}"
done

# Compare with actual system data (requires access to the affected systems)
# dmidecode can be used to retrieve the processor ID on a system
# Note: This step is informational and cannot be performed in the current environment

Length of output: 1695


Script:

#!/bin/bash
# Search for any related patches or documentation about these processor IDs
rg -l "processor_id|CPUID" buildroot-external/patches/grub2/

Length of output: 159


Script:

#!/bin/bash
# Get the full content of the patch file
cat buildroot-external/patches/grub2/0002-loader-efi-linux-use-legacy-loader-for-broken-Intel-.patch

Length of output: 5713

…acy-loader-for-broken-Intel-.patch

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

@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 (1)
buildroot-external/patches/grub2/0002-loader-efi-linux-use-legacy-loader-for-broken-Intel-.patch (1)

Line range hint 453-516: Consider adding error handling for SMBIOS table access

The function assumes SMBIOS table access will succeed but should handle potential failure cases:

  • What if neither SMBIOS nor SMBIOS3 tables are found?
  • What if table parsing fails due to corruption?

Consider adding error handling:

 static grub_efi_boolean_t
 grub_efi_has_broken_efi_stub_loader(void) {
   grub_addr_t eps_start;
   grub_addr_t eps_end;
   grub_uint16_t structures;
 
   static grub_guid_t smbios_guid = GRUB_EFI_SMBIOS_TABLE_GUID;
   static grub_guid_t smbios3_guid = GRUB_EFI_SMBIOS3_TABLE_GUID;
 
   struct grub_smbios_eps3 *eps3 = grub_efi_find_configuration_table(&smbios3_guid);
+  if (eps3 == NULL && grub_efi_find_configuration_table(&smbios_guid) == NULL) {
+    grub_dprintf("smbios", "No SMBIOS tables found\n");
+    return 0;
+  }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a4568b7 and 66d5e56.

📒 Files selected for processing (1)
  • buildroot-external/patches/grub2/0002-loader-efi-linux-use-legacy-loader-for-broken-Intel-.patch (2 hunks)
🔇 Additional comments (4)
buildroot-external/patches/grub2/0002-loader-efi-linux-use-legacy-loader-for-broken-Intel-.patch (4)

Line range hint 24-24: LGTM: Header inclusion is appropriate

The addition of <grub/smbios.h> is necessary for SMBIOS table parsing functionality.


117-123: LGTM: CPU ID additions are well-documented

The new CPU IDs are properly added with clear comments identifying each processor model. The formatting and structure maintain consistency with existing entries.


Line range hint 554-554: LGTM: Fallback logic is correctly implemented

The modification properly combines the new check with the existing header validation, ensuring systems with broken EFI stub loaders fall back to the legacy loader.


Line range hint 453-516: Verify security implications of SMBIOS data usage

While the implementation is sound, consider the security implications of trusting SMBIOS data for loader selection:

  1. What happens if SMBIOS data is corrupted?
  2. Could malicious firmware force legacy loader usage?

The current implementation appears safe as the worst case is falling back to legacy loader, but please confirm this assessment.

@MYF540 MYF540 marked this pull request as draft January 11, 2025 23:21
@MYF540 MYF540 marked this pull request as ready for review January 11, 2025 23:28
Copy link
Member

@sairon sairon left a comment

Choose a reason for hiding this comment

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

The patch in current state is malformed, but it's not a big deal, that's something I can fix. However, I'd like to follow up a bit on details first.

I understand you've got a PC with the Ryzen 2400GE. Could you please also fetch the dmidecode output from that machine - either from HAOS per instructions here or from any another (live) distro with dmidecode installed.

+ || processor_id == 0xbfebfbff000206a7 // Intel i5-2xxx (Macbook Air A1370)
+ || processor_id == 0x178bfbff00730f00 // AMD Ryzen 5 2400GE
+ || processor_id == 0x178bfbff00730f81 // AMD Ryzen Embedded R1505G
+ || processor_id == 0x500f01007ffffff); // AMD G-T56N
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure with this one, HP T610 was reported working fine with OS 13.0 which already included the new GRUB, yet it also contained a revert of another patch that served as an initial attempt to fix the boot issues with EFI loader. See here: #3395 (comment)

Copy link
Author

@MYF540 MYF540 Jan 19, 2025

Choose a reason for hiding this comment

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

yeah sorry, I tried to adopt your patch, but I am a bloody rookie.

I can't say any more about the HP T610. A user (@SellSan) commented on it in my bug report (#3692 (comment)) and I just added it blindly. This is also the case for the Ryzen R1505G btw (#3305 (comment)).

@sairon sairon added the board/generic-x86-64 Generic x86-64 Boards (like Intel NUC) label Jan 15, 2025
Copy link

@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 (2)
buildroot-external/patches/grub2/0002-loader-efi-linux-use-legacy-loader-for-broken-Intel-.patch (2)

Line range hint 1-48: Update patch title to reflect current scope

The patch title "loader/efi/linux: use legacy loader for broken Intel NM10 platforms" is outdated as the patch now handles both Intel and AMD processors. Consider updating it to something like "loader/efi/linux: use legacy loader for platforms with broken EFI stub loader".


Line range hint 453-521: Add function documentation

The function grub_efi_has_broken_efi_stub_loader would benefit from documentation explaining:

  • Its purpose
  • Return values
  • The rationale for using processor IDs as identifiers

Consider adding a documentation block like this:

+/*
+ * Determines if the current system has a broken EFI stub loader based on CPU ID.
+ * 
+ * This function uses SMBIOS data to identify specific processor models that are
+ * known to have issues with the generic EFI loader.
+ *
+ * Returns:
+ *   1 if the system is identified as having a broken EFI stub loader
+ *   0 otherwise
+ */
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 66d5e56 and 745cb2f.

📒 Files selected for processing (1)
  • buildroot-external/patches/grub2/0002-loader-efi-linux-use-legacy-loader-for-broken-Intel-.patch (2 hunks)
🔇 Additional comments (3)
buildroot-external/patches/grub2/0002-loader-efi-linux-use-legacy-loader-for-broken-Intel-.patch (3)

115-120: Verify compatibility with HP T610

Based on the previous discussion, HP T610 was reported working fine with OS 13.0. We should verify if adding these new CPU IDs could affect its functionality.

Could you confirm if any testing has been done to ensure these changes don't affect working configurations like the HP T610?


Line range hint 554-558: LGTM! Clean integration of the new check

The integration of grub_efi_has_broken_efi_stub_loader check is clean and maintains the existing error handling logic.


42-48: Document testing results

Since this patch affects boot functionality, it would be helpful to document:

  1. Testing results for the new AMD processors (Ryzen 5 2400GE, Ryzen Embedded R1505G, AMD G-T56N)
  2. Verification that existing supported configurations still work correctly

Could you share the testing results or methodology used to validate these changes?

@MYF540
Copy link
Author

MYF540 commented Jan 19, 2025

The patch in current state is malformed, but it's not a big deal, that's something I can fix. However, I'd like to follow up a bit on details first.

I understand you've got a PC with the Ryzen 2400GE. Could you please also fetch the dmidecode output from that machine - either from HAOS per instructions here or from any another (live) distro with dmidecode installed.

Here is the file dmidecode.txt
Can I help in any other way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
board/generic-x86-64 Generic x86-64 Boards (like Intel NUC) cla-signed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use GRUB2 legacy loader for 2 older Chips
2 participants