[qemu_edu] Talk to hardware

Rather than implement FIDL purely in software, this patch enables
qemu_edu to map registers in the pci bar and use them to communicate
with the fake hardware.

Tested: ffx component run \
  "fuchsia-pkg://fuchsiasamples.com/eductl#meta/eductl.cm"
Fixed: 98881
Change-Id: I14e6a30d8856480b298efb0c2c98e623c2b97c5e
Reviewed-on: https://fuchsia-review.googlesource.com/c/sdk-samples/drivers/+/675202
Reviewed-by: Christopher Anderson <cja@google.com>
Fuchsia-Auto-Submit: Suraj Malhotra <surajmalhotra@google.com>
Reviewed-by: Suraj Malhotra <surajmalhotra@google.com>
Reviewed-by: Gurjant Kalsi <gkalsi@google.com>
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
7 files changed
tree: a0e29b6bc66c60bd4801aa7e5b011585578fd603
  1. scripts/
  2. src/
  3. third_party/
  4. tools/
  5. .bazelrc
  6. .clang-format
  7. .gitignore
  8. .gitmodules
  9. AUTHORS
  10. CONTRIBUTING.md
  11. LICENSE
  12. OWNERS
  13. PATENTS
  14. README.md
  15. update_dependencies.md
  16. WORKSPACE.bazel
README.md

Fuchsia samples using the Fuchsia SDK

This repository contains instructions and source code to build, package and run Fuchsia samples using only the Fuchsia SDK. To update the dependencies of this repository, follow the instructions in update_dependencies.md.

Requirements

  1. Install Bazel version 5.1 or later by following the instructions at https://bazel.build/install. In some Linux distributions, sudo apt-get install bazel should be enough.

  2. Make sure this repository has the required submodules:

    git submodule update --recursive --init
    
  3. Ensure that there are Fuchsia SSH keys in your host machine. You will need them for running the Fuchsia emulator.

     [[ -f "${HOME}/.ssh/fuchsia_ed25519" ]] || ssh-keygen -P "" -t ed25519 -f "${HOME}/.ssh/fuchsia_ed25519" -C "${USER}@$(hostname -f) Shared SSH Key for Fuchsia"
    
     [[ -f "${HOME}/.ssh/fuchsia_authorized_keys" ]] || ssh-keygen -y -f "${HOME}/.ssh/fuchsia_ed25519" > "${HOME}/.ssh/fuchsia_authorized_keys"
    

Build, run and test the samples

Now the repository is ready to build the samples.

  1. Build the samples:

    Note: in order to use an SDK produced by a local Fuchsia platform tree, you can set an environment variable named LOCAL_FUCHSIA_PLATFORM_BUILD as described in https://fuchsia.googlesource.com/sdk-integration/+/0503b02c059a6de76242280b467898358ba30ae3

    bazel build --config=fuchsia_x64 src:samples_repository
    

    This command will build all the samples and make them available as packages on a local Fuchsia repository.

  2. Fetch an emulator image and start an emulator

    tools/ffx product-bundle get workstation.qemu-x64
    
    tools/ffx emu start -H workstation.qemu-x64 -c devmgr.enable-ephemeral=true
    

    The product bundle comes with on-demand packages in a separate repository. Use the following command to register it with the emulator:

    tools/ffx target repository register -r workstation.qemu-x64 --alias fuchsia.com
    
  3. Register the package repositories

    tools/ffx repository add-from-pm -r fuchsiasamples.com bazel-bin/src/fuchsiasamples.com.repo
    tools/ffx target repository register -r fuchsiasamples.com
    
  4. (optional) watch the device log in a separate window

    tools/ffx log
    
  5. Load the sample drivers

Now you are ready to register a driver. Starting with the example driver:

First, let's confirm that the driver is not loaded:

tools/ffx driver list | grep example_driver

The command above should not return any driver named “example_driver” because it has not been registered.

Now register the driver:

tools/ffx driver register fuchsia-pkg://fuchsiasamples.com/example_driver#lib/libexample_driver.so

The driver now should show in the list of loaded drivers:

tools/ffx driver list | grep example_driver
example_driver      : lib/libexample_driver.so

You can also watch in the log that the driver loads correctly. The ffx log window should show a message similar to:

[88.961][bootstrap/driver_manager][driver_manager.cm][I] Loaded driver 'fuchsia-pkg://fuchsiasamples.com/example_driver#lib/libexample_driver.so'