Get started with driver development

This guide provides step-by-step instructions on setting up the Fuchsia driver development environment on your host machine using a terminal or Visual Studio Code (VS Code). Then the guide walks through the basic workflows of building, running, debugging, and updating drivers in a Fuchsia system using the Fuchsia SDK.

Which development environment are you using for this guide?

Found an issue? Please let us know.

Prerequisites

This guide requires that your host machine meets the following criteria:

  • An x64-based machine running Linux or macOS.
  • Has at least 15 GB of storage space.
  • Supports KVM (Kernel Virtual Machine) for running a QEMU-based emulator.
  • IPv6 is enabled.
  • Git is installed.

Clone the SDK driver samples repository

Start the emulator

Build and load the sample driver

Build and run a tool

Debug the sample driver

Modify and reload the sample driver

Congratulations! You’re now all set with the Fuchsia driver development!

Next steps

Learn more about how the qemu_edu driver works in Codelab: QEMU edu driver.

Appendices

Update the environment to the latest SDK

To update your development environment to use the latest version of the Fuchsia SDK, do the following:

  1. In a terminal, go to your fuchsia-drivers directory:

    cd $HOME/fuchsia-drivers
    
  2. Update the project repository and its submodules to the latest version:

    git pull --rebase --recurse-submodules
    
  3. Update the Fuchsia SDK toolchain and dependencies:

    tools/bazel build @fuchsia_sdk//:fuchsia_toolchain_sdk
    
  4. Check the new version of the Fuchsia SDK:

    tools/ffx sdk version
    

    Verify that the SDK version is now the latest release version.

Clean up the environment

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 devhost.fuchsia.com
tools/ffx repository server stop

Remove all existing configurations and data of ffx:

Linux

tools/ffx daemon stop
rm -rf $HOME/.local/share/Fuchsia/ffx

macOS

tools/ffx daemon stop
rm -rf $HOME/Library/Caches/Fuchsia/ffx
rm -rf $HOME/Library/Fuchsia/ffx
rm -rf $HOME/Library/Preferences/Fuchsia/ffx
rm -rf $HOME/Library/Application\ Support/Fuchsia/ffx

When Bazel fails to build, try the commands below:

Linux

tools/bazel clean --expunge
tools/bazel shutdown && rm -rf $HOME/.cache/bazel

macOS

tools/bazel clean --expunge
tools/bazel shutdown && rm -rf /private/var/tmp/bazel$USER

Remove the fuchsia-drivers directory and its artifacts:

rm -rf $HOME/fuchsia-drivers

Other clean up commands:

killall ffx
killall pm