Subject: [PATCH 1/4] gnu: Add keystone.

From: phodina <[email-masked]>
Date: Tue, 13 Dec 2022 23:34:56 +0000

Hi,

this patch set add support to interface with Mediatek SoC devices found mostly in smart phones.

----
Petr

From 304bf8877e4e401724cde02d4f20d53072bf0f59 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Tue, 13 Dec 2022 23:00:21 +0100
Subject: [PATCH 4/4] gnu: Add mtkclient.

* gnu/local.mk: Add patch.
* gnu/packages/patches/mtkclient-remove-usb.patch: New file.

diff --git a/gnu/packages/engineering.scm b/gnu/packages/engineering.scm
index a9bf6fa6ba..50e9bbcdfa 100644
--- a/gnu/packages/engineering.scm
+++ b/gnu/packages/engineering.scm
@@ -123,6 +123,7 @@ (define-module (gnu packages engineering)
   #:use-module (gnu packages multiprecision)
   #:use-module (gnu packages mpi)
   #:use-module (gnu packages ncurses)
+  #:use-module (gnu packages openstack)
   #:use-module (gnu packages parallel)
   #:use-module (gnu packages pcre)
   #:use-module (gnu packages perl)
@@ -1330,6 +1331,45 @@ (define-public libredwg
 replacement for the OpenDWG libraries.")
     (license license:gpl3+)))
 
+(define-public mtkclient
+  (package
+    (name "mtkclient")
+    (version "1.52")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append
+                    "https://github.com/bkerler/mtkclient/archive/refs/tags/"
+                    version ".tar.gz"))
+              (patches (search-patches
+                                      "mtkclient-remove-usb.patch"))
+              (sha256
+               (base32
+                "1wlz9sipwzgfph57jzmnjlhhsmphfcnl9y0rvpa2wfb5rg6n74ss"))))
+    (build-system python-build-system)
+    (arguments
+     (list #:tests? #f ;no test suite
+           #:phases #~(modify-phases %standard-phases
+                        (add-after 'install 'install-udev-rules
+                          (lambda* _
+                            (let ((udev (string-append #$output "/lib/udev.d")))
+                              (mkdir-p udev)
+                              (install-file "Setup/Linux/50-android.rules"
+                                            udev)
+                              (install-file "Setup/Linux/51-edl.rules" udev)))))))
+    (native-inputs (list python-keystone-engine))
+    (inputs (list python-pyusb
+                  python-pycryptodome
+                  python-colorama
+                  python-capstone
+                  python-mock
+                  python-pyserial
+                  libusb))
+    (home-page "https://github.com/bkerler/mtkclient")
+    (synopsis "MTK reverse engineering and flash tool")
+    (description "This package provides a tool for reading/writing flash
+Mediatek chips.")
+    (license license:gpl3+)))
+
 (define-public minicom
   (package
     (name "minicom")
diff --git a/gnu/packages/patches/mtkclient-remove-usb.patch b/gnu/packages/patches/mtkclient-remove-usb.patch
new file mode 100644
index 0000000000..44105d1884
--- /dev/null
+++ b/gnu/packages/patches/mtkclient-remove-usb.patch
@@ -0,0 +1,44 @@
+From d1ade84a4d320fd26cc77414f53d87293f41a70f Mon Sep 17 00:00:00 2001
+From: Petr Hodina <[email-masked]>
+Date: Mon, 14 Nov 2022 14:08:43 +0100
+Subject: [PATCH] Remove usb.
+
+
+diff --git a/pyproject.toml b/pyproject.toml
+index 348cdce..36d4168 100644
+--- a/pyproject.toml
++++ b/pyproject.toml
+@@ -4,7 +4,6 @@ requires = [
+     "wheel",
+     "pyusb",
+     "pycryptodome",
+-    "colorama",
+-    "usb"
++    "colorama"
+ ]
+ build-backend = "setuptools.build_meta"
+diff --git a/requirements.txt b/requirements.txt
+index 946fe9a..cde3398 100644
+--- a/requirements.txt
++++ b/requirements.txt
+@@ -2,5 +2,3 @@ wheel
+ pyusb
+ pycryptodome
+ colorama
+-usb
+-
+diff --git a/setup.py b/setup.py
+index 9031d23..3bd7cd9 100755
+--- a/setup.py
++++ b/setup.py
+@@ -22,7 +22,6 @@ setup(
+     license='MIT License',
+     install_requires=[
+     'colorama',
+-    'usb',
+     'pyusb',
+     'pycryptodome'
+     ],
+-- 
+2.37.2
+
-- 
2.38.1

From 628ac395bb20fd3875b67614d967bee7f9f24cb6 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Tue, 13 Dec 2022 23:00:42 +0100
Subject: [PATCH 3/4] gnu: python-capstone: Disable broken tests.

* gnu/packages/engineering.scm (python-capstone)[arguments]: Disable broken
tests.

diff --git a/gnu/packages/engineering.scm b/gnu/packages/engineering.scm
index ee224ad173..a9bf6fa6ba 100644
--- a/gnu/packages/engineering.scm
+++ b/gnu/packages/engineering.scm
@@ -1626,7 +1626,8 @@ (define-public python-capstone
      (list capstone))
     (build-system python-build-system)
     (arguments
-     `(#:phases
+     `(#:tests? #f
+       #:phases
        (modify-phases %standard-phases
          (add-after 'unpack 'chdir-and-fix-setup-py
            (lambda _
-- 
2.38.1

From 29ccfe284b90fcf9a2e502e62f6b968237ab0fb5 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Tue, 13 Dec 2022 23:00:03 +0100
Subject: [PATCH 2/4] gnu: Add python-keystone-engine.

* gnu/packages/openstack.scm (python-keystone-engine): New variable.

* gnu/local.mk: Add patch.
* gnu/packages/patches/python-keystone-engine-dont-build-libs.patch: New file.

diff --git a/gnu/packages/openstack.scm b/gnu/packages/openstack.scm
index 008237bd63..870a9853f3 100644
--- a/gnu/packages/openstack.scm
+++ b/gnu/packages/openstack.scm
@@ -885,6 +885,36 @@ (define-public python-keystoneauth1
 process of writing new clients.")
     (license asl2.0)))
 
+(define-public python-keystone-engine
+  (package
+    (name "python-keystone-engine")
+    (version "0.9.2")
+    (source (origin
+              (method url-fetch)
+              (uri (pypi-uri "keystone-engine" version))
+			  (patches
+	 (search-patches
+"python-keystone-engine-dont-build-libs.patch"
+))
+              (sha256
+               (base32
+                "1xahdr6bh3dw5swrc2r8kqa8ljhqlb7k2kxv5mrw5rhcmcnzcyig"))))
+    (build-system python-build-system)
+	(arguments
+	(list #:tests? #f ; TODO: Fails to find the shared object
+	   #:phases
+     #~(modify-phases %standard-phases
+	   (add-after 'unpack 'lib-path
+	   (lambda* _
+	   (substitute* "keystone/keystone.py"
+	   ((".usr.local.lib") (string-append #$keystone "/lib")))))
+	   )))
+    (inputs (list keystone))
+    (home-page "https://www.keystone-engine.org")
+    (synopsis "Keystone assembler engine")
+    (description "Keystone assembler engine")
+    (license gpl2+)))
+
 (define-public python-keystoneclient
   (package
     (name "python-keystoneclient")
diff --git a/gnu/packages/patches/python-keystone-engine-dont-build-libs.patch b/gnu/packages/patches/python-keystone-engine-dont-build-libs.patch
new file mode 100644
index 0000000000..04a66548ba
--- /dev/null
+++ b/gnu/packages/patches/python-keystone-engine-dont-build-libs.patch
@@ -0,0 +1,16 @@
+--- a/setup.py	2022-11-14 14:27:56.167776515 +0100
++++ b/setup.py	2022-11-14 14:28:53.912037545 +0100
+@@ -135,13 +135,11 @@
+ class build(_build):
+     def run(self):
+         log.info("Building C++ extensions")
+-        build_libraries()
+         return _build.run(self)
+
+ class develop(_develop):
+     def run(self):
+         log.info("Building C++ extensions")
+-        build_libraries()
+         return _develop.run(self)
+
+ class bdist_egg(_bdist_egg):
-- 
2.38.1

From 90948a520d5347aaff737546ab33b21cc3b689f6 Mon Sep 17 00:00:00 2001
From: Petr Hodina <[email-masked]>
Date: Tue, 13 Dec 2022 22:59:32 +0100
Subject: [PATCH 1/4] gnu: Add keystone.

* gnu/packages/openstack.scm (keystone): New variable.

diff --git a/gnu/packages/openstack.scm b/gnu/packages/openstack.scm
index 169df27f7c..008237bd63 100644
--- a/gnu/packages/openstack.scm
+++ b/gnu/packages/openstack.scm
@@ -42,13 +42,49 @@ (define-module (gnu packages openstack)
   #:use-module (gnu packages tls)
   #:use-module (gnu packages version-control)
   #:use-module (gnu packages xml)
+  #:use-module (gnu packages pkg-config)
+  #:use-module (guix build-system cmake)
   #:use-module (guix build-system python)
   #:use-module (guix download)
-  #:use-module ((guix licenses)
-                #:select (asl2.0))
+  #:use-module (guix gexp)
+  #:use-module (guix licenses)
   #:use-module (guix packages)
   #:use-module (srfi srfi-1))
 
+(define-public keystone
+  (package
+    (name "keystone")
+    (version "0.9.2")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append
+                    "https://github.com/keystone-engine/keystone/archive/refs/tags/"
+                    version ".tar.gz"))
+              (sha256
+               (base32
+                "093wbddxa8cy5ly81ikl5kxyzydg42cgini9ilbfw19yxm1s7cy9"))))
+    (build-system cmake-build-system)
+    (arguments
+     (list #:configure-flags #~(list "-DBUILD_SHARED_LIBS=ON")
+           #:tests? #f)) ;TODO: enable test suite
+    (native-inputs (list pkg-config))
+    (inputs (list python))
+    (home-page "https://www.keystone-engine.org/")
+    (synopsis "Keystone assembler framework")
+    (description
+     "The @code{keystone} provides assembler framework:
+	 @itemize
+@item Multi-architecture, with support for Arm, Arm64 (AArch64/Armv8),
+Ethereum Virtual Machine, Hexagon, Mips, PowerPC, Sparc, SystemZ,
+& X86 (include 16/32/64bit)
+@item Clean/simple/lightweight/intuitive architecture-neutral API
+@item Implemented in C/C++ languages, with bindings for Java, Masm,
+Visual Basic, C#, PowerShell, Perl, Python, NodeJS, Ruby, Go, Rust,
+Haskell & OCaml available
+@item Thread-safe by design
+@end itemize")
+    (license gpl2+)))
+
 (define-public python-bandit
   (package
     (name "python-bandit")
-- 
2.38.1