gc3355.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /*
  2. * Copyright 2014 Nate Woolls
  3. * Copyright 2013 Luke Dashjr
  4. * Copyright 2014 GridSeed Team
  5. * Copyright 2014 Dualminer Team
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 3 of the License, or (at your option)
  10. * any later version. See COPYING for more details.
  11. */
  12. #include "config.h"
  13. #include "gc3355.h"
  14. #include <stdint.h>
  15. #include <string.h>
  16. #include "miner.h"
  17. #include "driver-icarus.h"
  18. #include "logging.h"
  19. #include "lowl-vcom.h"
  20. #ifndef WIN32
  21. #include <sys/ioctl.h>
  22. #else
  23. #include <io.h>
  24. #endif
  25. // options configurable by the end-user
  26. int opt_sha2_units = -1;
  27. int opt_pll_freq = 0; // default is set in gc3355_set_pll_freq
  28. #define GC3355_CHIP_NAME "gc3355"
  29. // General GC3355 commands
  30. static
  31. const char *firmware_request_cmd[] =
  32. {
  33. "55AAC000909090900000000001000000", // get firmware version of GC3355
  34. NULL
  35. };
  36. // SHA-2 commands
  37. static
  38. const char *sha2_gating_cmd[] =
  39. {
  40. "55AAEF0200000000", // Chip 1 - power down SHA-2 (unless masked w/PLL)
  41. "55AAEF0300000000", // Chip 2
  42. "55AAEF0400000000", // Chip 3
  43. "55AAEF0500000000", // Chip 4
  44. "55AAEF0600000000", // Chip 5
  45. NULL
  46. };
  47. // maps the above SHA chip gating with SHA-2 units
  48. static
  49. const char *sha2_open_cmd[] =
  50. {
  51. "55AAEF0200000001",
  52. "55AAEF0200000003",
  53. "55AAEF0200000007",
  54. "55AAEF020000000F",
  55. "55AAEF020000001F",
  56. "55AAEF020000003F",
  57. "55AAEF020000007F",
  58. "55AAEF02000000FF",
  59. "55AAEF02000001FF",
  60. "55AAEF02000003FF",
  61. "55AAEF02000007FF",
  62. "55AAEF0200000FFF",
  63. "55AAEF0200001FFF",
  64. "55AAEF0200003FFF",
  65. "55AAEF0200007FFF",
  66. "55AAEF020000FFFF",
  67. "55AAEF020001FFFF",
  68. "55AAEF020003FFFF",
  69. "55AAEF020007FFFF",
  70. "55AAEF02000FFFFF",
  71. "55AAEF02001FFFFF",
  72. "55AAEF02003FFFFF",
  73. "55AAEF02007FFFFF",
  74. "55AAEF0200FFFFFF",
  75. "55AAEF0201FFFFFF",
  76. "55AAEF0203FFFFFF",
  77. "55AAEF0207FFFFFF",
  78. "55AAEF020FFFFFFF",
  79. "55AAEF021FFFFFFF",
  80. "55AAEF023FFFFFFF",
  81. "55AAEF027FFFFFFF",
  82. "55AAEF02FFFFFFFF",
  83. "55AAEF0300000001",
  84. "55AAEF0300000003",
  85. "55AAEF0300000007",
  86. "55AAEF030000000F",
  87. "55AAEF030000001F",
  88. "55AAEF030000003F",
  89. "55AAEF030000007F",
  90. "55AAEF03000000FF",
  91. "55AAEF03000001FF",
  92. "55AAEF03000003FF",
  93. "55AAEF03000007FF",
  94. "55AAEF0300000FFF",
  95. "55AAEF0300001FFF",
  96. "55AAEF0300003FFF",
  97. "55AAEF0300007FFF",
  98. "55AAEF030000FFFF",
  99. "55AAEF030001FFFF",
  100. "55AAEF030003FFFF",
  101. "55AAEF030007FFFF",
  102. "55AAEF03000FFFFF",
  103. "55AAEF03001FFFFF",
  104. "55AAEF03003FFFFF",
  105. "55AAEF03007FFFFF",
  106. "55AAEF0300FFFFFF",
  107. "55AAEF0301FFFFFF",
  108. "55AAEF0303FFFFFF",
  109. "55AAEF0307FFFFFF",
  110. "55AAEF030FFFFFFF",
  111. "55AAEF031FFFFFFF",
  112. "55AAEF033FFFFFFF",
  113. "55AAEF037FFFFFFF",
  114. "55AAEF03FFFFFFFF",
  115. "55AAEF0400000001",
  116. "55AAEF0400000003",
  117. "55AAEF0400000007",
  118. "55AAEF040000000F",
  119. "55AAEF040000001F",
  120. "55AAEF040000003F",
  121. "55AAEF040000007F",
  122. "55AAEF04000000FF",
  123. "55AAEF04000001FF",
  124. "55AAEF04000003FF",
  125. "55AAEF04000007FF",
  126. "55AAEF0400000FFF",
  127. "55AAEF0400001FFF",
  128. "55AAEF0400003FFF",
  129. "55AAEF0400007FFF",
  130. "55AAEF040000FFFF",
  131. "55AAEF040001FFFF",
  132. "55AAEF040003FFFF",
  133. "55AAEF040007FFFF",
  134. "55AAEF04000FFFFF",
  135. "55AAEF04001FFFFF",
  136. "55AAEF04003FFFFF",
  137. "55AAEF04007FFFFF",
  138. "55AAEF0400FFFFFF",
  139. "55AAEF0401FFFFFF",
  140. "55AAEF0403FFFFFF",
  141. "55AAEF0407FFFFFF",
  142. "55AAEF040FFFFFFF",
  143. "55AAEF041FFFFFFF",
  144. "55AAEF043FFFFFFF",
  145. "55AAEF047FFFFFFF",
  146. "55AAEF04FFFFFFFF",
  147. "55AAEF0500000001",
  148. "55AAEF0500000003",
  149. "55AAEF0500000007",
  150. "55AAEF050000000F",
  151. "55AAEF050000001F",
  152. "55AAEF050000003F",
  153. "55AAEF050000007F",
  154. "55AAEF05000000FF",
  155. "55AAEF05000001FF",
  156. "55AAEF05000003FF",
  157. "55AAEF05000007FF",
  158. "55AAEF0500000FFF",
  159. "55AAEF0500001FFF",
  160. "55AAEF0500003FFF",
  161. "55AAEF0500007FFF",
  162. "55AAEF050000FFFF",
  163. "55AAEF050001FFFF",
  164. "55AAEF050003FFFF",
  165. "55AAEF050007FFFF",
  166. "55AAEF05000FFFFF",
  167. "55AAEF05001FFFFF",
  168. "55AAEF05003FFFFF",
  169. "55AAEF05007FFFFF",
  170. "55AAEF0500FFFFFF",
  171. "55AAEF0501FFFFFF",
  172. "55AAEF0503FFFFFF",
  173. "55AAEF0507FFFFFF",
  174. "55AAEF050FFFFFFF",
  175. "55AAEF051FFFFFFF",
  176. "55AAEF053FFFFFFF",
  177. "55AAEF057FFFFFFF",
  178. "55AAEF05FFFFFFFF",
  179. "55AAEF0600000001",
  180. "55AAEF0600000003",
  181. "55AAEF0600000007",
  182. "55AAEF060000000F",
  183. "55AAEF060000001F",
  184. "55AAEF060000003F",
  185. "55AAEF060000007F",
  186. "55AAEF06000000FF",
  187. "55AAEF06000001FF",
  188. "55AAEF06000003FF",
  189. "55AAEF06000007FF",
  190. "55AAEF0600000FFF",
  191. "55AAEF0600001FFF",
  192. "55AAEF0600003FFF",
  193. "55AAEF0600007FFF",
  194. "55AAEF060000FFFF",
  195. "55AAEF060001FFFF",
  196. "55AAEF060003FFFF",
  197. "55AAEF060007FFFF",
  198. "55AAEF06000FFFFF",
  199. "55AAEF06001FFFFF",
  200. "55AAEF06003FFFFF",
  201. "55AAEF06007FFFFF",
  202. "55AAEF0600FFFFFF",
  203. "55AAEF0601FFFFFF",
  204. "55AAEF0603FFFFFF",
  205. "55AAEF0607FFFFFF",
  206. "55AAEF060FFFFFFF",
  207. "55AAEF061FFFFFFF",
  208. "55AAEF063FFFFFFF",
  209. "55AAEF067FFFFFFF",
  210. "55AAEF06FFFFFFFF",
  211. NULL
  212. };
  213. static
  214. const char *multichip_init_cmd[] =
  215. {
  216. "55AAC000C0C0C0C00500000001000000", // set number of sub-chips (05 in this case)
  217. "55AAEF020000000000000000000000000000000000000000", // power down all SHA-2 modules
  218. "55AAEF3020000000", // Enable SHA-2 OR NOT - NO SCRYPT ACCEPTS WITHOUT THIS???
  219. NULL
  220. };
  221. static
  222. const char *sha2_init_cmd[] =
  223. {
  224. "55AAEF3020000000", // Enable SHA-2
  225. "55AA1F2817000000", // Enable GCP
  226. NULL
  227. };
  228. // called when initializing GridSeed device
  229. // called while initializing DualMiner when mining in scrypt+sha (dual-mode)
  230. static
  231. const char *scrypt_init_cmd[] =
  232. {
  233. "55AA1F2814000000", // Enable Scrypt
  234. "55AA1F2817000000", // Enable GCP
  235. NULL
  236. };
  237. // called before job start by GridSeed when mining scrypt
  238. // called before job start by DualMiner when mining scrypt in scrypt+sha (dual-mode)
  239. static
  240. const char *scrypt_reset_cmd[] =
  241. {
  242. // faster, for start of each job:
  243. "55AA1F2816000000", // Reset Scrypt(?)
  244. "55AA1F2817000000", // Enable GCP(?)
  245. NULL
  246. };
  247. // called while initializing DualMiner when mining scrypt in scrypt-only (not dual-mode)
  248. static
  249. const char *scrypt_only_init_cmd[] =
  250. {
  251. "55AAEF0200000000",
  252. "55AAEF0300000000",
  253. "55AAEF0400000000",
  254. "55AAEF0500000000",
  255. "55AAEF0600000000",
  256. "55AAEF3040000000",
  257. "55AA1F2810000000",
  258. "55AA1F2813000000",
  259. NULL
  260. };
  261. // called before job start by DualMiner when mining scrypt in scrypt-only (not dual-mode)
  262. // called while initializing DualMiner when mining scrypt in scrypt-only (not dual-mode)
  263. static
  264. const char *scrypt_only_reset_cmd[] =
  265. {
  266. "55AA1F2810000000", // Close Scrypt(?)
  267. "55AA1F2813000000", // Open Scrypt(?)
  268. NULL
  269. };
  270. static
  271. const char *gcp_chip_reset_cmd[] =
  272. {
  273. "55AAC000808080800000000001000000", // GCP (GridChip) reset
  274. NULL
  275. };
  276. static
  277. const char *sha2_chip_reset_cmd[] =
  278. {
  279. "55AAC000E0E0E0E00000000001000000", // SHA2 reset
  280. NULL
  281. };
  282. void gc3355_reset_dtr(int fd)
  283. {
  284. // set data terminal ready (DTR) status
  285. set_serial_dtr(fd, BGV_HIGH);
  286. cgsleep_ms(GC3355_COMMAND_DELAY_MS);
  287. set_serial_dtr(fd, BGV_LOW);
  288. }
  289. static
  290. void gc3355_set_register(uint8_t * const buf, const uint8_t clusaddr, const uint8_t chipaddr, const uint8_t regaddr, const uint32_t val)
  291. {
  292. buf[0] = 0x55;
  293. buf[1] = 0xaa;
  294. buf[2] = (clusaddr << 4) | chipaddr;
  295. buf[3] = regaddr;
  296. buf[4] = (val >> 0) & 0xff;
  297. buf[5] = (val >> 8) & 0xff;
  298. buf[6] = (val >> 0x10) & 0xff;
  299. buf[7] = (val >> 0x18) & 0xff;
  300. }
  301. static
  302. void gc3355_config_cpm(uint8_t * const buf, const uint8_t chipaddr, const float mhz)
  303. {
  304. // See https://github.com/gridseed/gc3355-doc/blob/master/GC3355_Register_Spec.pdf
  305. const uint8_t pll_bypass = 1;
  306. const uint8_t pll_bandselect = 0;
  307. const uint8_t pll_outdiv = 0;
  308. uint8_t freq_div, freq_mult, last_freq_mult = 0; // mhz = (25 / freq_div * freq_mult)
  309. float actual_mhz, last_actual_mhz = -1;
  310. for (freq_div = 1; freq_div <= 32; ++freq_div)
  311. {
  312. freq_mult = mhz * freq_div / 25;
  313. if (freq_mult > 0x80)
  314. freq_mult = 0x80;
  315. actual_mhz = 25. / freq_div * freq_mult;
  316. if (last_actual_mhz > actual_mhz)
  317. {
  318. --freq_div;
  319. freq_mult = last_freq_mult;
  320. if (opt_debug)
  321. actual_mhz = 25. / freq_div * freq_mult;
  322. break;
  323. }
  324. if (actual_mhz > mhz - .5)
  325. break;
  326. last_actual_mhz = actual_mhz;
  327. last_freq_mult = freq_mult;
  328. }
  329. const uint8_t pll_F = freq_mult - 1;
  330. const uint8_t pll_R = freq_div - 1;
  331. const uint8_t core_clk_out1_diven = 0;
  332. const uint8_t core_clk_sel1 = 0;
  333. const uint8_t core_clk_sel0 = 0;
  334. const uint8_t pll_clk_gate = 0;
  335. const uint8_t pll_recfg = 1;
  336. const uint8_t cfg_cpm = 1;
  337. const uint32_t cfg = (pll_bypass << 31) | (pll_bandselect << 30) | (pll_outdiv << 28) | (pll_F << 21) | (pll_R << 16) | (core_clk_out1_diven << 6) | (core_clk_sel1 << 5) | (core_clk_sel0 << 4) | (pll_clk_gate << 3) | (pll_recfg << 2) | (cfg_cpm << 0);
  338. gc3355_set_register(buf, 0xe, chipaddr, 0, cfg);
  339. }
  340. // NOTE: MHz must match CPM config
  341. static
  342. void gc3355_config_sha256d(uint8_t * const buf, const uint8_t chipaddr, const float mhz, const uint32_t baud)
  343. {
  344. // See https://github.com/gridseed/gc3355-doc/blob/master/GC3355_Register_Spec.pdf
  345. const uint8_t force_start = 1;
  346. const uint8_t uart_enable = 1;
  347. const uint8_t uart_debug = 0;
  348. const uint8_t byte_order = 0;
  349. const uint16_t rpt_cycle = (mhz * 1000000 / baud);
  350. const uint32_t cfg = (force_start << 31) | (uart_enable << 30) | (uart_debug << 29) | (byte_order << 28) | rpt_cycle;
  351. gc3355_set_register(buf, 0, chipaddr, 0xff, cfg);
  352. }
  353. static
  354. void gc3355_log_protocol(int fd, const char *buf, size_t size, const char *prefix)
  355. {
  356. char hex[(size * 2) + 1];
  357. bin2hex(hex, buf, size);
  358. applog(LOG_DEBUG, "%s fd=%d: DEVPROTO: %s(%3lu) %s",
  359. GC3355_CHIP_NAME, fd, prefix, (unsigned long)size, hex);
  360. }
  361. ssize_t gc3355_read(int fd, char *buf, size_t size)
  362. {
  363. size_t read = serial_read(fd, buf, size);
  364. if ((read > 0) && opt_dev_protocol)
  365. gc3355_log_protocol(fd, buf, read, "RECV");
  366. return read;
  367. }
  368. ssize_t gc3355_write(int fd, const void * const buf, const size_t size)
  369. {
  370. if (opt_dev_protocol)
  371. gc3355_log_protocol(fd, buf, size, "SEND");
  372. return write(fd, buf, size);
  373. }
  374. static
  375. void _gc3355_send_cmds_bin(int fd, const char *cmds[], bool is_bin, int size)
  376. {
  377. int i = 0;
  378. unsigned char ob_bin[512];
  379. for (i = 0; ; i++)
  380. {
  381. const char *cmd = cmds[i];
  382. if (cmd == NULL)
  383. break;
  384. if (is_bin)
  385. gc3355_write(fd, cmd, size);
  386. else
  387. {
  388. int bin_size = strlen(cmd) / 2;
  389. hex2bin(ob_bin, cmd, bin_size);
  390. gc3355_write(fd, ob_bin, bin_size);
  391. }
  392. cgsleep_ms(GC3355_COMMAND_DELAY_MS);
  393. }
  394. }
  395. #define gc3355_send_cmds_bin(fd, cmds, size) _gc3355_send_cmds_bin(fd, cmds, true, size)
  396. #define gc3355_send_cmds(fd, cmds) _gc3355_send_cmds_bin(fd, cmds, false, -1)
  397. void gc3355_scrypt_only_reset(int fd)
  398. {
  399. gc3355_send_cmds(fd, scrypt_only_reset_cmd);
  400. }
  401. void gc3355_set_pll_freq(int fd, int pll_freq)
  402. {
  403. const uint8_t chipaddr = 0xf;
  404. const uint32_t baud = 115200; // FIXME: Make this configurable
  405. uint8_t buf[8];
  406. gc3355_config_cpm(buf, chipaddr, pll_freq);
  407. gc3355_write(fd, buf, sizeof(buf));
  408. cgsleep_ms(GC3355_COMMAND_DELAY_MS);
  409. gc3355_config_sha256d(buf, chipaddr, pll_freq, baud);
  410. gc3355_write(fd, buf, sizeof(buf));
  411. }
  412. static
  413. void gc3355_open_sha2_units(int fd, int sha2_units)
  414. {
  415. int unit_count = 0;
  416. unsigned char ob_bin[8];
  417. int i;
  418. // should be 0 - 160
  419. unit_count = sha2_units < 0 ? 0 : sha2_units > 160 ? 160 : sha2_units;
  420. if (unit_count > 0)
  421. {
  422. for(i = 0; i <= unit_count; i++)
  423. {
  424. hex2bin(ob_bin, sha2_open_cmd[i], sizeof(ob_bin));
  425. gc3355_write(fd, ob_bin, 8);
  426. cgsleep_ms(GC3355_COMMAND_DELAY_MS);
  427. }
  428. }
  429. else if (unit_count == 0)
  430. gc3355_send_cmds(fd, sha2_gating_cmd);
  431. }
  432. void gc3355_scrypt_init(int fd)
  433. {
  434. gc3355_send_cmds(fd, scrypt_init_cmd);
  435. }
  436. static
  437. void gc3355_scrypt_only_init(int fd)
  438. {
  439. gc3355_send_cmds(fd, sha2_gating_cmd);
  440. gc3355_send_cmds(fd, scrypt_only_init_cmd);
  441. gc3355_scrypt_only_reset(fd);
  442. }
  443. void gc3355_sha2_init(int fd)
  444. {
  445. gc3355_send_cmds(fd, sha2_gating_cmd);
  446. gc3355_send_cmds(fd, sha2_init_cmd);
  447. }
  448. void gc3355_init_device(int fd, int pll_freq, bool scrypt_only, bool detect_only, bool usbstick)
  449. {
  450. gc3355_send_cmds(fd, gcp_chip_reset_cmd);
  451. // zzz
  452. cgsleep_ms(GC3355_COMMAND_DELAY_MS);
  453. if (usbstick)
  454. {
  455. gc3355_send_cmds(fd, sha2_chip_reset_cmd);
  456. // initialize units
  457. gc3355_reset_dtr(fd);
  458. if (opt_scrypt && scrypt_only)
  459. gc3355_scrypt_only_init(fd);
  460. else
  461. {
  462. gc3355_sha2_init(fd);
  463. gc3355_scrypt_init(fd);
  464. }
  465. }
  466. else
  467. {
  468. // initialize units
  469. gc3355_send_cmds(fd, multichip_init_cmd);
  470. gc3355_scrypt_init(fd);
  471. }
  472. //set freq
  473. gc3355_set_pll_freq(fd, pll_freq);
  474. // zzz
  475. cgsleep_ms(GC3355_COMMAND_DELAY_MS);
  476. if (usbstick && !detect_only)
  477. {
  478. if (!opt_scrypt)
  479. // open sha2 units
  480. gc3355_open_sha2_units(fd, opt_sha2_units);
  481. // set request to send (RTS) status
  482. set_serial_rts(fd, BGV_HIGH);
  483. }
  484. }
  485. void gc3355_init_usborb(int fd, int pll_freq, bool scrypt_only, bool detect_only)
  486. {
  487. gc3355_init_device(fd, pll_freq, scrypt_only, detect_only, false);
  488. }
  489. void gc3355_init_usbstick(int fd, int pll_freq, bool scrypt_only, bool detect_only)
  490. {
  491. gc3355_init_device(fd, pll_freq, scrypt_only, detect_only, true);
  492. }
  493. void gc3355_scrypt_reset(int fd)
  494. {
  495. gc3355_send_cmds(fd, scrypt_reset_cmd);
  496. }
  497. void gc3355_scrypt_prepare_work(unsigned char cmd[156], struct work *work)
  498. {
  499. // command header
  500. cmd[0] = 0x55;
  501. cmd[1] = 0xaa;
  502. cmd[2] = 0x1f;
  503. cmd[3] = 0x00;
  504. // task data
  505. memcpy(cmd + 4, work->target, 32);
  506. memcpy(cmd + 36, work->midstate, 32);
  507. memcpy(cmd + 68, work->data, 80);
  508. // nonce_max
  509. cmd[148] = 0xff;
  510. cmd[149] = 0xff;
  511. cmd[150] = 0xff;
  512. cmd[151] = 0xff;
  513. // taskid
  514. int workid = work->id;
  515. memcpy(cmd + 152, &(workid), 4);
  516. }
  517. void gc3355_sha2_prepare_work(unsigned char cmd[52], struct work *work)
  518. {
  519. // command header
  520. cmd[0] = 0x55;
  521. cmd[1] = 0xaa;
  522. cmd[2] = 0x0f;
  523. cmd[3] = 0x00; // Scrypt header sig - used by DualMiner in Dual Mode
  524. uint8_t temp_bin[64];
  525. memset(temp_bin, 0, 64);
  526. memcpy(temp_bin, work->midstate, 32);
  527. memcpy(temp_bin + 52, work->data + 64, 12);
  528. memcpy(cmd + 8, work->midstate, 32);
  529. memcpy(cmd + 40, temp_bin + 52, 12);
  530. }
  531. int64_t gc3355_get_firmware_version(int fd)
  532. {
  533. gc3355_send_cmds(fd, firmware_request_cmd);
  534. char buf[GC3355_READ_SIZE];
  535. int read = gc3355_read(fd, buf, GC3355_READ_SIZE);
  536. if (read != GC3355_READ_SIZE)
  537. {
  538. applog(LOG_ERR, "%s: Failed reading work from %d", GC3355_CHIP_NAME, fd);
  539. return -1;
  540. }
  541. // firmware response begins with 55aac000 90909090
  542. if (memcmp(buf, "\x55\xaa\xc0\x00\x90\x90\x90\x90", GC3355_READ_SIZE - 4) != 0)
  543. {
  544. return -1;
  545. }
  546. uint32_t fw_version = be32toh(*(uint32_t *)(buf + 8));
  547. return fw_version;
  548. }