From aaa66731528b181e3d68f56cc3657a74e2e0e75f Mon Sep 17 00:00:00 2001 From: Michael Bishop Date: Wed, 29 Jan 2020 02:49:06 -0400 Subject: [PATCH] add the basis for nix CI --- arch/vc4/intc.c | 2 +- default.nix | 4 +- nix/sources.json | 38 ++++++++ nix/sources.nix | 93 ++++++++++++++++++++ {arch/vc4 => platform/bcm28xx}/start.ld | 0 project/{rpi4-vpu-test.mk => rpi4-start4.mk} | 0 6 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 nix/sources.json create mode 100644 nix/sources.nix rename {arch/vc4 => platform/bcm28xx}/start.ld (100%) rename project/{rpi4-vpu-test.mk => rpi4-start4.mk} (100%) diff --git a/arch/vc4/intc.c b/arch/vc4/intc.c index cff3b4d17..35942329d 100644 --- a/arch/vc4/intc.c +++ b/arch/vc4/intc.c @@ -19,7 +19,7 @@ struct handlerArgPair irq_handlers[64]; // it will then push pc and sr onto the new stack // it will then read an entry from this vector table, and set the PC to that entry // if the highest bit on this addr is set, the cpu will switch into supervisor mode -irqType __attribute__ ((aligned (512))) vectorTable[128]; // might only need to be 128 entries +irqType __attribute__ ((aligned (512))) vectorTable[128]; uint8_t irq_stack0[4096]; diff --git a/default.nix b/default.nix index b70434bad..c5af5236c 100644 --- a/default.nix +++ b/default.nix @@ -21,7 +21,9 @@ in { inherit (arm7) littlekernel; }; vc4 = { - inherit (vc4) littlekernel; + shell = vc4.littlekernel; + rpi3.bootcode = vc4.callPackage ./lk.nix { project = "rpi3-bootcode"; }; + rpi4.start4 = vc4.callPackage ./lk.nix { project = "rpi4-start4"; }; }; x86_64 = { inherit (x86_64) uart-manager; diff --git a/nix/sources.json b/nix/sources.json new file mode 100644 index 000000000..1687272a5 --- /dev/null +++ b/nix/sources.json @@ -0,0 +1,38 @@ +{ + "niv": { + "branch": "master", + "description": "Easy dependency management for Nix projects", + "homepage": "https://github.com/nmattia/niv", + "owner": "nmattia", + "repo": "niv", + "rev": "61b61d1e5f8096fe65fb825bec23f33e861c51d0", + "sha256": "1dwfkd942wisccpsv0kf47abl0n17d9v4zasv4bm8lvy1dhv82ia", + "type": "tarball", + "url": "https://github.com/nmattia/niv/archive/61b61d1e5f8096fe65fb825bec23f33e861c51d0.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "nixpkgs": { + "branch": "nixos-19.03", + "description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to", + "homepage": "https://github.com/NixOS/nixpkgs", + "owner": "NixOS", + "repo": "nixpkgs-channels", + "rev": "c8db7a8a16ee9d54103cade6e766509e1d1c8d7b", + "sha256": "1b3h4mwpi10blzpvgsc0191k4shaw3nw0qd2p82hygbr8vv4g9dv", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs-channels/archive/c8db7a8a16ee9d54103cade6e766509e1d1c8d7b.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "rpi-open-firmware": { + "branch": "master", + "description": "Open source VPU side bootloader for Raspberry Pi.", + "homepage": null, + "owner": "cleverca22", + "repo": "rpi-open-firmware", + "rev": "b2d019aca2cc788a8f656ea28ca91c0df9ff7291", + "sha256": "1kiimh0gbjai6nbd1i06kbk1ymvhyr4xqd0196048hq8a9wf8kdb", + "type": "tarball", + "url": "https://github.com/cleverca22/rpi-open-firmware/archive/b2d019aca2cc788a8f656ea28ca91c0df9ff7291.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + } +} diff --git a/nix/sources.nix b/nix/sources.nix new file mode 100644 index 000000000..d4ac577f2 --- /dev/null +++ b/nix/sources.nix @@ -0,0 +1,93 @@ +# This file has been generated by Niv. + +# A record, from name to path, of the third-party packages +with rec +{ + pkgs = + if hasNixpkgsPath + then + if hasThisAsNixpkgsPath + then import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {} + else import {} + else + import (builtins_fetchTarball { inherit (sources_nixpkgs) url sha256; }) {}; + + sources_nixpkgs = + if builtins.hasAttr "nixpkgs" sources + then sources.nixpkgs + else abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; + + # fetchTarball version that is compatible between all the versions of Nix + builtins_fetchTarball = + { url, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchTarball; + in + if lessThan nixVersion "1.12" then + fetchTarball { inherit url; } + else + fetchTarball attrs; + + # fetchurl version that is compatible between all the versions of Nix + builtins_fetchurl = + { url, sha256 }@attrs: + let + inherit (builtins) lessThan nixVersion fetchurl; + in + if lessThan nixVersion "1.12" then + fetchurl { inherit url; } + else + fetchurl attrs; + + # A wrapper around pkgs.fetchzip that has inspectable arguments, + # annoyingly this means we have to specify them + fetchzip = { url, sha256 }@attrs: pkgs.fetchzip attrs; + + # A wrapper around pkgs.fetchurl that has inspectable arguments, + # annoyingly this means we have to specify them + fetchurl = { url, sha256 }@attrs: pkgs.fetchurl attrs; + + hasNixpkgsPath = (builtins.tryEval ).success; + hasThisAsNixpkgsPath = + (builtins.tryEval ).success && == ./.; + + sources = builtins.fromJSON (builtins.readFile ./sources.json); + + mapAttrs = builtins.mapAttrs or + (f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))); + + # borrowed from nixpkgs + functionArgs = f: f.__functionArgs or (builtins.functionArgs f); + callFunctionWith = autoArgs: f: args: + let auto = builtins.intersectAttrs (functionArgs f) autoArgs; + in f (auto // args); + + getFetcher = spec: + let fetcherName = + if builtins.hasAttr "type" spec + then builtins.getAttr "type" spec + else "builtin-tarball"; + in builtins.getAttr fetcherName { + "tarball" = fetchzip; + "builtin-tarball" = builtins_fetchTarball; + "file" = fetchurl; + "builtin-url" = builtins_fetchurl; + }; +}; +# NOTE: spec must _not_ have an "outPath" attribute +mapAttrs (_: spec: + if builtins.hasAttr "outPath" spec + then abort + "The values in sources.json should not have an 'outPath' attribute" + else + if builtins.hasAttr "url" spec && builtins.hasAttr "sha256" spec + then + spec // + { outPath = callFunctionWith spec (getFetcher spec) { }; } + else spec + ) sources diff --git a/arch/vc4/start.ld b/platform/bcm28xx/start.ld similarity index 100% rename from arch/vc4/start.ld rename to platform/bcm28xx/start.ld diff --git a/project/rpi4-vpu-test.mk b/project/rpi4-start4.mk similarity index 100% rename from project/rpi4-vpu-test.mk rename to project/rpi4-start4.mk