Skip to content

Conversation

@artiepoole
Copy link

@artiepoole artiepoole commented Nov 13, 2025

In an ongoing attempt to enable fpga device functionality in Ubuntu Core, three issues have arisen in relation to the requirement for snaps to be strictly confined. In our case, we are attempting to redistribute dfx-mgr (and libdfx) as part of FPGAd. Once the concept of "softeners" is in place, this snap will enable downstream customers to use dfx-mgr as they expect to be able to, but with the caveat that FPGAd will be the gatekeeper for accessing the FPGA subsystems.

In these efforts, we found three challenges in the way dfx-mgr and libdfx operate:

  1. both parts of this application write to a file called state.txt. In real operation, this file is created at /state.txt which is not allowed in a strictly confined snap, and no layout can be applied to files in the root directory, except as files inside known pre-defined directories.
  2. files are freely moved in and our of /lib/firmware. In a snap's environment, this directory does not exist, so accesses to it fail. Repeatedly copying is bad for performance as well.
  3. the device tree overlay subsystem's files (configfs) are remounted to /configfs. This mount call requires strong permissions, which the store team can't/wont to grant to the fpgad snap.

In order to tackle these three problems, I have edited dfx-mgr and libdfx with the following solutions:

  1. for libdfx, state.txt is now moved to /etc/dfx/state.txt /run/dfx/state.txt. I would actually prefer to remove the "system(command)" calls to mitigate the need for this file at all, but that is out of scope here. C stdlib io operations are used to write into internal buffers instead of relying on state.txt, generated using system calls. Several of the functions are exported for use in dfx-mgr (and similar) to save duplication.
  2. Before anything which will trigger the kernel to look for firmware, instead of copying files to /lib/firmware, the containing directory is written to /sys/module/firmware_class/parameters/path instead. This is exported for use by dfx-mgr to save duplication.
  3. the calls to mount /configfs are removed, and all paths pointing to "/configfs/" are replaced by /sys/kernel/config/

Please see Xilinx/dfx-mgr#12 for the dfx-mgr changes

Please do not hesitate to suggest changes or ask for clarification.

@artiepoole artiepoole force-pushed the xlnx_rel_v2025.2 branch 2 times, most recently from 1088fc4 to 2891143 Compare November 17, 2025 12:28
@sivadur
Copy link

sivadur commented Nov 17, 2025

@artiepoole Thanks for reporting these, we will check and get back on these

@artiepoole artiepoole marked this pull request as ready for review November 17, 2025 12:32
@artiepoole
Copy link
Author

@sivadur Thank you for the haste! I created this as a draft. There have been some tweaks since creation, so please take these into account during assessment. I have now tested it more thoroughly and have marked this as "ready for review"

@talhaHavadar
Copy link

do we have any update on review @sivadur ?

@artiepoole
Copy link
Author

Hey @sivadur,

On the dfx-mgr side of things, it was suggested that we should remove the state.txt file completely and instead do the comparisons handled by state.txt using C, instead of using the shell via system commands. If you agree, I would like to make those changes in this PR as well.
The relevant commit is here

@arthokal
Copy link
Collaborator

arthokal commented Dec 9, 2025

Hi @artiepoole ,

Agree with removing dependency on state.txt file in libdfx and directly reading contents of /sys/class/fpga_manager/fpga0/state using file handling in C.

@artiepoole
Copy link
Author

Thanks @arthokal, I'll go ahead and implement this then

Is there any objection to adding DFX_DBG and DFX_ERR equivalent macros to libdfx? Currently all messages are printed with printf.

@artiepoole
Copy link
Author

To save you having to explore:

DFX_DBG example:
DFX_DBG("Found base design %s", base_designs[i].base_path); becomes DFX-MGRD> findBaseDesign_path():195 Found base design /lib/firmware/xilinx/k26-starter-kits

DFX_ERR example:
DFX_ERR("Failed to close `%s` after writing", path); became DFX-MGRD> ERROR:write_string_to_file():157 Failed to close `/sys/class/fpga_manager/fpga0/firmware` after writing: No such file or directory

Current libdfx print example:
printf("dfx_set_firmware_lookup_path: Setting lookup path for `%s`\n", file_path); of course prints like dfx_set_firmware_lookup_path: Setting lookup path for `/lib/firmware/xilinx/k24-starter-kits/k24_starter_kits.bit.bin

@arthokal
Copy link
Collaborator

@artiepoole ,

Regarding addition of DFX_DBG and DFX_ERR equivalent macros to libdfx, we can take these in a separate PR.

…tion

Use `/sys/kernel/config/device-tree/overlays/` insted of remounting
Signed-off-by: Artie Poole <stuart.poole@canonical.com>
the kernel provides a mechanism to set where firmware loads will look to
 match filenames during probe events.
This file is located at `/sys/module/firmware_class/parameters/path`.
 These changes remove the need for copying firmware files into /lib/firmware.
 The /lib/firmware location is still probed if the file is not found in the
custom location. See
https://docs.kernel.org/driver-api/firmware/fw_search_path.html for more
information.

Signed-off-by: Artie Poole <stuart.poole@canonical.com>
@artiepoole artiepoole force-pushed the xlnx_rel_v2025.2 branch 3 times, most recently from 73426df to 50a362b Compare December 10, 2025 13:23
@artiepoole
Copy link
Author

@arthokal @sivadur,

Please be aware that I am unable to test dfx_cfg_drivers_load since I do not have a package containing a driver to test with.

I have made the changes to remove the need for state.txt. I have tested to the best of my ability the functionality of the dfx-mgr's -load, -o, -b, remove and -listPackage commands. Please review/comment when possible.

P.S. dfx-mgr has been adjusted to use the functions I exposed in libdfx.h to save duplication

this made it preferable to implement several helper functions which are
convenient to export for use in dfx-mgr.

define debugging macros

Signed-off-by: Artie Poole <stuart.poole@canonical.com>
Adds docs for functions:
- dfx_set_firmware_search_path
- dfx_get_fpga_state
- dfx_set_overlay_path
- dfx_set_fpga_firmware
- dfx_set_fpga_flags
- dfx_set_fpga_key
- dfx_get_overlay_path
- dfx_get_overlay_status

Signed-off-by: Artie Poole <stuart.poole@canonical.com>
@artiepoole
Copy link
Author

@arthokal

Thanks for spotting those mistakes and missing README changes.
I amended the commit to fix the docstrings and have created a new commit containing the README updates.
Please review the docs/README.txt when you can. I kept the usage examples very minimal to match the surrounding. If you would like more detailed examples, please let me know.

Best,
Artie

Copy link
Collaborator

@arthokal arthokal left a comment

Choose a reason for hiding this comment

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

Changes looks fine to me.
@NavaKishoreManne, please review and approve if changes looks fine.

Copy link
Collaborator

@arthokal arthokal left a comment

Choose a reason for hiding this comment

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

With these changes, we tested libdfx application from our end including dfx_cfg_drivers_load. Testing looks good.
Approving from my end. Let @sivadur review too and approve.

Thank you,
Aravind.

@talhaHavadar
Copy link

I see all parties agreed, do we know when we would have this merged?

@arthokal
Copy link
Collaborator

Hi @talhaHavadar
Before merging to GitHub, we follow an internal validation process to ensure consistency across our repositories. This typically takes a week. We'll update you as soon as it's complete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants