You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

810 lines
17 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2007-2008 by √ėyvind Harboe *
  3. * *
  4. * This program is free software; you can redistribute it and/or modify *
  5. * it under the terms of the GNU General Public License as published by *
  6. * the Free Software Foundation; either version 2 of the License, or *
  7. * (at your option) any later version. *
  8. * *
  9. * This program is distributed in the hope that it will be useful, *
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  12. * GNU General Public License for more details. *
  13. * *
  14. * You should have received a copy of the GNU General Public License *
  15. * along with this program; if not, write to the *
  16. * Free Software Foundation, Inc., *
  17. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  18. ***************************************************************************/
  19. #ifdef HAVE_CONFIG_H
  20. #include "config.h"
  21. #endif
  22. #include "embeddedice.h"
  23. #include "minidriver.h"
  24. #include "interface.h"
  25. #include <cyg/hal/hal_io.h> // low level i/o
  26. #include <cyg/hal/hal_diag.h>
  27. #define ZYLIN_VERSION "1.52"
  28. #define ZYLIN_DATE __DATE__
  29. #define ZYLIN_TIME __TIME__
  30. #define ZYLIN_OPENOCD "$Revision$"
  31. #define ZYLIN_OPENOCD_VERSION "Zylin JTAG ZY1000 " ZYLIN_VERSION " " ZYLIN_DATE " " ZYLIN_TIME
  32. const char *zylin_config_dir="/config/settings";
  33. /* low level command set
  34. */
  35. int zy1000_read(void);
  36. static void zy1000_write(int tck, int tms, int tdi);
  37. void zy1000_reset(int trst, int srst);
  38. int zy1000_speed(int speed);
  39. int zy1000_register_commands(struct command_context_s *cmd_ctx);
  40. int zy1000_init(void);
  41. int zy1000_quit(void);
  42. /* interface commands */
  43. int zy1000_handle_zy1000_port_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
  44. static int zy1000_khz(int khz, int *jtag_speed)
  45. {
  46. if (khz==0)
  47. {
  48. *jtag_speed=0;
  49. }
  50. else
  51. {
  52. *jtag_speed=64000/khz;
  53. }
  54. return ERROR_OK;
  55. }
  56. static int zy1000_speed_div(int speed, int *khz)
  57. {
  58. if (speed==0)
  59. {
  60. *khz = 0;
  61. }
  62. else
  63. {
  64. *khz=64000/speed;
  65. }
  66. return ERROR_OK;
  67. }
  68. static bool readPowerDropout(void)
  69. {
  70. cyg_uint32 state;
  71. // sample and clear power dropout
  72. HAL_WRITE_UINT32(ZY1000_JTAG_BASE+0x10, 0x80);
  73. HAL_READ_UINT32(ZY1000_JTAG_BASE+0x10, state);
  74. bool powerDropout;
  75. powerDropout = (state & 0x80) != 0;
  76. return powerDropout;
  77. }
  78. static bool readSRST(void)
  79. {
  80. cyg_uint32 state;
  81. // sample and clear SRST sensing
  82. HAL_WRITE_UINT32(ZY1000_JTAG_BASE+0x10, 0x00000040);
  83. HAL_READ_UINT32(ZY1000_JTAG_BASE+0x10, state);
  84. bool srstAsserted;
  85. srstAsserted = (state & 0x40) != 0;
  86. return srstAsserted;
  87. }
  88. static int zy1000_srst_asserted(int *srst_asserted)
  89. {
  90. *srst_asserted=readSRST();
  91. return ERROR_OK;
  92. }
  93. static int zy1000_power_dropout(int *dropout)
  94. {
  95. *dropout=readPowerDropout();
  96. return ERROR_OK;
  97. }
  98. jtag_interface_t zy1000_interface =
  99. {
  100. .name = "ZY1000",
  101. .execute_queue = NULL,
  102. .speed = zy1000_speed,
  103. .register_commands = zy1000_register_commands,
  104. .init = zy1000_init,
  105. .quit = zy1000_quit,
  106. .khz = zy1000_khz,
  107. .speed_div = zy1000_speed_div,
  108. .power_dropout = zy1000_power_dropout,
  109. .srst_asserted = zy1000_srst_asserted,
  110. };
  111. static void zy1000_write(int tck, int tms, int tdi)
  112. {
  113. }
  114. int zy1000_read(void)
  115. {
  116. return -1;
  117. }
  118. extern bool readSRST(void);
  119. void zy1000_reset(int trst, int srst)
  120. {
  121. LOG_DEBUG("zy1000 trst=%d, srst=%d", trst, srst);
  122. if(!srst)
  123. {
  124. ZY1000_POKE(ZY1000_JTAG_BASE+0x14, 0x00000001);
  125. }
  126. else
  127. {
  128. /* Danger!!! if clk!=0 when in
  129. * idle in TAP_IDLE, reset halt on str912 will fail.
  130. */
  131. ZY1000_POKE(ZY1000_JTAG_BASE+0x10, 0x00000001);
  132. }
  133. if(!trst)
  134. {
  135. ZY1000_POKE(ZY1000_JTAG_BASE+0x14, 0x00000002);
  136. }
  137. else
  138. {
  139. /* assert reset */
  140. ZY1000_POKE(ZY1000_JTAG_BASE+0x10, 0x00000002);
  141. }
  142. if (trst||(srst&&(jtag_reset_config & RESET_SRST_PULLS_TRST)))
  143. {
  144. waitIdle();
  145. /* we're now in the RESET state until trst is deasserted */
  146. ZY1000_POKE(ZY1000_JTAG_BASE+0x20, TAP_RESET);
  147. } else
  148. {
  149. /* We'll get RCLK failure when we assert TRST, so clear any false positives here */
  150. ZY1000_POKE(ZY1000_JTAG_BASE+0x14, 0x400);
  151. }
  152. /* wait for srst to float back up */
  153. if (!srst)
  154. {
  155. int i;
  156. for (i=0; i<1000; i++)
  157. {
  158. // We don't want to sense our own reset, so we clear here.
  159. // There is of course a timing hole where we could loose
  160. // a "real" reset.
  161. if (!readSRST())
  162. break;
  163. /* wait 1ms */
  164. alive_sleep(1);
  165. }
  166. if (i==1000)
  167. {
  168. LOG_USER("SRST didn't deassert after %dms", i);
  169. } else if (i>1)
  170. {
  171. LOG_USER("SRST took %dms to deassert", i);
  172. }
  173. }
  174. }
  175. int zy1000_speed(int speed)
  176. {
  177. if(speed == 0)
  178. {
  179. /*0 means RCLK*/
  180. speed = 0;
  181. ZY1000_POKE(ZY1000_JTAG_BASE+0x10, 0x100);
  182. LOG_DEBUG("jtag_speed using RCLK");
  183. }
  184. else
  185. {
  186. if(speed > 8190 || speed < 2)
  187. {
  188. LOG_USER("valid ZY1000 jtag_speed=[8190,2]. Divisor is 64MHz / even values between 8190-2, i.e. min 7814Hz, max 32MHz");
  189. return ERROR_INVALID_ARGUMENTS;
  190. }
  191. LOG_USER("jtag_speed %d => JTAG clk=%f", speed, 64.0/(float)speed);
  192. ZY1000_POKE(ZY1000_JTAG_BASE+0x14, 0x100);
  193. ZY1000_POKE(ZY1000_JTAG_BASE+0x1c, speed&~1);
  194. }
  195. return ERROR_OK;
  196. }
  197. static bool savePower;
  198. static void setPower(bool power)
  199. {
  200. savePower = power;
  201. if (power)
  202. {
  203. HAL_WRITE_UINT32(ZY1000_JTAG_BASE+0x14, 0x8);
  204. } else
  205. {
  206. HAL_WRITE_UINT32(ZY1000_JTAG_BASE+0x10, 0x8);
  207. }
  208. }
  209. int handle_power_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  210. {
  211. if (argc > 1)
  212. {
  213. return ERROR_INVALID_ARGUMENTS;
  214. }
  215. if (argc == 1)
  216. {
  217. if (strcmp(args[0], "on") == 0)
  218. {
  219. setPower(1);
  220. }
  221. else if (strcmp(args[0], "off") == 0)
  222. {
  223. setPower(0);
  224. } else
  225. {
  226. command_print(cmd_ctx, "arg is \"on\" or \"off\"");
  227. return ERROR_INVALID_ARGUMENTS;
  228. }
  229. }
  230. command_print(cmd_ctx, "Target power %s", savePower ? "on" : "off");
  231. return ERROR_OK;
  232. }
  233. /* Give TELNET a way to find out what version this is */
  234. static int jim_zy1000_version(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
  235. {
  236. if ((argc < 1) || (argc > 2))
  237. return JIM_ERR;
  238. char buff[128];
  239. const char *version_str=NULL;
  240. if (argc == 1)
  241. {
  242. version_str=ZYLIN_OPENOCD_VERSION;
  243. } else
  244. {
  245. const char *str = Jim_GetString(argv[1], NULL);
  246. if (strcmp("openocd", str) == 0)
  247. {
  248. int revision;
  249. revision = atol(ZYLIN_OPENOCD+strlen("XRevision: "));
  250. sprintf(buff, "%d", revision);
  251. version_str=buff;
  252. }
  253. else if (strcmp("zy1000", str) == 0)
  254. {
  255. version_str=ZYLIN_VERSION;
  256. }
  257. else if (strcmp("date", str) == 0)
  258. {
  259. version_str=ZYLIN_DATE;
  260. }
  261. else
  262. {
  263. return JIM_ERR;
  264. }
  265. }
  266. Jim_SetResult(interp, Jim_NewStringObj(interp, version_str, -1));
  267. return JIM_OK;
  268. }
  269. static int
  270. zylinjtag_Jim_Command_powerstatus(Jim_Interp *interp,
  271. int argc,
  272. Jim_Obj * const *argv)
  273. {
  274. if (argc != 1)
  275. {
  276. Jim_WrongNumArgs(interp, 1, argv, "powerstatus");
  277. return JIM_ERR;
  278. }
  279. cyg_uint32 status;
  280. ZY1000_PEEK(ZY1000_JTAG_BASE+0x10, status);
  281. Jim_SetResult(interp, Jim_NewIntObj(interp, (status&0x80)!=0));
  282. return JIM_OK;
  283. }
  284. int zy1000_register_commands(struct command_context_s *cmd_ctx)
  285. {
  286. register_command(cmd_ctx, NULL, "power", handle_power_command, COMMAND_ANY,
  287. "power <on/off> - turn power switch to target on/off. No arguments - print status.");
  288. Jim_CreateCommand(interp, "zy1000_version", jim_zy1000_version, NULL, NULL);
  289. Jim_CreateCommand(interp, "powerstatus", zylinjtag_Jim_Command_powerstatus, NULL, NULL);
  290. return ERROR_OK;
  291. }
  292. int zy1000_init(void)
  293. {
  294. LOG_USER("%s", ZYLIN_OPENOCD_VERSION);
  295. ZY1000_POKE(ZY1000_JTAG_BASE+0x10, 0x30); // Turn on LED1 & LED2
  296. setPower(true); // on by default
  297. /* deassert resets. Important to avoid infinite loop waiting for SRST to deassert */
  298. zy1000_reset(0, 0);
  299. zy1000_speed(jtag_speed);
  300. return ERROR_OK;
  301. }
  302. int zy1000_quit(void)
  303. {
  304. return ERROR_OK;
  305. }
  306. int interface_jtag_execute_queue(void)
  307. {
  308. cyg_uint32 empty;
  309. waitIdle();
  310. ZY1000_PEEK(ZY1000_JTAG_BASE+0x10, empty);
  311. /* clear JTAG error register */
  312. ZY1000_POKE(ZY1000_JTAG_BASE+0x14, 0x400);
  313. if ((empty&0x400)!=0)
  314. {
  315. LOG_WARNING("RCLK timeout");
  316. /* the error is informative only as we don't want to break the firmware if there
  317. * is a false positive.
  318. */
  319. // return ERROR_FAIL;
  320. }
  321. return ERROR_OK;
  322. }
  323. static cyg_uint32 getShiftValue(void)
  324. {
  325. cyg_uint32 value;
  326. waitIdle();
  327. ZY1000_PEEK(ZY1000_JTAG_BASE+0xc, value);
  328. VERBOSE(LOG_INFO("getShiftValue %08x", value));
  329. return value;
  330. }
  331. #if 0
  332. static cyg_uint32 getShiftValueFlip(void)
  333. {
  334. cyg_uint32 value;
  335. waitIdle();
  336. ZY1000_PEEK(ZY1000_JTAG_BASE+0x18, value);
  337. VERBOSE(LOG_INFO("getShiftValue %08x (flipped)", value));
  338. return value;
  339. }
  340. #endif
  341. #if 0
  342. static void shiftValueInnerFlip(const tap_state_t state, const tap_state_t endState, int repeat, cyg_uint32 value)
  343. {
  344. VERBOSE(LOG_INFO("shiftValueInner %s %s %d %08x (flipped)", tap_state_name(state), tap_state_name(endState), repeat, value));
  345. cyg_uint32 a,b;
  346. a=state;
  347. b=endState;
  348. ZY1000_POKE(ZY1000_JTAG_BASE+0xc, value);
  349. ZY1000_POKE(ZY1000_JTAG_BASE+0x8, (1<<15)|(repeat<<8)|(a<<4)|b);
  350. VERBOSE(getShiftValueFlip());
  351. }
  352. #endif
  353. extern int jtag_check_value(u8 *captured, void *priv);
  354. static __inline void scanFields(int num_fields, scan_field_t *fields, tap_state_t shiftState, tap_state_t end_state)
  355. {
  356. int i;
  357. int j;
  358. int k;
  359. for (i = 0; i < num_fields; i++)
  360. {
  361. cyg_uint32 value;
  362. static u8 *in_buff=NULL; /* pointer to buffer for scanned data */
  363. static int in_buff_size=0;
  364. u8 *inBuffer=NULL;
  365. // figure out where to store the input data
  366. int num_bits=fields[i].num_bits;
  367. if (fields[i].in_value!=NULL)
  368. {
  369. inBuffer=fields[i].in_value;
  370. }
  371. // here we shuffle N bits out/in
  372. j=0;
  373. while (j<num_bits)
  374. {
  375. tap_state_t pause_state;
  376. int l;
  377. k=num_bits-j;
  378. pause_state=(shiftState==TAP_DRSHIFT)?TAP_DRSHIFT:TAP_IRSHIFT;
  379. if (k>32)
  380. {
  381. k=32;
  382. /* we have more to shift out */
  383. } else if (i == num_fields-1)
  384. {
  385. /* this was the last to shift out this time */
  386. pause_state=end_state;
  387. }
  388. // we have (num_bits+7)/8 bytes of bits to toggle out.
  389. // bits are pushed out LSB to MSB
  390. value=0;
  391. if (fields[i].out_value!=NULL)
  392. {
  393. for (l=0; l<k; l+=8)
  394. {
  395. value|=fields[i].out_value[(j+l)/8]<<l;
  396. }
  397. }
  398. /* mask away unused bits for easier debugging */
  399. value&=~(((u32)0xffffffff)<<k);
  400. shiftValueInner(shiftState, pause_state, k, value);
  401. if (inBuffer!=NULL)
  402. {
  403. // data in, LSB to MSB
  404. value=getShiftValue();
  405. // we're shifting in data to MSB, shift data to be aligned for returning the value
  406. value >>= 32-k;
  407. for (l=0; l<k; l+=8)
  408. {
  409. inBuffer[(j+l)/8]=(value>>l)&0xff;
  410. }
  411. }
  412. j+=k;
  413. }
  414. }
  415. }
  416. int interface_jtag_set_end_state(tap_state_t state)
  417. {
  418. return ERROR_OK;
  419. }
  420. int interface_jtag_add_ir_scan(int num_fields, const scan_field_t *fields, tap_state_t state)
  421. {
  422. int j;
  423. int scan_size = 0;
  424. jtag_tap_t *tap, *nextTap;
  425. for(tap = jtag_NextEnabledTap(NULL); tap!= NULL; tap=nextTap)
  426. {
  427. nextTap=jtag_NextEnabledTap(tap);
  428. tap_state_t end_state;
  429. if (nextTap==NULL)
  430. {
  431. end_state = state;
  432. } else
  433. {
  434. end_state = TAP_IRSHIFT;
  435. }
  436. int found = 0;
  437. scan_size = tap->ir_length;
  438. /* search the list */
  439. for (j=0; j < num_fields; j++)
  440. {
  441. if (tap == fields[j].tap)
  442. {
  443. found = 1;
  444. scanFields(1, fields+j, TAP_IRSHIFT, end_state);
  445. /* update device information */
  446. buf_cpy(fields[j].out_value, tap->cur_instr, scan_size);
  447. tap->bypass = 0;
  448. break;
  449. }
  450. }
  451. if (!found)
  452. {
  453. /* if a device isn't listed, set it to BYPASS */
  454. u8 ones[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
  455. scan_field_t tmp;
  456. memset(&tmp, 0, sizeof(tmp));
  457. tmp.out_value = ones;
  458. tmp.num_bits = scan_size;
  459. scanFields(1, &tmp, TAP_IRSHIFT, end_state);
  460. /* update device information */
  461. buf_cpy(tmp.out_value, tap->cur_instr, scan_size);
  462. tap->bypass = 1;
  463. }
  464. }
  465. return ERROR_OK;
  466. }
  467. int interface_jtag_add_plain_ir_scan(int num_fields, const scan_field_t *fields, tap_state_t state)
  468. {
  469. scanFields(num_fields, fields, TAP_IRSHIFT, state);
  470. return ERROR_OK;
  471. }
  472. /*extern jtag_command_t **jtag_get_last_command_p(void);*/
  473. int interface_jtag_add_dr_scan(int num_fields, const scan_field_t *fields, tap_state_t state)
  474. {
  475. int j;
  476. jtag_tap_t *tap, *nextTap;
  477. for(tap = jtag_NextEnabledTap(NULL); tap!= NULL; tap=nextTap)
  478. {
  479. nextTap=jtag_NextEnabledTap(tap);
  480. int found=0;
  481. tap_state_t end_state;
  482. if (nextTap==NULL)
  483. {
  484. end_state = state;
  485. } else
  486. {
  487. end_state = TAP_DRSHIFT;
  488. }
  489. for (j=0; j < num_fields; j++)
  490. {
  491. if (tap == fields[j].tap)
  492. {
  493. found = 1;
  494. scanFields(1, fields+j, TAP_DRSHIFT, end_state);
  495. }
  496. }
  497. if (!found)
  498. {
  499. scan_field_t tmp;
  500. /* program the scan field to 1 bit length, and ignore it's value */
  501. tmp.num_bits = 1;
  502. tmp.out_value = NULL;
  503. tmp.in_value = NULL;
  504. scanFields(1, &tmp, TAP_DRSHIFT, end_state);
  505. }
  506. else
  507. {
  508. }
  509. }
  510. return ERROR_OK;
  511. }
  512. int interface_jtag_add_plain_dr_scan(int num_fields, const scan_field_t *fields, tap_state_t state)
  513. {
  514. scanFields(num_fields, fields, TAP_DRSHIFT, state);
  515. return ERROR_OK;
  516. }
  517. int interface_jtag_add_tlr()
  518. {
  519. setCurrentState(TAP_RESET);
  520. return ERROR_OK;
  521. }
  522. extern int jtag_nsrst_delay;
  523. extern int jtag_ntrst_delay;
  524. int interface_jtag_add_reset(int req_trst, int req_srst)
  525. {
  526. zy1000_reset(req_trst, req_srst);
  527. return ERROR_OK;
  528. }
  529. static int zy1000_jtag_add_clocks(int num_cycles, tap_state_t state, tap_state_t clockstate)
  530. {
  531. /* num_cycles can be 0 */
  532. setCurrentState(clockstate);
  533. /* execute num_cycles, 32 at the time. */
  534. int i;
  535. for (i=0; i<num_cycles; i+=32)
  536. {
  537. int num;
  538. num=32;
  539. if (num_cycles-i<num)
  540. {
  541. num=num_cycles-i;
  542. }
  543. shiftValueInner(clockstate, clockstate, num, 0);
  544. }
  545. #if !TEST_MANUAL()
  546. /* finish in end_state */
  547. setCurrentState(state);
  548. #else
  549. tap_state_t t=TAP_IDLE;
  550. /* test manual drive code on any target */
  551. int tms;
  552. u8 tms_scan = tap_get_tms_path(t, state);
  553. int tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
  554. for (i = 0; i < tms_count; i++)
  555. {
  556. tms = (tms_scan >> i) & 1;
  557. waitIdle();
  558. ZY1000_POKE(ZY1000_JTAG_BASE+0x28, tms);
  559. }
  560. waitIdle();
  561. ZY1000_POKE(ZY1000_JTAG_BASE+0x20, state);
  562. #endif
  563. return ERROR_OK;
  564. }
  565. int interface_jtag_add_runtest(int num_cycles, tap_state_t state)
  566. {
  567. return zy1000_jtag_add_clocks(num_cycles, state, TAP_IDLE);
  568. }
  569. int interface_jtag_add_clocks(int num_cycles)
  570. {
  571. return zy1000_jtag_add_clocks(num_cycles, cmd_queue_cur_state, cmd_queue_cur_state);
  572. }
  573. int interface_jtag_add_sleep(u32 us)
  574. {
  575. jtag_sleep(us);
  576. return ERROR_OK;
  577. }
  578. int interface_jtag_add_pathmove(int num_states, const tap_state_t *path)
  579. {
  580. int state_count;
  581. int tms = 0;
  582. /*wait for the fifo to be empty*/
  583. waitIdle();
  584. state_count = 0;
  585. tap_state_t cur_state=cmd_queue_cur_state;
  586. while (num_states)
  587. {
  588. if (tap_state_transition(cur_state, false) == path[state_count])
  589. {
  590. tms = 0;
  591. }
  592. else if (tap_state_transition(cur_state, true) == path[state_count])
  593. {
  594. tms = 1;
  595. }
  596. else
  597. {
  598. LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(cur_state), tap_state_name(path[state_count]));
  599. exit(-1);
  600. }
  601. waitIdle();
  602. ZY1000_POKE(ZY1000_JTAG_BASE+0x28, tms);
  603. cur_state = path[state_count];
  604. state_count++;
  605. num_states--;
  606. }
  607. waitIdle();
  608. ZY1000_POKE(ZY1000_JTAG_BASE+0x20, cur_state);
  609. return ERROR_OK;
  610. }
  611. void embeddedice_write_dcc(jtag_tap_t *tap, int reg_addr, u8 *buffer, int little, int count)
  612. {
  613. // static int const reg_addr=0x5;
  614. tap_state_t end_state=jtag_get_end_state();
  615. if (jtag_NextEnabledTap(jtag_NextEnabledTap(NULL))==NULL)
  616. {
  617. /* better performance via code duplication */
  618. if (little)
  619. {
  620. int i;
  621. for (i = 0; i < count; i++)
  622. {
  623. shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, 32, fast_target_buffer_get_u32(buffer, 1));
  624. shiftValueInner(TAP_DRSHIFT, end_state, 6, reg_addr|(1<<5));
  625. buffer+=4;
  626. }
  627. } else
  628. {
  629. int i;
  630. for (i = 0; i < count; i++)
  631. {
  632. shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, 32, fast_target_buffer_get_u32(buffer, 0));
  633. shiftValueInner(TAP_DRSHIFT, end_state, 6, reg_addr|(1<<5));
  634. buffer+=4;
  635. }
  636. }
  637. }
  638. else
  639. {
  640. int i;
  641. for (i = 0; i < count; i++)
  642. {
  643. embeddedice_write_reg_inner(tap, reg_addr, fast_target_buffer_get_u32(buffer, little));
  644. buffer += 4;
  645. }
  646. }
  647. }
  648. int loadFile(const char *fileName, void **data, int *len);
  649. /* boolean parameter stored on config */
  650. int boolParam(char *var)
  651. {
  652. bool result = false;
  653. char *name = alloc_printf("%s/%s", zylin_config_dir, var);
  654. if (name == NULL)
  655. return result;
  656. void *data;
  657. int len;
  658. if (loadFile(name, &data, &len) == ERROR_OK)
  659. {
  660. if (len > 1)
  661. len = 1;
  662. result = strncmp((char *) data, "1", len) == 0;
  663. free(data);
  664. }
  665. free(name);
  666. return result;
  667. }