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

Make support for u-boot #227

Merged
merged 13 commits into from
Aug 27, 2024
Merged

Make support for u-boot #227

merged 13 commits into from
Aug 27, 2024

Conversation

mekosko
Copy link
Contributor

@mekosko mekosko commented Aug 23, 2024

U-Boot passes arguments through int argc and char *const argv[]. In order to work with them riscv-rt should accept appropriate entry point signature. Also because the only way to get boot-hart is through fdt this feature implies single-hart.

Expected entry point signature for u-boot: https://github.com/u-boot/u-boot/blob/master/lib/elf.c#L26

@mekosko mekosko requested a review from a team as a code owner August 23, 2024 16:59
@mekosko
Copy link
Contributor Author

mekosko commented Aug 23, 2024

From CI seems that #[entry] macros should accept not only two arguments when u-boot is enabled, but also one or no arguments at all.

@mekosko
Copy link
Contributor Author

mekosko commented Aug 23, 2024

I've also tried to reduce code complexity.

@mekosko
Copy link
Contributor Author

mekosko commented Aug 23, 2024

Updated CHANGELOG.md, now CI should pass without any troubles.

@romancardenas
Copy link
Contributor

Thanks for your contribution! Please, fix the CI so it works with your new feature

@mekosko
Copy link
Contributor Author

mekosko commented Aug 24, 2024

hartid should be taken from fdt when booting through u-boot
https://github.com/u-boot/u-boot/blob/master/arch/riscv/lib/fdt_fixup.c#L157
image

@mekosko
Copy link
Contributor Author

mekosko commented Aug 24, 2024

I found out that something else preventing from booting through u-boot. So PR should not be merged yet. :(

@romancardenas
Copy link
Contributor

Don't worry, let's mark it as draft :)

@mekosko
Copy link
Contributor Author

mekosko commented Aug 24, 2024

Initialization of multiple harts breaks booting through u-boot. I disabled it for u-boot so now everything works well and you can pass arguments such as fdt_addr from u-boot. I think it's up to user to initialize harts when working through u-boot.
image

@romancardenas
Copy link
Contributor

Can you please add documentation to guide users on how to use this feature?

@mekosko
Copy link
Contributor Author

mekosko commented Aug 25, 2024

Can you please add documentation to guide users on how to use this feature?

Done. I'm not sure about writing docs on how to use u-boot to boot resulting elf binary. I don't think this is the right place for that.

Copy link
Contributor

@romancardenas romancardenas left a comment

Choose a reason for hiding this comment

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

I'm not familiar with u-boot, so there are some details that I missed. For instance, if u-boot passes arguments via the stack, shouldn't we load the input parameters to a0 and a1 so the Rust main function gets the correct input?

If you tested this and it works, I am probably missing something, but I would like to understand what is going on 😁

.github/workflows/riscv-rt.yaml Show resolved Hide resolved
riscv-rt/macros/src/lib.rs Outdated Show resolved Hide resolved
@romancardenas
Copy link
Contributor

Can you please add documentation to guide users on how to use this feature?

Done. I'm not sure about writing docs on how to use u-boot to boot resulting elf binary. I don't think this is the right place for that.

What you did is more than enough, thanks!

@romancardenas
Copy link
Contributor

Also, while the current assembly code pushes three registers to the stack, they are popped out before calling main, so it shouldn't be necessary to opt-out of this code, right? The stack pointer will have the original value.

@mekosko
Copy link
Contributor Author

mekosko commented Aug 26, 2024

I'm not familiar with u-boot, so there are some details that I missed. For instance, if u-boot passes arguments via the stack, shouldn't we load the input parameters to a0 and a1 so the Rust main function gets the correct input?

If you tested this and it works, I am probably missing something, but I would like to understand what is going on 😁

I tested this, was able to work with arguments and they were correct.

@mekosko
Copy link
Contributor Author

mekosko commented Aug 26, 2024

Also, while the current assembly code pushes three registers to the stack, they are popped out before calling main, so it shouldn't be necessary to opt-out of this code, right? The stack pointer will have the original value.

There is a chance that I was wrong and they are passed through a0 and a1. Will check with debugger.

@mekosko
Copy link
Contributor Author

mekosko commented Aug 26, 2024

I think everything said about stack was wrong 😐
image

@mekosko
Copy link
Contributor Author

mekosko commented Aug 26, 2024

I don't know why caller also places argv address in a2

@romancardenas
Copy link
Contributor

I don't know why caller also places argv address in a2

Maybe it points to the last element of argv? Can you try to forward two arguments?

@mekosko
Copy link
Contributor Author

mekosko commented Aug 26, 2024

Now macro can check for pointer types and strips type's path.
core::ffi::c_char == c_char -> true
*const *const core::ffi::c_char == *const *const c_char -> true
*const c_char == *const *const c_char -> false

@mekosko
Copy link
Contributor Author

mekosko commented Aug 26, 2024

I also changed expected type of argv to *const *const c_char in that commit.

@mekosko
Copy link
Contributor Author

mekosko commented Aug 26, 2024

I don't know why caller also places argv address in a2

Maybe it points to the last element of argv? Can you try to forward two arguments?

Same behavior with two arguments
image

@mekosko
Copy link
Contributor Author

mekosko commented Aug 26, 2024

I think that might be just some kind of side effect.

@mekosko
Copy link
Contributor Author

mekosko commented Aug 26, 2024

s4 is also set to that address
image

@mekosko mekosko requested a review from romancardenas August 27, 2024 15:17
@mekosko
Copy link
Contributor Author

mekosko commented Aug 27, 2024

CI failure seems unrelated to this PR

@romancardenas
Copy link
Contributor

Yep, from time to time, Clippy gets more strict. Please, fix the new lints

@mekosko
Copy link
Contributor Author

mekosko commented Aug 27, 2024

I checked locally and seems like now clippy should not complain.

@mekosko
Copy link
Contributor Author

mekosko commented Aug 27, 2024

Should I add entry to CHANGELOG that I fixed clippy warnings?

@romancardenas romancardenas added this pull request to the merge queue Aug 27, 2024
Merged via the queue into rust-embedded:master with commit a4d6961 Aug 27, 2024
96 of 97 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants