Add fast-servo board support #24

Merged
sb10q merged 1 commits from fsagbuya/nix-servo:fast-servo into master 2024-08-17 17:37:24 +08:00
Collaborator

Description

This patch aims to add firmware board support for Sinara Fast Servo.

Note: ps7_init and device tree are generated manually via Vitis IDE.

TODO:

  • build fsbl
    • removed the old fsbl.patch, it is fixed when switching to v2022.2 version.
    • add fsbl support files from Fast-Servo-Firmware source
    • add a new fsbl.patch for fast-servo build files
  • build device tree
    • move dts source to u-boot for consistency and since zc706 dts in kernel is outdated
  • patch and build u-boot
  • test boot in fast-servo
    • 1st trial (failed to boot)
    • 2nd trial (working in qemu but not booting in board)
    • 3rd trial - already booted (updated the fsbl. patch xparameters.h to make it work)
### Description This patch aims to add firmware board support for Sinara [Fast Servo](https://github.com/sinara-hw/Fast_Servo/wiki). Note: `ps7_init` and device tree are generated manually via Vitis IDE. TODO: - [x] build fsbl - removed the old fsbl.patch, it is [fixed ](https://github.com/Xilinx/embeddedsw/commit/334a4aa3b45cbe8af0dbeb7efa3b8af68c96e9f5)when switching to `v2022.2` version. - add fsbl support files from [Fast-Servo-Firmware](https://github.com/elhep/Fast-Servo-Firmware/tree/master/builds/fast_servo_petalinux/project-spec/hw-description) source - add a new fsbl.patch for fast-servo build files - [x] build device tree - move dts source to u-boot for consistency and since zc706 dts in kernel is outdated - [x] patch and build u-boot - [x] test boot in fast-servo - 1st trial (failed to boot) - 2nd trial (working in qemu but not booting in board) - 3rd trial - already booted (updated the fsbl. patch `xparameters.h` to make it work)
Owner

fsbl.elf should not be committed. Just build it like the others.

fsbl.elf should not be committed. Just build it like the others.
sb10q reviewed 2024-01-26 18:46:15 +08:00
@ -0,0 +10,4 @@
zynq-cc108.dtb \
zynq-cse-nand.dtb \
zynq-cse-nor.dtb \
diff --git a/arch/arm/dts/fast-servo.dts b/arch/arm/dts/fast-servo.dts
Owner

Where is this file used? I only see the .dtb referenced.

Where is this file used? I only see the .dtb referenced.
Author
Collaborator

The .dts file generated is also needed to be copied to u-boot. But we only need the .dtb for building the OS.

The `.dts` file generated is also needed to be copied to u-boot. But we only need the `.dtb` for building the OS.
Owner
https://stackoverflow.com/questions/21670967/how-to-compile-dts-linux-device-tree-source-files-to-dtb Please remove the .dtb and generate it from the .dts.
Author
Collaborator

.dts can also be generated from these file recipes https://github.com/farbius/linux-vitis-zynq/tree/main/devicetree-src/zynq, see the build.sh script. Should I instead commit those files?

`.dts` can also be generated from these file recipes https://github.com/farbius/linux-vitis-zynq/tree/main/devicetree-src/zynq, see the build.sh script. Should I instead commit those files?
Owner

Yes.

Yes.
fsagbuya marked this conversation as resolved
fsagbuya force-pushed fast-servo from e90d0d6ea6 to f31b46c70e 2024-01-26 19:02:38 +08:00 Compare
fsagbuya force-pushed fast-servo from f31b46c70e to 7accfd2c42 2024-01-26 19:34:40 +08:00 Compare
fsagbuya force-pushed fast-servo from 7accfd2c42 to d49c926197 2024-01-29 17:08:37 +08:00 Compare
Owner

Gateware, FSBL and device tree are generated manually via Vitis IDE.

No. You just need to generate a few device tree file, the rest can be built without Vitis. The gateware isn't a concern yet.

And you don't need a 26k-line patch to build FSBL for a board.

> Gateware, FSBL and device tree are generated manually via Vitis IDE. No. You just need to generate a few device tree file, the rest can be built without Vitis. The gateware isn't a concern yet. And you don't need a 26k-line patch to build FSBL for a board.
sb10q reviewed 2024-01-29 21:02:46 +08:00
@ -0,0 +14,4 @@
new file mode 100644
index 0000000000..918d44a32c
--- /dev/null
+++ b/arch/arm/dts/fast-servo.dts
Owner

Isn't that duplicated from the files above?

Isn't that duplicated from the files above?
Owner

Any progress on getting this sorted? This is the biggest issue with this PR right now.

Any progress on getting this sorted? This is the biggest issue with this PR right now.
Author
Collaborator

Will revert on committing only the .dts file in the repo to be consistent with the linux kernel https://github.com/torvalds/linux/tree/master/arch/arm/boot/dts/xilinx. So the dtb builder will be consistent on both the fast-servo and not-os zynq. I'm currently fixing the not-os patch to extract the zc706 dts file.

Will revert on committing only the `.dts` file in the repo to be consistent with the linux kernel https://github.com/torvalds/linux/tree/master/arch/arm/boot/dts/xilinx. So the dtb builder will be consistent on both the fast-servo and not-os zynq. I'm currently fixing the not-os patch to extract the zc706 dts file.
Author
Collaborator

Updated the u-boot patch to prevent duplication.

Updated the u-boot patch to prevent duplication.
fsagbuya marked this conversation as resolved
sb10q reviewed 2024-01-29 21:03:18 +08:00
@ -0,0 +688,4 @@
CONFIG_ENV_OFFSET=0xE00000
CONFIG_DM_GPIO=y
-CONFIG_DEFAULT_DEVICE_TREE="zynq-zc706"
+CONFIG_DEFAULT_DEVICE_TREE="fast-servo"
Owner

How is that working with the board selection in nix?

How is that working with the board selection in nix?
Author
Collaborator

Patch for fast-servo will only be applied if fast-servo board is selected. d75530b07b/flake.nix (L239)

Patch for fast-servo will only be applied if fast-servo board is selected. https://git.m-labs.hk/M-Labs/nix-servo/src/commit/d75530b07ba5498e11ea9919fc78036b8d3ed86e/flake.nix#L239
fsagbuya marked this conversation as resolved
sb10q reviewed 2024-01-29 21:04:07 +08:00
flake.nix Outdated
@ -234,0 +219,4 @@
}
''
mkdir -p $out
if [ "${board}" = "fast-servo" ]; then
Owner

Purpose of this grossly inconsistent test?

Purpose of this grossly inconsistent test?
Author
Collaborator

Updated the name of the device-tree runCommand to device-tree for clarity. This builds the device tree in two ways, one from the dts files committed to the repo and one from not-os build.

Updated the name of the device-tree runCommand to `device-tree` for clarity. This builds the device tree in two ways, one from the dts files committed to the repo and one from `not-os` build.
Owner

There should be only one source of truth for the device tree, from which other formats are built using open tools and Nix derivations.

There should be only one source of truth for the device tree, from which other formats are built using open tools and Nix derivations.
Author
Collaborator

Ahh.. I get what you mean. Will revise the code to align with a more standard approach.

Ahh.. I get what you mean. Will revise the code to align with a more standard approach.
fsagbuya marked this conversation as resolved
Author
Collaborator

No. You just need to generate a few device tree file, the rest can be built without Vitis. The gateware isn't a concern yet.

Understood.

And you don't need a 26k-line patch to build FSBL for a board.

Initially, I just copied the hw files from vitis to replicate the BSP template from this repo https://github.com/Xilinx/embeddedsw/tree/master/lib/sw_apps/zynq_fsbl/misc.
Will find a better approach for this.

> No. You just need to generate a few device tree file, the rest can be built without Vitis. The gateware isn't a concern yet. Understood. > And you don't need a 26k-line patch to build FSBL for a board. Initially, I just copied the hw files from vitis to replicate the BSP template from this repo https://github.com/Xilinx/embeddedsw/tree/master/lib/sw_apps/zynq_fsbl/misc. Will find a better approach for this.
Owner

copied the hw files from vitis
replicate the BSP template from this repo

A lot of Xilinx software is garbage and not an example to follow.

> copied the hw files from vitis > replicate the BSP template from this repo A lot of Xilinx software is garbage and not an example to follow.
fsagbuya force-pushed fast-servo from 05f1a9ae33 to 825cc7c55d 2024-01-30 10:12:22 +08:00 Compare
Author
Collaborator

A lot of Xilinx software is garbage and not an example to follow.

Should we not rely now on the Xilinx tool to build the fsbl? Need your suggestions.

> A lot of Xilinx software is garbage and not an example to follow. Should we not rely now on the Xilinx tool to build the fsbl? Need your suggestions.
Owner

Just copy the existing FSBL derivation that is in zynq-rs and change its settings to match the fast-servo hardware, fix #1 (i.e. use the Linux toolchain, there's no good reason it wouldn't work), and don't do anything else.

Just copy the existing FSBL derivation that is in zynq-rs and change its settings to match the fast-servo hardware, fix https://git.m-labs.hk/M-Labs/nix-servo/issues/1 (i.e. use the Linux toolchain, there's no good reason it wouldn't work), and don't do anything else.
Author
Collaborator

Just copy the existing FSBL derivation that is in zynq-rs and change its settings to match the fast-servo hardware.

This is also what I did here, the challenging part is making this line work. https://git.m-labs.hk/M-Labs/zynq-rs/src/branch/master/flake.nix#L187. The tool currently supports only the 3 boards in the upstream (zc702, zc706 and zed), that's why the current approach is to make another directory for fast-servo with its hw files to have this supported. Thus, the 26k patch. :( We can also commit those files here and just patch the fsbl tool to look in our repo instead. This will make the patch shorter.

> Just copy the existing FSBL derivation that is in zynq-rs and change its settings to match the fast-servo hardware. This is also what I did here, the challenging part is making this line work. https://git.m-labs.hk/M-Labs/zynq-rs/src/branch/master/flake.nix#L187. The tool currently supports only the 3 boards in the upstream (zc702, zc706 and zed), that's why the current approach is to make another directory for fast-servo with its hw files to have this supported. Thus, the 26k patch. :( We can also commit those files here and just patch the fsbl tool to look in our repo instead. This will make the patch shorter.
Owner

Can you just inject the required files with shell commands in postPatch or similar? That should be less than 30 lines of code, not 26000+.

Can you just inject the required files with shell commands in postPatch or similar? That should be less than 30 lines of code, not 26000+.
Author
Collaborator

Can you just inject the required files with shell commands in postPatch or similar? That should be less than 30 lines of code, not 26000+.

I think this is possible. Will work on this solution. 👍

> Can you just inject the required files with shell commands in postPatch or similar? That should be less than 30 lines of code, not 26000+. I think this is possible. Will work on this solution. 👍
fsagbuya force-pushed fast-servo from 825cc7c55d to 454096067f 2024-01-30 17:33:05 +08:00 Compare
sb10q reviewed 2024-01-31 10:43:01 +08:00
flake.nix Outdated
@ -166,2 +161,2 @@
rev = "65c849ed46c88c67457e1fc742744f96db968ff1";
sha256 = "1rvl06ha40dzd6s9aa4sylmksh4xb9dqaxq462lffv1fdk342pda";
fsbl = { board ? "zc706" }: let
fast-servo-hw = ./fast-servo/hw;
Owner
  1. "hw" is a bad directory name
  2. Most of those files appear to have been copied from somewhere else. Use the nix fetchers and/or the cp command, then patch if required?
1. "hw" is a bad directory name 2. Most of those files appear to have been copied from somewhere else. Use the nix fetchers and/or the cp command, then patch if required?
Owner

Call the directory "fsbl-support" or similar, other software doesn't need this stuff.

Call the directory "fsbl-support" or similar, other software doesn't need this stuff.
fsagbuya marked this conversation as resolved
sb10q reviewed 2024-01-31 10:43:23 +08:00
flake.nix Outdated
@ -168,0 +165,4 @@
src = pkgs.fetchFromGitHub {
owner = "Xilinx";
repo = "embeddedsw";
# Previous version can't build fast-servo wdtps driver
Owner

Remove this comment from here. Goes in the PR description.

Remove this comment from here. Goes in the PR description.
fsagbuya marked this conversation as resolved
sb10q reviewed 2024-01-31 10:44:30 +08:00
fsbl.patch Outdated
@ -1,12 +1,9 @@
diff --git a/lib/sw_apps/zynq_fsbl/src/Makefile b/lib/sw_apps/zynq_fsbl/src/Makefile
Owner

Does this patch still do anything? Or should you remove it entirely?

Does this patch still do anything? Or should you remove it entirely?
Author
Collaborator

Tested without the patch and fsbl still builds for this version. Will remove it.

Tested without the patch and `fsbl` still builds for this version. Will remove it.
Owner

See the commit history. Xilinx fixed it upstream.

See the commit history. Xilinx fixed it upstream.
fsagbuya marked this conversation as resolved
sb10q reviewed 2024-01-31 10:45:15 +08:00
flake.nix Outdated
@ -168,0 +177,4 @@
];
postUnpack = ''
mkdir -p $sourceRoot/lib/sw_apps/zynq_fsbl/misc/fast-servo
cp -r ${fast-servo-hw}/* $sourceRoot/lib/sw_apps/zynq_fsbl/misc/fast-servo
Owner

If you use -r you don't need *

If you use -r you don't need *
fsagbuya marked this conversation as resolved
sb10q reviewed 2024-01-31 10:46:25 +08:00
flake.nix Outdated
@ -168,0 +190,4 @@
'';
installPhase = ''
mkdir $out
cp fsbl.elf $out
Owner

What is the directory for? $out can be the elf file directly, no?

What is the directory for? $out can be the elf file directly, no?
fsagbuya marked this conversation as resolved
fsagbuya force-pushed fast-servo from 454096067f to 51fdb70452 2024-01-31 17:46:46 +08:00 Compare
sb10q reviewed 2024-01-31 17:51:59 +08:00
@ -0,0 +10,4 @@
dmaps
emacps
gpiops
+iicps
Owner

And we need this in FSBL because?

And we need this in FSBL because?
Author
Collaborator

The additional drivers here are generated from the xsa file of fast-servo. Adding them makes the fast-servo fsbl build.

The additional drivers here are generated from the xsa file of fast-servo. Adding them makes the fast-servo fsbl build.
Owner

I'm pretty sure it builds without them. FSBL doesn't need I2C nor most of the other things. Why are they there?

I'm pretty sure it builds without them. FSBL doesn't need I2C nor most of the other things. Why are they there?
Author
Collaborator

I see. Will revise it for a minimal build, removing those that are not necessary.

I see. Will revise it for a minimal build, removing those that are not necessary.
Owner

Rather minimal patch. Just what is needed vs. the existing code in FSBL.

Rather minimal patch. Just what is needed vs. the existing code in FSBL.
fsagbuya marked this conversation as resolved
sb10q reviewed 2024-01-31 17:54:13 +08:00
flake.nix Outdated
@ -161,0 +162,4 @@
fsbl-support = pkgs.stdenv.mkDerivation {
name = "fast-servo-fsbl-support";
src = pkgs.fetchFromGitHub {
owner = "elhep";
Owner

No, we shouldn't depend on that repos.

No, we shouldn't depend on that repos.
fsagbuya marked this conversation as resolved
sb10q reviewed 2024-01-31 17:54:44 +08:00
flake.nix Outdated
@ -161,0 +170,4 @@
postUnpack = "sourceRoot=$sourceRoot/builds/fast_servo_petalinux/project-spec/hw-description";
installPhase = ''
mkdir -p $out
cp ps7_init.c $out
Owner

How different are they from the existing ones in FSBL?
Are the differences relevant?

How different are they from the existing ones in FSBL? Are the differences relevant?
Author
Collaborator

Files with relevant differences are ps7_init.c and ps7_init_gpl.c with 3000+ diff, will just commit these to the repos.

Files with relevant differences are `ps7_init.c` and `ps7_init_gpl.c` with 3000+ diff, will just commit these to the repos.
fsagbuya marked this conversation as resolved
fsagbuya force-pushed fast-servo from 51fdb70452 to d75530b07b 2024-02-01 18:19:48 +08:00 Compare
Author
Collaborator

Updated. Still need to work out the device tree to have one source of truth (i.e. .dts file).

Updated. Still need to work out the device tree to have one source of truth (i.e. `.dts` file).
fsagbuya force-pushed fast-servo from d75530b07b to ef3d574020 2024-02-02 16:41:04 +08:00 Compare
fsagbuya force-pushed fast-servo from ef3d574020 to 17183a4b08 2024-02-12 10:28:05 +08:00 Compare
fsagbuya force-pushed fast-servo from 6fac78ce76 to 1ce024b8ea 2024-02-12 13:25:23 +08:00 Compare
fsagbuya force-pushed fast-servo from 1ce024b8ea to 24d668ac46 2024-02-13 17:47:18 +08:00 Compare
fsagbuya changed title from WIP: Add fast-servo board support to Add fast-servo board support 2024-02-14 10:37:36 +08:00
sb10q reviewed 2024-02-14 15:53:58 +08:00
flake.nix Outdated
@ -292,0 +242,4 @@
fi
dtc -I dts -O dtb -o ${board}.dtb ${board}.dts
chmod +x ${board}.dtb
Owner

Why does this need to be executable?

Why does this need to be executable?
Author
Collaborator

I have added this before because .dtb file from linux kernel nix build is executable. So I did it as well in fast-servo.dtb for consistency. However from testing, it also boots fine without making it executable. Will just remove this.

I have added this before because `.dtb` file from linux kernel nix build is executable. So I did it as well in fast-servo.dtb for consistency. However from testing, it also boots fine without making it executable. Will just remove this.
fsagbuya marked this conversation as resolved
fsagbuya force-pushed fast-servo from e980c9255f to b6c55eeb66 2024-02-14 15:54:21 +08:00 Compare
sb10q reviewed 2024-02-14 15:55:54 +08:00
pr-28.patch Outdated
@ -26,0 +31,4 @@
'';
"service/nix/run".source = pkgs.writeScript "nix" ''
#!${pkgs.runtimeShell}
- nix-store --load-db < /nix/store/nix-path-registration
Owner

This pr-28.patch file should be in a separate PR I believe?

This pr-28.patch file should be in a separate PR I believe?
Author
Collaborator

Will add this to a separate PR.

Will add this to a separate PR.
fsagbuya marked this conversation as resolved
fsagbuya force-pushed fast-servo from b6c55eeb66 to 08bcf27579 2024-02-14 16:12:19 +08:00 Compare
Owner

Note: Gateware and device tree are generated manually via Vitis IDE.

ps7_init isn't the gateware.

> Note: Gateware and device tree are generated manually via Vitis IDE. ps7_init isn't the gateware.
sb10q reviewed 2024-02-14 17:07:02 +08:00
flake.nix Outdated
@ -194,2 +209,3 @@
patches = [] ++ pkgs.lib.optional (board == "fast-servo") ./fast-servo/u-boot.patch;
preConfigure = ''
export DEVICE_TREE=zynq-${board}
export DEVICE_TREE=$([ "${board}" = "zc706" ] && echo "zynq-${board}" || echo "${board}")
Owner

Why the difference?

Why the difference?
Owner

Can't you just call the device tree zynq-fast-servo in u-boot?

Can't you just call the device tree zynq-fast-servo in u-boot?
Author
Collaborator

Ah yes. I didn't think of that. Will change it to zynq-fast-servo in u-boot.

Ah yes. I didn't think of that. Will change it to `zynq-fast-servo` in u-boot.
fsagbuya marked this conversation as resolved
fsagbuya force-pushed fast-servo from 08bcf27579 to 49f9b3e095 2024-02-14 17:49:17 +08:00 Compare
sb10q reviewed 2024-02-15 12:38:50 +08:00
flake.nix Outdated
@ -347,3 +380,3 @@
};
packages.armv7l-linux = {
zc706-u-boot = u-boot { board = "zc706"; };
not-os = not-os-cfg.build.zynq_image;
Owner

For which board is this? And isn't it redundant with the others?

For which board is this? And isn't it redundant with the others?
Author
Collaborator

Here's the current content of the package:

 20K -r-xr-xr-x 19 root root  18K Jan  1  1970 devicetree.dtb
4.0K dr-xr-xr-x  2 root root 4.0K Jan  1  1970 toplevel
 14M -r--r--r--  2 root root  14M Jan  1  1970 uImage
2.1M -r--r--r--  2 root root 2.1M Jan  1  1970 uRamdisk.image.gz

devicetree.dtb here is not necessary since we are sourcing the device tree from u-boot. We can remove the devicetree.dtb here or remove the not-os from the package list, since uImage and uRamdisk.image.gz is already inside sd-image package.

Here's the current content of the package: ``` 20K -r-xr-xr-x 19 root root 18K Jan 1 1970 devicetree.dtb 4.0K dr-xr-xr-x 2 root root 4.0K Jan 1 1970 toplevel 14M -r--r--r-- 2 root root 14M Jan 1 1970 uImage 2.1M -r--r--r-- 2 root root 2.1M Jan 1 1970 uRamdisk.image.gz ``` `devicetree.dtb` here is not necessary since we are sourcing the device tree from u-boot. We can remove the `devicetree.dtb` here or remove the `not-os` from the package list, since `uImage` and `uRamdisk.image.gz` is already inside sd-image package.
Owner

In any case the board ambiguity needs to be resolved and cleaned up, perhaps deeper into the code.

In any case the board ambiguity needs to be resolved and cleaned up, perhaps deeper into the code.
fsagbuya force-pushed fast-servo from 49f9b3e095 to 2e0ba854e3 2024-02-16 13:13:26 +08:00 Compare
Owner

Why the directory dts-support? There's only one file there? The patches don't have their own directory.

Why the directory dts-support? There's only one file there? The patches don't have their own directory.
sb10q reviewed 2024-02-16 16:46:00 +08:00
flake.nix Outdated
@ -344,0 +274,4 @@
}
''
mkdir -p $out
DTSDIR=$(mktemp -d /tmp/dts-XXXXXX)
Owner

Not needed AFAICT? You can always create temporary build files in the current directory in a Nix derivation.

Not needed AFAICT? You can always create temporary build files in the current directory in a Nix derivation.
sb10q reviewed 2024-02-16 16:47:08 +08:00
flake.nix Outdated
@ -354,2 +390,2 @@
zc706-not-os = not-os-cfg.build.zynq_image;
};
packages.armv7l-linux =
(build { board = "zc706"; }) //
Owner

"build" is too general of a name.

"build" is too general of a name.
Author
Collaborator

Do you have a more suitable name in mind? I only get this from the artiq-zynq flake.

Do you have a more suitable name in mind? I only get this from the `artiq-zynq` flake.
Owner

Maybe something like board-package-set

Maybe something like board-package-set
Author
Collaborator

Why the directory dts-support? There's only one file there? The patches don't have their own directory.

Will remove the dts-support directory and also add a directory for the patches.

> Why the directory dts-support? There's only one file there? The patches don't have their own directory. Will remove the `dts-support` directory and also add a directory for the patches.
Owner

I didn't say the patches needed a dir, just pointed out the inconsistency.

I didn't say the patches needed a dir, just pointed out the inconsistency.
fsagbuya force-pushed fast-servo from 2e0ba854e3 to 293f1eb54f 2024-02-16 23:59:08 +08:00 Compare
Owner

CONFLICT (content): Merge conflict in pr-28.patch

CONFLICT (content): Merge conflict in pr-28.patch
fsagbuya force-pushed fast-servo from 293f1eb54f to afa00efee3 2024-02-20 09:56:23 +08:00 Compare
Author
Collaborator

CONFLICT (content): Merge conflict in pr-28.patch

Conflict resolved.

> CONFLICT (content): Merge conflict in pr-28.patch Conflict resolved.
sb10q merged commit afa00efee3 into master 2024-02-20 10:55:16 +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#24
No description provided.