From 9c818c89bece3de8037614a2325af679f40e7adc Mon Sep 17 00:00:00 2001 From: Michael Bishop Date: Sun, 7 Nov 2021 03:25:49 -0400 Subject: [PATCH] allow building with nix --- Makefile | 5 ++++- emulator.c | 12 ++++++------ flake.lock | 25 +++++++++++++++++++++++++ flake.nix | 36 ++++++++++++++++++++++++++++++++++++ pistorm.nix | 35 +++++++++++++++++++++++++++++++++++ userland.patch | 14 ++++++++++++++ 6 files changed, 120 insertions(+), 7 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 pistorm.nix create mode 100644 userland.patch diff --git a/Makefile b/Makefile index 086d32a..5f4e8c3 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,7 @@ TARGET = $(EXENAME)$(EXE) DELETEFILES = $(MUSASHIGENCFILES) $(MUSASHIGENHFILES) $(.OFILES) $(.OFILES:%.o=%.d) $(TARGET) $(MUSASHIGENERATOR)$(EXE) -all: $(MUSASHIGENCFILES) $(MUSASHIGENHFILES) $(TARGET) +all: $(MUSASHIGENCFILES) $(MUSASHIGENHFILES) $(TARGET) buptest clean: rm -f $(DELETEFILES) @@ -70,6 +70,9 @@ clean: $(TARGET): $(MUSAHIGENCFILES:%.c=%.o) $(.CFILES:%.c=%.o) a314/a314.o $(CC) -o $@ $^ -O3 -pthread $(LFLAGS) -lm -lstdc++ +buptest: buptest.c gpio/ps_protocol.c + $(CC) $^ -o $@ -I./ -march=armv8-a -mfloat-abi=hard -mfpu=neon-fp-armv8 -O0 + a314/a314.o: a314/a314.cc a314/a314.h $(CXX) -MMD -MP -c -o a314/a314.o -O3 a314/a314.cc -march=armv8-a -mfloat-abi=hard -mfpu=neon-fp-armv8 -O3 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -I. -I.. diff --git a/emulator.c b/emulator.c index 80e81bd..978b010 100644 --- a/emulator.c +++ b/emulator.c @@ -358,14 +358,14 @@ void *keyboard_task() { struct pollfd kbdpoll[1]; int kpollrc; char c = 0, c_code = 0, c_type = 0; - char grab_message[] = "[KBD] Grabbing keyboard from input layer\n", - ungrab_message[] = "[KBD] Ungrabbing keyboard\n"; + char grab_message[] = "[KBD] Grabbing keyboard from input layer", + ungrab_message[] = "[KBD] Ungrabbing keyboard"; printf("[KBD] Keyboard thread started\n"); // because we permit the keyboard to be grabbed on startup, quickly check if we need to grab it if (kb_hook_enabled && cfg->keyboard_grab) { - printf(grab_message); + puts(grab_message); grab_device(keyboard_fd); } @@ -395,7 +395,7 @@ key_loop: printf("[KBD] Keyboard hook enabled.\n"); if (cfg->keyboard_grab) { grab_device(keyboard_fd); - printf(grab_message); + puts(grab_message); } } else if (kb_hook_enabled) { if (c == 0x1B && c_type) { @@ -403,7 +403,7 @@ key_loop: printf("[KBD] Keyboard hook disabled.\n"); if (cfg->keyboard_grab) { release_device(keyboard_fd); - printf(ungrab_message); + puts(ungrab_message); } } else { if (queue_keypress(c_code, c_type, cfg->platform->id)) { @@ -472,7 +472,7 @@ key_loop: key_end: printf("[KBD] Keyboard thread ending\n"); if (cfg->keyboard_grab) { - printf(ungrab_message); + puts(ungrab_message); release_device(keyboard_fd); } return (void*)NULL; diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..f4c335d --- /dev/null +++ b/flake.lock @@ -0,0 +1,25 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1636242081, + "narHash": "sha256-lfMU1G5sj1E5xBaR8JF0Nu2GBZ40iMNm205fh9cCJj4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "50d250c7db4070963cb403ad616042220e6bb221", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..a606903 --- /dev/null +++ b/flake.nix @@ -0,0 +1,36 @@ +{ + outputs = { self, nixpkgs }: + let + hostPkgs = import nixpkgs { system = "x86_64-linux"; }; + overlay = self: super: { + pistorm = self.callPackage ./pistorm.nix {}; + e2fsprogs = null; + libraspberrypi = super.libraspberrypi.overrideAttrs (old: { patches = [ ./userland.patch ]; }); + pistorm-tar = hostPkgs.callPackage (nixpkgs + "/nixos/lib/make-system-tarball.nix") { + contents = []; + storeContents = [ + { + object = self.pistorm; + symlink = "/pistorm"; + } + ]; + }; + }; + in { + packages.aarch64-linux = + let + pkgs = import nixpkgs { system = "aarch64-linux"; overlays = [ overlay ]; }; + in { + inherit (pkgs) pistorm; + }; + packages.armv7l-linux = + let + pkgs = import nixpkgs { system = "armv7l-linux"; overlays = [ overlay ]; }; + in { + inherit (pkgs) pistorm pistorm-tar; + }; + hydraJobs.armv7l-linux = { + inherit (self.packages.armv7l-linux) pistorm pistorm-tar; + }; + }; +} diff --git a/pistorm.nix b/pistorm.nix new file mode 100644 index 0000000..07319cb --- /dev/null +++ b/pistorm.nix @@ -0,0 +1,35 @@ +{ stdenv, libraspberrypi, alsaLib, openocd, makeWrapper }: + +stdenv.mkDerivation { + name = "pistorm"; + src = ./.; + enableParallelBuilding = false; + buildInputs = [ libraspberrypi alsaLib makeWrapper ]; + installPhase = '' + find | grep --color buptest + pwd + ls -ltrh + mkdir -pv $out/bin $out/share/pistorm + cp -vi emulator buptest $out/bin/ + cp -vr rtl $out/share/pistorm + cp -vr nprog $out/share/pistorm + cp -v *.cfg $out/share/pistorm + cp -vr data $out/share/pistorm + mkdir -pv $out/share/pistorm/platforms/amiga/piscsi + cp -v platforms/amiga/piscsi/piscsi.rom $out/share/pistorm/platforms/amiga/piscsi/ + cp -v platforms/amiga/pistorm.hdf $out/share/pistorm/platforms/amiga/ + + mkdir -pv $out/share/pistorm/platforms/amiga/rtg + cp -v platforms/amiga/rtg/*.shader $out/share/pistorm/platforms/amiga/rtg/ + + cat < $out/bin/pistorm + #!${stdenv.shell} + cd $out/share/pistorm + $out/bin/emulator "\''${@}" + EOF + chmod +x $out/bin/pistorm + + cp -v *.sh $out/bin/ + #wrapProgram $out/bin/nprog.sh --prefix PATH : {openocd}/bin + ''; +} diff --git a/userland.patch b/userland.patch new file mode 100644 index 0000000..3235fa7 --- /dev/null +++ b/userland.patch @@ -0,0 +1,14 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index fe67fc8..5154630 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -66,9 +66,7 @@ endif() + add_subdirectory(interface/vcos) + add_subdirectory(interface/vmcs_host) + add_subdirectory(interface/vchiq_arm) +-if(NOT ARM64) + add_subdirectory(interface/khronos) +-endif() + + #add_subdirectory(opensrc/tools/lua) + if(BUILD_MMAL)