Page MenuHomeFreeBSD

Prepare sys/boot for MIPS (32 and 64 bit) ubldr support

Authored by on Feb 17 2016, 2:04 PM.



This changes attempt to put things in order before the introduction of MIPS ubldr.

The changes are mostly dealing with removing unnecessary casts from the U-Boot API (we're passing only pointers, no obvious reason to cast them to uint32_t), cleaning up some compiler warnings and using the proper printf format specifiers in order to be able to compile cleanly for both 32-bit and 64-bit MIPS targets.

Diff Detail

rS FreeBSD src repository - subversion
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline retitled this revision from to Prepare sys/boot for MIPS (32 and 64 bit) ubldr support. updated this object. edited the test plan for this revision. (Show Details) added reviewers: adrian, imp. set the repository for this revision to rS FreeBSD src repository - subversion. added a project: MIPS.
andrew added inline comments.
300–301 ↗(On Diff #13393)


138 ↗(On Diff #13393)

Cast to a uintmax_t and use %ju

431 ↗(On Diff #13393)


516–517 ↗(On Diff #13393)

I think a ptrdiff_t is %td

160 ↗(On Diff #13393)

Should be %zu as size is a size_t

34 ↗(On Diff #13393)

Missing the trailing __?

89 ↗(On Diff #13393)

why not %p?

86–92 ↗(On Diff #13393)

What are these numbers?

441 ↗(On Diff #13393)


I'm unclear how this supports 64-bit mips. Perhaps a quick note about what I'm missing would be in order?

167 ↗(On Diff #13393)

This looks independent, but likely good.

43 ↗(On Diff #13393)

don't you need mips64 in this list?

59–61 ↗(On Diff #13393)


34 ↗(On Diff #13393)

And do you need 64-bit flavors?

Thanks for the reviews. I've responded to some of the comments and will take care of them and submit a new version.

In order to clarify: this revision in itself does not add the support for 64-bit (or 32-bit) MIPS, it just makes it possible to add.
The changes to sys/boot/uboot/lib/glue.c are the actual part that allows this to happen (removing the uint32_t casts in calls to syscall())). The rest is mostly fixing compiler warnings due to improper printf formats used, etc.

167 ↗(On Diff #13393)

Yes, this is not directly related to the preparation for MIPS ubldr, but it was producing a warning during build and I decided to clean it up. Interestingly, due to this it appears that the ARM ubldr had its error on warnings disabled in the Makefiles. I thought it was a better idea to fix the warning instead of doing the same for MIPS :-)

43 ↗(On Diff #13393)

Initially I intended to support self-relocation on MIPS as it was done for ARM, but so far I am failing to produce a proper PIC executable with proper dynamic symbols and proper relocation data for MIPS (it may be due to the combination of parameters being passed to gcc and ld). Since there are other MIPS targets in sys/boot (e.g., BERI) which I wouldn't want to break if I were to drastically change compile and link flags and since dynamic relocation is "nice to have", but not mandatory, I decided to defer its support for now. So I may simply remove the mips case altogether or leave it as it is for now and get back to it when dynamic relocation support is on the table.

59–61 ↗(On Diff #13393)

Please see above comment.

34 ↗(On Diff #13393)

Yes, I meant to use mips instead of __mips, although GCC defines both. I'll fix this.

34 ↗(On Diff #13393)

We don't need anything 64-bit specific here, this compiles (and works) properly for both 32- and 64-bit MIPS under QEMU.

The actual MIPS ubldr support will come with D5313. edited edge metadata.

Addressed review comments.
I decided to drop sys/boot/common/self_reloc.c changes, as currently self relocation is not supported by the MIPS ubldr.

imp edited edge metadata.

This looks ready to go. If you happen to know why MIPS is different, it would be cool if you could address that in the comment. If not, then no big deal. Differences like that will be a mystery later if we don't document what we know today.

53 ↗(On Diff #13760)

Is this ARM specific, or does PPC do that too? Or is MIPS really the only odd-man out? I'm left wondering why mips is different. If you know the reason, perhaps it would be good to add that here. If not, it isn't a huge deal.

This revision is now accepted and ready to land.Feb 26 2016, 3:36 PM
adrian edited edge metadata.


431 ↗(On Diff #13393)

why's this ifdef'ed out?

In D5312#116404, @imp wrote:

This looks ready to go. If you happen to know why MIPS is different, it would be cool if you could address that in the comment. If not, then no big deal. Differences like that will be a mystery later if we don't document what we know today.

I had actually figured out that the API signature is very near to the end of RAM on QEMU-MIPS in the very beginning of my work on ubldr for MIPS and have left it like that since.
Thanks for bringing it up - now I decided to look at it a bit deeper and realised that it is actually very dependent on U-Boot's CONFIG_SYS_MALLOC_LEN, which in the case of QEMU-MIPS is set to 128*1024 (128KiB) :-)
Unfortunately it may be set to whatever value in other boards' configs and there's no way to know that at the stage where we need it. With quick tests I have done just now it seems that even having the MIPS case be the same as the non-MIPS case according to the definitions in glue.h (e.g., have MIPS search within 3MiB) seems to work fine now.

However, if we fail to find a valid API signature before we hit the end of memory we'd risk getting an exception. As I am not sure what is the best way to handle this at the moment I'll commit as is (with MIPS searching within 1MiB and ARM within 3MiB) and I'll come back to this if I get a better idea in the coming days... added inline comments.
430 ↗(On Diff #13760)

This is a static function that is not called by any other function in sys/boot/fdt/fdt_loader_cmd.c and gcc was spitting out warnings about it. Not being sure whether it's still useful to someone or not I decided to ifdef it out.

This revision was automatically updated to reflect the committed changes.