code:
From b5314c20d8e3caf62fe0dc96ad937a2950158b23 Mon Sep 17 00:00:00 2001
From: Louis Gesbert <louis.gesbert@ocamlpro.com>
Date: Thu, 2 Mar 2017 12:19:56 +0100
Subject: [PATCH] Install mli, cmx, etc.

---
 Makefile | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/Makefile b/Makefile
index 09464ff..5044d7f 100644
--- a/Makefile
+++ b/Makefile
@@ -56,7 +56,7 @@ $(DOSELIBS)/cudf.%:
 	@for i in _build/cudf/cudf.*; do \
 	  if [ -e $$i ]; then \
 	  cp $$i $(DOSELIBS) ; \
-	  rm -f $(DOSELIBS)/*.mlpack $(DOSELIBS)/*.cmx ; \
+	  rm -f $(DOSELIBS)/*.mlpack ; \
 	  fi ; \
 	done

@@ -67,7 +67,7 @@ $(DOSELIBS)/common.%: common/*.ml common/*.mli
 	  if [ -e $$i ]; then \
 	  cp $$i $(DOSELIBS) ; \
 		rm $$i ;\
-	  rm -f $(DOSELIBS)/*.mlpack $(DOSELIBS)/*.cmx ; \
+	  rm -f $(DOSELIBS)/*.mlpack ; \
 	  fi ; \
 	done

@@ -78,7 +78,7 @@ $(DOSELIBS)/versioning.%: versioning/*.ml versioning/*.mli
 	  if [ -e $$i ]; then \
 	  cp $$i $(DOSELIBS) ; \
 		rm $$i ;\
-	  rm -f $(DOSELIBS)/*.mlpack $(DOSELIBS)/*.cmx ; \
+	  rm -f $(DOSELIBS)/*.mlpack ; \
 	  fi ; \
 	done

@@ -88,7 +88,7 @@ $(DOSELIBS)/algo.%: algo/*.ml algo/*.mli $(DOSELIBS)/common.%
 	  if [ -e $$i ]; then \
 	  cp $$i $(DOSELIBS) ; \
 		rm $$i ;\
-	  rm -f $(DOSELIBS)/*.mlpack $(DOSELIBS)/*.cmx ; \
+	  rm -f $(DOSELIBS)/*.mlpack ; \
 	  fi ; \
 	done

@@ -98,7 +98,7 @@ $(DOSELIBS)/debian.%: deb/*.ml deb/*.mli $(DOSELIBS)/pef.%
 	  if [ -e $$i ]; then \
 	  cp $$i $(DOSELIBS) ; \
 		rm $$i ;\
-	  rm -f $(DOSELIBS)/*.mlpack $(DOSELIBS)/*.cmx ; \
+	  rm -f $(DOSELIBS)/*.mlpack ; \
 	  fi ; \
 	done

@@ -108,7 +108,7 @@ $(DOSELIBS)/opam.%: opam/*.ml opam/*.mli $(DOSELIBS)/pef.%
 	  if [ -e $$i ]; then \
 	  cp $$i $(DOSELIBS) ; \
 		rm $$i ;\
-	  rm -f $(DOSELIBS)/*.mlpack $(DOSELIBS)/*.cmx ; \
+	  rm -f $(DOSELIBS)/*.mlpack ; \
 	  fi ; \
 	done

@@ -118,7 +118,7 @@ $(DOSELIBS)/npm.%: npm/*.ml npm/*.mli $(DOSELIBS)/versioning.% $(DOSELIBS)/pef.%
 	  if [ -e $$i ]; then \
 	  cp $$i $(DOSELIBS) ; \
 		rm $$i ;\
-	  rm -f $(DOSELIBS)/*.mlpack $(DOSELIBS)/*.cmx ; \
+	  rm -f $(DOSELIBS)/*.mlpack ; \
 	  fi ; \
 	done

@@ -128,7 +128,7 @@ $(DOSELIBS)/rpm.%: rpm/*.ml $(DOSELIBS)/algo.%
 	  if [ -e $$i ]; then \
 	  cp $$i $(DOSELIBS) ; \
 		rm $$i ;\
-	  rm -f $(DOSELIBS)/*.mlpack $(DOSELIBS)/*.cmx ; \
+	  rm -f $(DOSELIBS)/*.mlpack ; \
 	  fi ; \
 	done

@@ -138,7 +138,7 @@ $(DOSELIBS)/pef.%: pef/*.ml pef/*.mli
 	  if [ -e $$i ]; then \
 	  cp $$i $(DOSELIBS) ; \
 		rm $$i ;\
-	  rm -f $(DOSELIBS)/*.mlpack $(DOSELIBS)/*.cmx ; \
+	  rm -f $(DOSELIBS)/*.mlpack ; \
 	  fi ; \
 	done

@@ -148,7 +148,7 @@ $(DOSELIBS)/csw.%: opencsw/*.ml $(DOSELIBS)/versioning.%
 	  if [ -e $$i ]; then \
 	  cp $$i $(DOSELIBS) ; \
 		rm $$i ;\
-	  rm -f $(DOSELIBS)/*.mlpack $(DOSELIBS)/*.cmx ; \
+	  rm -f $(DOSELIBS)/*.mlpack ; \
 	  fi ; \
 	done

@@ -158,7 +158,7 @@ $(DOSELIBS)/doseparse.%: $(DOSELIBS)/pef.% $(DOSELIBS)/debian.%
 	  if [ -e $$i ]; then \
 	  cp $$i $(DOSELIBS) ; \
 		rm $$i ;\
-	  rm -f $(DOSELIBS)/*.mlpack $(DOSELIBS)/*.cmx $(DOSELIBS)/*.ml ; \
+	  rm -f $(DOSELIBS)/*.mlpack $(DOSELIBS)/*.ml ; \
 	  fi ; \
 	done

@@ -168,7 +168,7 @@ $(DOSELIBS)/doseparseNoRpm.%: $(DOSELIBS)/pef.% $(DOSELIBS)/debian.%
 	  if [ -e $$i ]; then \
 			cp $$i $(DOSELIBS) ;\
 			rm $$i ;\
-			rm -f $(DOSELIBS)/*.mlpack $(DOSELIBS)/*.cmx ;\
+			rm -f $(DOSELIBS)/*.mlpack ;\
 	  fi ; \
 	done

@@ -223,7 +223,7 @@ INSTALL_STUFF_ = META
 INSTALL_STUFF_ += $(wildcard _build/doselibs/*.cma _build/doselibs/*.cmi)
 INSTALL_STUFF_ += $(wildcard _build/doselibs/*.cmxa _build/doselibs/*.cmxs)
 INSTALL_STUFF_ += $(wildcard _build/doselibs/*.a)
-#INSTALL_STUFF_ += $(wildcard _build/*/*.mli)
+INSTALL_STUFF_ += $(wildcard _build/doselibs/*.mli) $(wildcard _build/doselibs/*.cmti) $(wildcard _build/doselibs/*.cmx)
 INSTALL_STUFF_ += $(wildcard _build/rpm/*.so)

 exclude_cudf = $(wildcard _build/doselibs/*cudf* _build/cudf/*)
--
2.11.0


code:
From b94cf24739818e5aff397e0a83b19ea32dc81f42 Mon Sep 17 00:00:00 2001
From: Louis Gesbert <louis.gesbert@ocamlpro.com>
Date: Tue, 6 Feb 2018 10:15:45 +0100
Subject: [PATCH 3/3] Add "unix" as dependency to dose3.common in META.in

---
 META.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/META.in b/META.in
index aa2cd8d..0f9d337 100644
--- a/META.in
+++ b/META.in
@@ -8,7 +8,7 @@ package "common" (
 version = "@PACKAGE_VERSION@"
 archive(byte) = "common.cma"
 archive(native) = "common.cmxa"
-requires = "extlib, re.pcre, cudf, @ZIP@, @BZ2@"
+requires = "extlib, re.pcre, cudf, unix, @ZIP@, @BZ2@"
 )

 package "algo" (
--
2.11.0

license: mit


code:
--- a/configure
+++ b/configure
@@ -6552,6 +6552,3 @@ if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
   { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
 fi
-
-
-make printconf


code:
From a87c3f20e846c00e53d695497dba7038edbd12f0 Mon Sep 17 00:00:00 2001
From: Valentin Lorentz <progval@progval.net>
Date: Thu, 13 Aug 2015 11:59:04 +0200
Subject: [PATCH] Enable ocamldoc to build reproducible manpages

Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=794586
Signed-off-by: Stephane Glondu <steph@glondu.net>
---
 ocamldoc/odoc_man.ml   | 15 +++++----------
 ocamldoc/odoc_misc.ml  | 12 ++++++++++--
 ocamldoc/odoc_misc.mli |  7 ++++++-
 3 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/ocamldoc/odoc_man.ml b/ocamldoc/odoc_man.ml
index 615c5e172..3c85aa32a 100644
--- a/ocamldoc/odoc_man.ml
+++ b/ocamldoc/odoc_man.ml
@@ -864,14 +864,13 @@ class man =
     (** Generate the man page for the given class.*)
     method generate_for_class cl =
       Odoc_info.reset_type_names () ;
-      let date = Unix.time () in
       let file = self#file_name cl.cl_name in
       try
         let chanout = self#open_out file in
         let b = new_buf () in
         bs b (".TH \""^cl.cl_name^"\" ");
         bs b !man_section ;
-        bs b (" "^(Odoc_misc.string_of_date ~hour: false date)^" ");
+        bs b (" source: "^Odoc_misc.current_date^" ");
         bs b "OCamldoc ";
         bs b ("\""^(match !Global.title with Some t -> t | None -> "")^"\"\n");

@@ -923,14 +922,13 @@ class man =
     (** Generate the man page for the given class type.*)
     method generate_for_class_type ct =
       Odoc_info.reset_type_names () ;
-      let date = Unix.time () in
       let file = self#file_name ct.clt_name in
       try
         let chanout = self#open_out file in
         let b = new_buf () in
         bs b (".TH \""^ct.clt_name^"\" ");
         bs b !man_section ;
-        bs b (" "^(Odoc_misc.string_of_date ~hour: false date)^" ");
+        bs b (" source: "^Odoc_misc.current_date^" ");
         bs b "OCamldoc ";
         bs b ("\""^(match !Global.title with Some t -> t | None -> "")^"\"\n");

@@ -1016,14 +1014,13 @@ class man =
     (** Generate the man file for the given module type.
        @raise Failure if an error occurs.*)
     method generate_for_module_type mt =
-      let date = Unix.time () in
       let file = self#file_name mt.mt_name in
       try
         let chanout = self#open_out file in
         let b = new_buf () in
         bs b (".TH \""^mt.mt_name^"\" ");
         bs b !man_section ;
-        bs b (" "^(Odoc_misc.string_of_date ~hour: false date)^" ");
+        bs b (" source: "^Odoc_misc.current_date^" ");
         bs b "OCamldoc ";
         bs b ("\""^(match !Global.title with Some t -> t | None -> "")^"\"\n");

@@ -1099,14 +1096,13 @@ class man =
     (** Generate the man file for the given module.
        @raise Failure if an error occurs.*)
     method generate_for_module m =
-      let date = Unix.time () in
       let file = self#file_name m.m_name in
       try
         let chanout = self#open_out file in
         let b = new_buf () in
         bs b (".TH \""^m.m_name^"\" ");
         bs b !man_section ;
-        bs b (" "^(Odoc_misc.string_of_date ~hour: false date)^" ");
+        bs b (" source: "^Odoc_misc.current_date^" ");
         bs b "OCamldoc ";
         bs b ("\""^(match !Global.title with Some t -> t | None -> "")^"\"\n");

@@ -1206,14 +1202,13 @@ class man =
           | Res_const (_,f) -> f.vc_name
          )
      in
-     let date = Unix.time () in
       let file = self#file_name name in
       try
         let chanout = self#open_out file in
         let b = new_buf () in
         bs b (".TH \""^name^"\" ");
         bs b !man_section ;
-        bs b (" "^(Odoc_misc.string_of_date ~hour: false date)^" ");
+        bs b (" source: "^Odoc_misc.current_date^" ");
         bs b "OCamldoc ";
         bs b ("\""^(match !Global.title with Some t -> t | None -> "")^"\"\n");
         bs b ".SH NAME\n";
diff --git a/ocamldoc/odoc_misc.ml b/ocamldoc/odoc_misc.ml
index 4c74476da..456225f62 100644
--- a/ocamldoc/odoc_misc.ml
+++ b/ocamldoc/odoc_misc.ml
@@ -223,9 +223,9 @@ let apply_opt f v_opt =
     None -> None
   | Some v -> Some (f v)

-let string_of_date ?(hour=true) d =
+let string_of_date ?(absolute=false) ?(hour=true) d =
   let add_0 s = if String.length s < 2 then "0"^s else s in
-  let t = Unix.localtime d in
+  let t = (if absolute then Unix.gmtime else Unix.localtime) d in
   (string_of_int (t.Unix.tm_year + 1900))^"-"^
   (add_0 (string_of_int (t.Unix.tm_mon + 1)))^"-"^
   (add_0 (string_of_int t.Unix.tm_mday))^
@@ -238,6 +238,14 @@ let string_of_date ?(hour=true) d =
      ""
   )

+let current_date =
+  let time =
+    try
+      float_of_string (Sys.getenv "SOURCE_DATE_EPOCH")
+    with
+      Not_found -> Unix.time ()
+  in string_of_date ~absolute: true ~hour: false time
+

 let rec text_list_concat sep l =
   match l with
diff --git a/ocamldoc/odoc_misc.mli b/ocamldoc/odoc_misc.mli
index dd5a7fcb9..38ff0612b 100644
--- a/ocamldoc/odoc_misc.mli
+++ b/ocamldoc/odoc_misc.mli
@@ -62,7 +62,12 @@ val apply_opt : ('a -> 'b) -> 'a option -> 'b option

 (** Return a string representing a date given as a number of seconds
    since 1970. The hour is optionnaly displayed. *)
-val string_of_date : ?hour:bool -> float -> string
+val string_of_date : ?absolute:bool -> ?hour:bool -> float -> string
+
+(* Value returned by string_of_date for current time.
+ * Uses environment variable SOURCE_DATE_EPOCH if set; falls back to
+ * current timestamp otherwise. *)
+val current_date : string

 (** Return the first sentence (until the first dot) of a text.
    Don't stop in the middle of [Code], [Verbatim], [List], [Lnum],
--
2.17.1


code:
From 2e7e254160506dc00f1beabf170512a8e932934b Mon Sep 17 00:00:00 2001
From: Julien Lepiller <julien@lepiller.eu>
Date: Sat, 31 Dec 2016 15:43:38 +0100
Subject: [PATCH] fix build date in binary

---
 src/magic/omake_gen_magic.ml | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/src/magic/omake_gen_magic.ml b/src/magic/omake_gen_magic.ml
index b2419ba..fad52f5 100644
--- a/src/magic/omake_gen_magic.ml
+++ b/src/magic/omake_gen_magic.ml
@@ -150,7 +150,7 @@ let ir_magic = "%s"
 let obj_magic = "%s"
 let lib_dir = "%s"
 let version = "%s"
-let version_message = "OMake %s:\\n\\tbuild [%s %s %d %02d:%02d:%02d %d]\\n\\ton %s"
+let version_message = "OMake %s"
 |}
        default_save_interval
        digest_len
@@ -160,15 +160,7 @@ let version_message = "OMake %s:\\n\\tbuild [%s %s %d %02d:%02d:%02d %d]\\n\\ton
        (digest_files ".omo.magic" ".omo" omo_files)
        (String.escaped libdir)
        (String.escaped (shorten_version version))
-       (String.escaped version)
-       [|"Sun"; "Mon"; "Tue"; "Wed"; "Thu"; "Fri"; "Sat"|].(tm.tm_wday)
-       [|"Jan"; "Feb"; "Mar"; "Apr"; "May"; "Jun"; "Jul"; "Aug"; "Sep"; "Oct"; "Nov"; "Dec"|].(tm.tm_mon)
-       tm.tm_mday
-       tm.tm_hour
-       tm.tm_min
-       tm.tm_sec
-       (tm.tm_year + 1900)
-       (String.escaped (Unix.gethostname ()));
+       (String.escaped version);
   List.iter
     (fun (name,value) ->
        Printf.fprintf buf "let %s = %S\n" name value
--
2.11.0


code:
Build against the system's HIDAPI instead of the bundled one.

--- open-zwave-1.6-checkout/cpp/build/support.mk	2019-06-16 15:15:34.258331628 +0200
+++ open-zwave-1.6-checkout/cpp/build/support.mk	2019-06-16 15:15:54.698249462 +0200
@@ -86,6 +86,10 @@ endif
 endif
 SED    := sed

+# Build against the system's HIDAPI.
+CPPFLAGS += $(shell pkg-config hidapi-libusb --cflags)
+LDFLAGS  += $(shell pkg-config hidapi-libusb --libs)
+
 #determine if we are release or debug Build and set appropriate flags
 ifeq ($(BUILD), release)
 CFLAGS	+= -c $(RELEASE_CFLAGS)


code:
From 52cea818bf68f8a2d3c48d55d00c2f8b7da25e4c Mon Sep 17 00:00:00 2001
From: Daniel Hogan <daniel.hogan@usask.ca>
Date: Tue, 28 Mar 2017 22:21:18 -0600
Subject: [PATCH] Remove delete statement.

When from_scratch is true, coordinates is not allocated. A separate if
statement was added to handle the case when from_scratch is true that
does not try to free coordinates.
---
 src/formats/nwchemformat.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/formats/nwchemformat.cpp b/src/formats/nwchemformat.cpp
index 6f625ad5b..79298555f 100644
--- a/src/formats/nwchemformat.cpp
+++ b/src/formats/nwchemformat.cpp
@@ -232,11 +232,14 @@ static const char* OPTIMIZATION_END_PATTERN = "  Optimization converged";
           break;
         tokenize(vs,buffer);
     }
-    if ((from_scratch)||(i != natoms))
-      {
+    if (from_scratch)
+    {
+        return;
+    }
+    if (i != natoms) {
         delete[] coordinates;
         return;
-      }
+    }
     molecule->AddConformer(coordinates);
   }


code:
Fix build with glibc 2.26:

https://github.com/tpaviot/oce/issues/675

Patch copied from upstream source repository:

https://github.com/tpaviot/oce/commit/aa1321e68cc004e3debe38d79ae74581a617c767

From aa1321e68cc004e3debe38d79ae74581a617c767 Mon Sep 17 00:00:00 2001
From: Janus Weil <janus@gcc.gnu.org>
Date: Mon, 18 Dec 2017 11:27:55 +0100
Subject: [PATCH] fix build errors with glibc 2.26+ due to missing xlocale.h
 (issue #675)

* check for the presence of xlocale.h via cmake
* remove related logic from Standard_CLocaleSentry.hxx
---
 CMakeLists.txt                          |  1 +
 src/Standard/Standard_CLocaleSentry.hxx | 15 ---------------
 2 files changed, 1 insertion(+), 15 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b782b4101..50e9500b2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -616,6 +616,7 @@ if (NOT WIN32)
 	# compilation anywhere in OCE
 	include(CheckIncludeFile)
 	check_include_file(strings.h HAVE_STRINGS_H)
+	check_include_file(xlocale.h HAVE_XLOCALE_H)
 	include(CheckIncludeFileCXX)
 	check_include_file_cxx(mm_malloc.h HAVE_MM_MALLOC_H)
 	check_include_file_cxx(atomic.h OCE_HAVE_ATOMIC_H)
diff --git a/src/Standard/Standard_CLocaleSentry.hxx b/src/Standard/Standard_CLocaleSentry.hxx
index 2b226e7f3..1a4c1dadc 100644
--- a/src/Standard/Standard_CLocaleSentry.hxx
+++ b/src/Standard/Standard_CLocaleSentry.hxx
@@ -20,21 +20,6 @@

 #include <locale.h>

-#ifndef HAVE_XLOCALE_H
-  //! "xlocale.h" available in Mac OS X and glibc (Linux) for a long time as an extension
-  //! and become part of POSIX since '2008.
-  //! Notice that this is impossible to test (_POSIX_C_SOURCE >= 200809L)
-  //! since POSIX didn't declared such identifier.
-  #if defined(__APPLE__)
-    #define HAVE_XLOCALE_H
-  #endif
-
-  //! We check _GNU_SOURCE for glibc extensions here and it is always defined by g++ compiler.
-  #if defined(_GNU_SOURCE) && !defined(__ANDROID__)
-    #define HAVE_XLOCALE_H
-  #endif
-#endif // ifndef HAVE_LOCALE_H
-
 #ifdef HAVE_XLOCALE_H
   #include <xlocale.h>
 #endif
--
2.15.1


code:
From: Tobias Geerinckx-Rice <me@tobias.gr>
Date: Thu, 13 Aug 2020 15:21:30 +0200
Subject: [PATCH] gnu: opencv: Fix build with Jasper 2.0.19.

Taken verbatim from upstream: <https://github.com/opencv/opencv/issues/17984>.

From f66fc199a20882c546fa31142e9c0f5a8b3cf983 Mon Sep 17 00:00:00 2001
From: Florian Jung <flo@windfis.ch>
Date: Wed, 29 Jul 2020 18:51:55 +0200
Subject: [PATCH] Fix build of grfmt_jpeg2000.cpp

libjasper has recently changed `jas_matrix_get` from a macro to an inline function
(389951d071 in https://github.com/jasper-software/jasper), causing the build to fail.
---
 modules/imgcodecs/src/grfmt_jpeg2000.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/modules/imgcodecs/src/grfmt_jpeg2000.cpp b/modules/imgcodecs/src/grfmt_jpeg2000.cpp
index fe69f80c86f..0f4d28d6f4d 100644
--- a/modules/imgcodecs/src/grfmt_jpeg2000.cpp
+++ b/modules/imgcodecs/src/grfmt_jpeg2000.cpp
@@ -377,7 +377,7 @@ bool  Jpeg2KDecoder::readComponent8u( uchar *data, void *_buffer,

     for( y = 0; y < yend - ystart; )
     {
-        jas_seqent_t* pix_row = &jas_matrix_get( buffer, y / ystep, 0 );
+        jas_seqent_t* pix_row = jas_matrix_getref( buffer, y / ystep, 0 );
         uchar* dst = data + (y - yoffset) * step - xoffset;

         if( xstep == 1 )
@@ -443,7 +443,7 @@ bool  Jpeg2KDecoder::readComponent16u( unsigned short *data, void *_buffer,

     for( y = 0; y < yend - ystart; )
     {
-        jas_seqent_t* pix_row = &jas_matrix_get( buffer, y / ystep, 0 );
+        jas_seqent_t* pix_row = jas_matrix_getref( buffer, y / ystep, 0 );
         ushort* dst = data + (y - yoffset) * step - xoffset;

         if( xstep == 1 )


code:
https://github.com/opencv/opencv_contrib/commit/8aaa91c3dc835690477d7777e66948dbf5a87edc.patch

From 8aaa91c3dc835690477d7777e66948dbf5a87edc Mon Sep 17 00:00:00 2001
From: Tomoaki Teshima <tomoaki.teshima@gmail.com>
Date: Mon, 5 Nov 2018 20:32:23 +0900
Subject: [PATCH] avoid test failing on Aarch64   * loosen the threshold in
 Rgbd_Normals.compute   * make the minimum tvec larger in
 RGBD_Odometry_Rgbd.algorithmic

---
 modules/rgbd/test/test_normal.cpp   | 2 +-
 modules/rgbd/test/test_odometry.cpp | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/modules/rgbd/test/test_normal.cpp b/modules/rgbd/test/test_normal.cpp
index f2233553a7..ed54f2cd98 100644
--- a/modules/rgbd/test/test_normal.cpp
+++ b/modules/rgbd/test/test_normal.cpp
@@ -211,7 +211,7 @@ class CV_RgbdNormalsTest: public cvtest::BaseTest
             std::cout << std::endl << "*** FALS" << std::endl;
             errors[0][0] = 0.006f;
             errors[0][1] = 0.03f;
-            errors[1][0] = 0.00008f;
+            errors[1][0] = 0.0001f;
             errors[1][1] = 0.02f;
             break;
           case 1:
diff --git a/modules/rgbd/test/test_odometry.cpp b/modules/rgbd/test/test_odometry.cpp
index 62b654a1ec..f5a2084504 100644
--- a/modules/rgbd/test/test_odometry.cpp
+++ b/modules/rgbd/test/test_odometry.cpp
@@ -213,7 +213,7 @@ void CV_OdometryTest::generateRandomTransformation(Mat& rvec, Mat& tvec)
     normalize(rvec, rvec, rng.uniform(0.007f, maxRotation));

     randu(tvec, Scalar(-1000), Scalar(1000));
-    normalize(tvec, tvec, rng.uniform(0.007f, maxTranslation));
+    normalize(tvec, tvec, rng.uniform(0.008f, maxTranslation));
 }

 void CV_OdometryTest::run(int)


code:
From e2b39dd3a0742853e00f9c3e8c46c911da20bed7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Tue, 30 Jun 2020 10:42:49 -0400
Subject: [PATCH 1/4] http/request: make terminate public

---
 include/opendht/http.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/include/opendht/http.h b/include/opendht/http.h
index cc8d5f9..46b722c 100644
--- a/include/opendht/http.h
+++ b/include/opendht/http.h
@@ -294,6 +294,7 @@ public:
      * User action to cancel the Request and call the completion callbacks.
      */
     void cancel();
+    void terminate(const asio::error_code& ec);

 private:
     using OnCompleteCb = std::function<void()>;
@@ -320,8 +321,6 @@ private:

     void connect(std::vector<asio::ip::tcp::endpoint>&& endpoints, HandlerCb cb = {});

-    void terminate(const asio::error_code& ec);
-
     void post();

     void handle_request(const asio::error_code& ec);
--
2.27.0


code:
# This patch removes all need for the ThirdParty files of OpenFOAM.

# Derived from EasyBuild patch by Ward Poelmans <wpoely86@gmail.com>.
# Modified for GNU Guix by Paul Garlick <pgarlick@tourbillion-technology.com>.

diff -ur OpenFOAM-4.x-version-4.1.org/applications/utilities/mesh/manipulation/setSet/Allwmake OpenFOAM-4.x-version-4.1/applications/utilities/mesh/manipulation/setSet/Allwmake
--- OpenFOAM-4.x-version-4.1.org/applications/utilities/mesh/manipulation/setSet/Allwmake
+++ OpenFOAM-4.x-version-4.1/applications/utilities/mesh/manipulation/setSet/Allwmake
@@ -9,7 +9,7 @@
 #
 # use readline if available
 #
-if [ -f /usr/include/readline/readline.h ]
+if true
 then
     echo "Found <readline/readline.h>  --  enabling readline support."
     export COMP_FLAGS="-DHAS_READLINE"
diff -ur OpenFOAM-4.x-version-4.1.org/etc/bashrc OpenFOAM-4.x-version-4.1/etc/bashrc
--- OpenFOAM-4.x-version-4.1.org/etc/bashrc
+++ OpenFOAM-4.x-version-4.1/etc/bashrc
@@ -43,8 +43,10 @@
 # Please set to the appropriate path if the default is not correct.
 #
 [ $BASH_SOURCE ] && \
-export FOAM_INST_DIR=$(cd ${BASH_SOURCE%/*/*/*} && pwd -P) || \
+export FOAM_INST_DIR=$(cd $(dirname $BASH_SOURCE)/../.. && pwd -P) || \
 export FOAM_INST_DIR=$HOME/$WM_PROJECT
+# For GNU Guix: set initially for build then re-set at runtime
+#
 # export FOAM_INST_DIR=~$WM_PROJECT
 # export FOAM_INST_DIR=/opt/$WM_PROJECT
 # export FOAM_INST_DIR=/usr/local/$WM_PROJECT
diff -ur OpenFOAM-4.x-version-4.1.org/etc/config.sh/CGAL OpenFOAM-4.x-version-4.1/etc/config.sh/CGAL
--- OpenFOAM-4.x-version-4.1.org/etc/config.sh/CGAL
+++ OpenFOAM-4.x-version-4.1/etc/config.sh/CGAL
@@ -36,37 +36,7 @@
 #
 #------------------------------------------------------------------------------

-boost_version=boost-system
-cgal_version=cgal-system
-#cgal_version=CGAL-4.8
-
-if [ -z "$SOURCE_CGAL_VERSIONS_ONLY" ]
-then
-
-    common_path=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER
-
-    export BOOST_ARCH_PATH=$common_path/$boost_version
-    export CGAL_ARCH_PATH=$common_path/$cgal_version
-
-    if [ "$FOAM_VERBOSE" -a "$PS1" ]
-    then
-        echo "Using CGAL and boost" 1>&2
-        echo "    $cgal_version at $CGAL_ARCH_PATH" 1>&2
-        echo "    $boost_version at $BOOST_ARCH_PATH" 1>&2
-    fi
-
-    if [ -d "$CGAL_ARCH_PATH" -a "$cgal_version" != "cgal-system" ]
-    then
-        _foamAddLib $CGAL_ARCH_PATH/lib
-    fi
-
-    if [ -d "$BOOST_ARCH_PATH" -a "$boost_version" != "boost-system" ]
-    then
-        _foamAddLib $BOOST_ARCH_PATH/lib
-    fi
-
-    unset boost_version cgal_version common_path
-
-fi
+export CGAL_ARCH_PATH=$CGAL_ROOT
+export BOOST_ARCH_PATH=$BOOST_ROOT

 #------------------------------------------------------------------------------
diff -ur OpenFOAM-4.x-version-4.1.org/etc/config.sh/gperftools OpenFOAM-4.x-version-4.1/etc/config.sh/gperftools
--- OpenFOAM-4.x-version-4.1.org/etc/config.sh/gperftools
+++ OpenFOAM-4.x-version-4.1/etc/config.sh/gperftools
@@ -29,13 +29,5 @@
 #
 #------------------------------------------------------------------------------

-version=svn
-gperftools_install=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER
-
-GPERFTOOLS_VERSION=gperftools-$version
-GPERFTOOLS_ARCH_PATH=$gperftools_install/$GPERFTOOLS_VERSION
-
-export PATH=$GPERFTOOLS_ARCH_PATH/bin:$PATH
-export LD_LIBRARY_PATH=$GPERFTOOLS_ARCH_PATH/lib:$LD_LIBRARY_PATH

 #------------------------------------------------------------------------------
diff -ur OpenFOAM-4.x-version-4.1.org/etc/config.sh/metis OpenFOAM-4.x-version-4.1/etc/config.sh/metis
--- OpenFOAM-4.x-version-4.1.org/etc/config.sh/metis
+++ OpenFOAM-4.x-version-4.1/etc/config.sh/metis
@@ -34,7 +34,7 @@
 #
 #------------------------------------------------------------------------------

-export METIS_VERSION=metis-5.1.0
-export METIS_ARCH_PATH=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER$WM_PRECISION_OPTION$WM_LABEL_OPTION/$METIS_VERSION
+export METIS_VERSION=metis-$METISVERSION
+export METIS_ARCH_PATH=$METIS_ROOT

 #------------------------------------------------------------------------------
diff -ur OpenFOAM-4.x-version-4.1.org/etc/config.sh/scotch OpenFOAM-4.x-version-4.1/etc/config.sh/scotch
--- OpenFOAM-4.x-version-4.1.org/etc/config.sh/scotch
+++ OpenFOAM-4.x-version-4.1/etc/config.sh/scotch
@@ -37,7 +37,7 @@
 #
 #------------------------------------------------------------------------------

-export SCOTCH_VERSION=scotch_6.0.3
-export SCOTCH_ARCH_PATH=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER$WM_PRECISION_OPTION$WM_LABEL_OPTION/$SCOTCH_VERSION
+export SCOTCH_VERSION=scotch_$SCOTCHVERSION
+export SCOTCH_ARCH_PATH=$SCOTCH_ROOT

 #------------------------------------------------------------------------------
diff -ur OpenFOAM-4.x-version-4.1.org/etc/config.sh/settings OpenFOAM-4.x-version-4.1/etc/config.sh/settings
--- OpenFOAM-4.x-version-4.1.org/etc/config.sh/settings
+++ OpenFOAM-4.x-version-4.1/etc/config.sh/settings
@@ -279,6 +279,9 @@
     ;;
 system)
     # Use system compiler
+    # Use system GMP and MPFR packages
+    export GMP_ARCH_PATH=$GMP_ROOT
+    export MPFR_ARCH_PATH=$MPFR_ROOT
     ;;
 *)
     echo "Warn: WM_COMPILER_TYPE='$WM_COMPILER_TYPE' is unsupported" 1>&2
diff -ur OpenFOAM-4.x-version-4.1.org/src/parallel/decompose/ptscotchDecomp/Make/options OpenFOAM-4.x-version-4.1/src/parallel/decompose/ptscotchDecomp/Make/options
--- OpenFOAM-4.x-version-4.1.org/src/parallel/decompose/ptscotchDecomp/Make/options
+++ OpenFOAM-4.x-version-4.1/src/parallel/decompose/ptscotchDecomp/Make/options
@@ -5,8 +5,7 @@
     $(PFLAGS) $(PINC) \
     -I$(SCOTCH_ROOT)/include \
     -I$(SCOTCH_ARCH_PATH)/include/$(FOAM_MPI) \
-    -I/usr/include/scotch \
     -I../decompositionMethods/lnInclude

 LIB_LIBS = \
-    -L$(SCOTCH_ROOT)/lib -L$(FOAM_EXT_LIBBIN)/$(FOAM_MPI) -lptscotch -lptscotcherrexit -lscotch ${LINK_FLAGS} -lrt
+    -L$(SCOTCH_ROOT)/lib -L$(MPI_ARCH_PATH)/lib -lptscotch -lptscotcherrexit -lscotch ${LINK_FLAGS} -lrt
diff -ur OpenFOAM-4.x-version-4.1.org/src/parallel/decompose/scotchDecomp/Make/options OpenFOAM-4.x-version-4.1/src/parallel/decompose/scotchDecomp/Make/options
--- OpenFOAM-4.x-version-4.1.org/src/parallel/decompose/scotchDecomp/Make/options
+++ OpenFOAM-4.x-version-4.1/src/parallel/decompose/scotchDecomp/Make/options
@@ -9,8 +9,7 @@
     $(PFLAGS) $(PINC) \
     -I$(SCOTCH_ROOT)/include \
     -I$(SCOTCH_ARCH_PATH)/include \
-    -I/usr/include/scotch \
     -I../decompositionMethods/lnInclude

 LIB_LIBS = \
-    -L$(SCOTCH_ROOT)/lib -L$(FOAM_EXT_LIBBIN) -lscotch -lscotcherrexit -lrt
+    -L$(SCOTCH_ROOT)/lib -lscotch -lscotcherrexit -lrt
diff -ur OpenFOAM-4.x-version-4.1.org/wmake/makefiles/general OpenFOAM-4.x-version-4.1/wmake/makefiles/general
--- OpenFOAM-4.x-version-4.1.org/wmake/makefiles/general
+++ OpenFOAM-4.x-version-4.1/wmake/makefiles/general
@@ -33,7 +33,6 @@
 # The Makefile uses a POSIX shell
 #------------------------------------------------------------------------------

-SHELL           = /bin/sh

 #------------------------------------------------------------------------------
diff -ur OpenFOAM-4.x-version-4.1.org/wmake/wmake OpenFOAM-4.x-version-4.1/wmake/wmake
--- OpenFOAM-4.x-version-4.1.org/wmake/wmake
+++ OpenFOAM-4.x-version-4.1/wmake/wmake
@@ -163,7 +163,7 @@
 then
     if [ "$WM_NCOMPPROCS" -gt 1 -a ! "$MAKEFLAGS" ]
     then
-        lockDir=$HOME/.$WM_PROJECT/.wmake
+        lockDir=$(cd $(dirname $BASH_SOURCE)/../.. && pwd -P)/.$WM_PROJECT/.wmake

         if [ -d $lockDir ]
         then
diff -ur OpenFOAM-4.x-version-4.1.org/wmake/wmakeScheduler OpenFOAM-4.x-version-4.1/wmake/wmakeScheduler
--- OpenFOAM-4.x-version-4.1.org/wmake/wmakeScheduler
+++ OpenFOAM-4.x-version-4.1/wmake/wmakeScheduler
@@ -53,7 +53,7 @@
 # csh sets HOST, bash sets HOSTNAME
 : ${HOST:=$HOSTNAME}

-lockDir=$HOME/.$WM_PROJECT/.wmake
+lockDir=$(cd $(dirname $BASH_SOURCE)/../.. && pwd -P)/.$WM_PROJECT/.wmake

 # Fallback - 1 core on current host
 : ${WM_HOSTS:=$HOST:1}
diff -ur OpenFOAM-4.x-version-4.1.org/wmake/wmakeSchedulerUptime OpenFOAM-4.x-version-4.1/wmake/wmakeSchedulerUptime
--- OpenFOAM-4.x-version-4.1.org/wmake/wmakeSchedulerUptime
+++ OpenFOAM-4.x-version-4.1/wmake/wmakeSchedulerUptime
@@ -53,7 +53,7 @@
 # csh sets HOST, bash sets HOSTNAME
 : ${HOST:=$HOSTNAME}

-lockDir=$HOME/.$WM_PROJECT/.wmake
+lockDir=$(cd $(dirname $BASH_SOURCE)/../.. && pwd -P)/.$WM_PROJECT/.wmake
 # Fallback - 1 core on current host
 : ${WM_HOSTS:=$HOST:1}

diff -ur OpenFOAM-4.x-version-4.1.org/src/parallel/decompose/metisDecomp/metisDecomp.C OpenFOAM-4.x-version-4.1/src/parallel/decompose/metisDecomp/metisDecomp.C
--- OpenFOAM-4.x-version-4.1.org/src/parallel/decompose/metisDecomp/metisDecomp.C
+++ OpenFOAM-4.x-version-4.1/src/parallel/decompose/metisDecomp/metisDecomp.C
@@ -67,7 +67,7 @@

     // Processor weights initialised with no size, only used if specified in
     // a file
-    Field<scalar> processorWeights;
+    Field<floatScalar> processorWeights;

     // Cell weights (so on the vertices of the dual)
     List<label> cellWeights;
diff -ur OpenFOAM-4.x-version-4.1.org/wmake/rules/General/CGAL OpenFOAM-4.x-version-4.1/wmake/rules/General/CGAL
--- OpenFOAM-4.x-version-4.1.org/wmake/rules/General/CGAL
+++ OpenFOAM-4.x-version-4.1/wmake/rules/General/CGAL
@@ -6,9 +6,10 @@
     -I/usr/include

 CGAL_LIBS = \
-    -L$(MPFR_ARCH_PATH)/lib$(WM_COMPILER_LIB_ARCH) \
-    -L$(GMP_ARCH_PATH)/lib$(WM_COMPILER_LIB_ARCH) \
+    -L$(MPFR_ARCH_PATH)/lib \
+    -L$(GMP_ARCH_PATH)/lib \
     -L$(BOOST_ARCH_PATH)/lib \
     -L$(CGAL_ARCH_PATH)/lib \
     -lCGAL \
+    -lgmp \
     -lmpfr
diff -ur OpenFOAM-4.x-version-4.1.org/wmake/rules/linux64Gcc/c++ OpenFOAM-4.x-version-4.1/wmake/rules/linux64Gcc/c++
--- OpenFOAM-4.x-version-4.1.org/wmake/rules/linux64Gcc/c++
+++ OpenFOAM-4.x-version-4.1/wmake/rules/linux64Gcc/c++
@@ -20,5 +20,5 @@

 LINK_LIBS   = $(c++DBUG)

-LINKLIBSO   = $(CC) $(c++FLAGS) -shared -Xlinker --add-needed -Xlinker --no-as-needed
-LINKEXE     = $(CC) $(c++FLAGS) -Xlinker --add-needed -Xlinker --no-as-needed
+LINKLIBSO   = $(CC) $(c++FLAGS) $(LDFLAGS) -shared -Xlinker --add-needed -Xlinker --no-as-needed
+LINKEXE     = $(CC) $(c++FLAGS) $(LDFLAGS) -Xlinker --add-needed -Xlinker --no-as-needed


code:
From a0a0c6a43b88d946f2b5484892cf0209bd7c0e68 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=A1bor=20Boskovits?= <boskovits@gmail.com>
Date: Sat, 8 Dec 2018 21:25:31 +0100
Subject: [PATCH] Make idlj respect SOURCE_DATE_EPOCH.

---
 .../sun/tools/corba/se/idl/toJavaPortable/Util.java | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/java.corba/share/classes/com/sun/tools/corba/se/idl/toJavaPortable/Util.java b/src/java.corba/share/classes/com/sun/tools/corba/se/idl/toJavaPortable/Util.java
index 7397619f2..583d6b8e4 100644
--- a/src/java.corba/share/classes/com/sun/tools/corba/se/idl/toJavaPortable/Util.java
+++ b/src/java.corba/share/classes/com/sun/tools/corba/se/idl/toJavaPortable/Util.java
@@ -1146,7 +1146,18 @@ public class Util extends com.sun.tools.corba.se.idl.Util
     else
       formatter.setTimeZone (java.util.TimeZone.getDefault ());

-    stream.println ("* " + formatter.format (new Date ()));
+    try {
+	String epoch = System.getenv("SOURCE_DATE_EPOCH");
+	if(epoch != null) {
+	    long unixTime = Long.parseLong(epoch);
+	    stream.println ("* " + formatter.format (new Date (unixTime*1000L)));
+	} else {
+	    stream.println ("* " + formatter.format (new Date ()));
+	}
+    } catch (Exception e) {
+	//in case of error fall back to default
+	stream.println ("* " + formatter.format (new Date ()));
+    }

     // <daz>
     ///////////////
--
2.19.2


code:
--- jdk14-bc54620a3848/make/autoconf/basics.m4	2020-02-07 04:40:54.000000000 +1030
+++ jdk14-bc54620a3848-new/make/autoconf/basics.m4	2020-04-24 10:59:33.056098506 +0930
@@ -583,7 +583,7 @@
   BASIC_SETUP_TOOL($1, [AC_PATH_PROGS($1, $2, , $3)])
   if test "x[$]$1" = x; then
     AC_MSG_NOTICE([Required tool $2 not found in PATH, checking built-in])
-    if help $2 > /dev/null 2>&1; then
+    if command -v $2 > /dev/null 2>&1; then
       AC_MSG_NOTICE([Found $2 as shell built-in. Using it])
       $1="$2"
     else


code:
PSM2 is the only valid implementation for OmniPath (OPA).  UCX also
supports OmniPath, but it does so via Verbs, thus getting much lower
performance (typically 3 GiB/s instead of 10 GiB/s).

To work around that, give the mtl_psm2 component a higher priority
than the pml_ucx component.

See <https://www.mail-archive.com/users@lists.open-mpi.org/msg33581.html>.

--- openmpi-4.0.2/ompi/mca/mtl/psm2/mtl_psm2_component.c	2019-11-15 17:06:15.142076840 +0100
+++ openmpi-4.0.2/ompi/mca/mtl/psm2/mtl_psm2_component.c	2019-11-15 17:06:22.242009379 +0100
@@ -126,7 +126,7 @@ ompi_mtl_psm2_component_register(void)
         setenv("PSM2_DEVICES", "self,shm", 0);
     }

-    param_priority = 40;
+    param_priority = 55;
     (void) mca_base_component_var_register (&mca_mtl_psm2_component.super.mtl_version,
                                             "priority", "Priority of the PSM2 MTL component",
                                             MCA_BASE_VAR_TYPE_INT, NULL, 0, 0,

Likewise for PSM: we want InfiniPath to be taken care of by PSM, not by UCX,
since UCX achieves worse performance.

--- openmpi-4.0.2/ompi/mca/mtl/psm/mtl_psm_component.c
+++ openmpi-4.0.2/ompi/mca/mtl/psm/mtl_psm_component.c
@@ -92,7 +92,7 @@ ompi_mtl_psm_component_register(void)

     /* set priority high enough to beat ob1's default */
-    param_priority = 30;
+    param_priority = 54;
     (void) mca_base_component_var_register (&mca_mtl_psm_component.super.mtl_version,
                                             "priority", "Priority of the PSM MTL component",
                                             MCA_BASE_VAR_TYPE_INT, NULL, 0, 0,


code:
This patch adds support for nRF52 series devices.  It is patchset 7 from
<http://openocd.zylin.com/#/c/3511/>, which has been tested, but not
merged yet in master.

From: Michael Dietz <mjdietzx@gmail.com>
Date: Mon, 30 May 2016 12:50:44 +0000 (-0700)
Subject: Added support for nRF52 Series Devices.
X-Git-Url: http://openocd.zylin.com/gitweb?p=openocd.git;a=commitdiff_plain;h=9ba15633e221d9d72e320372ba8f49d3f30d4bce

Added support for nRF52 Series Devices.

Both nrf52.c and nrf52.cfg are based off of previous nRF51 files.
- Some possible race conditions with NVMC have been fixed in nRF52.c
- Removed nrf51_get_probed_chip_if_halted() as the core does not have to be halted to perform operations where it is called.
- Only registers that are needed by openOCD are defined, some registers in nRF51 don't exist in nRF52 and are removed.
- Some all around cleanup has been done.
- The protection mechanism is completely different on nRF52 and this has not been implemented yet - just prints a warning and returns for now.

Change-Id: I4dd42c86f33f450709bb981806c2655f04aa6201
Signed-off-by: Michael Dietz <mjdietzx@gmail.com>
---

diff --git a/src/flash/nor/Makefile.am b/src/flash/nor/Makefile.am
index 727e4f2..839667c 100644
--- a/src/flash/nor/Makefile.am
+++ b/src/flash/nor/Makefile.am
@@ -36,6 +36,7 @@ NOR_DRIVERS = \
 	%D%/niietcm4.c \
 	%D%/non_cfi.c \
 	%D%/nrf51.c \
+	%D%/nrf52.c \
 	%D%/numicro.c \
 	%D%/ocl.c \
 	%D%/pic32mx.c \
diff --git a/src/flash/nor/drivers.c b/src/flash/nor/drivers.c
index 56a5cb2..071273e 100644
--- a/src/flash/nor/drivers.c
+++ b/src/flash/nor/drivers.c
@@ -48,6 +48,7 @@ extern struct flash_driver mdr_flash;
 extern struct flash_driver mrvlqspi_flash;
 extern struct flash_driver niietcm4_flash;
 extern struct flash_driver nrf51_flash;
+extern struct flash_driver nrf52_flash;
 extern struct flash_driver numicro_flash;
 extern struct flash_driver ocl_flash;
 extern struct flash_driver pic32mx_flash;
@@ -100,6 +101,7 @@ static struct flash_driver *flash_drivers[] = {
 	&mrvlqspi_flash,
 	&niietcm4_flash,
 	&nrf51_flash,
+       &nrf52_flash,
 	&numicro_flash,
 	&ocl_flash,
 	&pic32mx_flash,
diff --git a/src/flash/nor/nrf52.c b/src/flash/nor/nrf52.c
new file mode 100644
index 0000000..7f2bd35
--- /dev/null
+++ b/src/flash/nor/nrf52.c
@@ -0,0 +1,733 @@
+/***************************************************************************
+ *   Copyright (C) 2013 Synapse Product Development                        *
+ *   Andrey Smirnov <andrew.smironv@gmail.com>                             *
+ *   Angus Gratton <gus@projectgus.com>                                    *
+ *   Erdem U. Altunyurt <spamjunkeater@gmail.com>                          *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
+ ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+
+#include "imp.h"
+#include <target/algorithm.h>
+#include <target/armv7m.h>
+#include <helper/types.h>
+
+/* nRF52 Register addresses used by openOCD. */
+#define NRF52_FLASH_BASE_ADDR        (0x0)
+
+#define NRF52_FICR_BASE_ADDR         (0x10000000)
+#define NRF52_FICR_CODEPAGESIZE_ADDR (NRF52_FICR_BASE_ADDR | 0x010)
+#define NRF52_FICR_CODESIZE_ADDR     (NRF52_FICR_BASE_ADDR | 0x014)
+
+#define NRF52_UICR_BASE_ADDR         (0x10001000)
+
+#define NRF52_NVMC_BASE_ADDR         (0x4001E000)
+#define NRF52_NVMC_READY_ADDR        (NRF52_NVMC_BASE_ADDR | 0x400)
+#define NRF52_NVMC_CONFIG_ADDR       (NRF52_NVMC_BASE_ADDR | 0x504)
+#define NRF52_NVMC_ERASEPAGE_ADDR    (NRF52_NVMC_BASE_ADDR | 0x508)
+#define NRF52_NVMC_ERASEALL_ADDR     (NRF52_NVMC_BASE_ADDR | 0x50C)
+#define NRF52_NVMC_ERASEUICR_ADDR    (NRF52_NVMC_BASE_ADDR | 0x514)
+
+/* nRF52 bit fields. */
+enum nrf52_nvmc_config_bits {
+	NRF52_NVMC_CONFIG_REN = 0x0,
+	NRF52_NVMC_CONFIG_WEN = 0x01,
+	NRF52_NVMC_CONFIG_EEN = 0x02
+};
+
+enum nrf52_nvmc_ready_bits {
+	NRF52_NVMC_BUSY  = 0x0,
+	NRF52_NVMC_READY = 0x01
+};
+
+/* nRF52 state information. */
+struct nrf52_info {
+	uint32_t code_page_size; /* Size of FLASH page in bytes. */
+	uint32_t code_memory_size; /* Size of Code FLASH region in bytes. */
+
+	struct {
+		bool probed;
+		int (*write) (struct flash_bank *bank,
+				struct nrf52_info *chip,
+				const uint8_t *buffer, uint32_t offset, uint32_t count);
+	} bank[2]; /* There are two regions in nRF52 FLASH - Code and UICR. */
+	struct target *target;
+};
+
+static int nrf52_protect_check(struct flash_bank *bank);
+
+static int nrf52_probe(struct flash_bank *bank)
+{
+	int res;
+	struct nrf52_info *chip = bank->driver_priv;
+	assert(chip != NULL);
+
+	res = target_read_u32(chip->target,
+						NRF52_FICR_CODEPAGESIZE_ADDR,
+						&chip->code_page_size);
+	if (res != ERROR_OK) {
+		LOG_ERROR("Couldn't read code page size");
+		return res;
+	}
+
+	res = target_read_u32(chip->target,
+						NRF52_FICR_CODESIZE_ADDR,
+						&chip->code_memory_size);
+	if (res != ERROR_OK) {
+		LOG_ERROR("Couldn't read code memory size");
+		return res;
+	}
+
+	chip->code_memory_size = chip->code_memory_size * chip->code_page_size;
+
+	if (bank->base == NRF52_FLASH_BASE_ADDR) {
+		bank->size = chip->code_memory_size;
+		bank->num_sectors = bank->size / chip->code_page_size;
+		bank->sectors = calloc(bank->num_sectors,
+							sizeof((bank->sectors)[0]));
+		if (!bank->sectors)
+			return ERROR_FLASH_BANK_NOT_PROBED;
+
+		/* Fill out the sector information: All nRF51 sectors are the same size. */
+		for (int i = 0; i < bank->num_sectors; i++) {
+			bank->sectors[i].size = chip->code_page_size;
+			bank->sectors[i].offset	= i * chip->code_page_size;
+
+			/* Mark as unknown. */
+			bank->sectors[i].is_erased = -1;
+			bank->sectors[i].is_protected = -1;
+		}
+
+		nrf52_protect_check(bank);
+
+		chip->bank[0].probed = true;
+	} else { /* This is the UICR bank. */
+		bank->size = chip->code_page_size;
+		bank->num_sectors = 1;
+		bank->sectors = calloc(bank->num_sectors,
+							sizeof((bank->sectors)[0]));
+		if (!bank->sectors)
+			return ERROR_FLASH_BANK_NOT_PROBED;
+
+		bank->sectors[0].size = bank->size;
+		bank->sectors[0].offset	= 0;
+
+		bank->sectors[0].is_erased = -1;
+		bank->sectors[0].is_protected = -1;
+
+		chip->bank[1].probed = true;
+	}
+
+	return ERROR_OK;
+}
+
+static int nrf52_bank_is_probed(struct flash_bank *bank)
+{
+	struct nrf52_info *chip = bank->driver_priv;
+	assert(chip != NULL);
+
+	return chip->bank[bank->bank_number].probed;
+}
+
+static int nrf52_auto_probe(struct flash_bank *bank)
+{
+	if (!nrf52_bank_is_probed(bank))
+		return nrf52_probe(bank);
+	else
+		return ERROR_OK;
+}
+
+static int nrf52_wait_for_nvmc(struct nrf52_info *chip)
+{
+	int res;
+	uint32_t ready;
+	int timeout = 100;
+
+	do {
+		res = target_read_u32(chip->target, NRF52_NVMC_READY_ADDR, &ready);
+		if (res != ERROR_OK) {
+			LOG_ERROR("Couldn't read NVMC_READY register");
+			return res;
+		}
+
+		if (ready == NRF52_NVMC_READY)
+			return ERROR_OK;
+
+		alive_sleep(1);
+	} while (timeout--);
+
+	LOG_DEBUG("Timed out waiting for the NVMC to be ready");
+	return ERROR_FLASH_BUSY;
+}
+
+static int nrf52_nvmc_erase_enable(struct nrf52_info *chip)
+{
+	int res;
+
+	res = nrf52_wait_for_nvmc(chip);
+	if (res != ERROR_OK)
+		return res;
+
+	res = target_write_u32(chip->target,
+						NRF52_NVMC_CONFIG_ADDR,
+						NRF52_NVMC_CONFIG_EEN);
+	if (res != ERROR_OK) {
+		LOG_ERROR("Failed to configure the NVMC for erasing");
+		return res;
+	}
+
+	return res;
+}
+
+static int nrf52_nvmc_write_enable(struct nrf52_info *chip)
+{
+	int res;
+
+	res = nrf52_wait_for_nvmc(chip);
+	if (res != ERROR_OK)
+		return res;
+
+	res = target_write_u32(chip->target,
+						NRF52_NVMC_CONFIG_ADDR,
+						NRF52_NVMC_CONFIG_WEN);
+	if (res != ERROR_OK) {
+		LOG_ERROR("Failed to configure the NVMC for writing");
+		return res;
+	}
+
+	return res;
+}
+
+static int nrf52_nvmc_read_only(struct nrf52_info *chip)
+{
+	int res;
+
+	res = nrf52_wait_for_nvmc(chip);
+	if (res != ERROR_OK)
+		return res;
+
+	res = target_write_u32(chip->target,
+						NRF52_NVMC_CONFIG_ADDR,
+						NRF52_NVMC_CONFIG_REN);
+	if (res != ERROR_OK) {
+		LOG_ERROR("Failed to configure the NVMC for read-only");
+		return res;
+	}
+
+	return res;
+}
+
+static int nrf52_nvmc_generic_erase(struct nrf52_info *chip,
+								uint32_t erase_register,
+								uint32_t erase_value)
+{
+	int res;
+
+	res = nrf52_nvmc_erase_enable(chip);
+	if (res != ERROR_OK)
+		return res;
+
+	res = target_write_u32(chip->target,
+						erase_register,
+						erase_value);
+	if (res != ERROR_OK)
+		LOG_ERROR("Failed to write NVMC erase register");
+
+	return nrf52_nvmc_read_only(chip);
+}
+
+static int nrf52_protect_check(struct flash_bank *bank)
+{
+	LOG_WARNING("nrf52_protect_check() is not implemented for nRF52 series devices yet");
+	return ERROR_OK;
+}
+
+static int nrf52_protect(struct flash_bank *bank, int set, int first, int last)
+{
+	LOG_WARNING("nrf52_protect() is not implemented for nRF52 series devices yet");
+	return ERROR_OK;
+}
+
+static struct flash_sector *nrf52_find_sector_by_address(struct flash_bank *bank, uint32_t address)
+{
+	struct nrf52_info *chip = bank->driver_priv;
+	assert(chip != NULL);
+
+	for (int i = 0; i < bank->num_sectors; i++)
+		if (bank->sectors[i].offset <= address &&
+			address < (bank->sectors[i].offset + chip->code_page_size)) {
+			return &bank->sectors[i];
+		}
+
+	return NULL;
+}
+
+static int nrf52_erase_all(struct nrf52_info *chip)
+{
+	LOG_DEBUG("Erasing all non-volatile memory");
+	return nrf52_nvmc_generic_erase(chip,
+								NRF52_NVMC_ERASEALL_ADDR,
+								0x01);
+}
+
+static int nrf52_erase_page(struct flash_bank *bank,
+							struct nrf52_info *chip,
+							struct flash_sector *sector)
+{
+	int res;
+
+	LOG_DEBUG("Erasing page at 0x%"PRIx32, sector->offset);
+	if (sector->is_protected == 1) {
+		LOG_ERROR("Cannot erase protected sector at 0x%" PRIx32, sector->offset);
+		return ERROR_FAIL;
+	}
+
+	if (bank->base == NRF52_UICR_BASE_ADDR) {
+		res = nrf52_nvmc_generic_erase(chip,
+									NRF52_NVMC_ERASEUICR_ADDR,
+									0x00000001);
+	} else {
+		res = nrf52_nvmc_generic_erase(chip,
+									NRF52_NVMC_ERASEPAGE_ADDR,
+									sector->offset);
+	}
+
+	if (res == ERROR_OK)
+		sector->is_erased = 1;
+	return res;
+}
+
+static const uint8_t nrf52_flash_write_code[] = {
+	/* See contrib/loaders/flash/cortex-m0.S */
+	/* <wait_fifo>: */
+	0x0d, 0x68,		/* ldr	r5,	[r1,	#0] */
+	0x00, 0x2d,		/* cmp	r5,	#0 */
+	0x0b, 0xd0,		/* beq.n	1e <exit> */
+	0x4c, 0x68,		/* ldr	r4,	[r1,	#4] */
+	0xac, 0x42,		/* cmp	r4,	r5 */
+	0xf9, 0xd0,		/* beq.n	0 <wait_fifo> */
+	0x20, 0xcc,		/* ldmia	r4!,	{r5} */
+	0x20, 0xc3,		/* stmia	r3!,	{r5} */
+	0x94, 0x42,		/* cmp	r4,	r2 */
+	0x01, 0xd3,		/* bcc.n	18 <no_wrap> */
+	0x0c, 0x46,		/* mov	r4,	r1 */
+	0x08, 0x34,		/* adds	r4,	#8 */
+	/* <no_wrap>: */
+	0x4c, 0x60,		/* str	r4, [r1,	#4] */
+	0x04, 0x38,		/* subs	r0, #4 */
+	0xf0, 0xd1,		/* bne.n	0 <wait_fifo> */
+	/* <exit>: */
+	0x00, 0xbe		/* bkpt	0x0000 */
+};
+
+
+/* Start a low level flash write for the specified region */
+static int nrf52_ll_flash_write(struct nrf52_info *chip, uint32_t offset, const uint8_t *buffer, uint32_t bytes)
+{
+	struct target *target = chip->target;
+	uint32_t buffer_size = 8192;
+	struct working_area *write_algorithm;
+	struct working_area *source;
+	uint32_t address = NRF52_FLASH_BASE_ADDR + offset;
+	struct reg_param reg_params[4];
+	struct armv7m_algorithm armv7m_info;
+	int retval = ERROR_OK;
+
+	LOG_DEBUG("Writing buffer to flash offset=0x%"PRIx32" bytes=0x%"PRIx32, offset, bytes);
+	assert(bytes % 4 == 0);
+
+	/* allocate working area with flash programming code */
+	if (target_alloc_working_area(target, sizeof(nrf52_flash_write_code),
+			&write_algorithm) != ERROR_OK) {
+		LOG_WARNING("no working area available, falling back to slow memory writes");
+
+		for (; bytes > 0; bytes -= 4) {
+			retval = target_write_memory(chip->target,
+										offset, 4, 1, buffer);
+			if (retval != ERROR_OK)
+				return retval;
+
+			retval = nrf52_wait_for_nvmc(chip);
+			if (retval != ERROR_OK)
+				return retval;
+
+			offset += 4;
+			buffer += 4;
+		}
+
+		return ERROR_OK;
+	}
+
+	LOG_WARNING("using fast async flash loader. This is currently supported");
+	LOG_WARNING("only with ST-Link and CMSIS-DAP. If you have issues, add");
+	LOG_WARNING("\"set WORKAREASIZE 0\" before sourcing nrf52.cfg to disable it");
+
+	retval = target_write_buffer(target, write_algorithm->address,
+				sizeof(nrf52_flash_write_code),
+				nrf52_flash_write_code);
+	if (retval != ERROR_OK)
+		return retval;
+
+	/* memory buffer */
+	while (target_alloc_working_area(target, buffer_size, &source) != ERROR_OK) {
+		buffer_size /= 2;
+		buffer_size &= ~3UL; /* Make sure it's 4 byte aligned */
+		if (buffer_size <= 256) {
+			/* free working area, write algorithm already allocated */
+			target_free_working_area(target, write_algorithm);
+
+			LOG_WARNING("No large enough working area available, can't do block memory writes");
+			return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
+		}
+	}
+
+	armv7m_info.common_magic = ARMV7M_COMMON_MAGIC;
+	armv7m_info.core_mode = ARM_MODE_THREAD;
+
+	init_reg_param(&reg_params[0], "r0", 32, PARAM_IN_OUT);	/* byte count */
+	init_reg_param(&reg_params[1], "r1", 32, PARAM_OUT);	/* buffer start */
+	init_reg_param(&reg_params[2], "r2", 32, PARAM_OUT);	/* buffer end */
+	init_reg_param(&reg_params[3], "r3", 32, PARAM_IN_OUT);	/* target address */
+
+	buf_set_u32(reg_params[0].value, 0, 32, bytes);
+	buf_set_u32(reg_params[1].value, 0, 32, source->address);
+	buf_set_u32(reg_params[2].value, 0, 32, source->address + source->size);
+	buf_set_u32(reg_params[3].value, 0, 32, address);
+
+	retval = target_run_flash_async_algorithm(target, buffer, bytes/4, 4,
+			0, NULL,
+			4, reg_params,
+			source->address, source->size,
+			write_algorithm->address, 0,
+			&armv7m_info);
+
+	target_free_working_area(target, source);
+	target_free_working_area(target, write_algorithm);
+
+	destroy_reg_param(&reg_params[0]);
+	destroy_reg_param(&reg_params[1]);
+	destroy_reg_param(&reg_params[2]);
+	destroy_reg_param(&reg_params[3]);
+
+	return retval;
+}
+
+/* Check and erase flash sectors in specified range, then start a low level page write.
+   start/end must be sector aligned.
+*/
+static int nrf52_write_pages(struct flash_bank *bank, uint32_t start, uint32_t end, const uint8_t *buffer)
+{
+	int res;
+	uint32_t offset;
+	struct flash_sector *sector;
+	struct nrf52_info *chip = bank->driver_priv;
+	assert(chip != NULL);
+
+	assert(start % chip->code_page_size == 0);
+	assert(end % chip->code_page_size == 0);
+
+	/* Erase all sectors */
+	for (offset = start; offset < end; offset += chip->code_page_size) {
+		sector = nrf52_find_sector_by_address(bank, offset);
+
+		if (sector == NULL) {
+			LOG_ERROR("Invalid sector @ 0x%08"PRIx32, offset);
+			return ERROR_FLASH_SECTOR_INVALID;
+		}
+
+		if (sector->is_protected == 1) {
+			LOG_ERROR("Can't erase protected sector @ 0x%08"PRIx32, offset);
+			return ERROR_FAIL;
+		}
+
+		if (sector->is_erased != 1) {	/* 1 = erased, 0= not erased, -1 = unknown */
+			res = nrf52_erase_page(bank, chip, sector);
+			if (res != ERROR_OK) {
+				LOG_ERROR("Failed to erase sector @ 0x%08"PRIx32, sector->offset);
+				return res;
+			}
+		}
+		sector->is_erased = 1;
+	}
+
+	res = nrf52_nvmc_write_enable(chip);
+	if (res != ERROR_OK)
+		return res;
+
+	res = nrf52_ll_flash_write(chip, start, buffer, (end - start));
+	if (res != ERROR_OK) {
+		LOG_ERROR("Failed to write FLASH");
+		nrf52_nvmc_read_only(chip);
+		return res;
+	}
+
+	return nrf52_nvmc_read_only(chip);
+}
+
+static int nrf52_erase(struct flash_bank *bank, int first, int last)
+{
+	int res = ERROR_OK;
+	struct nrf52_info *chip = bank->driver_priv;
+	assert(chip != NULL);
+
+	/* For each sector to be erased */
+	for (int s = first; s <= last && res == ERROR_OK; s++)
+		res = nrf52_erase_page(bank, chip, &bank->sectors[s]);
+
+	return res;
+}
+
+static int nrf52_code_flash_write(struct flash_bank *bank,
+								struct nrf52_info *chip,
+								const uint8_t *buffer, uint32_t offset, uint32_t count)
+{
+	int res;
+	/* Need to perform reads to fill any gaps we need to preserve in the first page,
+	   before the start of buffer, or in the last page, after the end of buffer */
+	uint32_t first_page = offset / chip->code_page_size;
+	uint32_t last_page = DIV_ROUND_UP(offset+count, chip->code_page_size);
+
+	uint32_t first_page_offset = first_page * chip->code_page_size;
+	uint32_t last_page_offset = last_page * chip->code_page_size;
+
+	LOG_DEBUG("Padding write from 0x%08"PRIx32"-0x%08"PRIx32" as 0x%08"PRIx32"-0x%08"PRIx32,
+			offset, offset+count, first_page_offset, last_page_offset);
+
+	uint32_t page_cnt = last_page - first_page;
+	uint8_t buffer_to_flash[page_cnt * chip->code_page_size];
+
+	/* Fill in any space between start of first page and start of buffer */
+	uint32_t pre = offset - first_page_offset;
+	if (pre > 0) {
+		res = target_read_memory(bank->target, first_page_offset, 1, pre, buffer_to_flash);
+		if (res != ERROR_OK)
+			return res;
+	}
+
+	/* Fill in main contents of buffer */
+	memcpy(buffer_to_flash + pre, buffer, count);
+
+	/* Fill in any space between end of buffer and end of last page */
+	uint32_t post = last_page_offset - (offset + count);
+	if (post > 0) {
+		/* Retrieve the full row contents from Flash */
+		res = target_read_memory(bank->target, offset + count, 1, post, buffer_to_flash + pre + count);
+		if (res != ERROR_OK)
+			return res;
+	}
+
+	return nrf52_write_pages(bank, first_page_offset, last_page_offset, buffer_to_flash);
+}
+
+static int nrf52_uicr_flash_write(struct flash_bank *bank,
+								struct nrf52_info *chip,
+								const uint8_t *buffer, uint32_t offset, uint32_t count)
+{
+	int res;
+	uint32_t nrf52_uicr_size = chip->code_page_size;
+	uint8_t uicr[nrf52_uicr_size];
+	struct flash_sector *sector = &bank->sectors[0];
+
+	if ((offset + count) > nrf52_uicr_size)
+		return ERROR_FAIL;
+
+	res = target_read_memory(bank->target, NRF52_UICR_BASE_ADDR, 1, nrf52_uicr_size, uicr);
+
+	if (res != ERROR_OK)
+		return res;
+
+	if (sector->is_erased != 1) {
+		res = nrf52_erase_page(bank, chip, sector);
+		if (res != ERROR_OK)
+			return res;
+	}
+
+	memcpy(&uicr[offset], buffer, count);
+
+	res = nrf52_nvmc_write_enable(chip);
+	if (res != ERROR_OK)
+		return res;
+
+	res = nrf52_ll_flash_write(chip, NRF52_UICR_BASE_ADDR, uicr, nrf52_uicr_size);
+	if (res != ERROR_OK) {
+		nrf52_nvmc_read_only(chip);
+		return res;
+	}
+
+	return nrf52_nvmc_read_only(chip);
+}
+
+
+static int nrf52_write(struct flash_bank *bank, const uint8_t *buffer,
+					uint32_t offset, uint32_t count)
+{
+	struct nrf52_info *chip = bank->driver_priv;
+	assert(chip != NULL);
+
+	return chip->bank[bank->bank_number].write(bank, chip, buffer, offset, count);
+}
+
+
+FLASH_BANK_COMMAND_HANDLER(nrf52_flash_bank_command)
+{
+	static struct nrf52_info *chip;
+
+	assert(bank != NULL);
+
+	switch (bank->base) {
+	case NRF52_FLASH_BASE_ADDR:
+		bank->bank_number = 0;
+		break;
+	case NRF52_UICR_BASE_ADDR:
+		bank->bank_number = 1;
+		break;
+	default:
+		LOG_ERROR("Invalid bank address 0x%08" PRIx32, bank->base);
+		return ERROR_FAIL;
+	}
+
+	if (!chip) {
+		/* Create a new chip */
+		chip = calloc(1, sizeof(*chip));
+		assert(chip != NULL);
+
+		chip->target = bank->target;
+	}
+
+	switch (bank->base) {
+	case NRF52_FLASH_BASE_ADDR:
+		chip->bank[bank->bank_number].write = nrf52_code_flash_write;
+		break;
+	case NRF52_UICR_BASE_ADDR:
+		chip->bank[bank->bank_number].write = nrf52_uicr_flash_write;
+		break;
+	}
+
+	chip->bank[bank->bank_number].probed = false;
+	bank->driver_priv = chip;
+
+	return ERROR_OK;
+}
+
+COMMAND_HANDLER(nrf52_handle_mass_erase_command)
+{
+	int res;
+	struct flash_bank *bank = NULL;
+	struct target *target = get_current_target(CMD_CTX);
+
+	res = get_flash_bank_by_addr(target, NRF52_FLASH_BASE_ADDR, true, &bank);
+	if (res != ERROR_OK)
+		return res;
+
+	assert(bank != NULL);
+
+	struct nrf52_info *chip = bank->driver_priv;
+	assert(chip != NULL);
+
+	res = nrf52_erase_all(chip);
+	if (res != ERROR_OK) {
+		LOG_ERROR("Failed to erase the chip");
+		nrf52_protect_check(bank);
+		return res;
+	}
+
+	for (int i = 0; i < bank->num_sectors; i++)
+		bank->sectors[i].is_erased = 1;
+
+	res = nrf52_protect_check(bank);
+	if (res != ERROR_OK) {
+		LOG_ERROR("Failed to check chip's write protection");
+		return res;
+	}
+
+	res = get_flash_bank_by_addr(target, NRF52_UICR_BASE_ADDR, true, &bank);
+	if (res != ERROR_OK)
+		return res;
+
+	bank->sectors[0].is_erased = 1;
+
+	return ERROR_OK;
+}
+
+static int nrf52_info(struct flash_bank *bank, char *buf, int buf_size)
+{
+	int res;
+	uint32_t ficr[2];
+	struct nrf52_info *chip = bank->driver_priv;
+	assert(chip != NULL);
+
+	res = target_read_u32(chip->target, NRF52_FICR_CODEPAGESIZE_ADDR, &ficr[0]);
+		if (res != ERROR_OK) {
+			LOG_ERROR("Couldn't read NVMC_READY register");
+			return res;
+		}
+
+	res = target_read_u32(chip->target, NRF52_FICR_CODESIZE_ADDR, &ficr[1]);
+		if (res != ERROR_OK) {
+			LOG_ERROR("Couldn't read NVMC_READY register");
+			return res;
+		}
+
+	snprintf(buf, buf_size,
+			"\n--------nRF52 Series Device--------\n\n"
+			"\n[factory information control block]\n"
+			"code page size: %"PRIu32"B\n"
+			"code memory size: %"PRIu32"kB\n",
+			ficr[0],
+			(ficr[1] * ficr[0]) / 1024);
+
+	return ERROR_OK;
+}
+
+static const struct command_registration nrf52_exec_command_handlers[] = {
+	{
+		.name		= "mass_erase",
+		.handler	= nrf52_handle_mass_erase_command,
+		.mode		= COMMAND_EXEC,
+		.help		= "Erase all flash contents of the chip.",
+	},
+	COMMAND_REGISTRATION_DONE
+};
+
+static const struct command_registration nrf52_command_handlers[] = {
+	{
+		.name	= "nrf52",
+		.mode	= COMMAND_ANY,
+		.help	= "nrf52 flash command group",
+		.usage	= "",
+		.chain	= nrf52_exec_command_handlers,
+	},
+	COMMAND_REGISTRATION_DONE
+};
+
+struct flash_driver nrf52_flash = {
+	.name			= "nrf52",
+	.commands		= nrf52_command_handlers,
+	.flash_bank_command	= nrf52_flash_bank_command,
+	.info			= nrf52_info,
+	.erase			= nrf52_erase,
+	.protect		= nrf52_protect,
+	.write			= nrf52_write,
+	.read			= default_flash_read,
+	.probe			= nrf52_probe,
+	.auto_probe		= nrf52_auto_probe,
+	.erase_check	= default_flash_blank_check,
+	.protect_check	= nrf52_protect_check,
+};
diff --git a/tcl/target/nrf52.cfg b/tcl/target/nrf52.cfg
index c1cbf1a..41a22ff 100644
--- a/tcl/target/nrf52.cfg
+++ b/tcl/target/nrf52.cfg
@@ -10,6 +10,13 @@ if { [info exists CHIPNAME] } {
 	set _CHIPNAME nrf52
 }

+# Work-area is a space in RAM used for flash programming, by default use 16kB.
+if { [info exists WORKAREASIZE] } {
+        set _WORKAREASIZE $WORKAREASIZE
+} else {
+        set _WORKAREASIZE 0x4000
+}
+
 if { [info exists CPUTAPID] } {
 	set _CPUTAPID $CPUTAPID
 } else {
@@ -22,7 +29,15 @@ set _TARGETNAME $_CHIPNAME.cpu
 target create $_TARGETNAME cortex_m -chain-position $_TARGETNAME

 adapter_khz 10000
+$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0

 if { ![using_hla] } {
 	cortex_m reset_config sysresetreq
 }
+
+flash bank $_CHIPNAME.flash nrf52 0x00000000 0 1 1 $_TARGETNAME
+flash bank $_CHIPNAME.uicr nrf52 0x10001000 0 1 1 $_TARGETNAME
+
+adapter_khz 1000
+
+$_TARGETNAME configure -event reset-end {}


code:
From 7f0ce36828ec1e130bee857b8236ca091e4d8a2c Mon Sep 17 00:00:00 2001
From: Brice Waegeneire <brice@waegenei.re>
Date: Sat, 9 May 2020 15:52:06 +0200
Subject: [PATCH] Add RESTARTCMD for Guix System.

---

openresolv need to know how to restart the nscd service, this patch teach it
to do it on Guix System by using shepherd.

 resolvconf.in | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/resolvconf.in b/resolvconf.in
index 3cad04d..5ef5294 100644
--- a/resolvconf.in
+++ b/resolvconf.in
@@ -369,6 +369,13 @@ detect_init()
 			then
 				/etc/rc.d/$1 restart
 			fi'
+	elif [ -e /gnu/store ] && [ -e /run/current-system/profile ]; then
+		# Guix System
+		RESTARTCMD='
+			if /run/current-system/profile/bin/herd status $1 2>&1
+			then
+				/run/current-system/profile/bin/herd restart $1
+			fi'
 	else
 		for x in /etc/init.d/rc.d /etc/rc.d /etc/init.d; do
 			[ -d $x ] || continue
--
2.26.0


code:
https://github.com/openscad/openscad/commit/b6c170cc5d.patch

From b6c170cc5dd1bc677176ee732cdb0ddae57e5cf0 Mon Sep 17 00:00:00 2001
From: Jan Beich <jbeich@FreeBSD.org>
Date: Fri, 25 Oct 2019 15:10:26 +0000
Subject: [PATCH] Add missing header bootlegged by Boost < 1.72

src/parser.y:76:6: error: no template named 'stack' in namespace 'std'
std::stack<LocalScope *> scope_stack;
~~~~~^
---
 src/parser.y | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/parser.y b/src/parser.y
index 7f4fd56ca7..4c77c989ea 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -46,6 +46,7 @@
 #include "printutils.h"
 #include "memory.h"
 #include <sstream>
+#include <stack>
 #include <boost/filesystem.hpp>
 #include "boost-utils.h"
 #include "feature.h"


code:
From 3a78134a35b448d9d4136ffbc55175be7fab6644 Mon Sep 17 00:00:00 2001
From: Raghav Gururajan <raghavgururajan@disroot.org>
Date: Mon, 6 Jul 2020 00:34:20 -0400
Subject: [PATCH] [PATCH]: Add license file.

---
 LICENSE.txt | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 LICENSE.txt

diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..0fce823
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2007-2011 The Khronos Group Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and /or associated documentation files (the "Materials "), to
+ * deal in the Materials without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Materials, and to permit persons to whom the Materials are
+ * furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Materials.
+ *
+ * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN THE
+ * MATERIALS.
+ *
+ * OpenSLES_IID.c - OpenSL ES version 1.1
+ *
+ */
\ No newline at end of file
--
2.26.2


code:
Author: Jan (janneke) Nieuwenhuizen" <janneke@gnu.org>
Not upstreamed.

From 1ddae040d67e9a4ebcc3e1b95af1bff12c0f086b Mon Sep 17 00:00:00 2001
From: "Jan (janneke) Nieuwenhuizen" <janneke@gnu.org>
Date: Tue, 7 Apr 2020 17:41:05 +0200
Subject: [PATCH] Build fix for the Hurd.

* gss-serv.c (ssh_gssapi_acquire_cred): Use HOST_NAME_MAX instead of
MAXHOSTNAMELEN.
---
 gss-serv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gss-serv.c b/gss-serv.c
index 1d47870e7..22081c6f1 100644
--- a/gss-serv.c
+++ b/gss-serv.c
@@ -107,7 +107,7 @@ ssh_gssapi_acquire_cred(Gssctxt *ctx)
 		gss_create_empty_oid_set(&status, &oidset);
 		gss_add_oid_set_member(&status, ctx->oid, &oidset);

-		if (gethostname(lname, MAXHOSTNAMELEN)) {
+		if (gethostname(lname, HOST_NAME_MAX)) {
 			gss_release_oid_set(&status, &oidset);
 			return (-1);
 		}
--
2.26.0


code:
This patch removes the explicit reference to the 'perl' binary,
such that OpenSSL does not retain a reference to Perl.

The 'c_rehash' program is seldom used, but it is used nonetheless
to create symbolic links to certificates, for instance in the 'nss-certs'
package.

diff --git a/tools/c_rehash.in b/tools/c_rehash.in
index 421fd89208..93aca4e168 100644
--- a/tools/c_rehash.in
+++ b/tools/c_rehash.in
@@ -1,4 +1,6 @@
-#!{- $config{HASHBANGPERL} -}
+eval '(exit $?0)' && eval 'exec perl -wS "$0" ${1+"$@"}'
+  & eval 'exec perl -wS "$0" $argv:q'
+    if 0;

 # {- join("\n# ", @autowarntext) -}
 # Copyright 1999-2018 The OpenSSL Project Authors. All Rights Reserved.


code:
From e9bbefbf0f24c57645e7ad6a5a71ae649d18ac8e Mon Sep 17 00:00:00 2001
From: Matt Caswell <matt@openssl.org>
Date: Fri, 14 Dec 2018 07:28:30 +0000
Subject: [PATCH] Go into the error state if a fatal alert is sent or received

If an application calls SSL_shutdown after a fatal alert has occured and
then behaves different based on error codes from that function then the
application may be vulnerable to a padding oracle.

CVE-2019-1559

Reviewed-by: Richard Levitte <levitte@openssl.org>
---
 ssl/d1_pkt.c |  1 +
 ssl/s3_pkt.c | 10 +++++++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/ssl/d1_pkt.c b/ssl/d1_pkt.c
index 23aa9db..c7fe977 100644
--- a/ssl/d1_pkt.c
+++ b/ssl/d1_pkt.c
@@ -1309,6 +1309,7 @@ int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
             ERR_add_error_data(2, "SSL alert number ", tmp);
             s->shutdown |= SSL_RECEIVED_SHUTDOWN;
             SSL_CTX_remove_session(s->session_ctx, s->session);
+            s->state = SSL_ST_ERR;
             return (0);
         } else {
             al = SSL_AD_ILLEGAL_PARAMETER;
diff --git a/ssl/s3_pkt.c b/ssl/s3_pkt.c
index 6527df8..830b723 100644
--- a/ssl/s3_pkt.c
+++ b/ssl/s3_pkt.c
@@ -1500,6 +1500,7 @@ int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
             ERR_add_error_data(2, "SSL alert number ", tmp);
             s->shutdown |= SSL_RECEIVED_SHUTDOWN;
             SSL_CTX_remove_session(s->session_ctx, s->session);
+            s->state = SSL_ST_ERR;
             return (0);
         } else {
             al = SSL_AD_ILLEGAL_PARAMETER;
@@ -1719,9 +1720,12 @@ int ssl3_send_alert(SSL *s, int level, int desc)
                                           * protocol_version alerts */
     if (desc < 0)
         return -1;
-    /* If a fatal one, remove from cache */
-    if ((level == 2) && (s->session != NULL))
-        SSL_CTX_remove_session(s->session_ctx, s->session);
+    /* If a fatal one, remove from cache and go into the error state */
+    if (level == SSL3_AL_FATAL) {
+        if (s->session != NULL)
+            SSL_CTX_remove_session(s->session_ctx, s->session);
+        s->state = SSL_ST_ERR;
+    }

     s->s3->alert_dispatch = 1;
     s->s3->send_alert[0] = level;
--
2.7.4


code:
This patch removes the explicit reference to the 'perl' binary,
such that OpenSSL does not retain a reference to Perl.

The 'c_rehash' program is seldom used, but it is used nonetheless
to create symbolic links to certificates, for instance in the 'nss-certs'
package.

--- openssl-1.0.2g/tools/c_rehash.in	2015-09-09 18:36:07.313316482 +0200
+++ openssl-1.0.2g/tools/c_rehash.in	2015-09-09 18:36:28.965458458 +0200
@@ -1,4 +1,6 @@
-#!/usr/local/bin/perl
+eval '(exit $?0)' && eval 'exec perl -wS "$0" ${1+"$@"}'
+  & eval 'exec perl -wS "$0" $argv:q'
+    if 0;

 # Perl c_rehash script, scan all files in a directory
 # and add symbolic links to their hash values.


code:
This patch makes the build system pass -Wl,-rpath=$out/lib even for
libraries (it already does so for executables, thanks to 'DO_GNU_APP'
in 'Makefile.shared'.)

--- openssl-1.0.2a/Makefile.shared	2015-04-05 01:07:35.357602454 +0200
+++ openssl-1.0.2a/Makefile.shared	2015-04-05 01:09:50.474513303 +0200
@@ -106,7 +106,7 @@ LINK_SO=	\
     LIBPATH=`for x in $$LIBDEPS; do echo $$x; done | sed -e 's/^ *-L//;t' -e d | uniq`; \
     LIBPATH=`echo $$LIBPATH | sed -e 's/ /:/g'`; \
     LD_LIBRARY_PATH=$$LIBPATH:$$LD_LIBRARY_PATH \
-    $${SHAREDCMD} $${SHAREDFLAGS} \
+    $${SHAREDCMD} $${SHAREDFLAGS} -Wl,-rpath,$(LIBRPATH) \
 	-o $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX \
 	$$ALLSYMSFLAGS $$SHOBJECTS $$NOALLSYMSFLAGS $$LIBDEPS \
   ) && $(SYMLINK_SO)


code:
The 'intcompare' definition was causing a "cast from 'void*' to 'int' loses
precision [-fpermissive]" error.  It isn't used anywhere, so simply remove it.
Same with 'findint' in texteditor.cc.

Fix other "cast from ‘void*’ to ‘int’ loses precision" errors.

--- a/kkstrtext-0.1/kkstrtext.cc	2005-01-31 18:13:24.000000000 -0600
+++ b/kkstrtext-0.1/kkstrtext.cc	2014-07-24 00:25:07.149305476 -0500
@@ -430,10 +430,6 @@
     }
 }

-int intcompare(void *s1, void *s2) {
-    return (int) s1 != (int) s2;
-}
-
 string i2str(int i) {
     char buf[64];
     sprintf(buf, "%d", i);
@@ -885,7 +881,7 @@
 #ifdef HAVE_ICONV
     iconv_t cd = iconv_open(tocs.c_str(), fromcs.c_str());

-    if(((int) cd) != -1) {
+    if(cd != (iconv_t) -1) {
 	string r, text(atext);
 	size_t inleft, outleft, soutleft;
 	char *inbuf, *outbuf, *sinbuf, *soutbuf;
--- a/kkconsui-0.1/src/texteditor.cc	2003-09-09 16:51:33.000000000 -0500
+++ b/kkconsui-0.1/src/texteditor.cc	2014-07-24 00:33:20.093279060 -0500
@@ -1939,10 +1939,6 @@
     if(ur) delete ur;
 }

-int texteditor::findint(void *p1, void *p2) {
-    return *(int *) p1 != (int) p2;
-}
-
 int texteditor::findhighline(void *p1, void *p2) {
     return *(int *) p1 != ((highline *) p2)->line;
 }
--- a/src/streamtrack.cc	2006-05-11 12:45:20.000000000 -0500
+++ b/src/streamtrack.cc	2014-07-24 00:38:10.797263482 -0500
@@ -34,6 +34,7 @@
 #include <sys/wait.h>
 #include <sys/stat.h>
 #include <signal.h>
+#include <unistd.h>

 #include <algorithm>


code:
Fix CVE-2017-7853:

https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-7853
https://savannah.gnu.org/support/index.php?109265

Patch copied from upstream source repository:

https://git.savannah.gnu.org/cgit/osip.git/commit/?id=1ae06daf3b2375c34af23083394a6f010be24a45

From 1ae06daf3b2375c34af23083394a6f010be24a45 Mon Sep 17 00:00:00 2001
From: Aymeric Moizard <amoizard@gmail.com>
Date: Tue, 21 Feb 2017 17:16:26 +0100
Subject: [PATCH]  * fix bug report: sr #109265: SIP message body length
 underflow in libosip2-4.1.0    https://savannah.gnu.org/support/?109265
 also applicable to current latest version

---
 src/osipparser2/osip_message_parse.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/osipparser2/osip_message_parse.c b/src/osipparser2/osip_message_parse.c
index 1628c60..aa35446 100644
--- a/src/osipparser2/osip_message_parse.c
+++ b/src/osipparser2/osip_message_parse.c
@@ -784,6 +784,12 @@ msg_osip_body_parse (osip_message_t * sip, const char *start_of_buf, const char
     if ('\n' == start_of_body[0] || '\r' == start_of_body[0])
       start_of_body++;

+    /* if message body is empty or contains a single CR/LF */
+    if (end_of_body <= start_of_body) {
+      osip_free (sep_boundary);
+      return OSIP_SYNTAXERROR;
+    }
+
     body_len = end_of_body - start_of_body;

     /* Skip CR before end boundary. */
--
2.13.1


code:
The file $(top_srcdir)/gtk-doc.make doesn't exist, so don't include it.

--- a/doc/Makefile.in	2007-04-08 20:17:25.000000000 +0200
+++ b/doc/Makefile.in	2014-09-06 23:19:41.413397662 +0200
@@ -240,9 +240,6 @@
 distclean-generic clean-generic maintainer-clean-generic clean \
 mostlyclean distclean maintainer-clean

-
-include $(top_srcdir)/gtk-doc.make
-
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 .NOEXPORT:


code:
This patch is taken from Debian and modified slightly

Description: Phoning-home version checks should be disabled in Debian packages
Author: Sandro Knauß <bugs@ssandroknauss.de>
Origin: debian
Bug-debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=721341
Forwarded: not-needed
Last-Update: 2014-02-17
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/src/libsync/configfile.cpp
+++ b/src/libsync/configfile.cpp
@@ -522,11 +522,14 @@ bool ConfigFile::skipUpdateCheck(const Q
     if (connection.isEmpty())
         con = defaultConnection();

-    QVariant fallback = getValue(QLatin1String(skipUpdateCheckC), con, false);
+    QVariant fallback = getValue(QLatin1String(skipUpdateCheckC), con, true);
     fallback = getValue(QLatin1String(skipUpdateCheckC), QString(), fallback);

     QVariant value = getPolicySetting(QLatin1String(skipUpdateCheckC), fallback);
-    return value.toBool();
+    if ( !value.toBool() )
+        qDebug() << "Guix has disabled the UpdateCheck mechanism.";
+
+    return true;
 }

 void ConfigFile::setSkipUpdateCheck(bool skip, const QString &connection)
--- a/src/gui/generalsettings.cpp
+++ b/src/gui/generalsettings.cpp
@@ -146,6 +149,7 @@ void GeneralSettings::loadMiscSettings()

 void GeneralSettings::slotUpdateInfo()
 {
+    /* Guix doesn't want an autoupdater
     if (ConfigFile().skipUpdateCheck() || !Updater::instance()) {
         // updater disabled on compile
         _ui->updaterWidget->setVisible(false);
@@ -174,6 +178,9 @@ void GeneralSettings::slotUpdateInfo()
     _ui->updateChannel->setCurrentIndex(ConfigFile().updateChannel() == "beta" ? 1 : 0);
     connect(_ui->updateChannel, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
         this, &GeneralSettings::slotUpdateChannelChanged, Qt::UniqueConnection);
+    */
+    //hide the update group box for Guix.
+    _ui->updaterWidget->setVisible(false);
 }

 void GeneralSettings::slotUpdateChannelChanged(int index)


code:
From: Robert Luberda <robert@debian.org>
Date: Sat, 19 Nov 2016 08:48:08 +0100
Subject: Fix nullptr dereference (CVE-2016-9296)

Patch taken from https://sourceforge.net/p/p7zip/bugs/185/
This patch file taken from Debian's patch set for p7zip
---
 CPP/7zip/Archive/7z/7zIn.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/CPP/7zip/Archive/7z/7zIn.cpp b/CPP/7zip/Archive/7z/7zIn.cpp
index b0c6b98..7c6dde2 100644
--- a/CPP/7zip/Archive/7z/7zIn.cpp
+++ b/CPP/7zip/Archive/7z/7zIn.cpp
@@ -1097,7 +1097,8 @@ HRESULT CInArchive::ReadAndDecodePackedStreams(
       if (CrcCalc(data, unpackSize) != folders.FolderCRCs.Vals[i])
         ThrowIncorrect();
   }
-  HeadersSize += folders.PackPositions[folders.NumPackStreams];
+  if (folders.PackPositions)
+      HeadersSize += folders.PackPositions[folders.NumPackStreams];
   return S_OK;
 }


code:
Fix CVE-2017-17969:

https://sourceforge.net/p/p7zip/bugs/204/
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-17969

Patch copied from Debian.

Subject: Heap-based buffer overflow in 7zip/Compress/ShrinkDecoder.cpp
Origin: vendor, https://sourceforge.net/p/p7zip/bugs/_discuss/thread/0920f369/27d7/attachment/CVE-2017-17969.patch
Forwarded: https://sourceforge.net/p/p7zip/bugs/_discuss/thread/0920f369/#27d7
Bug: https://sourceforge.net/p/p7zip/bugs/204/
Bug-Debian: https://bugs.debian.org/888297
Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2017-17969
Author: Antoine Beaupré <anarcat@debian.org>
Reviewed-by: Salvatore Bonaccorso <carnil@debian.org>
Last-Update: 2018-02-01
Applied-Upstream: 18.00-beta

--- a/CPP/7zip/Compress/ShrinkDecoder.cpp
+++ b/CPP/7zip/Compress/ShrinkDecoder.cpp
@@ -121,8 +121,13 @@ HRESULT CDecoder::CodeReal(ISequentialIn
     {
       _stack[i++] = _suffixes[cur];
       cur = _parents[cur];
+      if (cur >= kNumItems || i >= kNumItems)
+        break;
     }
-
+
+    if (cur >= kNumItems || i >= kNumItems)
+      break;
+
     _stack[i++] = (Byte)cur;
     lastChar2 = (Byte)cur;