diff options
author | Pooya Moradi <pvonmoradi@gmail.com> | 2021-08-14 20:03:23 +0430 |
---|---|---|
committer | Pooya Moradi <pvonmoradi@gmail.com> | 2021-08-16 15:30:04 +0430 |
commit | fd49ef2d0ada0ba385090fc8bb0c89c4697cbf6b (patch) | |
tree | 46d43716fae9f47eaf424fa23fba5afb29614be6 /pkgs/development/embedded/bossa | |
parent | 7a069de4684bcbdd3f2f12596acb9e778e7b909e (diff) |
bossa: move the directory to pkgs/development/embedded/
Diffstat (limited to 'pkgs/development/embedded/bossa')
-rw-r--r-- | pkgs/development/embedded/bossa/bin2c.c | 122 | ||||
-rw-r--r-- | pkgs/development/embedded/bossa/bossa-no-applet-build.patch | 16 | ||||
-rw-r--r-- | pkgs/development/embedded/bossa/default.nix | 53 |
3 files changed, 191 insertions, 0 deletions
diff --git a/pkgs/development/embedded/bossa/bin2c.c b/pkgs/development/embedded/bossa/bin2c.c new file mode 100644 index 0000000000000..f0b915de540a6 --- /dev/null +++ b/pkgs/development/embedded/bossa/bin2c.c @@ -0,0 +1,122 @@ +// bin2c.c +// +// convert a binary file into a C source vector +// +// THE "BEER-WARE LICENSE" (Revision 3.1415): +// sandro AT sigala DOT it wrote this file. As long as you retain this notice you can do +// whatever you want with this stuff. If we meet some day, and you think this stuff is +// worth it, you can buy me a beer in return. Sandro Sigala +// +// syntax: bin2c [-c] [-z] <input_file> <output_file> +// +// -c add the "const" keyword to definition +// -z terminate the array with a zero (useful for embedded C strings) +// +// examples: +// bin2c -c myimage.png myimage_png.cpp +// bin2c -z sometext.txt sometext_txt.cpp + +#include <ctype.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#ifndef PATH_MAX +#define PATH_MAX 1024 +#endif + +int useconst = 0; +int zeroterminated = 0; + +int myfgetc(FILE *f) +{ + int c = fgetc(f); + if (c == EOF && zeroterminated) + { + zeroterminated = 0; + return 0; + } + return c; +} + +void process(const char *ifname, const char *ofname) +{ + FILE *ifile, *ofile; + ifile = fopen(ifname, "rb"); + if (ifile == NULL) + { + fprintf(stderr, "cannot open %s for reading\n", ifname); + exit(1); + } + ofile = fopen(ofname, "wb"); + if (ofile == NULL) + { + fprintf(stderr, "cannot open %s for writing\n", ofname); + exit(1); + } + char buf[PATH_MAX], *p; + const char *cp; + if ((cp = strrchr(ifname, '/')) != NULL) + { + ++cp; + } else { + if ((cp = strrchr(ifname, '\\')) != NULL) + ++cp; + else + cp = ifname; + } + strcpy(buf, cp); + for (p = buf; *p != '\0'; ++p) + { + if (!isalnum(*p)) + *p = '_'; + } + fprintf(ofile, "static %sunsigned char %s[] = {\n", useconst ? "const " : "", buf); + int c, col = 1; + while ((c = myfgetc(ifile)) != EOF) + { + if (col >= 78 - 6) + { + fputc('\n', ofile); + col = 1; + } + fprintf(ofile, "0x%.2x, ", c); + col += 6; + } + fprintf(ofile, "\n};\n"); + + fclose(ifile); + fclose(ofile); +} + +void usage(void) +{ + fprintf(stderr, "usage: bin2c [-cz] <input_file> <output_file>\n"); + exit(1); +} + +int main(int argc, char **argv) +{ + while (argc > 3) + { + if (!strcmp(argv[1], "-c")) + { + useconst = 1; + --argc; + ++argv; + } else if (!strcmp(argv[1], "-z")) + { + zeroterminated = 1; + --argc; + ++argv; + } else { + usage(); + } + } + if (argc != 3) + { + usage(); + } + process(argv[1], argv[2]); + return 0; +} diff --git a/pkgs/development/embedded/bossa/bossa-no-applet-build.patch b/pkgs/development/embedded/bossa/bossa-no-applet-build.patch new file mode 100644 index 0000000000000..4284245f485d7 --- /dev/null +++ b/pkgs/development/embedded/bossa/bossa-no-applet-build.patch @@ -0,0 +1,16 @@ +diff --git a/Makefile b/Makefile +index cc8882e..97b11ee 100644 +--- a/Makefile ++++ b/Makefile +@@ -184,11 +184,6 @@ $(foreach src,$(COMMON_SRCS),$(eval $(call common_obj,$(src)))) + # Applet rules + # + define applet_obj +-$(SRCDIR)/$(1:%.asm=%.cpp): $(SRCDIR)/$(1) +- @echo APPLET $(1:%.asm=%) +- $$(Q)$$(ARMAS) -o $$(@:%.o=%.obj) $$< +- $$(Q)$$(ARMOBJCOPY) -O binary $$(@:%.o=%.obj) $$(@:%.o=%.bin) +- $$(Q)appletgen $(1:%.asm=%) $(SRCDIR) $(OBJDIR) + $(OBJDIR)/$(1:%.asm=%.o): $(SRCDIR)/$(1:%.asm=%.cpp) + @echo CPP APPLET $$< + $$(Q)$$(CXX) $$(COMMON_CXXFLAGS) -c -o $$(@) $$(<:%.asm=%.cpp) diff --git a/pkgs/development/embedded/bossa/default.nix b/pkgs/development/embedded/bossa/default.nix new file mode 100644 index 0000000000000..4e35ff35f6603 --- /dev/null +++ b/pkgs/development/embedded/bossa/default.nix @@ -0,0 +1,53 @@ +{ lib, stdenv, fetchgit, wxGTK, libX11, readline }: + +let + # BOSSA needs a "bin2c" program to embed images. + # Source taken from: + # http://wiki.wxwidgets.org/Embedding_PNG_Images-Bin2c_In_C + bin2c = stdenv.mkDerivation { + name = "bossa-bin2c"; + src = ./bin2c.c; + dontUnpack = true; + buildPhase = "cc $src -o bin2c"; + installPhase = "mkdir -p $out/bin; cp bin2c $out/bin/"; + }; + +in +stdenv.mkDerivation { + pname = "bossa"; + version = "1.8"; + + src = fetchgit { + url = "https://github.com/shumatech/BOSSA"; + rev = "3be622ca0aa6214a2fc51c1ec682c4a58a423d62"; + sha256 = "19ik86qbffcb04cgmi4mnascbkck4ynfj87ha65qdk6fmp5q35vm"; + }; + + patches = [ ./bossa-no-applet-build.patch ]; + + nativeBuildInputs = [ bin2c ]; + buildInputs = [ wxGTK libX11 readline ]; + + # Explicitly specify targets so they don't get stripped. + makeFlags = [ "bin/bossac" "bin/bossash" "bin/bossa" ]; + NIX_CFLAGS_COMPILE = "-Wno-error=deprecated-declarations"; + + installPhase = '' + mkdir -p $out/bin + cp bin/bossa{c,sh,} $out/bin/ + ''; + + meta = with lib; { + description = "A flash programming utility for Atmel's SAM family of flash-based ARM microcontrollers"; + longDescription = '' + BOSSA is a flash programming utility for Atmel's SAM family of + flash-based ARM microcontrollers. The motivation behind BOSSA is + to create a simple, easy-to-use, open source utility to replace + Atmel's SAM-BA software. BOSSA is an acronym for Basic Open + Source SAM-BA Application to reflect that goal. + ''; + homepage = "http://www.shumatech.com/web/products/bossa"; + license = licenses.bsd3; + platforms = platforms.linux; + }; +} |