forked from M-Labs/nix-servo
Compare commits
5 Commits
07e0d6aa0d
...
ff8bf82988
Author | SHA1 | Date |
---|---|---|
Florian Agbuya | ff8bf82988 | |
Florian Agbuya | 7a49e80c5a | |
Florian Agbuya | 64d83bc50d | |
Florian Agbuya | 733b809881 | |
Florian Agbuya | 0d3f87c5bc |
|
@ -22,8 +22,8 @@ MAP_SIZE = 0x1000
|
|||
MAP_MASK = 0xFFF
|
||||
PAGESIZE = 0x1000
|
||||
|
||||
LINIEN_OFFSET = 0x0
|
||||
# LINIEN_OFFSET = 0x300000
|
||||
# LINIEN_OFFSET = 0x0
|
||||
LINIEN_OFFSET = 0x300000
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# FRONT PANEL LEDS REGISTER ADDRESSES
|
||||
|
|
270
flake.nix
270
flake.nix
|
@ -10,8 +10,7 @@
|
|||
|
||||
outputs = { self, nixpkgs, not-os, src-migen, src-misoc }:
|
||||
let
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; };
|
||||
not-os-cfg = not-os-configured.config.system;
|
||||
pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ crosspkgs-overlay ]; };
|
||||
fsbl-support = ./fast-servo/fsbl-support;
|
||||
|
||||
patched-not-os = pkgs.applyPatches {
|
||||
|
@ -27,6 +26,20 @@
|
|||
];
|
||||
};
|
||||
|
||||
crosspkgs-overlay = (self: super: {
|
||||
pkgsCross = super.pkgsCross // {
|
||||
zynq-baremetal = import super.path {
|
||||
system = "x86_64-linux";
|
||||
crossSystem = {
|
||||
config = "arm-none-eabihf";
|
||||
libc = "newlib";
|
||||
gcc.cpu = "cortex-a9";
|
||||
gcc.fpu = "vfpv3";
|
||||
};
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
migen = pkgs.python3Packages.buildPythonPackage rec {
|
||||
name = "migen";
|
||||
src = src-migen;
|
||||
|
@ -69,171 +82,74 @@
|
|||
runScript = "vivado";
|
||||
};
|
||||
|
||||
pyrp3 = pkgs.python3Packages.buildPythonPackage rec {
|
||||
pname = "pyrp3";
|
||||
version = "1.2.0";
|
||||
pyproject = true;
|
||||
src = pkgs.fetchFromGitHub {
|
||||
owner = "linien-org";
|
||||
repo = "${pname}";
|
||||
rev = "v${version}";
|
||||
hash = "sha256-43TTlpJ5SMAjQM71bNVvrWQyciRXM3zpuA/Dw41AEgU=";
|
||||
fast-servo-extrapkg = ({ config, pkgs, ... }: let
|
||||
pyrp3 = pkgs.python3Packages.buildPythonPackage rec {
|
||||
pname = "pyrp3";
|
||||
version = "1.2.0";
|
||||
pyproject = true;
|
||||
src = pkgs.fetchFromGitHub {
|
||||
owner = "linien-org";
|
||||
repo = "pyrp3";
|
||||
rev = "v${version}";
|
||||
hash = "sha256-43TTlpJ5SMAjQM71bNVvrWQyciRXM3zpuA/Dw41AEgU=";
|
||||
};
|
||||
nativeBuildInputs = with pkgs.python3Packages; [ setuptools wheel setuptools-scm ];
|
||||
propagatedBuildInputs = with pkgs.python3Packages; [
|
||||
myhdl
|
||||
rpyc4
|
||||
cached-property
|
||||
numpy
|
||||
];
|
||||
};
|
||||
nativeBuildInputs = with pkgs.python3Packages; [ setuptools wheel setuptools-scm ];
|
||||
propagatedBuildInputs = with pkgs.python3Packages; [
|
||||
myhdl
|
||||
rpyc4
|
||||
cached-property
|
||||
numpy
|
||||
];
|
||||
};
|
||||
|
||||
linien-server = pkgs.python3Packages.buildPythonPackage rec {
|
||||
pname = "linien-server";
|
||||
pyproject = true;
|
||||
inherit (pkgs.python3Packages.linien-common) src version;
|
||||
sourceRoot = "source/linien-server";
|
||||
postPatch = ''
|
||||
substituteInPlace linien_server/acquisition.py \
|
||||
--replace " start_nginx()" "" \
|
||||
--replace " stop_nginx()" "" \
|
||||
--replace " flash_fpga()" ""
|
||||
'';
|
||||
nativeBuildInputs = [ pkgs.python3Packages.setuptools ];
|
||||
propagatedBuildInputs = with pkgs.python3Packages; [
|
||||
appdirs
|
||||
certifi
|
||||
click
|
||||
cma
|
||||
pylpsd
|
||||
pyrp3
|
||||
requests
|
||||
linien-common
|
||||
linien-server = pkgs.python3Packages.buildPythonPackage rec {
|
||||
pname = "linien-server";
|
||||
pyproject = true;
|
||||
inherit (pkgs.python3Packages.linien-common) src version;
|
||||
sourceRoot = "source/linien-server";
|
||||
postPatch = ''
|
||||
substituteInPlace linien_server/acquisition.py \
|
||||
--replace " start_nginx()" "" \
|
||||
--replace " stop_nginx()" "" \
|
||||
--replace " flash_fpga()" ""
|
||||
'';
|
||||
nativeBuildInputs = [ pkgs.python3Packages.setuptools ];
|
||||
propagatedBuildInputs = with pkgs.python3Packages; [
|
||||
appdirs
|
||||
certifi
|
||||
click
|
||||
cma
|
||||
pylpsd
|
||||
pyrp3
|
||||
requests
|
||||
linien-common
|
||||
];
|
||||
};
|
||||
in {
|
||||
system.build.linien-server = linien-server;
|
||||
environment.systemPackages = [
|
||||
linien-server
|
||||
(pkgs.python3.withPackages(ps: [ ps.spidev ps.smbus2 ]))
|
||||
];
|
||||
};
|
||||
|
||||
not-os-configured = (import patched-not-os {
|
||||
inherit nixpkgs;
|
||||
extraModules = [
|
||||
"${patched-not-os}/zynq_image.nix"
|
||||
];
|
||||
system = "x86_64-linux";
|
||||
crossSystem.system = "armv7l-linux";
|
||||
});
|
||||
|
||||
gnu-platform = "arm-none-eabi";
|
||||
fast-servo-init = ({ config, pkgs, lib, ... }: {
|
||||
boot.postBootCommands = lib.mkAfter ''
|
||||
|
||||
binutils-pkg = { zlib, extraConfigureFlags ? [] }: pkgs.stdenv.mkDerivation rec {
|
||||
basename = "binutils";
|
||||
version = "2.30";
|
||||
name = "${basename}-${gnu-platform}-${version}";
|
||||
src = pkgs.fetchurl {
|
||||
url = "https://ftp.gnu.org/gnu/binutils/binutils-${version}.tar.bz2";
|
||||
sha256 = "028cklfqaab24glva1ks2aqa1zxa6w6xmc8q34zs1sb7h22dxspg";
|
||||
};
|
||||
configureFlags = [
|
||||
"--enable-deterministic-archives"
|
||||
"--target=${gnu-platform}"
|
||||
"--with-cpu=cortex-a9"
|
||||
"--with-fpu=vfpv3"
|
||||
"--with-float=hard"
|
||||
"--with-mode=thumb"
|
||||
] ++ extraConfigureFlags;
|
||||
outputs = [ "out" "info" "man" ];
|
||||
depsBuildBuild = [ pkgs.buildPackages.stdenv.cc ];
|
||||
buildInputs = [ zlib ];
|
||||
enableParallelBuilding = true;
|
||||
meta = {
|
||||
description = "Tools for manipulating binaries (linker, assembler, etc.)";
|
||||
longDescription = ''
|
||||
The GNU Binutils are a collection of binary tools. The main
|
||||
ones are `ld' (the GNU linker) and `as' (the GNU assembler).
|
||||
They also include the BFD (Binary File Descriptor) library,
|
||||
`gprof', `nm', `strip', etc.
|
||||
'';
|
||||
homepage = http://www.gnu.org/software/binutils/;
|
||||
license = pkgs.lib.licenses.gpl3Plus;
|
||||
/* Give binutils a lower priority than gcc-wrapper to prevent a
|
||||
collision due to the ld/as wrappers/symlinks in the latter. */
|
||||
priority = "10";
|
||||
};
|
||||
};
|
||||
# Program the FPGA
|
||||
set +x
|
||||
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
|
||||
|
||||
gcc-pkg = { gmp, mpfr, libmpc, platform-binutils, extraConfigureFlags ? [] }: pkgs.stdenv.mkDerivation rec {
|
||||
basename = "gcc";
|
||||
version = "9.1.0";
|
||||
name = "${basename}-${gnu-platform}-${version}";
|
||||
src = pkgs.fetchurl {
|
||||
url = "https://ftp.gnu.org/gnu/gcc/gcc-${version}/gcc-${version}.tar.xz";
|
||||
sha256 = "1817nc2bqdc251k0lpc51cimna7v68xjrnvqzvc50q3ax4s6i9kr";
|
||||
};
|
||||
preConfigure = ''
|
||||
mkdir build
|
||||
cd build
|
||||
# Run device init scripts
|
||||
mkdir -p /opt/pyfastservo
|
||||
cp ${./fast-servo/pyfastservo}/* /opt/pyfastservo
|
||||
python3 /opt/pyfastservo/initialize.py
|
||||
'';
|
||||
configureScript = "../configure";
|
||||
configureFlags = [
|
||||
"--target=${gnu-platform}"
|
||||
"--with-arch=armv7-a"
|
||||
"--with-tune=cortex-a9"
|
||||
"--with-fpu=vfpv3"
|
||||
"--with-float=hard"
|
||||
"--disable-libssp"
|
||||
"--enable-languages=c"
|
||||
"--with-as=${platform-binutils}/bin/${gnu-platform}-as"
|
||||
"--with-ld=${platform-binutils}/bin/${gnu-platform}-ld" ] ++ extraConfigureFlags;
|
||||
outputs = [ "out" "info" "man" ];
|
||||
hardeningDisable = [ "format" "pie" ];
|
||||
propagatedBuildInputs = [ gmp mpfr libmpc platform-binutils ];
|
||||
enableParallelBuilding = true;
|
||||
dontFixup = true;
|
||||
};
|
||||
|
||||
newlib-pkg = { platform-binutils, platform-gcc }: pkgs.stdenv.mkDerivation rec {
|
||||
pname = "newlib";
|
||||
version = "3.1.0";
|
||||
src = pkgs.fetchurl {
|
||||
url = "ftp://sourceware.org/pub/newlib/newlib-${version}.tar.gz";
|
||||
sha256 = "0ahh3n079zjp7d9wynggwrnrs27440aac04340chf1p9476a2kzv";
|
||||
};
|
||||
nativeBuildInputs = [ platform-binutils platform-gcc ];
|
||||
configureFlags = [
|
||||
"--target=${gnu-platform}"
|
||||
|
||||
"--with-cpu=cortex-a9"
|
||||
"--with-fpu=vfpv3"
|
||||
"--with-float=hard"
|
||||
"--with-mode=thumb"
|
||||
"--enable-interwork"
|
||||
"--disable-multilib"
|
||||
|
||||
"--disable-newlib-supplied-syscalls"
|
||||
"--with-gnu-ld"
|
||||
"--with-gnu-as"
|
||||
"--disable-newlib-io-float"
|
||||
"--disable-werror"
|
||||
];
|
||||
dontFixup = true;
|
||||
};
|
||||
|
||||
gnutoolchain = rec {
|
||||
binutils-bootstrap = pkgs.callPackage binutils-pkg { };
|
||||
gcc-bootstrap = pkgs.callPackage gcc-pkg {
|
||||
platform-binutils = binutils-bootstrap;
|
||||
extraConfigureFlags = [ "--disable-libgcc" ];
|
||||
};
|
||||
newlib = pkgs.callPackage newlib-pkg {
|
||||
platform-binutils = binutils-bootstrap;
|
||||
platform-gcc = gcc-bootstrap;
|
||||
};
|
||||
binutils = pkgs.callPackage binutils-pkg {
|
||||
extraConfigureFlags = [ "--with-lib-path=${newlib}/arm-none-eabi/lib" ];
|
||||
};
|
||||
gcc = pkgs.callPackage gcc-pkg {
|
||||
platform-binutils = binutils;
|
||||
extraConfigureFlags = [ "--enable-newlib" "--with-headers=${newlib}/arm-none-eabi/include" ];
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
fast-servo-gateware = pkgs.stdenv.mkDerivation rec {
|
||||
name = "fast-servo-gateware";
|
||||
|
@ -296,6 +212,18 @@
|
|||
};
|
||||
|
||||
board-package-set = { board }: let
|
||||
not-os-configured = (import patched-not-os {
|
||||
inherit nixpkgs;
|
||||
extraModules = [
|
||||
"${patched-not-os}/zynq_image.nix"
|
||||
] ++ pkgs.lib.optional (board == "fast-servo") fast-servo-extrapkg
|
||||
++ pkgs.lib.optional (board == "fast-servo") fast-servo-init;
|
||||
system = "x86_64-linux";
|
||||
crossSystem.system = "armv7l-linux";
|
||||
});
|
||||
|
||||
not-os-build = not-os-configured.config.system.build;
|
||||
|
||||
fsbl = pkgs.stdenv.mkDerivation {
|
||||
name = "${board}-fsbl";
|
||||
src = pkgs.fetchFromGitHub {
|
||||
|
@ -305,9 +233,8 @@
|
|||
sha256 = "sha256-UDz9KK/Hw3qM1BAeKif30rE8Bi6C2uvuZlvyvtJCMfw=";
|
||||
};
|
||||
nativeBuildInputs = [
|
||||
pkgs.gnumake
|
||||
gnutoolchain.binutils
|
||||
gnutoolchain.gcc
|
||||
pkgs.pkgsCross.zynq-baremetal.buildPackages.binutils
|
||||
pkgs.pkgsCross.zynq-baremetal.buildPackages.gcc
|
||||
];
|
||||
postUnpack = ''
|
||||
mkdir -p $sourceRoot/lib/sw_apps/zynq_fsbl/misc/fast-servo
|
||||
|
@ -317,7 +244,11 @@
|
|||
patches = [] ++ pkgs.lib.optional (board == "fast-servo") ./fast-servo/fsbl.patch;
|
||||
postPatch = ''
|
||||
patchShebangs lib/sw_apps/zynq_fsbl/misc/copy_bsp.sh
|
||||
echo 'SEARCH_DIR("${gnutoolchain.newlib}/arm-none-eabi/lib");' >> lib/sw_apps/zynq_fsbl/src/lscript.ld
|
||||
|
||||
for x in lib/sw_apps/zynq_fsbl/src/Makefile lib/sw_apps/zynq_fsbl/misc/copy_bsp.sh lib/bsp/standalone/src/arm/cortexa9/gcc/Makefile; do
|
||||
substituteInPlace $x \
|
||||
--replace "arm-none-eabi-" "arm-none-eabihf-"
|
||||
done
|
||||
'';
|
||||
buildPhase = ''
|
||||
cd lib/sw_apps/zynq_fsbl/src
|
||||
|
@ -343,7 +274,7 @@
|
|||
CONFIG_SYS_PROMPT="${board}-boot> "
|
||||
CONFIG_AUTOBOOT=y
|
||||
CONFIG_BOOTCOMMAND="${builtins.replaceStrings [ "\n" ] [ "; " ] ''
|
||||
setenv bootargs 'root=/dev/mmcblk0p2 console=ttyPS0,115200n8 systemConfig=${builtins.unsafeDiscardStringContext not-os-cfg.build.toplevel}'
|
||||
setenv bootargs 'root=/dev/mmcblk0p2 console=ttyPS0,115200n8 systemConfig=${builtins.unsafeDiscardStringContext not-os-build.toplevel}'
|
||||
fatload mmc 0 0x6400000 uImage
|
||||
fatload mmc 0 0x8000000 ${board}.dtb
|
||||
fatload mmc 0 0xA400000 uRamdisk.image.gz
|
||||
|
@ -407,7 +338,7 @@
|
|||
|
||||
sd-image = let
|
||||
rootfsImage = pkgs.callPackage (pkgs.path + "/nixos/lib/make-ext4-fs.nix") {
|
||||
storePaths = [ not-os-cfg.build.toplevel ];
|
||||
storePaths = [ not-os-build.toplevel ];
|
||||
volumeLabel = "ROOT";
|
||||
};
|
||||
# Current firmware (kernel, bootimage, etc..) takes ~18MB
|
||||
|
@ -448,8 +379,8 @@
|
|||
mkdir firmware
|
||||
cp ${bootimage}/boot.bin firmware/
|
||||
cp ${dtb}/${board}.dtb firmware/
|
||||
cp ${not-os-cfg.build.kernel}/uImage firmware/
|
||||
cp ${not-os-cfg.build.uRamdisk}/initrd firmware/uRamdisk.image.gz
|
||||
cp ${not-os-build.kernel}/uImage firmware/
|
||||
cp ${not-os-build.uRamdisk}/initrd firmware/uRamdisk.image.gz
|
||||
|
||||
(cd firmware; mcopy -psvm -i ../firmware_part.img ./* ::)
|
||||
dd conv=notrunc if=firmware_part.img of=$img seek=$START count=$SECTORS
|
||||
|
@ -462,7 +393,7 @@
|
|||
export PATH=${pkgs.qemu}/bin:$PATH
|
||||
IMGDIR=$(mktemp -d /tmp/not-os-qemu-XXXXXX)
|
||||
BASE=$(realpath $(dirname $0))
|
||||
qemu-img create -F raw -f qcow2 -b $BASE/sd-image.img $IMGDIR/sd-overlay.qcow2 512M
|
||||
qemu-img create -F raw -f qcow2 -b $BASE/sd-image.img $IMGDIR/sd-overlay.qcow2 4G
|
||||
|
||||
# Some command arguments are based from samples in Xilinx QEMU User Documentation
|
||||
# See: https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/821854273/Running+Bare+Metal+Applications+on+QEMU
|
||||
|
@ -498,6 +429,7 @@
|
|||
"${board}-dtb" = dtb;
|
||||
"${board}-sd-image" = sd-image;
|
||||
"${board}-qemu" = not-os-qemu;
|
||||
linien-server = not-os-build.linien-server;
|
||||
};
|
||||
in rec {
|
||||
packages.x86_64-linux = {
|
||||
|
@ -505,7 +437,7 @@
|
|||
inherit migen misoc vivado;
|
||||
};
|
||||
packages.armv7l-linux = {
|
||||
inherit fast-servo-gateware linien-server;
|
||||
inherit fast-servo-gateware;
|
||||
} //
|
||||
(board-package-set { board = "zc706"; }) //
|
||||
(board-package-set { board = "fast-servo"; });
|
||||
|
|
Loading…
Reference in New Issue