Added FSIJ serial number support.
authorNIIBE Yutaka <gniibe@fsij.org>
Wed, 20 Oct 2010 04:34:04 +0000 (13:34 +0900)
committerNIIBE Yutaka <gniibe@fsij.org>
Wed, 20 Oct 2010 04:34:04 +0000 (13:34 +0900)
ChangeLog
FSIJ_SERIAL_NUMBER [new file with mode: 0644]
src/config.h.in
src/configure

index 4ef674d..551a63f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2010-10-20  NIIBE Yutaka  <gniibe@fsij.org>
 
+       * FSIJ_SERIAL_NUMBER: New.
+       * src/configure (with_fsij): Added FSIJ serial number support.
+       * src/config.h.in (@FSIJ_DEFINE@, @SERIAL_NUMBER_FOUR_BYTES@): New.
+
        * src/configure: Added CQ STARM target.
        * boards/CQ_STARM/mcuconf.h: New.
        * boards/CQ_STARM/board.mk: New.
diff --git a/FSIJ_SERIAL_NUMBER b/FSIJ_SERIAL_NUMBER
new file mode 100644 (file)
index 0000000..ecad1f5
--- /dev/null
@@ -0,0 +1,2 @@
+# Email         # 4-byte serial number, separated by ':'
+gniibe@fsij.org 00:00:00:01
index b3ae78b..bb5f898 100644 (file)
@@ -3,7 +3,8 @@
 #define ENABLE_VIRTUAL_COM_PORT 1
 #endif
 
-#if 0
+@FSIJ_DEFINE@
+#ifdef WITH_FSIJ_SERIAL_NUMBER
 /* FSIJ */
 #define MANUFACTURER_IN_AID            0xf5, 0x17
 #else
@@ -11,6 +12,6 @@
 #define MANUFACTURER_IN_AID            0xff, 0xfe
 #endif
 
-#define SERIAL_NUMBER_IN_AID  0x00, 0x00, 0x00, 0x01
+#define SERIAL_NUMBER_IN_AID  @SERIAL_NUMBER_FOUR_BYTES@
 
 @DFU_DEFINE@
index 8eb0798..9988d52 100755 (executable)
@@ -24,8 +24,15 @@ help=no
 target=OLIMEX_STM32_H103
 verbose=no
 with_dfu=default
+with_fsij=no
 debug=no
 
+# check /dev/random
+if test ! -e /dev/random; then
+  echo "/dev/random is required." >&2
+  exit 1
+fi
+
 # Process each option
 for option; do
   case $option in
@@ -48,6 +55,10 @@ for option; do
     with_dfu=yes ;;
   --without-dfu)
     with_dfu=no ;;
+  --with-fsij)
+    with_fsij=yes ;;
+  --without-fsij)
+    with_fsij=no ;;
   *)
     echo "Unrecognized option \`$option'" >&2
     echo "Try \`$0 --help' for more information." >&2
@@ -71,6 +82,7 @@ Configuration:
                           CQ_STARM
   --enable-debug       debug with virtual COM port     [no]
   --with-dfu           build image for DFU             [<target specific>]
+  --with-fsij          Use FSIJ serial number          [no: random number]
 EOF
   exit 0
 fi
@@ -95,6 +107,19 @@ CQ_STARM)
   fi  ;;
 esac
 
+# --with-fsij option
+if test "$with_fsij" = "no"; then
+  FSIJ_DEFINE="#undef WITH_FSIJ_SERIAL_NUMBER"
+  SERIAL_NUMBER_FOUR_BYTES=`od -t u1 -N 4 /dev/random | sed -n -e '/^0000000/s/^0000000  *//' -e 's/  */,/gp'`
+else
+  if test "x$MAIL" = "x"; then
+    echo "Please set MAIL shell variable to select FSIJ serial number." >&2
+    exit 1
+  fi
+  FSIJ_DEFINE="#define WITH_FSIJ_SERIAL_NUMBER 1"
+  SERIAL_NUMBER_FOUR_BYTES=`sed -n -e "/^$MAIL/s/^.* \(..\):\(..\):\(..\):\(..\)/0x\1, 0x\2, 0x\3, 0x\4/p" ../FSIJ_SERIAL_NUMBER`
+fi
+
 if test "$debug" = "yes"; then
   DEBUG_MAKE_OPTION="ENABLE_DEBUG=1"
   DEBUG_DEFINE="#define DEBUG 1"
@@ -122,5 +147,7 @@ sed -e "s/@ORIGIN@/$ORIGIN/" -e "s/@FLASH_SIZE@/$FLASH_SIZE/" \
        < gnuk.ld.in > gnuk.ld
 sed -e "s/@DEBUG_DEFINE@/$DEBUG_DEFINE/" \
     -e "s/@DFU_DEFINE@/$DFU_DEFINE/" \
+    -e "s/@FSIJ_DEFINE@/$FSIJ_DEFINE/" \
+    -e "s/@SERIAL_NUMBER_FOUR_BYTES@/$SERIAL_NUMBER_FOUR_BYTES/" \
        < config.h.in > config.h
 exit 0