From 9041596bf7a975dec043ecafb242092cfeece631 Mon Sep 17 00:00:00 2001
From: Gary Bisson <gary.bisson@boundarydevices.com>
Date: Wed, 27 Dec 2017 11:47:01 +0100
Subject: [PATCH] hciattach_rome: do not override module internal MAC address

Signed-off-by: Gary Bisson <gary.bisson@boundarydevices.com>
---
 tools/hciattach_rome.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/tools/hciattach_rome.c b/tools/hciattach_rome.c
index 34e7edfb5..6336bdc6b 100644
--- a/tools/hciattach_rome.c
+++ b/tools/hciattach_rome.c
@@ -29,6 +29,7 @@
  *
  ******************************************************************************/
 
+#define MODULE_HAS_MAC_ADDR
 #define LOG_TAG "bt_vendor"
 #include <stdio.h>
 #include <unistd.h>
@@ -1057,6 +1058,7 @@ int rome_get_tlv_file(char *file_path)
 			nvm_index+=sizeof(tlv_nvm_hdr);
 			nvm_byte_ptr+=sizeof(tlv_nvm_hdr);
 
+#ifndef MODULE_HAS_MAC_ADDR
 			/* Write BD Address */
 			if (nvm_ptr->tag_id == TAG_NUM_2 && read_bd_address(bdaddr) == 0) {
 				memcpy(nvm_byte_ptr, bdaddr, 6);
@@ -1065,6 +1067,21 @@ int rome_get_tlv_file(char *file_path)
 				       *nvm_byte_ptr, *(nvm_byte_ptr+1), *(nvm_byte_ptr+2),
 				       *(nvm_byte_ptr+3), *(nvm_byte_ptr+4), *(nvm_byte_ptr+5));
 			}
+#else
+			/* Remove it from NVM data */
+			if (nvm_ptr->tag_id == TAG_NUM_2) {
+				int nvm_size = nvm_ptr->tag_len + sizeof(tlv_nvm_hdr);
+				PR_DBG("Skip BD Address from NVM\n");
+				nvm_index += nvm_ptr->tag_len;
+				nvm_byte_ptr += nvm_ptr->tag_len;
+				memmove(nvm_ptr, nvm_byte_ptr, nvm_length - nvm_index);
+				nvm_length -= nvm_size;
+				nvm_byte_ptr -= nvm_size;
+				readSize -= nvm_size;
+				nvm_index -= nvm_size;
+				continue;
+			}
+#endif
 
 			if (nvm_ptr->tag_id == TAG_NUM_17) {
 				if ((ibs_value =
