Advertisement
Mister_Magister

0001-bluetooth-Add-bluetooth-support-for-QCA6174-chip.patch

Sep 20th, 2017
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 78.78 KB | None | 0 0
  1. /*
  2. * Copyright (c) 2014 Linux Foundation
  3. * All Rights Reserved.
  4. * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
  5.  
  6. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  7.  
  8. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  9.  
  10. */
  11. From 8c5aed296c21818671890b5e38d60288e79929f5 Mon Sep 17 00:00:00 2001
  12. From: Rupesh Tatiya <rtatiya@qti.qualcomm.com>
  13. Date: Tue, 19 Aug 2014 20:23:01 +0530
  14. Subject: [PATCH 1/8] bluetooth : Add bluetooth support for QCA6174 chip.
  15.  
  16. Register the QCA6174 initialization routine with hciattach for
  17. downloading firmware patches to the bluetooth controller.
  18. Add optional support 'f' to control installation of line
  19. discipline driver. Invoke hciattach from command line and
  20. download the firmware patches:
  21. hciattach /dev/ttyHS0 qca -t120 flow -f0
  22.  
  23. Change-Id: I87f2927d7096904071a02d73d3afef0dc34db414
  24. Signed-off-by: Rupesh Tatiya <rtatiya@codeaurora.org>
  25. ---
  26. Makefile.tools | 3 +-
  27. tools/hciattach.c | 26 +-
  28. tools/hciattach.h | 2 +
  29. tools/hciattach_rome.c | 1578 ++++++++++++++++++++++++++++++++++++++++++++++++
  30. tools/hciattach_rome.h | 317 ++++++++++
  31. 5 files changed, 1924 insertions(+), 2 deletions(-)
  32. create mode 100644 tools/hciattach_rome.c
  33. create mode 100644 tools/hciattach_rome.h
  34.  
  35. diff --git a/Makefile.tools b/Makefile.tools
  36. index 412a998..5ae3b78 100644
  37. --- a/Makefile.tools
  38. +++ b/Makefile.tools
  39. @@ -185,7 +185,8 @@ tools_hciattach_SOURCES = tools/hciattach.c tools/hciattach.h \
  40. tools/hciattach_ath3k.c \
  41. tools/hciattach_qualcomm.c \
  42. tools/hciattach_intel.c \
  43. - tools/hciattach_bcm43xx.c
  44. + tools/hciattach_bcm43xx.c \
  45. + tools/hciattach_rome.c tools/hciattach_rome.h
  46. tools_hciattach_LDADD = lib/libbluetooth-internal.la
  47.  
  48. tools_hciconfig_SOURCES = tools/hciconfig.c tools/csr.h tools/csr.c
  49. diff --git a/tools/hciattach.c b/tools/hciattach.c
  50. index 1904ac5..3f607cf 100644
  51. --- a/tools/hciattach.c
  52. +++ b/tools/hciattach.c
  53. @@ -67,6 +67,8 @@ struct uart_t {
  54. #define ENABLE_PM 1
  55. #define DISABLE_PM 0
  56.  
  57. +int line_disp = 1;
  58. +
  59. static volatile sig_atomic_t __io_canceled = 0;
  60.  
  61. static void sig_hup(int sig)
  62. @@ -317,6 +319,12 @@ static int ath3k_pm(int fd, struct uart_t *u, struct termios *ti)
  63. return ath3k_post(fd, u->pm);
  64. }
  65.  
  66. +static int qca(int fd, struct uart_t *u, struct termios *ti)
  67. +{
  68. + fprintf(stderr,"qca\n");
  69. + return qca_soc_init(fd, u->bdaddr);
  70. +}
  71. +
  72. static int qualcomm(int fd, struct uart_t *u, struct termios *ti)
  73. {
  74. return qualcomm_init(fd, u->speed, ti, u->bdaddr);
  75. @@ -1147,6 +1155,10 @@ struct uart_t uart[] = {
  76. { "ath3k", 0x0000, 0x0000, HCI_UART_ATH3K, 115200, 115200,
  77. FLOW_CTL, DISABLE_PM, NULL, ath3k_ps, ath3k_pm },
  78.  
  79. + /* QCA ROME */
  80. + { "qca", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200,
  81. + FLOW_CTL, DISABLE_PM, NULL, qca, NULL },
  82. +
  83. /* QUALCOMM BTS */
  84. { "qualcomm", 0x0000, 0x0000, HCI_UART_H4, 115200, 115200,
  85. FLOW_CTL, DISABLE_PM, NULL, qualcomm, NULL },
  86. @@ -1249,6 +1261,8 @@ static int init_uart(char *dev, struct uart_t *u, int send_break, int raw)
  87. return -1;
  88. }
  89.  
  90. +if (line_disp) {
  91. + fprintf(stderr, "Setting TTY to N_HCI line discipline\n");
  92. /* Set TTY to N_HCI line discipline */
  93. i = N_HCI;
  94. if (ioctl(fd, TIOCSETD, &i) < 0) {
  95. @@ -1265,6 +1279,7 @@ static int init_uart(char *dev, struct uart_t *u, int send_break, int raw)
  96. perror("Can't set device");
  97. return -1;
  98. }
  99. +}
  100.  
  101. if (u->post && u->post(fd, u, &ti) < 0)
  102. return -1;
  103. @@ -1297,7 +1312,7 @@ int main(int argc, char *argv[])
  104. printpid = 0;
  105. raw = 0;
  106.  
  107. - while ((opt=getopt(argc, argv, "bnpt:s:lr")) != EOF) {
  108. + while ((opt=getopt(argc, argv, "bnpt:s:lrf:")) != EOF) {
  109. switch(opt) {
  110. case 'b':
  111. send_break = 1;
  112. @@ -1330,6 +1345,11 @@ int main(int argc, char *argv[])
  113. raw = 1;
  114. break;
  115.  
  116. + case 'f':
  117. + line_disp = atoi(optarg);
  118. + fprintf(stderr, "Line_disp val : %d\n", line_disp);
  119. + break;
  120. +
  121. default:
  122. usage();
  123. exit(1);
  124. @@ -1392,6 +1412,7 @@ int main(int argc, char *argv[])
  125. case 5:
  126. u->bdaddr = argv[optind];
  127. break;
  128. +
  129. }
  130. }
  131.  
  132. @@ -1468,12 +1489,15 @@ int main(int argc, char *argv[])
  133. break;
  134. }
  135.  
  136. +if (line_disp) {
  137. /* Restore TTY line discipline */
  138. + fprintf(stderr, "Restoring the Line Discipline driver\n");
  139. ld = N_TTY;
  140. if (ioctl(n, TIOCSETD, &ld) < 0) {
  141. perror("Can't restore line discipline");
  142. exit(1);
  143. }
  144. +}
  145.  
  146. return 0;
  147. }
  148. diff --git a/tools/hciattach.h b/tools/hciattach.h
  149. index 4810a09..a3fceb2 100644
  150. --- a/tools/hciattach.h
  151. +++ b/tools/hciattach.h
  152. @@ -39,6 +39,7 @@
  153. #define HCI_UART_H4DS 3
  154. #define HCI_UART_LL 4
  155. #define HCI_UART_ATH3K 5
  156. +#define HCI_UART_IBS 6
  157.  
  158. #define HCI_UART_RAW_DEVICE 0
  159. #define HCI_UART_RESET_ON_INIT 1
  160. @@ -56,6 +57,7 @@ int bgb2xx_init(int dd, bdaddr_t *bdaddr);
  161. int ath3k_init(int fd, int speed, int init_speed, char *bdaddr,
  162. struct termios *ti);
  163. int ath3k_post(int fd, int pm);
  164. +int qca_soc_init(int fd, char *bdaddr);
  165. int qualcomm_init(int fd, int speed, struct termios *ti, const char *bdaddr);
  166. int intel_init(int fd, int init_speed, int *speed, struct termios *ti);
  167. int bcm43xx_init(int fd, int speed, struct termios *ti, const char *bdaddr);
  168. diff --git a/tools/hciattach_rome.c b/tools/hciattach_rome.c
  169. new file mode 100644
  170. index 0000000..f31be43
  171. --- /dev/null
  172. +++ b/tools/hciattach_rome.c
  173. @@ -0,0 +1,1578 @@
  174. +/*
  175. + *
  176. + * Copyright (c) 2013, The Linux Foundation. All rights reserved.
  177. + * Not a Contribution.
  178. + *
  179. + * Copyright 2012 The Android Open Source Project
  180. + *
  181. + * Licensed under the Apache License, Version 2.0 (the "License"); you
  182. + * may not use this file except in compliance with the License. You may
  183. + * obtain a copy of the License at
  184. + *
  185. + * http://www.apache.org/licenses/LICENSE-2.0
  186. + *
  187. + * Unless required by applicable law or agreed to in writing, software
  188. + * distributed under the License is distributed on an "AS IS" BASIS,
  189. + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  190. + * implied. See the License for the specific language governing
  191. + * permissions and limitations under the License.
  192. + *
  193. + */
  194. +
  195. +/******************************************************************************
  196. + *
  197. + * Filename: hciattach_rome.c
  198. + *
  199. + * Description: Contains controller-specific functions, like
  200. + * firmware patch download
  201. + * low power mode operations
  202. + *
  203. + ******************************************************************************/
  204. +
  205. +#define LOG_TAG "bt_vendor"
  206. +#include <stdio.h>
  207. +#include <sys/socket.h>
  208. +#include <sys/types.h>
  209. +#include <sys/stat.h>
  210. +#include <sys/ioctl.h>
  211. +#include <signal.h>
  212. +#include <time.h>
  213. +#include <errno.h>
  214. +#include <fcntl.h>
  215. +#include <dirent.h>
  216. +#include <ctype.h>
  217. +#include <stdlib.h>
  218. +#include <string.h>
  219. +#include <termios.h>
  220. +#include <bluetooth/bluetooth.h>
  221. +#include "hciattach_rome.h"
  222. +#include "hciattach.h"
  223. +
  224. +#ifdef __cplusplus
  225. +}
  226. +#endif
  227. +
  228. +
  229. +/******************************************************************************
  230. +** Variables
  231. +******************************************************************************/
  232. +FILE *file;
  233. +unsigned char *phdr_buffer;
  234. +unsigned char *pdata_buffer = NULL;
  235. +patch_info rampatch_patch_info;
  236. +int rome_ver = ROME_VER_UNKNOWN;
  237. +unsigned char gTlv_type;
  238. +char *rampatch_file_path;
  239. +char *nvm_file_path;
  240. +vnd_userial_cb_t vnd_userial;
  241. +/******************************************************************************
  242. +** Extern variables
  243. +******************************************************************************/
  244. +//extern unsigned char vnd_local_bd_addr[6];
  245. +
  246. +/*****************************************************************************
  247. +** Functions
  248. +*****************************************************************************/
  249. +
  250. +/*******************************************************************************
  251. +**
  252. +** Function userial_to_tcio_baud
  253. +**
  254. +** Description helper function converts USERIAL baud rates into TCIO
  255. +** conforming baud rates
  256. +**
  257. +** Returns TRUE/FALSE
  258. +**
  259. +*******************************************************************************/
  260. +unsigned char userial_to_tcio_baud(unsigned char cfg_baud, unsigned int *baud)
  261. +{
  262. + if (cfg_baud == USERIAL_BAUD_115200)
  263. + *baud = B115200;
  264. + else if (cfg_baud == USERIAL_BAUD_4M)
  265. + *baud = B4000000;
  266. + else if (cfg_baud == USERIAL_BAUD_3M)
  267. + *baud = B3000000;
  268. + else if (cfg_baud == USERIAL_BAUD_2M)
  269. + *baud = B2000000;
  270. + else if (cfg_baud == USERIAL_BAUD_1M)
  271. + *baud = B1000000;
  272. + else if (cfg_baud == USERIAL_BAUD_921600)
  273. + *baud = B921600;
  274. + else if (cfg_baud == USERIAL_BAUD_460800)
  275. + *baud = B460800;
  276. + else if (cfg_baud == USERIAL_BAUD_230400)
  277. + *baud = B230400;
  278. + else if (cfg_baud == USERIAL_BAUD_57600)
  279. + *baud = B57600;
  280. + else if (cfg_baud == USERIAL_BAUD_19200)
  281. + *baud = B19200;
  282. + else if (cfg_baud == USERIAL_BAUD_9600)
  283. + *baud = B9600;
  284. + else if (cfg_baud == USERIAL_BAUD_1200)
  285. + *baud = B1200;
  286. + else if (cfg_baud == USERIAL_BAUD_600)
  287. + *baud = B600;
  288. + else
  289. + {
  290. + fprintf(stderr, "userial vendor open: unsupported baud idx %i\n", cfg_baud);
  291. + *baud = B115200;
  292. + return FALSE;
  293. + }
  294. +
  295. + return TRUE;
  296. +}
  297. +
  298. +
  299. +/*******************************************************************************
  300. +**
  301. +** Function userial_vendor_set_baud
  302. +**
  303. +** Description Set new baud rate
  304. +**
  305. +** Returns None
  306. +**
  307. +*******************************************************************************/
  308. +void userial_vendor_set_baud(unsigned char userial_baud)
  309. +{
  310. + unsigned int tcio_baud;
  311. + fprintf(stderr, "## userial_vendor_set_baud: %d\n", userial_baud);
  312. +
  313. + userial_to_tcio_baud(userial_baud, &tcio_baud);
  314. +
  315. + cfsetospeed(&vnd_userial.termios, tcio_baud);
  316. + cfsetispeed(&vnd_userial.termios, tcio_baud);
  317. + tcsetattr(vnd_userial.fd, TCSADRAIN, &vnd_userial.termios); /* don't change speed until last write done */
  318. +
  319. +}
  320. +
  321. +
  322. +/*******************************************************************************
  323. +**
  324. +** Function userial_vendor_ioctl
  325. +**
  326. +** Description ioctl inteface
  327. +**
  328. +** Returns None
  329. +**
  330. +*******************************************************************************/
  331. +int userial_vendor_ioctl(int fd, userial_vendor_ioctl_op_t op, int *p_data)
  332. +{
  333. + int err = -1;
  334. + struct termios ti;
  335. +
  336. + if (tcgetattr(fd, &ti) < 0) {
  337. + perror("Can't get port settings");
  338. + return -1;
  339. + }
  340. + cfmakeraw(&ti);
  341. + ti.c_cflag |= CLOCAL;
  342. +
  343. + switch(op)
  344. + {
  345. +#if (BT_WAKE_VIA_USERIAL_IOCTL==TRUE)
  346. + case USERIAL_OP_ASSERT_BT_WAKE:
  347. + VNDUSERIALDBG("## userial_vendor_ioctl: Asserting BT_Wake ##");
  348. + err = ioctl(fd, USERIAL_IOCTL_BT_WAKE_ASSERT, NULL);
  349. + break;
  350. +
  351. + case USERIAL_OP_DEASSERT_BT_WAKE:
  352. + VNDUSERIALDBG("## userial_vendor_ioctl: De-asserting BT_Wake ##");
  353. + err = ioctl(fd, USERIAL_IOCTL_BT_WAKE_DEASSERT, NULL);
  354. + break;
  355. +
  356. + case USERIAL_OP_GET_BT_WAKE_STATE:
  357. + err = ioctl(fd, USERIAL_IOCTL_BT_WAKE_GET_ST, p_data);
  358. + break;
  359. +#endif // (BT_WAKE_VIA_USERIAL_IOCTL==TRUE)
  360. + case USERIAL_OP_FLOW_ON:
  361. + fprintf(stderr, "## userial_vendor_ioctl: UART Flow On\n ");
  362. + ti.c_cflag |= CRTSCTS;
  363. +
  364. + if (err = tcsetattr(fd, TCSANOW, &ti) < 0) {
  365. + perror("Can't set port settings");
  366. + return -1;
  367. + }
  368. +
  369. + break;
  370. +
  371. + case USERIAL_OP_FLOW_OFF:
  372. + fprintf(stderr, "## userial_vendor_ioctl: UART Flow Off\n ");
  373. + ti.c_cflag &= ~CRTSCTS;
  374. + if (err = tcsetattr(fd, TCSANOW, &ti) < 0) {
  375. + fprintf(stderr, "Can't set port settings");
  376. + return -1;
  377. + }
  378. + break;
  379. +
  380. + default:
  381. + break;
  382. + }
  383. +
  384. + return err;
  385. +}
  386. +
  387. +
  388. +int get_vs_hci_event(unsigned char *rsp)
  389. +{
  390. + int err = 0, soc_id =0;
  391. + unsigned char paramlen = 0;
  392. +
  393. + if( (rsp[EVENTCODE_OFFSET] == VSEVENT_CODE) || (rsp[EVENTCODE_OFFSET] == EVT_CMD_COMPLETE))
  394. + fprintf(stderr, "%s: Received HCI-Vendor Specific event\n", __FUNCTION__);
  395. + else {
  396. + fprintf(stderr, "%s: Failed to receive HCI-Vendor Specific event\n", __FUNCTION__);
  397. + err = -EIO;
  398. + goto failed;
  399. + }
  400. +
  401. + fprintf(stderr, "%s: Parameter Length: 0x%x\n", __FUNCTION__, paramlen = rsp[EVT_PLEN]);
  402. + fprintf(stderr, "%s: Command response: 0x%x\n", __FUNCTION__, rsp[CMD_RSP_OFFSET]);
  403. + fprintf(stderr, "%s: Response type : 0x%x\n", __FUNCTION__, rsp[RSP_TYPE_OFFSET]);
  404. +
  405. + /* Check the status of the operation */
  406. + switch ( rsp[CMD_RSP_OFFSET] )
  407. + {
  408. + case EDL_CMD_REQ_RES_EVT:
  409. + fprintf(stderr, "%s: Command Request Response\n", __FUNCTION__);
  410. + switch(rsp[RSP_TYPE_OFFSET])
  411. + {
  412. + case EDL_PATCH_VER_RES_EVT:
  413. + case EDL_APP_VER_RES_EVT:
  414. + fprintf(stderr, "\t Current Product ID\t\t: 0x%08x\n",
  415. + (unsigned int)(rsp[PATCH_PROD_ID_OFFSET +3] << 24 |
  416. + rsp[PATCH_PROD_ID_OFFSET+2] << 16 |
  417. + rsp[PATCH_PROD_ID_OFFSET+1] << 8 |
  418. + rsp[PATCH_PROD_ID_OFFSET] ));
  419. +
  420. + /* Patch Version indicates FW patch version */
  421. + fprintf(stderr, "\t Current Patch Version\t\t: 0x%04x\n",
  422. + (unsigned short)(rsp[PATCH_PATCH_VER_OFFSET + 1] << 8 |
  423. + rsp[PATCH_PATCH_VER_OFFSET] ));
  424. +
  425. + /* ROM Build Version indicates ROM build version like 1.0/1.1/2.0 */
  426. + fprintf(stderr, "\t Current ROM Build Version\t: 0x%04x\n", rome_ver =
  427. + (int)(rsp[PATCH_ROM_BUILD_VER_OFFSET + 1] << 8 |
  428. + rsp[PATCH_ROM_BUILD_VER_OFFSET] ));
  429. +
  430. + /* In case rome 1.0/1.1, there is no SOC ID version available */
  431. + if (paramlen - 10)
  432. + {
  433. + fprintf(stderr, "\t Current SOC Version\t\t: 0x%08x\n", soc_id =
  434. + (unsigned int)(rsp[PATCH_SOC_VER_OFFSET +3] << 24 |
  435. + rsp[PATCH_SOC_VER_OFFSET+2] << 16 |
  436. + rsp[PATCH_SOC_VER_OFFSET+1] << 8 |
  437. + rsp[PATCH_SOC_VER_OFFSET] ));
  438. + }
  439. +
  440. + /* Rome Chipset Version can be decided by Patch version and SOC version,
  441. + Upper 2 bytes will be used for Patch version and Lower 2 bytes will be
  442. + used for SOC as combination for BT host driver */
  443. + rome_ver = (rome_ver << 16) | (soc_id & 0x0000ffff);
  444. + break;
  445. + case EDL_TVL_DNLD_RES_EVT:
  446. + case EDL_CMD_EXE_STATUS_EVT:
  447. + switch (err = rsp[CMD_STATUS_OFFSET])
  448. + {
  449. + case HCI_CMD_SUCCESS:
  450. + fprintf(stderr, "%s: Download Packet successfully!\n", __FUNCTION__);
  451. + break;
  452. + case PATCH_LEN_ERROR:
  453. + fprintf(stderr, "%s: Invalid patch length argument passed for EDL PATCH "
  454. + "SET REQ cmd\n", __FUNCTION__);
  455. + break;
  456. + case PATCH_VER_ERROR:
  457. + fprintf(stderr, "%s: Invalid patch version argument passed for EDL PATCH "
  458. + "SET REQ cmd\n", __FUNCTION__);
  459. + break;
  460. + case PATCH_CRC_ERROR:
  461. + fprintf(stderr, "%s: CRC check of patch failed!!!\n", __FUNCTION__);
  462. + break;
  463. + case PATCH_NOT_FOUND:
  464. + fprintf(stderr, "%s: Invalid patch data!!!\n", __FUNCTION__);
  465. + break;
  466. + case TLV_TYPE_ERROR:
  467. + fprintf(stderr, "%s: TLV Type Error !!!\n", __FUNCTION__);
  468. + break;
  469. + default:
  470. + fprintf(stderr, "%s: Undefined error (0x%x)", __FUNCTION__, err);
  471. + break;
  472. + }
  473. + break;
  474. + }
  475. + break;
  476. +
  477. + case NVM_ACCESS_CODE:
  478. + fprintf(stderr, "%s: NVM Access Code!!!\n", __FUNCTION__);
  479. + err = HCI_CMD_SUCCESS;
  480. + break;
  481. + case EDL_SET_BAUDRATE_RSP_EVT:
  482. + /* Rome 1.1 has bug with the response, so it should ignore it. */
  483. + if (rsp[BAUDRATE_RSP_STATUS_OFFSET] != BAUDRATE_CHANGE_SUCCESS)
  484. + {
  485. + fprintf(stderr, "%s: Set Baudrate request failed - 0x%x\n", __FUNCTION__,
  486. + rsp[CMD_STATUS_OFFSET]);
  487. + err = -1;
  488. + }
  489. + break;
  490. + default:
  491. + fprintf(stderr, "%s: Not a valid status!!!\n", __FUNCTION__);
  492. + err = -1;
  493. + break;
  494. + }
  495. +
  496. +failed:
  497. + return err;
  498. +}
  499. +
  500. +
  501. +/*
  502. + * Read an VS HCI event from the given file descriptor.
  503. + */
  504. +int read_vs_hci_event(int fd, unsigned char* buf, int size)
  505. +{
  506. + int remain, r;
  507. + int count = 0;
  508. +
  509. + if (size <= 0) {
  510. + fprintf(stderr, "Invalid size arguement!\n");
  511. + return -1;
  512. + }
  513. +
  514. + fprintf(stderr, "%s: Wait for HCI-Vendor Specfic Event from SOC\n", __FUNCTION__);
  515. +
  516. + /* The first byte identifies the packet type. For HCI event packets, it
  517. + * should be 0x04, so we read until we get to the 0x04. */
  518. + /* It will keep reading until find 0x04 byte */
  519. + while (1) {
  520. + r = read(fd, buf, 1);
  521. + if (r <= 0)
  522. + return -1;
  523. + if (buf[0] == 0x04)
  524. + break;
  525. + }
  526. + count++;
  527. +
  528. + fprintf(stderr, "%s: Wait for HCI-Vendor Specfic Event from SOC, buf[0] - 0x%x\n", __FUNCTION__, buf[0]);
  529. + /* The next two bytes are the event code and parameter total length. */
  530. + while (count < 3) {
  531. + r = read(fd, buf + count, 3 - count);
  532. + if ((r <= 0) || (buf[1] != 0xFF )) {
  533. + fprintf(stderr, "It is not VS event !!\n");
  534. + return -1;
  535. + }
  536. + count += r;
  537. + }
  538. +
  539. + fprintf(stderr, "%s: Wait for HCI-Vendor Specfic Event from SOC, buf[1] - 0x%x\n", __FUNCTION__, buf[1]);
  540. + /* Now we read the parameters. */
  541. + if (buf[2] < (size - 3))
  542. + remain = buf[2];
  543. + else
  544. + remain = size - 3;
  545. +
  546. + while ((count - 3) < remain) {
  547. + r = read(fd, buf + count, remain - (count - 3));
  548. + if (r <= 0)
  549. + return -1;
  550. + count += r;
  551. + }
  552. +
  553. + /* Check if the set patch command is successful or not */
  554. + if(get_vs_hci_event(buf) != HCI_CMD_SUCCESS)
  555. + return -1;
  556. +
  557. + fprintf(stderr, "%s: Wait for HCI-Vendor Specfic Event from SOC, count - 0x%x\n", __FUNCTION__, count);
  558. + return count;
  559. +}
  560. +
  561. +
  562. +int hci_send_vs_cmd(int fd, unsigned char *cmd, unsigned char *rsp, int size)
  563. +{
  564. + int ret = 0;
  565. +
  566. + /* Send the HCI command packet to UART for transmission */
  567. + ret = write(fd, cmd, size);
  568. + if (ret != size) {
  569. + fprintf(stderr, "%s: Send failed with ret value: %d\n", __FUNCTION__, ret);
  570. + goto failed;
  571. + }
  572. +
  573. + /* Check for response from the Controller */
  574. + if (read_vs_hci_event(fd, rsp, HCI_MAX_EVENT_SIZE) < 0) {
  575. + ret = -ETIMEDOUT;
  576. + fprintf(stderr, "%s: Failed to get HCI-VS Event from SOC\n", __FUNCTION__);
  577. + goto failed;
  578. + }
  579. +
  580. + fprintf(stderr, "%s: Received HCI-Vendor Specific Event from SOC\n", __FUNCTION__);
  581. +failed:
  582. + return ret;
  583. +}
  584. +
  585. +void frame_hci_cmd_pkt(
  586. + unsigned char *cmd,
  587. + int edl_cmd, unsigned int p_base_addr,
  588. + int segtNo, int size
  589. + )
  590. +{
  591. + int offset = 0;
  592. + hci_command_hdr *cmd_hdr;
  593. +
  594. + memset(cmd, 0x0, HCI_MAX_CMD_SIZE);
  595. +
  596. + cmd_hdr = (void *) (cmd + 1);
  597. +
  598. + cmd[0] = HCI_COMMAND_PKT;
  599. + cmd_hdr->opcode = cmd_opcode_pack(HCI_VENDOR_CMD_OGF, HCI_PATCH_CMD_OCF);
  600. + cmd_hdr->plen = size;
  601. + cmd[4] = edl_cmd;
  602. +
  603. + switch (edl_cmd)
  604. + {
  605. + case EDL_PATCH_SET_REQ_CMD:
  606. + /* Copy the patch header info as CMD params */
  607. + memcpy(&cmd[5], phdr_buffer, PATCH_HDR_LEN);
  608. + fprintf(stderr, "%s: Sending EDL_PATCH_SET_REQ_CMD\n", __FUNCTION__);
  609. + fprintf(stderr, "HCI-CMD %d:\t0x%x \t0x%x \t0x%x \t0x%x \t0x%x\n",
  610. + segtNo, cmd[0], cmd[1], cmd[2], cmd[3], cmd[4]);
  611. + break;
  612. + case EDL_PATCH_DLD_REQ_CMD:
  613. + offset = ((segtNo - 1) * MAX_DATA_PER_SEGMENT);
  614. + p_base_addr += offset;
  615. + cmd_hdr->plen = (size + 6);
  616. + cmd[5] = (size + 4);
  617. + cmd[6] = EXTRACT_BYTE(p_base_addr, 0);
  618. + cmd[7] = EXTRACT_BYTE(p_base_addr, 1);
  619. + cmd[8] = EXTRACT_BYTE(p_base_addr, 2);
  620. + cmd[9] = EXTRACT_BYTE(p_base_addr, 3);
  621. + memcpy(&cmd[10], (pdata_buffer + offset), size);
  622. +
  623. + fprintf(stderr, "%s: Sending EDL_PATCH_DLD_REQ_CMD: size: %d bytes\n",
  624. + __FUNCTION__, size);
  625. + fprintf(stderr, "HCI-CMD %d:\t0x%x\t0x%x\t0x%x\t0x%x\t0x%x\t0x%x\t0x%x\t"
  626. + "0x%x\t0x%x\t0x%x\t\n", segtNo, cmd[0], cmd[1], cmd[2],
  627. + cmd[3], cmd[4], cmd[5], cmd[6], cmd[7], cmd[8], cmd[9]);
  628. + break;
  629. + case EDL_PATCH_ATCH_REQ_CMD:
  630. + fprintf(stderr, "%s: Sending EDL_PATCH_ATTACH_REQ_CMD\n", __FUNCTION__);
  631. + fprintf(stderr, "HCI-CMD %d:\t0x%x \t0x%x \t0x%x \t0x%x \t0x%x\n",
  632. + segtNo, cmd[0], cmd[1], cmd[2], cmd[3], cmd[4]);
  633. + break;
  634. + case EDL_PATCH_RST_REQ_CMD:
  635. + fprintf(stderr, "%s: Sending EDL_PATCH_RESET_REQ_CMD\n", __FUNCTION__);
  636. + fprintf(stderr, "HCI-CMD %d:\t0x%x \t0x%x \t0x%x \t0x%x \t0x%x\n",
  637. + segtNo, cmd[0], cmd[1], cmd[2], cmd[3], cmd[4]);
  638. + break;
  639. + case EDL_PATCH_VER_REQ_CMD:
  640. + fprintf(stderr, "%s: Sending EDL_PATCH_VER_REQ_CMD\n", __FUNCTION__);
  641. + fprintf(stderr, "HCI-CMD %d:\t0x%x \t0x%x \t0x%x \t0x%x \t0x%x\n",
  642. + segtNo, cmd[0], cmd[1], cmd[2], cmd[3], cmd[4]);
  643. + break;
  644. + case EDL_PATCH_TLV_REQ_CMD:
  645. + fprintf(stderr, "%s: Sending EDL_PATCH_TLV_REQ_CMD\n", __FUNCTION__);
  646. + /* Parameter Total Length */
  647. + cmd[3] = size +2;
  648. +
  649. + /* TLV Segment Length */
  650. + cmd[5] = size;
  651. + fprintf(stderr, "HCI-CMD %d:\t0x%x \t0x%x \t0x%x \t0x%x \t0x%x \t0x%x\n",
  652. + segtNo, cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], cmd[5]);
  653. + offset = (segtNo * MAX_SIZE_PER_TLV_SEGMENT);
  654. + memcpy(&cmd[6], (pdata_buffer + offset), size);
  655. + break;
  656. + default:
  657. + fprintf(stderr, "%s: Unknown EDL CMD !!!\n", __FUNCTION__);
  658. + }
  659. +}
  660. +
  661. +void rome_extract_patch_header_info(unsigned char *buf)
  662. +{
  663. + int index;
  664. +
  665. + /* Extract patch id */
  666. + for (index = 0; index < 4; index++)
  667. + rampatch_patch_info.patch_id |=
  668. + (LSH(buf[index + P_ID_OFFSET], (index * 8)));
  669. +
  670. + /* Extract (ROM and BUILD) version information */
  671. + for (index = 0; index < 2; index++)
  672. + rampatch_patch_info.patch_ver.rom_version |=
  673. + (LSH(buf[index + P_ROME_VER_OFFSET], (index * 8)));
  674. +
  675. + for (index = 0; index < 2; index++)
  676. + rampatch_patch_info.patch_ver.build_version |=
  677. + (LSH(buf[index + P_BUILD_VER_OFFSET], (index * 8)));
  678. +
  679. + /* Extract patch base and entry addresses */
  680. + for (index = 0; index < 4; index++)
  681. + rampatch_patch_info.patch_base_addr |=
  682. + (LSH(buf[index + P_BASE_ADDR_OFFSET], (index * 8)));
  683. +
  684. + /* Patch BASE & ENTRY addresses are same */
  685. + rampatch_patch_info.patch_entry_addr = rampatch_patch_info.patch_base_addr;
  686. +
  687. + /* Extract total length of the patch payload */
  688. + for (index = 0; index < 4; index++)
  689. + rampatch_patch_info.patch_length |=
  690. + (LSH(buf[index + P_LEN_OFFSET], (index * 8)));
  691. +
  692. + /* Extract the CRC checksum of the patch payload */
  693. + for (index = 0; index < 4; index++)
  694. + rampatch_patch_info.patch_crc |=
  695. + (LSH(buf[index + P_CRC_OFFSET], (index * 8)));
  696. +
  697. + /* Extract patch control value */
  698. + for (index = 0; index < 4; index++)
  699. + rampatch_patch_info.patch_ctrl |=
  700. + (LSH(buf[index + P_CONTROL_OFFSET], (index * 8)));
  701. +
  702. + fprintf(stderr, "PATCH_ID\t : 0x%x\n", rampatch_patch_info.patch_id);
  703. + fprintf(stderr, "ROM_VERSION\t : 0x%x\n", rampatch_patch_info.patch_ver.rom_version);
  704. + fprintf(stderr, "BUILD_VERSION\t : 0x%x\n", rampatch_patch_info.patch_ver.build_version);
  705. + fprintf(stderr, "PATCH_LENGTH\t : 0x%x\n", rampatch_patch_info.patch_length);
  706. + fprintf(stderr, "PATCH_CRC\t : 0x%x\n", rampatch_patch_info.patch_crc);
  707. + fprintf(stderr, "PATCH_CONTROL\t : 0x%x\n", rampatch_patch_info.patch_ctrl);
  708. + fprintf(stderr, "PATCH_BASE_ADDR\t : 0x%x\n", rampatch_patch_info.patch_base_addr);
  709. +
  710. +}
  711. +
  712. +int rome_edl_set_patch_request(int fd)
  713. +{
  714. + int size, err;
  715. + unsigned char cmd[HCI_MAX_CMD_SIZE];
  716. + unsigned char rsp[HCI_MAX_EVENT_SIZE];
  717. +
  718. + /* Frame the HCI CMD to be sent to the Controller */
  719. + frame_hci_cmd_pkt(cmd, EDL_PATCH_SET_REQ_CMD, 0,
  720. + -1, PATCH_HDR_LEN + 1);
  721. +
  722. + /* Total length of the packet to be sent to the Controller */
  723. + size = (HCI_CMD_IND + HCI_COMMAND_HDR_SIZE + cmd[PLEN]);
  724. +
  725. + /* Send HCI Command packet to Controller */
  726. + err = hci_send_vs_cmd(fd, (unsigned char *)cmd, rsp, size);
  727. + if ( err != size) {
  728. + fprintf(stderr, "Failed to set the patch info to the Controller!\n");
  729. + goto error;
  730. + }
  731. +
  732. + err = read_hci_event(fd, rsp, HCI_MAX_EVENT_SIZE);
  733. + if ( err < 0) {
  734. + fprintf(stderr, "%s: Failed to set patch info on Controller\n", __FUNCTION__);
  735. + goto error;
  736. + }
  737. + fprintf(stderr, "%s: Successfully set patch info on the Controller\n", __FUNCTION__);
  738. +error:
  739. + return err;
  740. +}
  741. +
  742. +int rome_edl_patch_download_request(int fd)
  743. +{
  744. + int no_of_patch_segment;
  745. + int index = 1, err = 0, size = 0;
  746. + unsigned int p_base_addr;
  747. + unsigned char cmd[HCI_MAX_CMD_SIZE];
  748. + unsigned char rsp[HCI_MAX_EVENT_SIZE];
  749. +
  750. + no_of_patch_segment = (rampatch_patch_info.patch_length /
  751. + MAX_DATA_PER_SEGMENT);
  752. + fprintf(stderr, "%s: %d patch segments to be d'loaded from patch base addr: 0x%x\n",
  753. + __FUNCTION__, no_of_patch_segment,
  754. + rampatch_patch_info.patch_base_addr);
  755. +
  756. + /* Initialize the patch base address from the one read from bin file */
  757. + p_base_addr = rampatch_patch_info.patch_base_addr;
  758. +
  759. + /*
  760. + * Depending upon size of the patch payload, download the patches in
  761. + * segments with a max. size of 239 bytes
  762. + */
  763. + for (index = 1; index <= no_of_patch_segment; index++) {
  764. +
  765. + fprintf(stderr, "%s: Downloading patch segment: %d\n", __FUNCTION__, index);
  766. +
  767. + /* Frame the HCI CMD PKT to be sent to Controller*/
  768. + frame_hci_cmd_pkt(cmd, EDL_PATCH_DLD_REQ_CMD, p_base_addr,
  769. + index, MAX_DATA_PER_SEGMENT);
  770. +
  771. + /* Total length of the packet to be sent to the Controller */
  772. + size = (HCI_CMD_IND + HCI_COMMAND_HDR_SIZE + cmd[PLEN]);
  773. +
  774. + /* Initialize the RSP packet everytime to 0 */
  775. + memset(rsp, 0x0, HCI_MAX_EVENT_SIZE);
  776. +
  777. + /* Send HCI Command packet to Controller */
  778. + err = hci_send_vs_cmd(fd, (unsigned char *)cmd, rsp, size);
  779. + if ( err != size) {
  780. + fprintf(stderr, "Failed to send the patch payload to the Controller!\n");
  781. + goto error;
  782. + }
  783. +
  784. + /* Read Command Complete Event */
  785. + err = read_hci_event(fd, rsp, HCI_MAX_EVENT_SIZE);
  786. + if ( err < 0) {
  787. + fprintf(stderr, "%s: Failed to downlaod patch segment: %d!\n",
  788. + __FUNCTION__, index);
  789. + goto error;
  790. + }
  791. + fprintf(stderr, "%s: Successfully downloaded patch segment: %d\n",
  792. + __FUNCTION__, index);
  793. + }
  794. +
  795. + /* Check if any pending patch data to be sent */
  796. + size = (rampatch_patch_info.patch_length < MAX_DATA_PER_SEGMENT) ?
  797. + rampatch_patch_info.patch_length :
  798. + (rampatch_patch_info.patch_length % MAX_DATA_PER_SEGMENT);
  799. +
  800. + if (size)
  801. + {
  802. + /* Frame the HCI CMD PKT to be sent to Controller*/
  803. + frame_hci_cmd_pkt(cmd, EDL_PATCH_DLD_REQ_CMD, p_base_addr, index, size);
  804. +
  805. + /* Initialize the RSP packet everytime to 0 */
  806. + memset(rsp, 0x0, HCI_MAX_EVENT_SIZE);
  807. +
  808. + /* Total length of the packet to be sent to the Controller */
  809. + size = (HCI_CMD_IND + HCI_COMMAND_HDR_SIZE + cmd[PLEN]);
  810. +
  811. + /* Send HCI Command packet to Controller */
  812. + err = hci_send_vs_cmd(fd, (unsigned char *)cmd, rsp, size);
  813. + if ( err != size) {
  814. + fprintf(stderr, "Failed to send the patch payload to the Controller!\n");
  815. + goto error;
  816. + }
  817. +
  818. + /* Read Command Complete Event */
  819. + err = read_hci_event(fd, rsp, HCI_MAX_EVENT_SIZE);
  820. + if ( err < 0) {
  821. + fprintf(stderr, "%s: Failed to downlaod patch segment: %d!\n",
  822. + __FUNCTION__, index);
  823. + goto error;
  824. + }
  825. +
  826. + fprintf(stderr, "%s: Successfully downloaded patch segment: %d\n",
  827. + __FUNCTION__, index);
  828. + }
  829. +
  830. +error:
  831. + return err;
  832. +}
  833. +
  834. +static int rome_download_rampatch(int fd)
  835. +{
  836. + int c, size, index, ret = -1;
  837. +
  838. + fprintf(stderr, "%s:\n", __FUNCTION__);
  839. +
  840. + /* Get handle to the RAMPATCH binary file */
  841. + fprintf(stderr, "%s: Getting handle to the RAMPATCH binary file from %s\n", __FUNCTION__, ROME_FW_PATH);
  842. + file = fopen(ROME_FW_PATH, "r");
  843. + if (file == NULL) {
  844. + fprintf(stderr, "%s: Failed to get handle to the RAMPATCH bin file!\n",
  845. + __FUNCTION__);
  846. + return -ENFILE;
  847. + }
  848. +
  849. + /* Allocate memory for the patch headder info */
  850. + fprintf(stderr, "%s: Allocating memory for the patch header\n", __FUNCTION__);
  851. + phdr_buffer = (unsigned char *) malloc(PATCH_HDR_LEN + 1);
  852. + if (phdr_buffer == NULL) {
  853. + fprintf(stderr, "%s: Failed to allocate memory for patch header\n",
  854. + __FUNCTION__);
  855. + goto phdr_alloc_failed;
  856. + }
  857. + for (index = 0; index < PATCH_HDR_LEN + 1; index++)
  858. + phdr_buffer[index] = 0x0;
  859. +
  860. + /* Read 28 bytes of patch header information */
  861. + fprintf(stderr, "%s: Reading patch header info\n", __FUNCTION__);
  862. + index = 0;
  863. + do {
  864. + c = fgetc (file);
  865. + phdr_buffer[index++] = (unsigned char)c;
  866. + } while (index != PATCH_HDR_LEN);
  867. +
  868. + /* Save the patch header info into local structure */
  869. + fprintf(stderr, "%s: Saving patch hdr. info\n", __FUNCTION__);
  870. + rome_extract_patch_header_info((unsigned char *)phdr_buffer);
  871. +
  872. + /* Set the patch header info onto the Controller */
  873. + ret = rome_edl_set_patch_request(fd);
  874. + if (ret < 0) {
  875. + fprintf(stderr, "%s: Error setting the patchheader info!\n", __FUNCTION__);
  876. + goto pdata_alloc_failed;
  877. + }
  878. +
  879. + /* Allocate memory for the patch payload */
  880. + fprintf(stderr, "%s: Allocating memory for patch payload\n", __FUNCTION__);
  881. + size = rampatch_patch_info.patch_length;
  882. + pdata_buffer = (unsigned char *) malloc(size+1);
  883. + if (pdata_buffer == NULL) {
  884. + fprintf(stderr, "%s: Failed to allocate memory for patch payload\n",
  885. + __FUNCTION__);
  886. + goto pdata_alloc_failed;
  887. + }
  888. + for (index = 0; index < size+1; index++)
  889. + pdata_buffer[index] = 0x0;
  890. +
  891. + /* Read the patch data from Rampatch binary image */
  892. + fprintf(stderr, "%s: Reading patch payload from RAMPATCH file\n", __FUNCTION__);
  893. + index = 0;
  894. + do {
  895. + c = fgetc (file);
  896. + pdata_buffer[index++] = (unsigned char)c;
  897. + } while (c != EOF);
  898. +
  899. + /* Downloading patches in segments to controller */
  900. + ret = rome_edl_patch_download_request(fd);
  901. + if (ret < 0) {
  902. + fprintf(stderr, "%s: Error downloading patch segments!\n", __FUNCTION__);
  903. + goto cleanup;
  904. + }
  905. +cleanup:
  906. + free(pdata_buffer);
  907. +pdata_alloc_failed:
  908. + free(phdr_buffer);
  909. +phdr_alloc_failed:
  910. + fclose(file);
  911. +
  912. + return ret;
  913. +}
  914. +
  915. +int rome_attach_rampatch(int fd)
  916. +{
  917. + int size, err;
  918. + unsigned char cmd[HCI_MAX_CMD_SIZE];
  919. + unsigned char rsp[HCI_MAX_EVENT_SIZE];
  920. +
  921. + /* Frame the HCI CMD to be sent to the Controller */
  922. + frame_hci_cmd_pkt(cmd, EDL_PATCH_ATCH_REQ_CMD, 0,
  923. + -1, EDL_PATCH_CMD_LEN);
  924. +
  925. + /* Total length of the packet to be sent to the Controller */
  926. + size = (HCI_CMD_IND + HCI_COMMAND_HDR_SIZE + cmd[PLEN]);
  927. +
  928. + /* Send HCI Command packet to Controller */
  929. + err = hci_send_vs_cmd(fd, (unsigned char *)cmd, rsp, size);
  930. + if ( err != size) {
  931. + fprintf(stderr, "Failed to attach the patch payload to the Controller!\n");
  932. + goto error;
  933. + }
  934. +
  935. + /* Read Command Complete Event */
  936. + err = read_hci_event(fd, rsp, HCI_MAX_EVENT_SIZE);
  937. + if ( err < 0) {
  938. + fprintf(stderr, "%s: Failed to attach the patch segment(s)\n", __FUNCTION__);
  939. + goto error;
  940. + }
  941. +error:
  942. + return err;
  943. +}
  944. +
  945. +int rome_rampatch_reset(int fd)
  946. +{
  947. + int size, err = 0;
  948. + unsigned char cmd[HCI_MAX_CMD_SIZE];
  949. + struct timespec tm = { 0, 100*1000*1000 }; /* 100 ms */
  950. +
  951. + /* Frame the HCI CMD to be sent to the Controller */
  952. + frame_hci_cmd_pkt(cmd, EDL_PATCH_RST_REQ_CMD, 0,
  953. + -1, EDL_PATCH_CMD_LEN);
  954. +
  955. + /* Total length of the packet to be sent to the Controller */
  956. + size = (HCI_CMD_IND + HCI_COMMAND_HDR_SIZE + EDL_PATCH_CMD_LEN);
  957. +
  958. + /* Send HCI Command packet to Controller */
  959. + err = write(fd, cmd, size);
  960. + if (err != size) {
  961. + fprintf(stderr, "%s: Send failed with ret value: %d\n", __FUNCTION__, err);
  962. + goto error;
  963. + }
  964. +
  965. + /*
  966. + * Controller doesn't sends any response for the patch reset
  967. + * command. HOST has to wait for 100ms before proceeding.
  968. + */
  969. + nanosleep(&tm, NULL);
  970. +
  971. +error:
  972. + return err;
  973. +}
  974. +
  975. +int rome_get_tlv_file(char *file_path)
  976. +{
  977. + FILE * pFile;
  978. + long fileSize;
  979. + int readSize, nvm_length, nvm_index, i;
  980. + unsigned short nvm_tag_len;
  981. + tlv_patch_info *ptlv_header;
  982. + tlv_nvm_hdr *nvm_ptr;
  983. + unsigned char data_buf[PRINT_BUF_SIZE]={0,};
  984. + unsigned char *nvm_byte_ptr;
  985. +
  986. + fprintf(stderr, "File Open (%s)\n", file_path);
  987. + pFile = fopen ( file_path , "r" );
  988. + if (pFile==NULL) {;
  989. + fprintf(stderr, "%s File Open Fail\n", file_path);
  990. + return -1;
  991. + }
  992. +
  993. + /* Get File Size */
  994. + fseek (pFile , 0 , SEEK_END);
  995. + fileSize = ftell (pFile);
  996. + rewind (pFile);
  997. +
  998. + pdata_buffer = (unsigned char*) malloc (sizeof(char)*fileSize);
  999. + if (pdata_buffer == NULL) {
  1000. + fprintf(stderr, "Allocated Memory failed\n");
  1001. + fclose (pFile);
  1002. + return -1;
  1003. + }
  1004. +
  1005. + /* Copy file into allocated buffer */
  1006. + readSize = fread (pdata_buffer,1,fileSize,pFile);
  1007. +
  1008. + /* File Close */
  1009. + fclose (pFile);
  1010. +
  1011. + if (readSize != fileSize) {
  1012. + fprintf(stderr, "Read file size(%d) not matched with actual file size (%ld bytes)\n",readSize,fileSize);
  1013. + return -1;
  1014. + }
  1015. +
  1016. + ptlv_header = (tlv_patch_info *) pdata_buffer;
  1017. +
  1018. + /* To handle different event between rampatch and NVM */
  1019. + gTlv_type = ptlv_header->tlv_type;
  1020. +
  1021. + if(ptlv_header->tlv_type == TLV_TYPE_PATCH){
  1022. + fprintf(stderr, "====================================================\n");
  1023. + fprintf(stderr, "TLV Type\t\t\t : 0x%x\n", ptlv_header->tlv_type);
  1024. + fprintf(stderr, "Length\t\t\t : %d bytes\n", (ptlv_header->tlv_length1) |
  1025. + (ptlv_header->tlv_length2 << 8) |
  1026. + (ptlv_header->tlv_length3 << 16));
  1027. + fprintf(stderr, "Total Length\t\t\t : %d bytes\n", ptlv_header->tlv_data_len);
  1028. + fprintf(stderr, "Patch Data Length\t\t\t : %d bytes\n",ptlv_header->tlv_patch_data_len);
  1029. + fprintf(stderr, "Signing Format Version\t : 0x%x\n", ptlv_header->tlv.patch.sign_ver);
  1030. + fprintf(stderr, "Signature Algorithm\t\t : 0x%x\n", ptlv_header->tlv.patch.sign_algorithm);
  1031. + fprintf(stderr, "Reserved\t\t\t : 0x%x\n", ptlv_header->tlv.patch.reserved1);
  1032. + fprintf(stderr, "Product ID\t\t\t : 0x%04x\n", ptlv_header->tlv.patch.prod_id);
  1033. + fprintf(stderr, "Rom Build Version\t\t : 0x%04x\n", ptlv_header->tlv.patch.build_ver);
  1034. + fprintf(stderr, "Patch Version\t\t : 0x%04x\n", ptlv_header->tlv.patch.patch_ver);
  1035. + fprintf(stderr, "Reserved\t\t\t : 0x%x\n", ptlv_header->tlv.patch.reserved2);
  1036. + fprintf(stderr, "Patch Entry Address\t\t : 0x%x\n", (ptlv_header->tlv.patch.patch_entry_addr));
  1037. + fprintf(stderr, "====================================================\n");
  1038. +
  1039. + } else if(ptlv_header->tlv_type == TLV_TYPE_NVM) {
  1040. + fprintf(stderr, "====================================================\n");
  1041. + fprintf(stderr, "TLV Type\t\t\t : 0x%x\n", ptlv_header->tlv_type);
  1042. + fprintf(stderr, "Length\t\t\t : %d bytes\n", nvm_length = (ptlv_header->tlv_length1) |
  1043. + (ptlv_header->tlv_length2 << 8) |
  1044. + (ptlv_header->tlv_length3 << 16));
  1045. +
  1046. + if(nvm_length <= 0)
  1047. + return readSize;
  1048. +
  1049. + for(nvm_byte_ptr=(unsigned char *)(nvm_ptr = &(ptlv_header->tlv.nvm)), nvm_index=0;
  1050. + nvm_index < nvm_length ; nvm_ptr = (tlv_nvm_hdr *) nvm_byte_ptr)
  1051. + {
  1052. + fprintf(stderr, "TAG ID\t\t\t : %d\n", nvm_ptr->tag_id);
  1053. + fprintf(stderr, "TAG Length\t\t\t : %d\n", nvm_tag_len = nvm_ptr->tag_len);
  1054. + fprintf(stderr, "TAG Pointer\t\t\t : %d\n", nvm_ptr->tag_ptr);
  1055. + fprintf(stderr, "TAG Extended Flag\t\t : %d\n", nvm_ptr->tag_ex_flag);
  1056. +
  1057. + /* Increase nvm_index to NVM data */
  1058. + nvm_index+=sizeof(tlv_nvm_hdr);
  1059. + nvm_byte_ptr+=sizeof(tlv_nvm_hdr);
  1060. +
  1061. + /* Write BD Address */
  1062. + if(nvm_ptr->tag_id == TAG_NUM_2){
  1063. + memcpy(nvm_byte_ptr, vnd_local_bd_addr, 6);
  1064. + fprintf(stderr, "BD Address: %.02x:%.02x:%.02x:%.02x:%.02x:%.02x\n",
  1065. + *nvm_byte_ptr, *(nvm_byte_ptr+1), *(nvm_byte_ptr+2),
  1066. + *(nvm_byte_ptr+3), *(nvm_byte_ptr+4), *(nvm_byte_ptr+5));
  1067. + }
  1068. +
  1069. + for(i =0;(i<nvm_ptr->tag_len && (i*3 + 2) <PRINT_BUF_SIZE);i++)
  1070. + snprintf((char *) data_buf, PRINT_BUF_SIZE, "%s%.02x ", (char *)data_buf, *(nvm_byte_ptr + i));
  1071. +
  1072. + fprintf(stderr, "TAG Data\t\t\t : %s\n", data_buf);
  1073. +
  1074. + /* Clear buffer */
  1075. + memset(data_buf, 0x0, PRINT_BUF_SIZE);
  1076. +
  1077. + /* increased by tag_len */
  1078. + nvm_index+=nvm_ptr->tag_len;
  1079. + nvm_byte_ptr +=nvm_ptr->tag_len;
  1080. + }
  1081. +
  1082. + fprintf(stderr, "====================================================\n");
  1083. +
  1084. + } else {
  1085. + fprintf(stderr, "TLV Header type is unknown (%d) \n", ptlv_header->tlv_type);
  1086. + }
  1087. +
  1088. + return readSize;
  1089. +}
  1090. +
  1091. +int rome_tlv_dnld_segment(int fd, int index, int seg_size, unsigned char wait_cc_evt)
  1092. +{
  1093. + int size=0, err = -1;
  1094. + unsigned char cmd[HCI_MAX_CMD_SIZE];
  1095. + unsigned char rsp[HCI_MAX_EVENT_SIZE];
  1096. +
  1097. + fprintf(stderr, "%s: Downloading TLV Patch segment no.%d, size:%d\n", __FUNCTION__, index, seg_size);
  1098. +
  1099. + /* Frame the HCI CMD PKT to be sent to Controller*/
  1100. + frame_hci_cmd_pkt(cmd, EDL_PATCH_TLV_REQ_CMD, 0, index, seg_size);
  1101. +
  1102. + /* Total length of the packet to be sent to the Controller */
  1103. + size = (HCI_CMD_IND + HCI_COMMAND_HDR_SIZE + cmd[PLEN]);
  1104. +
  1105. + /* Initialize the RSP packet everytime to 0 */
  1106. + memset(rsp, 0x0, HCI_MAX_EVENT_SIZE);
  1107. +
  1108. + /* Send HCI Command packet to Controller */
  1109. + err = hci_send_vs_cmd(fd, (unsigned char *)cmd, rsp, size);
  1110. + if ( err != size) {
  1111. + fprintf(stderr, "Failed to send the patch payload to the Controller! 0x%x\n", err);
  1112. + return err;
  1113. + }
  1114. +
  1115. + if(wait_cc_evt) {
  1116. + err = read_hci_event(fd, rsp, HCI_MAX_EVENT_SIZE);
  1117. + if ( err < 0) {
  1118. + fprintf(stderr, "%s: Failed to downlaod patch segment: %d!\n", __FUNCTION__, index);
  1119. + return err;
  1120. + }
  1121. + }
  1122. +
  1123. + fprintf(stderr, "%s: Successfully downloaded patch segment: %d\n", __FUNCTION__, index);
  1124. + return err;
  1125. +}
  1126. +
  1127. +int rome_tlv_dnld_req(int fd, int tlv_size)
  1128. +{
  1129. + int total_segment, remain_size, i, err = -1;
  1130. + unsigned char wait_cc_evt;
  1131. +
  1132. + total_segment = tlv_size/MAX_SIZE_PER_TLV_SEGMENT;
  1133. + remain_size = (tlv_size < MAX_SIZE_PER_TLV_SEGMENT)?\
  1134. + tlv_size: (tlv_size%MAX_SIZE_PER_TLV_SEGMENT);
  1135. +
  1136. + fprintf(stderr, "%s: TLV size: %d, Total Seg num: %d, remain size: %d\n",
  1137. + __FUNCTION__,tlv_size, total_segment, remain_size);
  1138. +
  1139. + for(i=0;i<total_segment ;i++){
  1140. + /* In case of ROME 1.1, last rampatch segment command will not wait for
  1141. + command complete event */
  1142. + wait_cc_evt = ((rome_ver >= ROME_VER_1_1) && (gTlv_type == TLV_TYPE_PATCH )
  1143. + && !remain_size && ((i+1) == total_segment))? FALSE: TRUE;
  1144. + if((err = rome_tlv_dnld_segment(fd, i, MAX_SIZE_PER_TLV_SEGMENT, wait_cc_evt )) < 0)
  1145. + goto error;
  1146. + }
  1147. +
  1148. + /* In case remain data still remain, last rampatch segment command will not wait
  1149. + for command complete event here */
  1150. + wait_cc_evt = ((rome_ver >= ROME_VER_1_1) && (gTlv_type == TLV_TYPE_PATCH )
  1151. + && remain_size )? FALSE:TRUE;
  1152. +
  1153. + if(remain_size) err =rome_tlv_dnld_segment(fd, i, remain_size, wait_cc_evt);
  1154. +
  1155. +error:
  1156. + return err;
  1157. +}
  1158. +
  1159. +int rome_download_tlv_file(int fd)
  1160. +{
  1161. + int tlv_size, err = -1;
  1162. +
  1163. + /* Rampatch TLV file Downloading */
  1164. + pdata_buffer = NULL;
  1165. +
  1166. + if((tlv_size = rome_get_tlv_file(rampatch_file_path)) < 0)
  1167. + goto error;
  1168. +
  1169. + if((err =rome_tlv_dnld_req(fd, tlv_size)) <0 )
  1170. + goto error;
  1171. +
  1172. + if (pdata_buffer != NULL){
  1173. + free (pdata_buffer);
  1174. + pdata_buffer = NULL;
  1175. + }
  1176. +
  1177. + /* NVM TLV file Downloading */
  1178. + if((tlv_size = rome_get_tlv_file(nvm_file_path)) < 0)
  1179. + goto error;
  1180. +
  1181. + if((err =rome_tlv_dnld_req(fd, tlv_size)) <0 )
  1182. + goto error;
  1183. +
  1184. +error:
  1185. + if (pdata_buffer != NULL)
  1186. + free (pdata_buffer);
  1187. +
  1188. + return err;
  1189. +}
  1190. +
  1191. +int rome_1_0_nvm_tag_dnld(int fd)
  1192. +{
  1193. + int i, size, err = 0;
  1194. + unsigned char rsp[HCI_MAX_EVENT_SIZE];
  1195. +
  1196. +#if (NVM_VERSION >= ROME_1_0_100019)
  1197. + unsigned char cmds[MAX_TAG_CMD][HCI_MAX_CMD_SIZE] =
  1198. + {
  1199. + /* Tag 2 */ /* BD Address */
  1200. + { /* Packet Type */HCI_COMMAND_PKT,
  1201. + /* Opcode */ 0x0b,0xfc,
  1202. + /* Total Len */ 9,
  1203. + /* NVM CMD */ NVM_ACCESS_SET,
  1204. + /* Tag Num */ 2,
  1205. + /* Tag Len */ 6,
  1206. + /* Tag Value */ 0x77,0x78,0x23,0x01,0x56,0x22
  1207. + },
  1208. + /* Tag 6 */ /* Bluetooth Support Features */
  1209. + { /* Packet Type */HCI_COMMAND_PKT,
  1210. + /* Opcode */ 0x0b,0xfc,
  1211. + /* Total Len */ 11,
  1212. + /* NVM CMD */ NVM_ACCESS_SET,
  1213. + /* Tag Num */ 6,
  1214. + /* Tag Len */ 8,
  1215. + /* Tag Value */ 0xFF,0xFE,0x8B,0xFE,0xD8,0x3F,0x5B,0x8B
  1216. + },
  1217. + /* Tag 17 */ /* HCI Transport Layer Setting */
  1218. + { /* Packet Type */HCI_COMMAND_PKT,
  1219. + /* Opcode */ 0x0b,0xfc,
  1220. + /* Total Len */ 11,
  1221. + /* NVM CMD */ NVM_ACCESS_SET,
  1222. + /* Tag Num */ 17,
  1223. + /* Tag Len */ 8,
  1224. + /* Tag Value */ 0x82,0x01,0x0E,0x08,0x04,0x32,0x0A,0x00
  1225. + },
  1226. + /* Tag 35 */
  1227. + { /* Packet Type */HCI_COMMAND_PKT,
  1228. + /* Opcode */ 0x0b,0xfc,
  1229. + /* Total Len */ 58,
  1230. + /* NVM CMD */ NVM_ACCESS_SET,
  1231. + /* Tag Num */ 35,
  1232. + /* Tag Len */ 55,
  1233. + /* Tag Value */ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x58, 0x59,
  1234. + 0x0E, 0x0E, 0x16, 0x16, 0x16, 0x1E, 0x26, 0x5F, 0x2F, 0x5F,
  1235. + 0x0E, 0x0E, 0x16, 0x16, 0x16, 0x1E, 0x26, 0x5F, 0x2F, 0x5F,
  1236. + 0x0C, 0x18, 0x14, 0x24, 0x40, 0x4C, 0x70, 0x80, 0x80, 0x80,
  1237. + 0x0C, 0x18, 0x14, 0x24, 0x40, 0x4C, 0x70, 0x80, 0x80, 0x80,
  1238. + 0x1B, 0x14, 0x01, 0x04, 0x48
  1239. + },
  1240. + /* Tag 36 */
  1241. + { /* Packet Type */HCI_COMMAND_PKT,
  1242. + /* Opcode */ 0x0b,0xfc,
  1243. + /* Total Len */ 15,
  1244. + /* NVM CMD */ NVM_ACCESS_SET,
  1245. + /* Tag Num */ 36,
  1246. + /* Tag Len */ 12,
  1247. + /* Tag Value */ 0x0F,0x00,0x03,0x03,0x03,0x03,0x00,0x00,0x03,0x03,0x04,0x00
  1248. + },
  1249. + /* Tag 39 */
  1250. + { /* Packet Type */HCI_COMMAND_PKT,
  1251. + /* Opcode */ 0x0b,0xfc,
  1252. + /* Total Len */ 7,
  1253. + /* NVM CMD */ NVM_ACCESS_SET,
  1254. + /* Tag Num */ 39,
  1255. + /* Tag Len */ 4,
  1256. + /* Tag Value */ 0x12,0x00,0x00,0x00
  1257. + },
  1258. + /* Tag 41 */
  1259. + { /* Packet Type */HCI_COMMAND_PKT,
  1260. + /* Opcode */ 0x0b,0xfc,
  1261. + /* Total Len */ 91,
  1262. + /* NVM CMD */ NVM_ACCESS_SET,
  1263. + /* Tag Num */ 41,
  1264. + /* Tag Len */ 88,
  1265. + /* Tag Value */ 0x15, 0x00, 0x00, 0x00, 0xF6, 0x02, 0x00, 0x00, 0x76, 0x00,
  1266. + 0x1E, 0x00, 0x29, 0x02, 0x1F, 0x00, 0x61, 0x00, 0x1A, 0x00,
  1267. + 0x76, 0x00, 0x1E, 0x00, 0x7D, 0x00, 0x40, 0x00, 0x91, 0x00,
  1268. + 0x06, 0x00, 0x92, 0x00, 0x03, 0x00, 0xA6, 0x01, 0x50, 0x00,
  1269. + 0xAA, 0x01, 0x15, 0x00, 0xAB, 0x01, 0x0A, 0x00, 0xAC, 0x01,
  1270. + 0x00, 0x00, 0xB0, 0x01, 0xC5, 0x00, 0xB3, 0x01, 0x03, 0x00,
  1271. + 0xB4, 0x01, 0x13, 0x00, 0xB5, 0x01, 0x0C, 0x00, 0xC5, 0x01,
  1272. + 0x0D, 0x00, 0xC6, 0x01, 0x10, 0x00, 0xCA, 0x01, 0x2B, 0x00,
  1273. + 0xCB, 0x01, 0x5F, 0x00, 0xCC, 0x01, 0x48, 0x00
  1274. + },
  1275. + /* Tag 42 */
  1276. + { /* Packet Type */HCI_COMMAND_PKT,
  1277. + /* Opcode */ 0x0b,0xfc,
  1278. + /* Total Len */ 63,
  1279. + /* NVM CMD */ NVM_ACCESS_SET,
  1280. + /* Tag Num */ 42,
  1281. + /* Tag Len */ 60,
  1282. + /* Tag Value */ 0xD7, 0xC0, 0x00, 0x00, 0x8F, 0x5C, 0x02, 0x00, 0x80, 0x47,
  1283. + 0x60, 0x0C, 0x70, 0x4C, 0x00, 0x00, 0x00, 0x01, 0x1F, 0x01,
  1284. + 0x42, 0x01, 0x69, 0x01, 0x95, 0x01, 0xC7, 0x01, 0xFE, 0x01,
  1285. + 0x3D, 0x02, 0x83, 0x02, 0xD1, 0x02, 0x29, 0x03, 0x00, 0x0A,
  1286. + 0x10, 0x00, 0x1F, 0x00, 0x3F, 0x00, 0x7F, 0x00, 0xFD, 0x00,
  1287. + 0xF9, 0x01, 0xF1, 0x03, 0xDE, 0x07, 0x00, 0x00, 0x9A, 0x01
  1288. + },
  1289. + /* Tag 84 */
  1290. + { /* Packet Type */HCI_COMMAND_PKT,
  1291. + /* Opcode */ 0x0b,0xfc,
  1292. + /* Total Len */ 153,
  1293. + /* NVM CMD */ NVM_ACCESS_SET,
  1294. + /* Tag Num */ 84,
  1295. + /* Tag Len */ 150,
  1296. + /* Tag Value */ 0x7C, 0x6A, 0x59, 0x47, 0x19, 0x36, 0x35, 0x25, 0x25, 0x28,
  1297. + 0x2C, 0x2B, 0x2B, 0x28, 0x2C, 0x28, 0x29, 0x28, 0x29, 0x28,
  1298. + 0x29, 0x29, 0x2C, 0x29, 0x2C, 0x29, 0x2C, 0x28, 0x29, 0x28,
  1299. + 0x29, 0x28, 0x29, 0x2A, 0x00, 0x00, 0x2C, 0x2A, 0x2C, 0x18,
  1300. + 0x98, 0x98, 0x98, 0x98, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E,
  1301. + 0x1E, 0x13, 0x1E, 0x1E, 0x1E, 0x1E, 0x13, 0x13, 0x11, 0x13,
  1302. + 0x1E, 0x1E, 0x13, 0x12, 0x12, 0x12, 0x11, 0x12, 0x1F, 0x12,
  1303. + 0x12, 0x12, 0x10, 0x0C, 0x18, 0x0D, 0x01, 0x01, 0x01, 0x01,
  1304. + 0x01, 0x01, 0x01, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x0D, 0x0D,
  1305. + 0x0E, 0x0D, 0x01, 0x01, 0x0D, 0x0D, 0x0D, 0x0D, 0x0F, 0x0D,
  1306. + 0x10, 0x0D, 0x0D, 0x0D, 0x0D, 0x10, 0x05, 0x10, 0x03, 0x00,
  1307. + 0x7E, 0x7B, 0x7B, 0x72, 0x71, 0x50, 0x50, 0x50, 0x00, 0x40,
  1308. + 0x60, 0x60, 0x30, 0x08, 0x02, 0x0F, 0x00, 0x01, 0x00, 0x00,
  1309. + 0x00, 0x00, 0x00, 0x00, 0x08, 0x16, 0x16, 0x08, 0x08, 0x00,
  1310. + 0x00, 0x00, 0x1E, 0x34, 0x2B, 0x1B, 0x23, 0x2B, 0x15, 0x0D
  1311. + },
  1312. + /* Tag 85 */
  1313. + { /* Packet Type */HCI_COMMAND_PKT,
  1314. + /* Opcode */ 0x0b,0xfc,
  1315. + /* Total Len */ 119,
  1316. + /* NVM CMD */ NVM_ACCESS_SET,
  1317. + /* Tag Num */ 85,
  1318. + /* Tag Len */ 116,
  1319. + /* Tag Value */ 0x03, 0x00, 0x38, 0x00, 0x45, 0x77, 0x00, 0xE8, 0x00, 0x59,
  1320. + 0x01, 0xCA, 0x01, 0x3B, 0x02, 0xAC, 0x02, 0x1D, 0x03, 0x8E,
  1321. + 0x03, 0x00, 0x89, 0x01, 0x0E, 0x02, 0x5C, 0x02, 0xD7, 0x02,
  1322. + 0xF8, 0x08, 0x01, 0x00, 0x1F, 0x00, 0x0A, 0x02, 0x55, 0x02,
  1323. + 0x00, 0x35, 0x00, 0x00, 0x00, 0x00, 0x2A, 0xD7, 0x00, 0x00,
  1324. + 0x00, 0x1E, 0xDE, 0x00, 0x00, 0x00, 0x14, 0x0F, 0x0A, 0x0F,
  1325. + 0x0A, 0x0C, 0x0C, 0x0C, 0x0C, 0x04, 0x04, 0x04, 0x0C, 0x0C,
  1326. + 0x0C, 0x0C, 0x06, 0x06, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02,
  1327. + 0x01, 0x00, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00,
  1328. + 0x06, 0x0F, 0x14, 0x05, 0x47, 0xCF, 0x77, 0x00, 0x00, 0x00,
  1329. + 0x00, 0x00, 0x00, 0xAC, 0x7C, 0xFF, 0x40, 0x00, 0x00, 0x00,
  1330. + 0x12, 0x04, 0x04, 0x01, 0x04, 0x03
  1331. + },
  1332. + {TAG_END}
  1333. + };
  1334. +#elif (NVM_VERSION == ROME_1_0_6002)
  1335. + unsigned char cmds[MAX_TAG_CMD][HCI_MAX_CMD_SIZE] =
  1336. + {
  1337. + /* Tag 2 */
  1338. + { /* Packet Type */HCI_COMMAND_PKT,
  1339. + /* Opcode */ 0x0b,0xfc,
  1340. + /* Total Len */ 9,
  1341. + /* NVM CMD */ NVM_ACCESS_SET,
  1342. + /* Tag Num */ 2,
  1343. + /* Tag Len */ 6,
  1344. + /* Tag Value */ 0x77,0x78,0x23,0x01,0x56,0x22 /* BD Address */
  1345. + },
  1346. + /* Tag 6 */
  1347. + { /* Packet Type */HCI_COMMAND_PKT,
  1348. + /* Opcode */ 0x0b,0xfc,
  1349. + /* Total Len */ 11,
  1350. + /* NVM CMD */ NVM_ACCESS_SET,
  1351. + /* Tag Num */ 6,
  1352. + /* Tag Len */ 8,
  1353. + /* Tag Value */ 0xFF,0xFE,0x8B,0xFE,0xD8,0x3F,0x5B,0x8B
  1354. + },
  1355. + /* Tag 17 */
  1356. + { /* Packet Type */HCI_COMMAND_PKT,
  1357. + /* Opcode */ 0x0b,0xfc,
  1358. + /* Total Len */ 11,
  1359. + /* NVM CMD */ NVM_ACCESS_SET,
  1360. + /* Tag Num */ 17,
  1361. + /* Tag Len */ 8,
  1362. + /* Tag Value */ 0x82,0x01,0x0E,0x08,0x04,0x32,0x0A,0x00
  1363. + },
  1364. + /* Tag 36 */
  1365. + { /* Packet Type */HCI_COMMAND_PKT,
  1366. + /* Opcode */ 0x0b,0xfc,
  1367. + /* Total Len */ 15,
  1368. + /* NVM CMD */ NVM_ACCESS_SET,
  1369. + /* Tag Num */ 36,
  1370. + /* Tag Len */ 12,
  1371. + /* Tag Value */ 0x0F,0x00,0x03,0x03,0x03,0x03,0x00,0x00,0x03,0x03,0x04,0x00
  1372. + },
  1373. +
  1374. + /* Tag 39 */
  1375. + { /* Packet Type */HCI_COMMAND_PKT,
  1376. + /* Opcode */ 0x0b,0xfc,
  1377. + /* Total Len */ 7,
  1378. + /* NVM CMD */ NVM_ACCESS_SET,
  1379. + /* Tag Num */ 39,
  1380. + /* Tag Len */ 4,
  1381. + /* Tag Value */ 0x12,0x00,0x00,0x00
  1382. + },
  1383. +
  1384. + /* Tag 41 */
  1385. + { /* Packet Type */HCI_COMMAND_PKT,
  1386. + /* Opcode */ 0x0b,0xfc,
  1387. + /* Total Len */ 199,
  1388. + /* NVM CMD */ NVM_ACCESS_SET,
  1389. + /* Tag Num */ 41,
  1390. + /* Tag Len */ 196,
  1391. + /* Tag Value */ 0x30,0x00,0x00,0x00,0xD5,0x00,0x0E,0x00,0xD6,0x00,0x0E,0x00,
  1392. + 0xD7,0x00,0x16,0x00,0xD8,0x00,0x16,0x00,0xD9,0x00,0x16,0x00,
  1393. + 0xDA,0x00,0x1E,0x00,0xDB,0x00,0x26,0x00,0xDC,0x00,0x5F,0x00,
  1394. + 0xDD,0x00,0x2F,0x00,0xDE,0x00,0x5F,0x00,0xE0,0x00,0x0E,0x00,
  1395. + 0xE1,0x00,0x0E,0x00,0xE2,0x00,0x16,0x00,0xE3,0x00,0x16,0x00,
  1396. + 0xE4,0x00,0x16,0x00,0xE5,0x00,0x1E,0x00,0xE6,0x00,0x26,0x00,
  1397. + 0xE7,0x00,0x5F,0x00,0xE8,0x00,0x2F,0x00,0xE9,0x00,0x5F,0x00,
  1398. + 0xEC,0x00,0x0C,0x00,0xED,0x00,0x08,0x00,0xEE,0x00,0x14,0x00,
  1399. + 0xEF,0x00,0x24,0x00,0xF0,0x00,0x40,0x00,0xF1,0x00,0x4C,0x00,
  1400. + 0xF2,0x00,0x70,0x00,0xF3,0x00,0x80,0x00,0xF4,0x00,0x80,0x00,
  1401. + 0xF5,0x00,0x80,0x00,0xF8,0x00,0x0C,0x00,0xF9,0x00,0x18,0x00,
  1402. + 0xFA,0x00,0x14,0x00,0xFB,0x00,0x24,0x00,0xFC,0x00,0x40,0x00,
  1403. + 0xFD,0x00,0x4C,0x00,0xFE,0x00,0x70,0x00,0xFF,0x00,0x80,0x00,
  1404. + 0x00,0x01,0x80,0x00,0x01,0x01,0x80,0x00,0x04,0x01,0x1B,0x00,
  1405. + 0x05,0x01,0x14,0x00,0x06,0x01,0x01,0x00,0x07,0x01,0x04,0x00,
  1406. + 0x08,0x01,0x00,0x00,0x09,0x01,0x00,0x00,0x0A,0x01,0x03,0x00,
  1407. + 0x0B,0x01,0x03,0x00
  1408. + },
  1409. +
  1410. + /* Tag 44 */
  1411. + { /* Packet Type */HCI_COMMAND_PKT,
  1412. + /* Opcode */ 0x0b,0xfc,
  1413. + /* Total Len */ 44,
  1414. + /* NVM CMD */ NVM_ACCESS_SET,
  1415. + /* Tag Num */ 44,
  1416. + /* Tag Len */ 41,
  1417. + /* Tag Value */ 0x6F,0x0A,0x00,0x00,0x00,0x00,0x00,0x50,0xFF,0x10,0x02,0x02,
  1418. + 0x01,0x00,0x14,0x01,0x06,0x28,0xA0,0x62,0x03,0x64,0x01,0x01,
  1419. + 0x0A,0x00,0x00,0x00,0x00,0x00,0x00,0xA0,0xFF,0x10,0x02,0x01,
  1420. + 0x00,0x14,0x01,0x02,0x03
  1421. + },
  1422. + {TAG_END}
  1423. + };
  1424. +#endif
  1425. +
  1426. + fprintf(stderr, "%s: Start sending NVM Tags (ver: 0x%x)\n", __FUNCTION__, (unsigned int) NVM_VERSION);
  1427. +
  1428. + for (i=0; (i < MAX_TAG_CMD) && (cmds[i][0] != TAG_END); i++)
  1429. + {
  1430. + /* Write BD Address */
  1431. + if(cmds[i][TAG_NUM_OFFSET] == TAG_NUM_2){
  1432. + memcpy(&cmds[i][TAG_BDADDR_OFFSET], vnd_local_bd_addr, 6);
  1433. + fprintf(stderr, "BD Address: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
  1434. + cmds[i][TAG_BDADDR_OFFSET ], cmds[i][TAG_BDADDR_OFFSET + 1],
  1435. + cmds[i][TAG_BDADDR_OFFSET + 2], cmds[i][TAG_BDADDR_OFFSET + 3],
  1436. + cmds[i][TAG_BDADDR_OFFSET + 4], cmds[i][TAG_BDADDR_OFFSET + 5]);
  1437. + }
  1438. + size = cmds[i][3] + HCI_COMMAND_HDR_SIZE + 1;
  1439. + /* Send HCI Command packet to Controller */
  1440. + err = hci_send_vs_cmd(fd, (unsigned char *)&cmds[i][0], rsp, size);
  1441. + if ( err != size) {
  1442. + fprintf(stderr, "Failed to attach the patch payload to the Controller!\n");
  1443. + goto error;
  1444. + }
  1445. +
  1446. + /* Read Command Complete Event - This is extra routine for ROME 1.0. From ROM 2.0, it should be removed. */
  1447. + err = read_hci_event(fd, rsp, HCI_MAX_EVENT_SIZE);
  1448. + if ( err < 0) {
  1449. + fprintf(stderr, "%s: Failed to get patch version(s)\n", __FUNCTION__);
  1450. + goto error;
  1451. + }
  1452. + }
  1453. +
  1454. +error:
  1455. + return err;
  1456. +}
  1457. +
  1458. +
  1459. +
  1460. +int rome_patch_ver_req(int fd)
  1461. +{
  1462. + int size, err = 0;
  1463. + unsigned char cmd[HCI_MAX_CMD_SIZE];
  1464. + unsigned char rsp[HCI_MAX_EVENT_SIZE];
  1465. +
  1466. + /* Frame the HCI CMD to be sent to the Controller */
  1467. + frame_hci_cmd_pkt(cmd, EDL_PATCH_VER_REQ_CMD, 0,
  1468. + -1, EDL_PATCH_CMD_LEN);
  1469. +
  1470. + /* Total length of the packet to be sent to the Controller */
  1471. + size = (HCI_CMD_IND + HCI_COMMAND_HDR_SIZE + EDL_PATCH_CMD_LEN);
  1472. +
  1473. + /* Send HCI Command packet to Controller */
  1474. + err = hci_send_vs_cmd(fd, (unsigned char *)cmd, rsp, size);
  1475. + if ( err != size) {
  1476. + fprintf(stderr, "Failed to attach the patch payload to the Controller!\n");
  1477. + goto error;
  1478. + }
  1479. +
  1480. + /* Read Command Complete Event - This is extra routine for ROME 1.0. From ROM 2.0, it should be removed. */
  1481. + err = read_hci_event(fd, rsp, HCI_MAX_EVENT_SIZE);
  1482. + if ( err < 0) {
  1483. + fprintf(stderr, "%s: Failed to get patch version(s)\n", __FUNCTION__);
  1484. + goto error;
  1485. + }
  1486. +error:
  1487. + return err;
  1488. +
  1489. +}
  1490. +
  1491. +int rome_disable_sleep(int fd)
  1492. +{
  1493. + int size, err = 0;
  1494. + unsigned char cmd[HCI_MAX_CMD_SIZE];
  1495. + unsigned char rsp[HCI_MAX_EVENT_SIZE];
  1496. + hci_command_hdr *cmd_hdr;
  1497. + int flags;
  1498. +
  1499. + memset(cmd, 0x0, HCI_MAX_CMD_SIZE);
  1500. +
  1501. + cmd_hdr = (void *) (cmd + 1);
  1502. + cmd[0] = HCI_COMMAND_PKT;
  1503. + cmd_hdr->opcode = cmd_opcode_pack(HCI_VENDOR_CMD_OGF, NVM_ACCESS_CODE);
  1504. + cmd_hdr->plen = VSC_DISABLE_IBS_LEN;
  1505. + cmd[4] = 0x01;
  1506. + cmd[5] = 0x1B;
  1507. + cmd[6] = 0x01;
  1508. + cmd[7] = 0x00;
  1509. +
  1510. + /* Total length of the packet to be sent to the Controller */
  1511. + size = (HCI_CMD_IND + HCI_COMMAND_HDR_SIZE + VSC_DISABLE_IBS_LEN);
  1512. + /* Send the HCI command packet to UART for transmission */
  1513. + fprintf(stderr, "%s: HCI CMD: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", __FUNCTION__, cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6], cmd[7]) ;
  1514. + err = write(fd, cmd, size);
  1515. + if (err != size) {
  1516. + fprintf(stderr, "%s: Send failed with ret value: %d\n", __FUNCTION__, err);
  1517. + goto error;
  1518. + }
  1519. +
  1520. + /* Check for response from the Controller */
  1521. + if ((err =read_vs_hci_event(fd, rsp, HCI_MAX_EVENT_SIZE)) < 0) {
  1522. + fprintf(stderr, "%s: Failed to get HCI-VS Event from SOC\n", __FUNCTION__);
  1523. + goto error;
  1524. + }
  1525. +
  1526. + fprintf(stderr, "%s: Received HCI-Vendor Specific Event from SOC\n", __FUNCTION__);
  1527. +
  1528. + /* Wait for command complete event */
  1529. + err = read_hci_event(fd, rsp, HCI_MAX_EVENT_SIZE);
  1530. + if ( err < 0) {
  1531. + fprintf(stderr, "%s: Failed to set patch info on Controller\n", __FUNCTION__);
  1532. + goto error;
  1533. + }
  1534. + fprintf(stderr, "%s\n", __FUNCTION__);
  1535. +error:
  1536. + return err;
  1537. +
  1538. +}
  1539. +
  1540. +int rome_set_baudrate_req(int fd)
  1541. +{
  1542. + int size, err = 0;
  1543. + unsigned char cmd[HCI_MAX_CMD_SIZE];
  1544. + unsigned char rsp[HCI_MAX_EVENT_SIZE];
  1545. + hci_command_hdr *cmd_hdr;
  1546. + int flags;
  1547. +
  1548. + memset(cmd, 0x0, HCI_MAX_CMD_SIZE);
  1549. +
  1550. + cmd_hdr = (void *) (cmd + 1);
  1551. + cmd[0] = HCI_COMMAND_PKT;
  1552. + cmd_hdr->opcode = cmd_opcode_pack(HCI_VENDOR_CMD_OGF, EDL_SET_BAUDRATE_CMD_OCF);
  1553. + cmd_hdr->plen = VSC_SET_BAUDRATE_REQ_LEN;
  1554. + cmd[4] = BAUDRATE_115200;
  1555. +
  1556. + /* Total length of the packet to be sent to the Controller */
  1557. + size = (HCI_CMD_IND + HCI_COMMAND_HDR_SIZE + VSC_SET_BAUDRATE_REQ_LEN);
  1558. + /* Send the HCI command packet to UART for transmission */
  1559. + fprintf(stderr, "%s: HCI CMD: 0x%x 0x%x 0x%x 0x%x 0x%x\n", __FUNCTION__, cmd[0], cmd[1], cmd[2], cmd[3],cmd[4]) ;
  1560. + err = write(fd, cmd, size);
  1561. + if (err != size) {
  1562. + fprintf(stderr, "%s: Send failed with ret value: %d\n", __FUNCTION__, err);
  1563. + goto error;
  1564. + }
  1565. +
  1566. + /* Check for response from the Controller */
  1567. + if ((err =read_vs_hci_event(fd, rsp, HCI_MAX_EVENT_SIZE)) < 0) {
  1568. + fprintf(stderr, "%s: Failed to get HCI-VS Event from SOC\n", __FUNCTION__);
  1569. + goto error;
  1570. + }
  1571. +
  1572. + fprintf(stderr, "%s: Received HCI-Vendor Specific Event from SOC\n", __FUNCTION__);
  1573. +
  1574. + /* Wait for command complete event */
  1575. + err = read_hci_event(fd, rsp, HCI_MAX_EVENT_SIZE);
  1576. + if ( err < 0) {
  1577. + fprintf(stderr, "%s: Failed to set patch info on Controller\n", __FUNCTION__);
  1578. + goto error;
  1579. + }
  1580. + fprintf(stderr, "%s\n", __FUNCTION__);
  1581. +error:
  1582. + return err;
  1583. +
  1584. +}
  1585. +
  1586. +
  1587. +int rome_hci_reset_req(int fd)
  1588. +{
  1589. + int size, err = 0;
  1590. + unsigned char cmd[HCI_MAX_CMD_SIZE];
  1591. + unsigned char rsp[HCI_MAX_EVENT_SIZE];
  1592. + hci_command_hdr *cmd_hdr;
  1593. + int flags;
  1594. +
  1595. + fprintf(stderr, "%s: HCI RESET \n", __FUNCTION__);
  1596. +
  1597. + memset(cmd, 0x0, HCI_MAX_CMD_SIZE);
  1598. +
  1599. + cmd_hdr = (void *) (cmd + 1);
  1600. + cmd[0] = HCI_COMMAND_PKT;
  1601. + cmd_hdr->opcode = HCI_RESET;
  1602. + cmd_hdr->plen = 0;
  1603. +
  1604. + /* Total length of the packet to be sent to the Controller */
  1605. + size = (HCI_CMD_IND + HCI_COMMAND_HDR_SIZE);
  1606. +
  1607. + /* Send the HCI command packet to UART for transmission */
  1608. + fprintf(stderr, "%s: HCI CMD: 0x%x 0x%x 0x%x 0x%x\n", __FUNCTION__, cmd[0], cmd[1], cmd[2], cmd[3]);
  1609. + err = write(fd, cmd, size);
  1610. + if (err != size) {
  1611. + fprintf(stderr, "%s: Send failed with ret value: %d\n", __FUNCTION__, err);
  1612. + goto error;
  1613. + }
  1614. +
  1615. + /* Wait for command complete event */
  1616. + err = read_hci_event(fd, rsp, HCI_MAX_EVENT_SIZE);
  1617. + if ( err < 0) {
  1618. + fprintf(stderr, "%s: Failed to set patch info on Controller\n", __FUNCTION__);
  1619. + goto error;
  1620. + }
  1621. +
  1622. +error:
  1623. + return err;
  1624. +
  1625. +}
  1626. +
  1627. +
  1628. +int qca_soc_init(int fd, char *bdaddr)
  1629. +{
  1630. + int err = -1;
  1631. + int size;
  1632. +
  1633. + fprintf(stderr, " %s \n", __FUNCTION__);
  1634. + vnd_userial.fd = fd;
  1635. + /* Get Rome version information */
  1636. + if((err = rome_patch_ver_req(fd)) <0){
  1637. + fprintf(stderr, "%s: Fail to get Rome Version (0x%x)\n", __FUNCTION__, err);
  1638. + goto error;
  1639. + }
  1640. +
  1641. + fprintf(stderr, "%s: Rome Version (0x%08x)\n", __FUNCTION__, rome_ver);
  1642. +
  1643. + switch (rome_ver){
  1644. + case ROME_VER_1_0:
  1645. + {
  1646. + /* Set and Download the RAMPATCH */
  1647. + fprintf(stderr, "%s: Setting Patch Header & Downloading Patches\n", __FUNCTION__);
  1648. + err = rome_download_rampatch(fd);
  1649. + if (err < 0) {
  1650. + fprintf(stderr, "%s: DOWNLOAD RAMPATCH failed!\n", __FUNCTION__);
  1651. + goto error;
  1652. + }
  1653. + fprintf(stderr, "%s: DOWNLOAD RAMPTACH complete\n", __FUNCTION__);
  1654. +
  1655. + /* Attach the RAMPATCH */
  1656. + fprintf(stderr, "%s: Attaching the patches\n", __FUNCTION__);
  1657. + err = rome_attach_rampatch(fd);
  1658. + if (err < 0) {
  1659. + fprintf(stderr, "%s: ATTACH RAMPATCH failed!\n", __FUNCTION__);
  1660. + goto error;
  1661. + }
  1662. + fprintf(stderr, "%s: ATTACH RAMPTACH complete\n", __FUNCTION__);
  1663. +
  1664. + /* Send Reset */
  1665. + size = (HCI_CMD_IND + HCI_COMMAND_HDR_SIZE + EDL_PATCH_CMD_LEN);
  1666. + err = rome_rampatch_reset(fd);
  1667. + if ( err < 0 ) {
  1668. + fprintf(stderr, "Failed to RESET after RAMPATCH upgrade!\n");
  1669. + goto error;
  1670. + }
  1671. +
  1672. + /* NVM download */
  1673. + fprintf(stderr, "%s: Downloading NVM\n", __FUNCTION__);
  1674. + err = rome_1_0_nvm_tag_dnld(fd);
  1675. + if ( err <0 ) {
  1676. + fprintf(stderr, "Downloading NVM Failed !!\n");
  1677. + goto error;
  1678. + }
  1679. +
  1680. + /* Change baud rate 115.2 kbps to 3Mbps*/
  1681. + err = rome_hci_reset_req(fd);
  1682. + if ( err <0 ) {
  1683. + fprintf(stderr, "HCI Reset Failed !!\n");
  1684. + goto error;
  1685. + }
  1686. +
  1687. + fprintf(stderr, "HCI Reset is done\n");
  1688. + }
  1689. + break;
  1690. + case ROME_VER_1_1:
  1691. + rampatch_file_path = ROME_RAMPATCH_TLV_PATH;
  1692. + nvm_file_path = ROME_NVM_TLV_PATH;
  1693. + goto download;
  1694. + case ROME_VER_1_3:
  1695. + rampatch_file_path = ROME_RAMPATCH_TLV_1_0_3_PATH;
  1696. + nvm_file_path = ROME_NVM_TLV_1_0_3_PATH;
  1697. + goto download;
  1698. + case ROME_VER_2_1:
  1699. + rampatch_file_path = ROME_RAMPATCH_TLV_2_0_1_PATH;
  1700. + nvm_file_path = ROME_NVM_TLV_2_0_1_PATH;
  1701. + goto download;
  1702. + case ROME_VER_3_0:
  1703. + case TUFELLO_VER_1_0:
  1704. + rampatch_file_path = ROME_RAMPATCH_TLV_3_0_0_PATH;
  1705. + nvm_file_path = ROME_NVM_TLV_3_0_0_PATH;
  1706. +
  1707. +download:
  1708. + /* Donwload TLV files (rampatch, NVM) */
  1709. + err = rome_download_tlv_file(fd);
  1710. + if (err < 0) {
  1711. + fprintf(stderr, "%s: Download TLV file failed!\n", __FUNCTION__);
  1712. + goto error;
  1713. + }
  1714. + fprintf(stderr, "%s: Download TLV file successfully \n", __FUNCTION__);
  1715. +
  1716. + /* Change baud rate back to user requested */
  1717. + fprintf(stderr, "Changing baud rate back from 3M --> 115K\n");
  1718. + err = rome_set_baudrate_req(fd);
  1719. + if (err < 0) {
  1720. + fprintf(stderr, "%s: Baud rate change failed!\n", __FUNCTION__);
  1721. + goto error;
  1722. + }
  1723. + fprintf(stderr, "%s: Baud rate changed successfully \n", __FUNCTION__);
  1724. +
  1725. + fprintf(stderr, "%s: Disabling In Band Sleep functionality\n", __FUNCTION__);
  1726. + err = rome_disable_sleep(fd);
  1727. + if (err < 0) {
  1728. + fprintf(stderr, "%s: Failed to disable IBS!\n", __FUNCTION__);
  1729. + goto error;
  1730. + }
  1731. + fprintf(stderr, "%s: IBS disabled successfully \n", __FUNCTION__);
  1732. +
  1733. + /* Perform HCI reset here*/
  1734. + err = rome_hci_reset_req(fd);
  1735. + if ( err <0 ) {
  1736. + fprintf(stderr, "HCI Reset Failed !!!\n");
  1737. + goto error;
  1738. + }
  1739. + fprintf(stderr, "HCI Reset is done\n");
  1740. +
  1741. + break;
  1742. + case ROME_VER_UNKNOWN:
  1743. + default:
  1744. + fprintf(stderr, "%s: Detected unknown ROME version\n", __FUNCTION__);
  1745. + err = -1;
  1746. + break;
  1747. + }
  1748. +
  1749. +error:
  1750. + return err;
  1751. +}
  1752. diff --git a/tools/hciattach_rome.h b/tools/hciattach_rome.h
  1753. new file mode 100644
  1754. index 0000000..3527eeb
  1755. --- /dev/null
  1756. +++ b/tools/hciattach_rome.h
  1757. @@ -0,0 +1,317 @@
  1758. +/*
  1759. + * Copyright 2012 The Android Open Source Project
  1760. + * Copyright (c) 2013, The Linux Foundation. All rights reserved.
  1761. + * Not a Contribution.
  1762. + *
  1763. + * Licensed under the Apache License, Version 2.0 (the "License");
  1764. + * you may not use this file except in compliance with the License.
  1765. + * You may obtain a copy of the License at
  1766. + *
  1767. + * http://www.apache.org/licenses/LICENSE-2.0
  1768. + *
  1769. + * Unless required by applicable law or agreed to in writing, software
  1770. + * distributed under the License is distributed on an "AS IS" BASIS,
  1771. + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1772. + * See the License for the specific language governing permissions and
  1773. + * limitations under the License.
  1774. + */
  1775. +#ifndef HW_ROME_H
  1776. +#define HW_ROME_H
  1777. +
  1778. +/******************************************************************************
  1779. +** Constants & Macros
  1780. +******************************************************************************/
  1781. +#define HCI_MAX_CMD_SIZE 260
  1782. +#define HCI_MAX_EVENT_SIZE 260
  1783. +#define PRINT_BUF_SIZE ((HCI_MAX_CMD_SIZE * 3) + 2)
  1784. +/* HCI Command/Event Opcode */
  1785. +#define HCI_RESET 0x0C03
  1786. +#define EVT_CMD_COMPLETE 0x0E
  1787. +/* HCI Packet types */
  1788. +#define HCI_COMMAND_PKT 0x01
  1789. +#define HCI_ACLDATA_PKT 0x02
  1790. +#define HCI_SCODATA_PKT 0x03
  1791. +#define HCI_EVENT_PKT 0x04
  1792. +#define HCI_VENDOR_PKT 0xff
  1793. +#define cmd_opcode_pack(ogf, ocf) (unsigned short)((ocf & 0x03ff)|(ogf << 10))
  1794. +unsigned char vnd_local_bd_addr[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  1795. +typedef enum {
  1796. + USERIAL_OP_FLOW_ON,
  1797. + USERIAL_OP_FLOW_OFF,
  1798. + USERIAL_OP_NOP,
  1799. +} userial_vendor_ioctl_op_t;
  1800. +
  1801. +
  1802. +/* vendor serial control block */
  1803. +typedef struct
  1804. +{
  1805. + int fd; /* fd to Bluetooth device */
  1806. + struct termios termios; /* serial terminal of BT port */
  1807. + char port_name[256];
  1808. +} vnd_userial_cb_t;
  1809. +
  1810. +/**** baud rates ****/
  1811. +#define USERIAL_BAUD_300 0
  1812. +#define USERIAL_BAUD_600 1
  1813. +#define USERIAL_BAUD_1200 2
  1814. +#define USERIAL_BAUD_2400 3
  1815. +#define USERIAL_BAUD_9600 4
  1816. +#define USERIAL_BAUD_19200 5
  1817. +#define USERIAL_BAUD_57600 6
  1818. +#define USERIAL_BAUD_115200 7
  1819. +#define USERIAL_BAUD_230400 8
  1820. +#define USERIAL_BAUD_460800 9
  1821. +#define USERIAL_BAUD_921600 10
  1822. +#define USERIAL_BAUD_1M 11
  1823. +#define USERIAL_BAUD_1_5M 12
  1824. +#define USERIAL_BAUD_2M 13
  1825. +#define USERIAL_BAUD_3M 14
  1826. +#define USERIAL_BAUD_4M 15
  1827. +#define USERIAL_BAUD_AUTO 16
  1828. +
  1829. +#ifndef FALSE
  1830. +#define FALSE 0
  1831. +#endif
  1832. +
  1833. +#ifndef TRUE
  1834. +#define TRUE (!FALSE)
  1835. +#endif
  1836. +
  1837. +#define HCI_CHG_BAUD_CMD_OCF 0x0C
  1838. +#define HCI_VENDOR_CMD_OGF 0x3F
  1839. +#define WRITE_BDADDR_CMD_LEN 14
  1840. +#define WRITE_BAUD_CMD_LEN 6
  1841. +#define MAX_CMD_LEN WRITE_BDADDR_CMD_LEN
  1842. +#define GET_VERSION_OCF 0x1E
  1843. +
  1844. +#define PS_HDR_LEN 4
  1845. +#define HCI_VENDOR_CMD_OGF 0x3F
  1846. +#define HCI_PS_CMD_OCF 0x0B
  1847. +
  1848. +#define HCI_COMMAND_HDR_SIZE 3
  1849. +#define EVT_CMD_COMPLETE_SIZE 3
  1850. +#define EVT_CMD_STATUS 0x0F
  1851. +#define EVT_CMD_STATUS_SIZE 4
  1852. +#define HCI_EVENT_HDR_SIZE 2
  1853. +#define HCI_EV_SUCCESS 0x00
  1854. +/* HCI Socket options */
  1855. +#define HCI_DATA_DIR 1
  1856. +#define HCI_FILTER 2
  1857. +#define HCI_TIME_STAMP 3
  1858. +
  1859. +#define P_ID_OFFSET (0)
  1860. +#define HCI_CMD_IND (1)
  1861. +#define EVENTCODE_OFFSET (1)
  1862. +#define EVT_PLEN (2)
  1863. +#define PLEN (3)
  1864. +#define CMD_RSP_OFFSET (3)
  1865. +#define RSP_TYPE_OFFSET (4)
  1866. +#define BAUDRATE_RSP_STATUS_OFFSET (4)
  1867. +#define CMD_STATUS_OFFSET (5)
  1868. +#define P_ROME_VER_OFFSET (4)
  1869. +#define P_BUILD_VER_OFFSET (6)
  1870. +#define P_BASE_ADDR_OFFSET (8)
  1871. +#define P_ENTRY_ADDR_OFFSET (12)
  1872. +#define P_LEN_OFFSET (16)
  1873. +#define P_CRC_OFFSET (20)
  1874. +#define P_CONTROL_OFFSET (24)
  1875. +#define PATCH_HDR_LEN (28)
  1876. +#define MAX_DATA_PER_SEGMENT (239)
  1877. +#define VSEVENT_CODE (0xFF)
  1878. +#define HC_VS_MAX_CMD_EVENT (0xFF)
  1879. +#define PATCH_PROD_ID_OFFSET (5)
  1880. +#define PATCH_PATCH_VER_OFFSET (9)
  1881. +#define PATCH_ROM_BUILD_VER_OFFSET (11)
  1882. +#define PATCH_SOC_VER_OFFSET (13)
  1883. +#define MAX_SIZE_PER_TLV_SEGMENT (243)
  1884. +
  1885. +/* VS Opcode */
  1886. +#define HCI_PATCH_CMD_OCF (0)
  1887. +#define EDL_SET_BAUDRATE_CMD_OCF (0x48)
  1888. +
  1889. +/* VS Commands */
  1890. +#define VSC_SET_BAUDRATE_REQ_LEN (1)
  1891. +#define EDL_PATCH_CMD_LEN (1)
  1892. +#define EDL_PATCH_CMD_REQ_LEN (1)
  1893. +#define EDL_PATCH_DLD_REQ_CMD (0x01)
  1894. +#define EDL_PATCH_RST_REQ_CMD (0x05)
  1895. +#define EDL_PATCH_SET_REQ_CMD (0x16)
  1896. +#define EDL_PATCH_ATCH_REQ_CMD (0x17)
  1897. +#define EDL_PATCH_VER_REQ_CMD (0x19)
  1898. +#define EDL_PATCH_TLV_REQ_CMD (0x1E)
  1899. +#define VSC_DISABLE_IBS_LEN (0x04)
  1900. +
  1901. +/* VS Event */
  1902. +#define EDL_CMD_REQ_RES_EVT (0x00)
  1903. +#define EDL_CMD_EXE_STATUS_EVT (0x00)
  1904. +#define EDL_SET_BAUDRATE_RSP_EVT (0x92)
  1905. +#define EDL_PATCH_VER_RES_EVT (0x19)
  1906. +#define EDL_TVL_DNLD_RES_EVT (0x04)
  1907. +#define EDL_APP_VER_RES_EVT (0x02)
  1908. +
  1909. +
  1910. +/* Status Codes of HCI CMD execution*/
  1911. +#define HCI_CMD_SUCCESS (0x0)
  1912. +#define PATCH_LEN_ERROR (0x1)
  1913. +#define PATCH_VER_ERROR (0x2)
  1914. +#define PATCH_CRC_ERROR (0x3)
  1915. +#define PATCH_NOT_FOUND (0x4)
  1916. +#define TLV_TYPE_ERROR (0x10)
  1917. +#define NVM_ACCESS_CODE (0x0B)
  1918. +#define BAUDRATE_CHANGE_SUCCESS (1)
  1919. +
  1920. +/* TLV_TYPE */
  1921. +#define TLV_TYPE_PATCH (1)
  1922. +#define TLV_TYPE_NVM (2)
  1923. +
  1924. +/* NVM */
  1925. +#define MAX_TAG_CMD 30
  1926. +#define TAG_END 0xFF
  1927. +#define NVM_ACCESS_SET 0x01
  1928. +#define TAG_NUM_OFFSET 5
  1929. +#define TAG_NUM_2 2
  1930. +#define TAG_BDADDR_OFFSET 7
  1931. +
  1932. +/* NVM Tags specifically used for ROME 1.0 */
  1933. +#define ROME_1_0_100022_1 0x101000221
  1934. +#define ROME_1_0_100019 0x101000190
  1935. +#define ROME_1_0_6002 0x100600200
  1936. +
  1937. +/* Default NVM Version setting for ROME 1.0 */
  1938. +#define NVM_VERSION ROME_1_0_100022_1
  1939. +
  1940. +
  1941. +#define LSH(val, n) ((unsigned int)(val) << (n))
  1942. +#define EXTRACT_BYTE(val, pos) (char) (((val) >> (8 * (pos))) & 0xFF)
  1943. +#define CALC_SEG_SIZE(len, max) ((plen) % (max))?((plen/max)+1) : ((plen) / (max))
  1944. +
  1945. +#define ROME_FW_PATH "/lib/firmware/rampatch.img"
  1946. +#define ROME_RAMPATCH_TLV_PATH "/lib/firmware/rampatch_tlv.img"
  1947. +#define ROME_NVM_TLV_PATH "/lib/firmware/nvm_tlv.bin"
  1948. +#define ROME_RAMPATCH_TLV_1_0_3_PATH "/lib/firmware/rampatch_tlv_1.3.tlv"
  1949. +#define ROME_NVM_TLV_1_0_3_PATH "/lib/firmware/nvm_tlv_1.3.bin"
  1950. +#define ROME_RAMPATCH_TLV_2_0_1_PATH "/lib/firmware/rampatch_tlv_2.1.tlv"
  1951. +#define ROME_NVM_TLV_2_0_1_PATH "/lib/firmware/nvm_tlv_2.1.bin"
  1952. +#define ROME_RAMPATCH_TLV_3_0_0_PATH "/lib/firmware/rampatch_tlv_3.0.tlv"
  1953. +#define ROME_NVM_TLV_3_0_0_PATH "/lib/firmware/nvm_tlv_3.0.bin"
  1954. +
  1955. +
  1956. +/******************************************************************************
  1957. +** Local type definitions
  1958. +******************************************************************************/
  1959. +
  1960. +typedef struct {
  1961. + unsigned char ncmd;
  1962. + unsigned short opcode;
  1963. +} __attribute__ ((packed)) evt_cmd_complete;
  1964. +
  1965. +typedef struct {
  1966. + unsigned char status;
  1967. + unsigned char ncmd;
  1968. + unsigned short opcode;
  1969. +} __attribute__ ((packed)) evt_cmd_status;
  1970. +
  1971. +typedef struct {
  1972. + unsigned short opcode;
  1973. + unsigned char plen;
  1974. +} __attribute__ ((packed)) hci_command_hdr;
  1975. +
  1976. +typedef struct {
  1977. + unsigned char evt;
  1978. + unsigned char plen;
  1979. +} __attribute__ ((packed)) hci_event_hdr;
  1980. +typedef struct {
  1981. + unsigned short rom_version;
  1982. + unsigned short build_version;
  1983. +} __attribute__ ((packed)) patch_version;
  1984. +
  1985. +typedef struct {
  1986. + unsigned int patch_id;
  1987. + patch_version patch_ver;
  1988. + unsigned int patch_base_addr;
  1989. + unsigned int patch_entry_addr;
  1990. + unsigned short patch_length;
  1991. + int patch_crc;
  1992. + unsigned short patch_ctrl;
  1993. +} __attribute__ ((packed)) patch_info;
  1994. +
  1995. +typedef struct {
  1996. + unsigned char sign_ver;
  1997. + unsigned char sign_algorithm;
  1998. + unsigned short reserved1;
  1999. + unsigned short prod_id;
  2000. + unsigned short build_ver;
  2001. + unsigned short patch_ver;
  2002. + unsigned short reserved2;
  2003. + unsigned int patch_entry_addr;
  2004. +} __attribute__ ((packed)) tlv_patch_hdr;
  2005. +
  2006. +typedef struct {
  2007. + unsigned short tag_id;
  2008. + unsigned short tag_len;
  2009. + unsigned int tag_ptr;
  2010. + unsigned int tag_ex_flag;
  2011. +} __attribute__ ((packed)) tlv_nvm_hdr;
  2012. +
  2013. +typedef struct {
  2014. + unsigned char tlv_type;
  2015. + unsigned char tlv_length1;
  2016. + unsigned char tlv_length2;
  2017. + unsigned char tlv_length3;
  2018. + unsigned int tlv_data_len;
  2019. + unsigned int tlv_patch_data_len;
  2020. +
  2021. + union{
  2022. + tlv_patch_hdr patch;
  2023. + tlv_nvm_hdr nvm;
  2024. + }tlv;
  2025. +} __attribute__ ((packed)) tlv_patch_info;
  2026. +
  2027. +enum{
  2028. + BAUDRATE_115200 = 0x00,
  2029. + BAUDRATE_57600 = 0x01,
  2030. + BAUDRATE_38400 = 0x02,
  2031. + BAUDRATE_19200 = 0x03,
  2032. + BAUDRATE_9600 = 0x04,
  2033. + BAUDRATE_230400 = 0x05,
  2034. + BAUDRATE_250000 = 0x06,
  2035. + BAUDRATE_460800 = 0x07,
  2036. + BAUDRATE_500000 = 0x08,
  2037. + BAUDRATE_720000 = 0x09,
  2038. + BAUDRATE_921600 = 0x0A,
  2039. + BAUDRATE_1000000 = 0x0B,
  2040. + BAUDRATE_1250000 = 0x0C,
  2041. + BAUDRATE_2000000 = 0x0D,
  2042. + BAUDRATE_3000000 = 0x0E,
  2043. + BAUDRATE_4000000 = 0x0F,
  2044. + BAUDRATE_1600000 = 0x10,
  2045. + BAUDRATE_3200000 = 0x11,
  2046. + BAUDRATE_3500000 = 0x12,
  2047. + BAUDRATE_AUTO = 0xFE,
  2048. + BAUDRATE_Reserved = 0xFF
  2049. +};
  2050. +
  2051. +enum{
  2052. + ROME_PATCH_VER_0100 = 0x0100,
  2053. + ROME_PATCH_VER_0101 = 0x0101,
  2054. + ROME_PATCH_VER_0200 = 0x0200,
  2055. + ROME_PATCH_VER_0300 = 0x0300
  2056. + };
  2057. +
  2058. +enum{
  2059. + ROME_SOC_ID_00 = 0x00000000,
  2060. + ROME_SOC_ID_11 = 0x00000011,
  2061. + ROME_SOC_ID_13 = 0x00000013,
  2062. + ROME_SOC_ID_22 = 0x00000022,
  2063. +};
  2064. +
  2065. +enum{
  2066. + ROME_VER_UNKNOWN = 0,
  2067. + ROME_VER_1_0 = ((ROME_PATCH_VER_0100 << 16 ) | ROME_SOC_ID_00 ),
  2068. + ROME_VER_1_1 = ((ROME_PATCH_VER_0101 << 16 ) | ROME_SOC_ID_00 ),
  2069. + ROME_VER_1_3 = ((ROME_PATCH_VER_0200 << 16 ) | ROME_SOC_ID_00 ),
  2070. + ROME_VER_2_1 = ((ROME_PATCH_VER_0200 << 16 ) | ROME_SOC_ID_11 ),
  2071. + ROME_VER_3_0 = ((ROME_PATCH_VER_0300 << 16 ) | ROME_SOC_ID_22 ),
  2072. + TUFELLO_VER_1_0 = ((ROME_PATCH_VER_0300 << 16 ) | ROME_SOC_ID_13 )
  2073. +};
  2074. +#endif /* HW_ROME_H */
  2075. --
  2076. 1.8.2.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement