From 978907f904f3ef1cff8d2b230afbf70665cf770d Mon Sep 17 00:00:00 2001
From: Federico Vaga <federico.vaga@cern.ch>
Date: Fri, 21 Oct 2016 18:12:02 +0200
Subject: [PATCH] userspace:startup: verify that the FPGA bitstream has been
 programmed

Signed-off-by: Federico Vaga <federico.vaga@cern.ch>
---
 userspace/rootfs_override/wr/sbin/startup-mb.sh | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/userspace/rootfs_override/wr/sbin/startup-mb.sh b/userspace/rootfs_override/wr/sbin/startup-mb.sh
index 2728511d1..38715677d 100755
--- a/userspace/rootfs_override/wr/sbin/startup-mb.sh
+++ b/userspace/rootfs_override/wr/sbin/startup-mb.sh
@@ -57,6 +57,20 @@ else
     echo "load_error" > $LOAD_FPGA_STATUS_FILE
 fi
 
+# At this offset there is an ID. Just check that it's there as a
+# small proof that we correctly programmed the FPGA
+CHK_ADDR=0x10030034
+CHK_EXP=0xcafebabe
+CHK_VAL=$(devmem $CHK_ADDR | tr '[:upper:]' '[:lower:]')
+if [ $CHK_VAL != $CHK_EXP ]
+then
+    echo "The bitstream $FP_FILE is not correct or there something is not working with the FPGA"
+    echo "Expected: [$CHK_ADDR] = $CHK_EXP"
+    echo "Current: [$CHK_ADDR] = $CHK_VAL"
+    echo "LM32 program and drivers for the bitstream components will not be loaded"
+    exit
+fi
+
 $WR_HOME/bin/load-lm32   $LM_FILE scb_ver=${scb_ver}
 if [ $? -eq 0 ];
 then
-- 
GitLab