From c34cd7d30bebc60e0af20c6e37b4a4759f4f8eb7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Romain=20Bron=C3=A8s?=
 <romain.broucquart@synchrotron-soleil.fr>
Date: Mon, 19 Feb 2024 17:47:21 +0100
Subject: [PATCH] feat(map): Use desy-utils recipe for map file install

* Append the recipe with the on the fly fix for mapt
---
 recipes-app/fofb-init/files/fofb-init.sh      |  3 +-
 recipes-app/fofb-init/fofb-init_1.3.bb        |  3 +-
 .../fofb-opcua-server_0.3.bb                  |  3 +-
 recipes-bsp/variant-mapt/variant-mapt.bb      | 55 -------------------
 .../deviceaccess-mapfiles.bbappend            | 33 +++++++++++
 5 files changed, 39 insertions(+), 58 deletions(-)
 delete mode 100644 recipes-bsp/variant-mapt/variant-mapt.bb
 create mode 100644 recipes-chimeratk/deviceaccess-mapfiles/deviceaccess-mapfiles.bbappend

diff --git a/recipes-app/fofb-init/files/fofb-init.sh b/recipes-app/fofb-init/files/fofb-init.sh
index ef786ce..9e9cae5 100755
--- a/recipes-app/fofb-init/files/fofb-init.sh
+++ b/recipes-app/fofb-init/files/fofb-init.sh
@@ -4,6 +4,7 @@
 
 PATH_CFG="/opt/fofb/cfg/"
 PATH_MAP="/opt/fofb/map/"
+PATH_MAPT="/usr/share/deviceaccess/map/"
 PATH_FPGABIN=${PATH_CFG}/fpga_bitstream.bin
 LOCK_FILE=/var/lock/subsys/fofb-init
 
@@ -71,7 +72,7 @@ link_mapt() {
         exit 1
     fi
 
-    LINK_TARGET="${PATH_MAP}/app_${FOFB_APP}.mapt"
+    LINK_TARGET="${PATH_MAPT}/${FOFB_APP}/${FOFB_APP}_ch8.mapt"
     if [ ! -f ${LINK_TARGET} ]; then
         log -p user.error "MAPT file not found: ${LINK_TARGET}"
         exit 1
diff --git a/recipes-app/fofb-init/fofb-init_1.3.bb b/recipes-app/fofb-init/fofb-init_1.3.bb
index 4ecd0c8..c5f7b53 100644
--- a/recipes-app/fofb-init/fofb-init_1.3.bb
+++ b/recipes-app/fofb-init/fofb-init_1.3.bb
@@ -14,7 +14,8 @@ SRC_URI += " file://fofb-configurator.py"
 SRC_URI += " file://configuration.example"
 SRC_URI += " file://config"
 
-RDEPENDS_${PN}=" fpga-manager-script bash variant-mapt"
+DEPENDS=" deviceaccess-mapfiles"
+RDEPENDS_${PN}=" deviceaccess-mapfiles fpga-manager-script bash"
 
 FILES_${PN}+="/etc/init.d/fofb-init.sh"
 FILES_${PN}+="/usr/bin/fpgaversion"
diff --git a/recipes-app/fofb-opcua-server/fofb-opcua-server_0.3.bb b/recipes-app/fofb-opcua-server/fofb-opcua-server_0.3.bb
index 2616762..ecba408 100644
--- a/recipes-app/fofb-opcua-server/fofb-opcua-server_0.3.bb
+++ b/recipes-app/fofb-opcua-server/fofb-opcua-server_0.3.bb
@@ -16,7 +16,8 @@ SRC_URI = " \
             file://fofb-opcua-server.sh \
 "
 
-RDEPENDS_${PN}=" genericdeviceserver-opcua bash variant-mapt"
+DEPENDS=" deviceaccess-mapfiles"
+RDEPENDS_${PN}=" genericdeviceserver-opcua bash"
 
 FILES_${PN}+="/opt/fofb/opcua-server/*"
 FILES_${PN}+="/etc/init.d/fofb-opcua-server.sh"
diff --git a/recipes-bsp/variant-mapt/variant-mapt.bb b/recipes-bsp/variant-mapt/variant-mapt.bb
deleted file mode 100644
index ae45f49..0000000
--- a/recipes-bsp/variant-mapt/variant-mapt.bb
+++ /dev/null
@@ -1,55 +0,0 @@
-SUMMARY = "Install MAPT files for each variants"
-SECTION = "opt"
-LICENSE = "MIT"
-LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
-
-
-# Adding MAPT files to SRC_URI and FILES for each variant
-python () {
-    import os, glob
-    from pathlib import Path
-
-    src_dir = d.getVar('PL_VARIANTS_DIR')
-    dest_path = os.path.join('/opt', 'fofb', 'map')
-
-    for var_name in  d.getVar('PL_VARIANTS').split():
-
-        mapt_path = next(Path(src_dir).rglob(f"{var_name}*ch8.mapt")).absolute()
-        dest_file = os.path.join(dest_path, f"app_{var_name}.mapt")
-
-        d.appendVar("SRC_URI", f" file://{mapt_path}")
-        d.appendVar("PL_MAPT_PATH", f" {mapt_path}")
-        d.appendVar("FILES_"+d.getVar("PN"), " "+dest_file)
-
-}
-
-# Changing BAR of mapt files to 0 (field #5 receive 0)
-# Replace each line of MATRIX coeff by a global entry
-do_compile () {
-    for MAPT in ${PL_MAPT_PATH}
-    do
-        awk 'FNR>1 {$5=0} {if ($1 ~ /MATRIXCOEF\.[^0]/ ) next} {if ($1 ~ /MATRIXCOEF\.0/) {$1="APP.corr_matrix_0.MATRIXCOEF" ; $2="12800" ; $4="51200"}}  {print}' ${WORKDIR}/${MAPT} > ${WORKDIR}/${MAPT}.bar0
-    done
-}
-
-
-# Adding MAPT files to install dir
-python do_install () {
-    import shutil, os
-
-    dest_path = os.path.join(d.getVar('D'), 'opt', 'fofb', 'map')
-    os.makedirs(dest_path, exist_ok=True)
-
-    for var_name, mapt_path in  zip(
-        d.getVar('PL_VARIANTS').split(),
-        d.getVar('PL_MAPT_PATH').split(),
-        ):
-
-        orig_file = d.getVar("WORKDIR")+mapt_path+".bar0"
-        dest_file = os.path.join(dest_path, f"app_{var_name}.mapt")
-
-        print(f"Install {orig_file} in {dest_file}")
-        shutil.copy(orig_file, dest_file)
-
-}
-
diff --git a/recipes-chimeratk/deviceaccess-mapfiles/deviceaccess-mapfiles.bbappend b/recipes-chimeratk/deviceaccess-mapfiles/deviceaccess-mapfiles.bbappend
new file mode 100644
index 0000000..4df741b
--- /dev/null
+++ b/recipes-chimeratk/deviceaccess-mapfiles/deviceaccess-mapfiles.bbappend
@@ -0,0 +1,33 @@
+MAPFILES_SRC_ORIG = "${RECIPE_SYSROOT}/opt/xilinx/hw-design"
+MAPFILES_SRC_BASE = "${WORKDIR}/map"
+
+# Changing BAR of mapt files to 0 (field #5 receive 0)
+# Replace each line of MATRIX coeff by a global entry
+do_compile () {
+    if [ "${PL_VARIANTS}" != "" ]; then
+        for PL_VARIANT in ${PL_VARIANTS}; do
+            VAR_SRCDIR=${MAPFILES_SRC_ORIG}/${PL_VARIANT}
+            VAR_DESTDIR=${MAPFILES_SRC_BASE}/${PL_VARIANT}
+            mkdir -p ${VAR_DESTDIR}
+
+            for MAPFILE_SRC in ${VAR_SRCDIR}/*.map[pt]; do
+                echo "Transform file ${MAPFILE_SRC}"
+                awk 'FNR>1 {$5=0}
+                    {if ($1 ~ /MATRIXCOEF\.[^0]/ ) next}
+                    {if ($1 ~ /MATRIXCOEF\.0/) {$1="APP.corr_matrix_0.MATRIXCOEF" ; $2="12800" ; $4="51200"}}
+                    {print}' ${MAPFILE_SRC} > ${VAR_DESTDIR}/$(basename ${MAPFILE_SRC})
+            done
+        done
+    else
+        HDF_BASENAME=$(echo ${HDF_SUFFIX} | cut -c2-)
+        VAR_DESTDIR=${D}${MAPFILES_DST_BASE}/${HDF_BASENAME}
+        for MAPFILE_SRC in ${MAPFILES_SRC_BASE}/*.map[pt]; do
+            echo "Transform file ${MAPFILE_SRC}"
+            awk 'FNR>1 {$5=0}
+                {if ($1 ~ /MATRIXCOEF\.[^0]/ ) next}
+                {if ($1 ~ /MATRIXCOEF\.0/) {$1="APP.corr_matrix_0.MATRIXCOEF" ; $2="12800" ; $4="51200"}}
+                {print}' ${MAPFILE_SRC} > ${VAR_DESTDIR}/$(basename ${MAPFILE_SRC})
+        done
+    fi
+
+}
-- 
GitLab