This guide provides step-by-step instructions that walk you through the basic workflows of building, running, debugging, and updating drivers in a Fuchsia system using the Fuchsia SDK.
Important: This guide is the driver equivalent of the Get started with the Fuchsia SDK guide. If you haven‘t already, it’s strongly recommended that you first complete the Get started with the Fuchsia SDK guide to become familiar with the comprehensive set of Fuchsia SDK-based workflows.
Complete the following sections:
Found an issue? Please let us know{:.external}.
This guide requires that your host machine meets the following criteria:
Clone the SDK driver samples repository{:.external} on your host machine. This repository contains sample driver components and the Bazel-based Fuchsia SDK.
The tasks include:
ffx
commands.Do the following:
In a terminal, change to your home directory:
Note: This guide uses the home directory ($HOME
) as a base directory. This is where a new work directory (drivers
) will be created for this guide. You may also select a different base directory (for instance, cd $HOME/my-fuchsia-project
).
cd $HOME
Clone the SDK driver samples repository:
git clone https://fuchsia.googlesource.com/sdk-samples/drivers fuchsia-drivers --recurse-submodules
This git clone
command creates a new directory named fuchsia-drivers
(see the command's second argument above) and clones the content of the SDK driver samples repository.
Go to the new directory:
cd fuchsia-drivers
Run the bootstrap script to install Bazel and other required dependencies:
scripts/bootstrap.sh
To verify the Fuchsia SDK environment setup, build the sample drivers:
tools/bazel build --config=fuchsia_x64 //src/qemu_edu/drivers:qemu_edu
The first build may take a few minutes to download dependencies, such as Bazel build rules, Clang, and Fuchsia IDK (which includes the ffx
tool).
When finished successfully, it prints output similar to the following in the end:
$ tools/bazel build --config=fuchsia_x64 //src/qemu_edu/drivers:qemu_edu ... INFO: Elapsed time: 246.794s, Critical Path: 49.78s INFO: 971 processes: 597 internal, 374 linux-sandbox. INFO: Build completed successfully, 971 total actions
To verify that you can use the ffx
tool in your environment, run the following command:
tools/ffx sdk version
This command prints output similar to the following:
$ tools/ffx sdk version 9.20220919.2.1
At this point, you only need to confirm that you can run ffx
commands without error. (However for your information, the output above shows the version 9.20220919.2.1
, which indicates that this SDK was built and published on September 19, 2022.)
Note: To ensure that you’re using the right version of ffx
during development, consider updating your PATH
to include the SDK‘s tools
directory (for instance, export PATH="$PATH:$HOME/fuchsia-drivers/tools"
). However, if you don’t wish to update your PATH
, ensure that you specify the relative path to this ffx
tool (tools/ffx
) whenever you run ffx
commands.
Start the Fuchsia emulator on the host machine while configuring the emulator instance to use Fuchsia’s new driver framework (DFv2).
The tasks include:
Do the following:
Download the latest Workstation image for the emulator:
tools/ffx product-bundle get workstation_eng.qemu-x64 --repository workstation-packages
This command may take a few minutes to download the image and product metadata.
Note: If the product-bundle
command fails with an error due to multiple product bundle instances or SDK versions, clean up the environment before proceeding.
Once the download is finished, the ffx product-bundle get
command creates a local Fuchsia package repository named workstation-packages
on your host machine. This package repository hosts additional system packages for this Workstation prebuilt image. Later in Step 8 you’ll register this package repository to the emulator instance.
Stop all emulator instances:
tools/ffx emu stop --all
Start the Fuchsia emulator:
tools/ffx emu start workstation_eng.qemu-x64 --headless \ --kernel-args "driver_manager.use_driver_framework_v2=true" \ --kernel-args "driver_manager.root-driver=fuchsia-boot:///#meta/platform-bus.cm" \ --kernel-args "devmgr.enable-ephemeral=true"
This command starts a headless emulator instance running the Workstation prebuilt image.
When the instance is up and running, the command prints output similar to the following:
$ tools/ffx emu start workstation_eng.qemu-x64 --headless \ --kernel-args "driver_manager.use_driver_framework_v2=true" \ --kernel-args "driver_manager.root-driver=fuchsia-boot:///#meta/platform-bus.cm" \ --kernel-args "devmgr.enable-ephemeral=true" Creating SSH key pair: /home/alice/.ssh/fuchsia_ed25519 Writing authorized_keys file: /home/alice/.ssh/fuchsia_authorized_keys Logging to "/home/alice/.local/share/Fuchsia/ffx/emu/instances/fuchsia-emulator/emulator.log" Waiting for Fuchsia to start (up to 60 seconds). Emulator is ready.
Verify that the new emulator instance is running:
tools/ffx emu list
This command prints output similar to the following:
$ tools/ffx emu list [Active] fuchsia-emulator
Set the default target device:
tools/ffx target default set fuchsia-emulator
This command exits silently without output.
Start the Fuchsia package server:
tools/ffx repository server start
This command prints output similar to the following:
$ tools/ffx repository server start ffx repository server is listening on [::]:8083
Check the list of Fuchsia package repositories available on your host machine:
tools/ffx repository list
This command prints output similar to the following:
$ tools/ffx repository list +-----------------------+------+-------------------------------------------------------------------------------------------------+ | NAME | TYPE | EXTRA | +=======================+======+=================================================================================================+ | workstation-packages* | pm | /home/alice/.local/share/Fuchsia/ffx/pbms/4751486831982119909/workstation_eng.qemu-x64/packages | +-----------------------+------+-------------------------------------------------------------------------------------------------+
Notice a package repository (workstation-packages
) is created for the Workstation prebuilt image.
Register the workstation-packages
package repository to the target device:
tools/ffx target repository register -r workstation-packages --alias fuchsia.com --alias chromium.org
This command exits silently without output.
The Fuchsia emulator (launched in the Start the emulator section above) is configured to create a virtual device named edu
, which is an educational device for writing drivers. In the previous section, when the emulator started, Fuchsia’s driver framework detected this edu
device in the system, but it wasn’t able to find a driver that could serve the edu
device. So the edu
device was left unmatched.
In this section, we build and publish the qemu_edu
sample driver (which is a Fuchsia component). Upon detecting a new driver, the driver framework will discover that this new qemu_edu
driver is a match for the edu
device. Once matched, the qemu_edu
driver starts providing the edu
device’s services (capabilities) to other components in the system – one of the services provided by the edu
device is that it computes a factorial given an integer.
The tasks include:
qemu_edu
driver component.qemu_edu
driver is loaded to the emulator instance.qemu_edu
component.Do the following:
View the list of the currently loaded drivers:
tools/ffx driver list --loaded
This command prints output similar to the following:
$ tools/ffx driver list --loaded fuchsia-boot:///#meta/block.core.cm fuchsia-boot:///#meta/bus-pci.cm fuchsia-boot:///#meta/display.cm fuchsia-boot:///#meta/fvm.cm fuchsia-boot:///#meta/goldfish-display.cm fuchsia-boot:///#meta/goldfish.cm fuchsia-boot:///#meta/goldfish_address_space.cm fuchsia-boot:///#meta/goldfish_control.cm fuchsia-boot:///#meta/goldfish_sensor.cm fuchsia-boot:///#meta/goldfish_sync.cm fuchsia-boot:///#meta/hid-input-report.cm fuchsia-boot:///#meta/hid.cm fuchsia-boot:///#meta/intel-hda.cm fuchsia-boot:///#meta/intel-rtc.cm fuchsia-boot:///#meta/netdevice-migration.cm fuchsia-boot:///#meta/network-device.cm fuchsia-boot:///#meta/pc-ps2.cm fuchsia-boot:///#meta/platform-bus-x86.cm fuchsia-boot:///#meta/platform-bus.cm fuchsia-boot:///#meta/qemu-audio-codec.cm fuchsia-boot:///#meta/ramdisk.cm fuchsia-boot:///#meta/sysmem.cm fuchsia-boot:///#meta/virtio_block.cm fuchsia-boot:///#meta/virtio_ethernet.cm fuchsia-boot:///#meta/virtio_input.cm fuchsia-pkg://fuchsia.com/virtual_audio#meta/virtual_audio_driver.cm fuchsia-boot:///#meta/ahci.cm
Build and publish the qemu_edu
driver component:
tools/bazel run --config=fuchsia_x64 //src/qemu_edu/drivers:pkg.component
This command prints output similar to the following:
$ tools/bazel run --config=fuchsia_x64 //src/qemu_edu/drivers:pkg.component INFO: Analyzed target //src/qemu_edu/drivers:pkg.component (8 packages loaded, 514 targets configured). INFO: Found 1 target... Target //src/qemu_edu/drivers:pkg.component up-to-date: bazel-bin/src/qemu_edu/drivers/pkg.component_run_component.sh INFO: Elapsed time: 92.307s, Critical Path: 56.84s INFO: 989 processes: 606 internal, 382 linux-sandbox, 1 local. INFO: Build completed successfully, 989 total actions INFO: Build completed successfully, 989 total actions added repository bazel.pkg.component Registering fuchsia-pkg://bazel.pkg.component/qemu_edu#meta/qemu_edu.cm Successfully bound: Node 'root.sys.platform.platform-passthrough.PCI0.bus.00_06_0_.pci-00_06.0-fidl', Driver 'fuchsia-pkg://bazel.pkg.component/qemu_edu#meta/qemu_edu.cm'.
Verify that the qemu_edu
driver is now loaded to the Fuchsia emulator instance:
tools/ffx driver list --loaded
This command prints output similar to the following:
$ tools/ffx driver list --loaded fuchsia-boot:///#meta/block.core.cm fuchsia-boot:///#meta/bus-pci.cm fuchsia-boot:///#meta/display.cm fuchsia-boot:///#meta/fvm.cm fuchsia-boot:///#meta/goldfish-display.cm fuchsia-boot:///#meta/goldfish.cm fuchsia-boot:///#meta/goldfish_address_space.cm fuchsia-boot:///#meta/goldfish_control.cm fuchsia-boot:///#meta/goldfish_sensor.cm fuchsia-boot:///#meta/goldfish_sync.cm fuchsia-boot:///#meta/hid-input-report.cm fuchsia-boot:///#meta/hid.cm fuchsia-boot:///#meta/intel-hda.cm fuchsia-boot:///#meta/intel-rtc.cm fuchsia-boot:///#meta/netdevice-migration.cm fuchsia-boot:///#meta/network-device.cm fuchsia-boot:///#meta/pc-ps2.cm fuchsia-boot:///#meta/platform-bus-x86.cm fuchsia-boot:///#meta/platform-bus.cm fuchsia-boot:///#meta/qemu-audio-codec.cm fuchsia-boot:///#meta/ramdisk.cm fuchsia-boot:///#meta/sysmem.cm fuchsia-boot:///#meta/virtio_block.cm fuchsia-boot:///#meta/virtio_ethernet.cm fuchsia-boot:///#meta/virtio_input.cm fuchsia-pkg://fuchsia.com/virtual_audio#meta/virtual_audio_driver.cm {{ '<strong>' }}fuchsia-pkg://bazel.pkg.component/qemu_edu#meta/qemu_edu.cm{{ '</strong>' }} fuchsia-boot:///#meta/ahci.cm
Notice that the qemu_edu
driver is shown in the loaded drivers list.
View the qemu_edu
component information:
tools/ffx component show qemu_edu.cm
This command prints output similar to the following:
$ tools/ffx component show qemu_edu.cm Moniker: /bootstrap/universe-pkg-drivers:root.sys.platform.platform-passthrough.PCI0.bus.00_06_0_.pci-00_06.0-fidl URL: fuchsia-pkg://bazel.pkg.component/qemu_edu#meta/qemu_edu.cm Instance ID: None Type: CML Component Component State: Resolved Incoming Capabilities: /svc/fuchsia.device.fs.Exporter /svc/fuchsia.driver.compat.Service /svc/fuchsia.logger.LogSink Exposed Capabilities: fuchsia.examples.qemuedu.Service Merkle root: df0fc9b427711e7a47dd286dc4f47d5dea8060607a7e968bf48f2e6fc8bdd4af Execution State: Running Start reason: Instance is in a single_run collection Outgoing Capabilities: fuchsia.examples.qemuedu.Service
View the device logs of the qemu-edu
driver:
tools/ffx log --tags qemu-edu dump
This command prints output similar to the following:
$ tools/ffx log --tags qemu-edu dump [2022-10-03 23:34:07.972][<ffx>]: logger started. [161.225][universe-pkg-drivers:root.sys.platform.platform-passthrough.PCI0.bus.00_06_0_.pci-00_06.0-fidl][qemu-edu,driver][I]: [src/qemu_edu/drivers/qemu_edu.cc:179] edu device version major=1 minor=0
The qemu_edu
driver sample includes tools for interacting with the qemu_edu
driver. Developers often include binary executables in a Fuchsia package and run those executables as a component for testing and debugging drivers running in a Fuchsia system.
In this driver sample, an executable named eductl_tool
provides two options: live
and fact
. The live
command checks for the liveness of the qemu_edu
driver in the system. The fact
command takes an integer as an additional argument. The value of the integer is passed to the qemu_edu
driver to be used as input for computing the factorial. The driver computes the factorial and returns the result to the fact
command, which then prints the result on the terminal.
The tasks include:
eductl_tool
.qemu_edu
driver.Do the following:
Build and run eductl_tool
(and run the live
command):
tools/bazel run --config=fuchsia_x64 //src/qemu_edu/tools:pkg.eductl_tool -- live
This command prints output similar to the following:
$ tools/bazel run --config=fuchsia_x64 //src/qemu_edu/tools:pkg.eductl_tool -- live INFO: Analyzed target //src/qemu_edu/tools:pkg.eductl_tool (0 packages loaded, 0 targets configured). INFO: Found 1 target... Target //src/qemu_edu/tools:pkg.eductl_tool up-to-date: bazel-bin/src/qemu_edu/tools/pkg.eductl_tool_run_driver_tool.sh INFO: Elapsed time: 0.286s, Critical Path: 0.01s INFO: 1 process: 1 internal. INFO: Build completed successfully, 1 total action INFO: Build completed successfully, 1 total action added repository bazel.pkg.eductl.tool {{ '<strong>' }}Liveness check passed!{{ '</strong>' }}
Verify that the line Liveness check passed!
is printed in the end.
Run eductl_tool
using fact
and 12
as input:
tools/bazel run --config=fuchsia_x64 //src/qemu_edu/tools:pkg.eductl_tool -- fact 12
This command prints output similar to the following:
$ tools/bazel run --config=fuchsia_x64 //src/qemu_edu/tools:pkg.eductl_tool -- fact 12 ... INFO: Build completed successfully, 1 total action added repository bazel.pkg.eductl.tool {{ '<strong>' }}Factorial(12) = 479001600{{ '</strong>' }}
The last line shows that the driver replied 479001600
as the result of the factorial to eductl_tool
, which passed 12 as input to the driver.
View the device logs of the qemu-edu
driver:
tools/ffx log --tags qemu-edu dump
This command prints output similar to the following:
$ tools/ffx log --tags qemu-edu dump [2022-10-03 23:34:07.972][<ffx>]: logger started. [161.225][universe-pkg-drivers:root.sys.platform.platform-passthrough.PCI0.bus.00_06_0_.pci-00_06.0-fidl][qemu-edu,driver][I]: [src/qemu_edu/drivers/qemu_edu.cc:179] edu device version major=1 minor=0 [434.054][universe-pkg-drivers:root.sys.platform.platform-passthrough.PCI0.bus.00_06_0_.pci-00_06.0-fidl][qemu-edu,driver][I]: [src/qemu_edu/drivers/qemu_edu.cc:108] Replying with result=true [444.714][universe-pkg-drivers:root.sys.platform.platform-passthrough.PCI0.bus.00_06_0_.pci-00_06.0-fidl][qemu-edu,driver][I]: [src/qemu_edu/drivers/edu_device.cc:124] Replying with factorial=479001600
Notice that more messages are now logged from the qemu-edu
driver.
Use the Fuchsia debugger (zxdb
) to step through the sample driver’s code as the driver is running on the emulator instance.
The tasks include:
qemu_edu
driver.eductl_tool
, which triggers the driver to execute its instructions.Do the following:
View the list of the running driver hosts:
tools/ffx driver list-hosts
This command prints output similar to the following:
$ tools/ffx driver list-hosts Driver Host: 5416 fuchsia-boot:///#meta/bus-pci.cm fuchsia-boot:///#meta/display.cm fuchsia-boot:///#meta/goldfish-display.cm fuchsia-boot:///#meta/goldfish.cm fuchsia-boot:///#meta/goldfish_control.cm fuchsia-boot:///#meta/goldfish_sensor.cm fuchsia-boot:///#meta/goldfish_sync.cm fuchsia-boot:///#meta/hid.cm fuchsia-boot:///#meta/intel-hda.cm fuchsia-boot:///#meta/platform-bus-x86.cm fuchsia-boot:///#meta/platform-bus.cm fuchsia-boot:///#meta/qemu-audio-codec.cm fuchsia-boot:///#meta/ramdisk.cm fuchsia-boot:///#meta/sysmem.cm fuchsia-pkg://fuchsia.com/virtual_audio#meta/virtual_audio_driver.cm Driver Host: 8248 fuchsia-boot:///#meta/intel-rtc.cm Driver Host: 8317 fuchsia-boot:///#meta/pc-ps2.cm Driver Host: 9604 fuchsia-boot:///#meta/block.core.cm fuchsia-boot:///#meta/fvm.cm fuchsia-boot:///#meta/virtio_block.cm Driver Host: 9781 fuchsia-boot:///#meta/hid-input-report.cm fuchsia-boot:///#meta/hid.cm fuchsia-boot:///#meta/virtio_input.cm Driver Host: 10066 fuchsia-boot:///#meta/netdevice-migration.cm fuchsia-boot:///#meta/network-device.cm fuchsia-boot:///#meta/virtio_ethernet.cm Driver Host: 10137 fuchsia-boot:///#meta/hid-input-report.cm fuchsia-boot:///#meta/hid.cm fuchsia-boot:///#meta/virtio_input.cm Driver Host: 10344 fuchsia-boot:///#meta/goldfish_address_space.cm Driver Host: 10387 fuchsia-boot:///#meta/ahci.cm Driver Host: 134104 fuchsia-pkg://bazel.pkg.component/qemu_edu#meta/qemu_edu.cm
Make a note of the PID of the qemu_edu
driver host (134104
in the example above).
Start the Fuchsia debugger:
tools/ffx debug connect
This command prints output similar to the following:
$ tools/ffx debug connect Connecting (use "disconnect" to cancel)... Connected successfully. 👉 To get started, try "status" or "help". [zxdb]
Attach the debugger to the qemu_edu
driver host:
Replace PID
with the PID of the qemu_edu
driver host identified in Step 1, for example:
[zxdb] attach 134104
This command prints output similar to the following:
[zxdb] attach 134104 Attached Process 1 state=Running koid=134104 name=driver_host2.cm component=driver_host2.cm Downloading symbols... Symbol downloading complete. 2 succeeded, 0 failed. [zxdb]
Set a breakpoint at the driver’s HandleIrq
function:
This command prints output similar to the following:
[zxdb] break QemuEduDevice::HandleIrq Created Breakpoint 1 @ QemuEduDevice::HandleIrq 94 void QemuEduDevice::HandleIrq(async_dispatcher_t* dispatcher, async::IrqBase* irq, {{ '<strong>' }}◉ 95 zx_status_t status, const zx_packet_interrupt_t* interrupt) { {{ '</strong>' }} 96 irq_.ack(); [zxdb]
In different terminal, run eductl_tool
(using fact
and 12
as input) to interact with the driver:
Note: In this new terminal, make sure that you change to the same work directory (for instance, cd $HOME/fuchsia-drivers
).
tools/bazel run --config=fuchsia_x64 //src/qemu_edu/tools:pkg.eductl_tool -- fact 12
Unlike in the previous section, after printing output similar to the following, the command now waits:
$ tools/bazel run --config=fuchsia_x64 //src/qemu_edu/tools:pkg.eductl_tool -- fact 12 INFO: Analyzed target //src/qemu_edu/tools:pkg.eductl_tool (0 packages loaded, 0 targets configured). INFO: Found 1 target... Target //src/qemu_edu/tools:pkg.eductl_tool up-to-date: bazel-bin/src/qemu_edu/tools/pkg.eductl_tool_run_driver_tool.sh INFO: Elapsed time: 0.348s, Critical Path: 0.01s INFO: 1 process: 1 internal. INFO: Build completed successfully, 1 total action INFO: Build completed successfully, 1 total action added repository bazel.pkg.eductl.tool
In the zxdb
terminal, verify that the debugger is stopped at the HandleIrq
function, for example:
🛑 thread 2 on bp 1 edu_device::QemuEduDevice::HandleIrq(edu_device::QemuEduDevice*, async_dispatcher_t*, async::IrqBase*, zx_status_t, zx_packet_interrupt_t const*) • edu_device.cc:95 93 // Respond to INTx interrupts triggered by the device, and return the compute result. 94 void QemuEduDevice::HandleIrq(async_dispatcher_t* dispatcher, async::IrqBase* irq, {{ '<strong>' }}▶ 95 zx_status_t status, const zx_packet_interrupt_t* interrupt) { {{ '</strong>' }} 96 irq_.ack(); 97 if (!pending_callback_.has_value()) { [zxdb]
In the zxdb
terminal, view the source code around the current breakpoint:
This command prints output similar to the following:
[zxdb] list 90 pending_callback_ = std::move(callback); 91 } 92 93 // Respond to INTx interrupts triggered by the device, and return the compute result. 94 void QemuEduDevice::HandleIrq(async_dispatcher_t* dispatcher, async::IrqBase* irq, {{ '<strong>' }}▶ 95 zx_status_t status, const zx_packet_interrupt_t* interrupt) { {{ '</strong>' }} 96 irq_.ack(); 97 if (!pending_callback_.has_value()) { 98 FDF_LOG(ERROR, "Received unexpected interrupt!"); 99 return; 100 } 101 auto callback = std::move(*pending_callback_); 102 pending_callback_ = std::nullopt; 103 if (status != ZX_OK) { 104 FDF_SLOG(ERROR, "Failed to wait for interrupt", KV("status", zx_status_get_string(status))); 105 callback(zx::error(status)); [zxdb]
In the zxdb
terminal, step through the HandleIrq
function using the next
command until the value of factorial
is computed and the callback is invoked (that is, until the line 126 is reached):
The last next
command prints output similar to the following:
... [zxdb] next 🛑 thread 2 edu_device::QemuEduDevice::HandleIrq(edu_device::QemuEduDevice*, async_dispatcher_t*, async::IrqBase*, zx_status_t, zx_packet_interrupt_t const*) • edu_device.cc:126 124 FDF_SLOG(INFO, "Replying with", KV("factorial", factorial)); 125 callback(zx::ok(factorial)); {{ '<strong>' }}▶ 126 } {{ '</strong>' }} 127 // [END compute_factorial] 128 [zxdb]
In the other terminal, after the HandleIrq
function invokes the callback, verify that eductl_tool
prints the factorial result and exits:
$ tools/bazel run --config=fuchsia_x64 //src/qemu_edu/tools:pkg.eductl_tool -- fact 12 ... INFO: Build completed successfully, 1 total action added repository bazel.pkg.eductl.tool {{ '<strong>' }}Factorial(12) = 479001600{{ '</strong>' }} $
In the zxdb
terminal, type exit
or press Ctrl-D
to exit the debugger.
Note: For more information on usages and best practices on zxdb
, see the zxdb user guide.
Update the source code of the sample driver and reload it to the emulator instance.
The tasks include:
qemu_edu
driver.qemu_edu
driver.eductl_tool
to verify the change.Do the following:
Stop the emulator instance:
tools/ffx emu stop
This command stops the currently running emulator instance.
Start a new instance of the Fuchsia emulator:
tools/ffx emu start workstation_eng.qemu-x64 --headless \ --kernel-args "driver_manager.use_driver_framework_v2=true" \ --kernel-args "driver_manager.root-driver=fuchsia-boot:///#meta/platform-bus.cm" \ --kernel-args "devmgr.enable-ephemeral=true"
This command starts a headless emulator instance running the Workstation prebuilt image.
Use a text editor to open the edu_device.cc
file of the sample driver, for example:
nano src/qemu_edu/drivers/edu_device.cc
In the QemuEduDevice::HandleIrq
function, between the line uint32_t factorial = mmio_->Read32(kFactorialComputationOffset);
(Line 123) and the line FDF_SLOG(INFO, "Replying with", KV("factorial", factorial));
(Line 124), add the following line:
factorial=12345;
The function should look like below:
void QemuEduDevice::HandleIrq(async_dispatcher_t* dispatcher, async::IrqBase* irq, zx_status_t status, const zx_packet_interrupt_t* interrupt) { irq_.ack(); if (!pending_callback_.has_value()) { FDF_LOG(ERROR, "Received unexpected interrupt!"); return; } auto callback = std::move(*pending_callback_); pending_callback_ = std::nullopt; if (status != ZX_OK) { FDF_SLOG(ERROR, "Failed to wait for interrupt", KV("status", zx_status_get_string(status))); callback(zx::error(status)); return; } // Acknowledge the interrupt with the edu device. auto int_status = mmio_->Read32(kInterruptStatusRegisterOffset); mmio_->Write32(int_status, kInterruptAcknowledgeRegisterOffset); // Deassert the legacy INTx interrupt on the PCI bus. auto irq_result = pci_->AckInterrupt(); if (!irq_result.ok() || irq_result->is_error()) { FDF_SLOG(ERROR, "Failed to ack PCI interrupt", KV("status", irq_result.ok() ? irq_result->error_value() : irq_result.status())); callback(zx::error(ZX_ERR_IO)); return; } // Reply with the result. uint32_t factorial = mmio_->Read32(kFactorialComputationOffset); {{ '<strong>' }}factorial=12345;{{ '</strong>' }} FDF_SLOG(INFO, "Replying with", KV("factorial", factorial)); callback(zx::ok(factorial)); }
The function is now updated to always return the value of 12345
.
Save the file and close the text editor.
Rebuild and run the modified sample driver:
tools/bazel run --config=fuchsia_x64 //src/qemu_edu/drivers:pkg.component
Run eductl_tool
using fact
and 12
as input:
tools/bazel run --config=fuchsia_x64 //src/qemu_edu/tools:pkg.eductl_tool -- fact 12
This command now prints output similar to the following:
$ tools/bazel run --config=fuchsia_x64 //src/qemu_edu/tools:pkg.eductl_tool -- fact 12 ... INFO: Build completed successfully, 1 total action added repository bazel.pkg.eductl.tool {{ '<strong>' }}Factorial(12) = 12345{{ '</strong>' }}
The last line shows that the qemu_edu
driver replied with the hardcoded value of 12345
to eductl_tool
.
Congratulations! You’re now all set with the Fuchsia driver development!
Learn more about how the qemu_edu
driver works in Codelab: QEMU edu driver.
If you run into a problem while following this guide and decide to start over from the beginning, consider running the commands below to clean up your development environment (that is, to clean up directories, build artifacts, downloaded files, symlinks, configuration settings, and more).
Remove the package repositories created in this guide:
tools/ffx repository remove workstation-packages
tools/ffx repository server stop
Remove all existing configurations and data of ffx
:
tools/ffx daemon stop
rm -rf $HOME/.local/share/Fuchsia/ffx
When Bazel fails to build, try the commands below:
Caution: Running bazel clean
or deleting the $HOME/.cache/bazel
directory deletes all the artifacts downloaded by Bazel, which can be around 4 GB. This means Bazel will need to download those dependencies again the next time you run bazel build
.
tools/bazel clean --expunge
tools/bazel shutdown && rm -rf $HOME/.cache/bazel
Remove the fuchsia-drivers
directory and its artifacts:
Caution: If the SDK samples repository is cloned to a different location than $HOME/fuchsia-drivers
, adjust the directory path in the command below. Be extremely careful with the directory path when you run the `rm -rf
rm -rf $HOME/fuchsia-drivers
Other clean up commands:
killall ffx
killall pm