Add bitstream loading and run init scripts at boot time #52

Merged
sb10q merged 2 commits from fsagbuya/nix-servo:fast-servo-init into master 2024-04-24 18:03:18 +08:00
Collaborator

Description

Note: This PR is rebased from #50. Need to merge that first before this.

  • Add the bitstream loading at boot time
  • Add pyfastservo and run init scripts at boot time
  • Linien offset switched to match the fast-servo linien gateware.

Use postBootCommand here rather than runit because it does not support one-shot services like this. Also there will be issues on running our program in parallel with other services and the log in prompt. See sample implementation below:

runit-services = ({ config, pkgs, lib, ... }: {
        environment.etc = lib.mkMerge [
          {
            "service/fpga/run".source = pkgs.writeScript "flash_fpga" ''
              #!${pkgs.runtimeShell}
              echo Flashing bitstream...
              echo 0 > /sys/class/fpga_manager/fpga0/flags
              mkdir -p /lib/firmware
              cp ${fast-servo-gateware}/gateware.bin /lib/firmware/
              echo gateware.bin > /sys/class/fpga_manager/fpga0/firmware
              sv force-stop /etc/service/fpga > /dev/null
              sv exit /etc/service/fpga
            '';
          }
        ];
      });

Note that it is imperative to use commands like sv force-stop and sv exit here to emulate a one-shot type of service, otherwise runit will restart the service continously.

Boot log: (Qemu)
The log-in prompt shows while the fpga manager is still on-going.

Flashing bitstream...
[   22.697845] fpga_manager fpga0: writing gateware.bin to Xilinx Zynq FPGA Manager

zynq login: 

[   25.307664] fpga_manager fpga0: Timeout waiting for PCFG_INIT
[   25.307792] fpga_manager fpga0: Error preparing FPGA for writing
./run: line 6: echo: write error: Connection timed out

See full fast-servo boot log here: https://gist.github.com/fsagbuya/aa5bc932b653bc9f96f07dfbcde12f64#file-servo_bootlog-txt-L54-L170.

### Description Note: This PR is rebased from #50. Need to merge that first before this. - Add the bitstream loading at boot time - Add pyfastservo and run init scripts at boot time - Linien offset switched to match the fast-servo linien gateware. Use `postBootCommand` here rather than runit because it does not support one-shot services like this. Also there will be issues on running our program in parallel with other services and the log in prompt. See sample implementation below: ``` runit-services = ({ config, pkgs, lib, ... }: { environment.etc = lib.mkMerge [ { "service/fpga/run".source = pkgs.writeScript "flash_fpga" '' #!${pkgs.runtimeShell} echo Flashing bitstream... echo 0 > /sys/class/fpga_manager/fpga0/flags mkdir -p /lib/firmware cp ${fast-servo-gateware}/gateware.bin /lib/firmware/ echo gateware.bin > /sys/class/fpga_manager/fpga0/firmware sv force-stop /etc/service/fpga > /dev/null sv exit /etc/service/fpga ''; } ]; }); ``` Note that it is imperative to use commands like `sv force-stop` and `sv exit` here to emulate a one-shot type of service, otherwise runit will restart the service continously. Boot log: (Qemu) The log-in prompt shows while the fpga manager is still on-going. ``` Flashing bitstream... [ 22.697845] fpga_manager fpga0: writing gateware.bin to Xilinx Zynq FPGA Manager zynq login: [ 25.307664] fpga_manager fpga0: Timeout waiting for PCFG_INIT [ 25.307792] fpga_manager fpga0: Error preparing FPGA for writing ./run: line 6: echo: write error: Connection timed out ``` See full fast-servo boot log here: https://gist.github.com/fsagbuya/aa5bc932b653bc9f96f07dfbcde12f64#file-servo_bootlog-txt-L54-L170.
fsagbuya added 3 commits 2024-03-21 18:52:37 +08:00
fsagbuya force-pushed fast-servo-init from 56c749eda4 to c06ad6ef1c 2024-03-22 13:38:55 +08:00 Compare
fsagbuya force-pushed fast-servo-init from c06ad6ef1c to 07e0d6aa0d 2024-03-22 13:46:24 +08:00 Compare
fsagbuya force-pushed fast-servo-init from 07e0d6aa0d to ff8bf82988 2024-04-02 10:50:09 +08:00 Compare
fsagbuya force-pushed fast-servo-init from ff8bf82988 to b7578e175a 2024-04-04 14:58:05 +08:00 Compare
sb10q reviewed 2024-04-04 16:32:17 +08:00
flake.nix Outdated
@ -214,0 +225,4 @@
echo gateware.bin > /sys/class/fpga_manager/fpga0/firmware
# Run device init scripts
mkdir -p /opt/pyfastservo

Put those into a regular derivation instead of doing nix's job (poorly).

Put those into a regular derivation instead of doing nix's job (poorly).
Poster
Collaborator

I can combine the systemPackages and postBootCommands to a single derivation and call it fast-servo-config or something. Is that acceptable?

I can combine the `systemPackages` and `postBootCommands` to a single derivation and call it `fast-servo-config` or something. Is that acceptable?

Obviously not. Those init scripts are a regular package.

Obviously not. Those init scripts are a regular package.
fsagbuya force-pushed fast-servo-init from b7578e175a to e149095e81 2024-04-04 17:09:38 +08:00 Compare
fsagbuya force-pushed fast-servo-init from e149095e81 to cc0879fcb0 2024-04-05 15:37:38 +08:00 Compare
sb10q reviewed 2024-04-24 18:03:08 +08:00
@ -214,0 +239,4 @@
# Program the FPGA
set +x
echo "Flashing bitstream..."

It's not flashing, just loading into SRAM. Please send another PR addressing this incorrect terminology.

It's not flashing, just loading into SRAM. Please send another PR addressing this incorrect terminology.
sb10q merged commit 1ee382564e into master 2024-04-24 18:03:18 +08:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nix-servo#52
There is no content yet.