-
Notifications
You must be signed in to change notification settings - Fork 118
feat(prototyper): allocate the patched fdt on the heap. #155
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
Conversation
Signed-off-by: jackfiled <xcrenchangjun@outlook.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the device tree patching mechanism in the prototyper to use heap allocation instead of static buffers. The main purpose is to dynamically allocate the patched FDT (Flattened Device Tree) on the heap with the exact required size.
- Removes static buffer allocation for patched FDT and uses heap allocation
- Implements a two-pass strategy to determine exact buffer size needed
- Increases heap size and buddy allocator max order to support larger allocations
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
prototyper/prototyper/src/sbi/heap.rs | Increases buddy allocator max order and adds detailed heap allocation error reporting |
prototyper/prototyper/src/firmware/mod.rs | Replaces static FDT buffer with dynamic heap allocation using two-pass sizing |
prototyper/prototyper/config/default.toml | Increases heap size from 32KB to 128KB to support larger allocations |
prototyper/prototyper/build.rs | Removes patched_fdt section from linker script since it's no longer needed |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
let mut temporary_buffer = vec![0u8; original_length + 2048]; | ||
serde_device_tree::ser::to_dtb(&tree, &list, &mut temporary_buffer).unwrap(); | ||
let Ok(patched_dtb_ptr) = DtbPtr::from_raw(temporary_buffer.as_mut_ptr()) else { | ||
panic!("Failed to parse the patched dtb.") | ||
}; | ||
let patched_length = patched_dtb_ptr.align(); | ||
|
||
// Secondly, allocate the exactly buffer to store the fdt. | ||
let mut patched_dtb_buffer = vec![0u8; patched_length]; | ||
serde_device_tree::ser::to_dtb(&tree, &list, &mut patched_dtb_buffer).unwrap(); |
Copilot
AI
Sep 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two-pass approach performs device tree serialization twice, which is inefficient. Consider using a single buffer with appropriate size calculation or checking if the serialization library provides a way to calculate required size without full serialization.
let mut temporary_buffer = vec![0u8; original_length + 2048]; | |
serde_device_tree::ser::to_dtb(&tree, &list, &mut temporary_buffer).unwrap(); | |
let Ok(patched_dtb_ptr) = DtbPtr::from_raw(temporary_buffer.as_mut_ptr()) else { | |
panic!("Failed to parse the patched dtb.") | |
}; | |
let patched_length = patched_dtb_ptr.align(); | |
// Secondly, allocate the exactly buffer to store the fdt. | |
let mut patched_dtb_buffer = vec![0u8; patched_length]; | |
serde_device_tree::ser::to_dtb(&tree, &list, &mut patched_dtb_buffer).unwrap(); | |
// Allocate a buffer large enough to hold the patched device tree. | |
let mut patched_dtb_buffer = vec![0u8; original_length + 2048]; | |
let written = serde_device_tree::ser::to_dtb(&tree, &list, &mut patched_dtb_buffer).unwrap(); | |
// If the function returns the number of bytes written, use it as the length. | |
let patched_length = written; |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function to calculate required size for serialization library is unimplemented, so currently the two-pass approach is needed.
…nd fix typo. Signed-off-by: jackfiled <xcrenchangjun@outlook.com>
Signed-off-by: jackfiled <xcrenchangjun@outlook.com>
Signed-off-by: jackfiled <xcrenchangjun@outlook.com>
Signed-off-by: jackfiled <xcrenchangjun@outlook.com>
📝 Click for commit rules checklist / 点击查看提交规范检查表
The main questions in allocating the patched
fdt
on the heap are:fdt
?In this pr,
fdt
is acquired by writing twice strategy.