Page MenuHomeFreeBSD

Use a template assembly file to generate the embedded MFS.
ClosedPublic

Authored by jhb on Oct 14 2020, 4:27 PM.
Tags
None
Referenced Files
Unknown Object (File)
Dec 20 2023, 6:02 AM
Unknown Object (File)
Nov 16 2023, 10:14 AM
Unknown Object (File)
Nov 7 2023, 10:02 AM
Unknown Object (File)
Oct 27 2023, 2:10 PM
Unknown Object (File)
Oct 25 2023, 3:43 PM
Unknown Object (File)
Oct 15 2023, 9:15 AM
Unknown Object (File)
Oct 6 2023, 8:58 AM
Unknown Object (File)
Sep 15 2023, 3:47 PM
Subscribers

Details

Summary

This uses the .incbin directive to pull in the MFS image contents.
Using assembly directly ensures that symbols can be defined with the
name and properties (such as .size) desired without having to rename
symbols, etc. via a second objcopy invocation. Since it is compiled
by the C compiler driver, it also avoids the need for all of the
EMBEDFS* make variables.

Suggested by: jrtc27
Obtained from: CheriBSD

Test Plan
  • tried to boot a RISC-V kernel with an MFS image but it panicked early because the larger kernel overlapped with the FDT, but it did build and link ok

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jhb requested review of this revision.Oct 14 2020, 4:27 PM
jhb created this revision.
sys/dev/md/embedfs.S
35 ↗(On Diff #78221)

Does this work on ARM ? AFAIR '@' is comment and the syntax is %progbits

sys/dev/md/embedfs.S
35 ↗(On Diff #78221)

No it doesn't, but %progbits is supported syntax on all architectures I believe and is easier than having a macro that each arch has to define.

I built both RISC-V and ARM (ARMADA38X with MD_ROOT enabled) kernels with this version. We use '%' in the ELF note assembly files for the same reason.

This revision is now accepted and ready to land.Oct 15 2020, 11:37 PM
sys/conf/kern.post.mk
472 ↗(On Diff #78289)

How does __mfs_root_size get defined in the new scheme?

sys/conf/kern.post.mk
472 ↗(On Diff #78289)

It doesn't, but that is never used. Even _binary_foo_size is unused in the kernel; everything subtracts _binary_foo_start from _binary_foo_end, because using symbols whose values are sizes not addresses is not really compatible with a lot of code models (and is something that should never have been done in the first place, IMO, yet people still love to do it with fancy linker scripts...).

It might be nice to generalize this a bit further to make it easy to embed arbitrary files within the kernel. There's nothing about embedfs.S that's really specific to MFS except the symbol names, I think. For a past project I've used a similar trick to embed a second kernel that gets launched upon a panic to dump memory without requiring a dedicated dump device.

sys/conf/kern.post.mk
472 ↗(On Diff #78289)

I see, thanks.

It might be nice to generalize this a bit further to make it easy to embed arbitrary files within the kernel. There's nothing about embedfs.S that's really specific to MFS except the symbol names, I think. For a past project I've used a similar trick to embed a second kernel that gets launched upon a panic to dump memory without requiring a dedicated dump device.

I'm not quite sure how to generalize it, per se, though perhaps one could pass the symbol name (mfs_root) via -DSYMBOL or some such on the command line. I would like to switch the firmware stuff over to this as that removes another case where linkers have to have special code (the firmware bits use ld directly rather than objcopy).

sys/conf/kern.post.mk
472 ↗(On Diff #78289)

I think in theory one could even now use sizeof(foo) due to the .size directive but I haven't tried that.

sys/conf/kern.post.mk
472 ↗(On Diff #78289)

No, sizeof is done at the language level when you compile the translation unit.

In D26781#597815, @jhb wrote:

It might be nice to generalize this a bit further to make it easy to embed arbitrary files within the kernel. There's nothing about embedfs.S that's really specific to MFS except the symbol names, I think. For a past project I've used a similar trick to embed a second kernel that gets launched upon a panic to dump memory without requiring a dedicated dump device.

I'm not quite sure how to generalize it, per se, though perhaps one could pass the symbol name (mfs_root) via -DSYMBOL or some such on the command line.

That's more or less what I had in mind. Alternately the stub could be generated using a parameterized awk script.

In D26781#597815, @jhb wrote:

It might be nice to generalize this a bit further to make it easy to embed arbitrary files within the kernel. There's nothing about embedfs.S that's really specific to MFS except the symbol names, I think. For a past project I've used a similar trick to embed a second kernel that gets launched upon a panic to dump memory without requiring a dedicated dump device.

I'm not quite sure how to generalize it, per se, though perhaps one could pass the symbol name (mfs_root) via -DSYMBOL or some such on the command line.

That's more or less what I had in mind. Alternately the stub could be generated using a parameterized awk script.

I think if I get around to replacing the objcopy/ld hack in fw_stub.awk, then I will see at that time if I can refactor if I can reuse a generalized version for that case.

jhb marked 2 inline comments as done.Oct 20 2020, 4:36 PM