zy1000: removed some redundant include
[openocd/cortex.git] / src / ecosboard.c
blob32eb085281505a146f4c9a136e9375105114cf2a
1 /***************************************************************************
2 * Copyright (C) 2007-2009 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 ***************************************************************************/
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
24 #include <helper/types.h>
25 #include <jtag/jtag.h>
26 #include <helper/ioutil.h>
27 #include <helper/configuration.h>
29 #include <server/server.h>
30 #include <server/telnet_server.h>
31 #include <server/gdb_server.h>
32 #include <openocd.h>
34 #include <helper/time_support.h>
36 #include <sys/time.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <unistd.h>
41 #include <errno.h>
43 #include <cyg/io/flash.h>
44 #include <pkgconf/fs_jffs2.h> // Address of JFFS2
45 #include <network.h>
47 #include <fcntl.h>
48 #include <sys/stat.h>
49 #include <cyg/fileio/fileio.h>
50 #include <dirent.h>
51 #include <cyg/athttpd/http.h>
52 #include <cyg/athttpd/socket.h>
53 #include <cyg/athttpd/handler.h>
54 #include <cyg/athttpd/cgi.h>
55 #include <cyg/athttpd/forms.h>
56 #include <cyg/discover/discover.h>
57 #include <cyg/io/io.h>
58 #include <cyg/io/serialio.h>
59 #include <netinet/tcp.h>
60 #include <cyg/hal/hal_diag.h>
62 #include "rom.h"
64 #ifdef CYGPKG_HAL_NIOS2
65 #define ZY1000_SER_DEV "/dev/uart_0"
66 #else
67 #define ZY1000_SER_DEV "/dev/ser0"
69 #endif
72 #define MAX_IFS 64
73 #if defined(CYGPKG_NET_FREEBSD_STACK)
74 #include <tftp_support.h>
75 /* posix compatibility broken*/
76 struct tftpd_fileops fileops =
78 (int (*)(const char *, int))open,
79 close,
80 (int (*)(int, const void *, int))write,
81 (int (*)(int, void *, int))read
84 #endif
87 void diag_write(char *buf, int len)
89 int j;
90 for (j = 0; j < len; j++)
92 diag_printf("%c", buf[j]);
96 static bool serialLog = true;
97 static bool writeLog = true;
99 char hwaddr[512];
102 extern struct flash_driver *flash_drivers[];
103 extern struct target_type *target_types[];
105 #ifdef CYGPKG_PROFILE_GPROF
106 #include <cyg/profile/profile.h>
108 extern char _stext, _etext; // Defined by the linker
110 static char *start_of_code=&_stext;
111 static char *end_of_code=&_etext;
113 void start_profile(void)
115 // This starts up the system-wide profiling, gathering
116 // profile information on all of the code, with a 16 byte
117 // "bucket" size, at a rate of 100us/profile hit.
118 // Note: a bucket size of 16 will give pretty good function
119 // resolution. Much smaller and the buffer becomes
120 // much too large for very little gain.
121 // Note: a timer period of 100us is also a reasonable
122 // compromise. Any smaller and the overhead of
123 // handling the timter (profile) interrupt could
124 // swamp the system. A fast processor might get
125 // by with a smaller value, but a slow one could
126 // even be swamped by this value. If the value is
127 // too large, the usefulness of the profile is reduced.
129 // no more interrupts than 1/10ms.
130 //profile_on((void *)0, (void *)0x40000, 16, 10000); // SRAM
131 // profile_on(0, &_etext, 16, 10000); // SRAM & DRAM
132 profile_on(start_of_code, end_of_code, 16, 10000); // Nios DRAM
134 #endif
136 static FILE *log;
138 static char reboot_stack[2048];
140 static void zylinjtag_reboot(cyg_addrword_t data)
142 serialLog = true;
143 diag_printf("Rebooting in 500 ticks..\n");
144 cyg_thread_delay(500);
145 diag_printf("Unmounting /config..\n");
146 umount("/config");
147 diag_printf("Rebooting..\n");
148 HAL_PLATFORM_RESET();
150 static cyg_thread zylinjtag_thread_object;
151 static cyg_handle_t zylinjtag_thread_handle;
153 void reboot(void)
155 cyg_thread_create(1, zylinjtag_reboot, (cyg_addrword_t) 0, "reboot Thread",
156 (void *) reboot_stack, sizeof(reboot_stack),
157 &zylinjtag_thread_handle, &zylinjtag_thread_object);
158 cyg_thread_resume(zylinjtag_thread_handle);
161 static char zylinjtag_reboot_port_stack[2048];
162 static cyg_thread zylinjtag_reboot_port_thread_object;
163 static cyg_handle_t zylinjtag_reboot_port_thread_handle;
165 static void zylinjtag_reboot_port_task(cyg_addrword_t data)
167 int so_reuseaddr_option = 1;
169 int fd;
170 if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
172 LOG_ERROR("error creating socket: %s", strerror(errno));
173 exit(-1);
176 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void*) &so_reuseaddr_option,
177 sizeof(int));
179 struct sockaddr_in sin;
180 unsigned int address_size;
181 address_size = sizeof(sin);
182 memset(&sin, 0, sizeof(sin));
183 sin.sin_family = AF_INET;
184 sin.sin_addr.s_addr = INADDR_ANY;
185 sin.sin_port = htons(1234);
187 if (bind(fd, (struct sockaddr *) &sin, sizeof(sin)) == -1)
189 LOG_ERROR("couldn't bind to socket: %s", strerror(errno));
190 exit(-1);
193 if (listen(fd, 1) == -1)
195 LOG_ERROR("couldn't listen on socket: %s", strerror(errno));
196 exit(-1);
198 // socket_nonblock(fd);
201 accept(fd, (struct sockaddr *) &sin, &address_size);
203 diag_printf("Got reboot signal on port 1234");
205 reboot();
209 void reboot_port(void)
211 cyg_thread_create(1, zylinjtag_reboot_port_task, (cyg_addrword_t) 0, "wait for reboot signal on port 1234",
212 (void *) zylinjtag_reboot_port_stack, sizeof(zylinjtag_reboot_port_stack),
213 &zylinjtag_reboot_port_thread_handle, &zylinjtag_reboot_port_thread_object);
214 cyg_thread_resume(zylinjtag_reboot_port_thread_handle);
217 int configuration_output_handler(struct command_context *context,
218 const char* line)
220 diag_printf("%s", line);
222 return ERROR_OK;
225 int zy1000_configuration_output_handler_log(struct command_context *context,
226 const char* line)
228 LOG_USER_N("%s", line);
230 return ERROR_OK;
233 #ifdef CYGPKG_PROFILE_GPROF
234 //extern int64_t totaltime;
236 static int zylinjtag_Jim_Command_profile(Jim_Interp *interp, int argc,
237 Jim_Obj * const *argv)
239 if ((argc == 2) && (strcmp(Jim_GetString(argv[1], NULL), "stats")==0))
241 // profile_off();
242 //LOG_USER("Stats %dms sleeping in select()", (int)totaltime);
243 } else
245 LOG_USER("Profiling started");
246 start_profile();
247 //totaltime = 0;
249 return ERROR_OK;
252 #endif
254 externC void phi_init_all_network_interfaces(void);
256 struct command_context *cmd_ctx;
258 static bool webRunning = false;
260 void keep_webserver(void)
262 // Target initialisation is only attempted at startup, so we sleep forever and
263 // let the http server bail us out(i.e. get config files set up).
264 diag_printf("OpenOCD has invoked exit().\n"
265 "Use web server to correct any configuration settings and reboot.\n");
266 if (!webRunning)
267 reboot();
269 // exit() will terminate the current thread and we we'll then sleep eternally or
270 // we'll have a reboot scheduled.
273 extern void printDccChar(char c);
275 static char logBuffer[128 * 1024];
276 static const int logSize = sizeof(logBuffer);
277 int writePtr = 0;
278 int logCount = 0;
280 void _zylinjtag_diag_write_char(char c, void **param)
282 if (writeLog)
284 logBuffer[writePtr] = c;
285 writePtr = (writePtr + 1) % logSize;
286 logCount++;
288 if (serialLog)
290 if (c == '\n')
292 HAL_DIAG_WRITE_CHAR('\r');
294 HAL_DIAG_WRITE_CHAR(c);
297 #ifdef CYGPKG_HAL_ZYLIN_PHI
298 printDccChar(c);
299 #endif
302 void copyfile(char *name2, char *name1);
304 void copydir(char *name, char *destdir);
306 #if 0
307 MTAB_ENTRY(romfs_mte1,
308 "/rom",
309 "romfs",
311 (CYG_ADDRWORD) &filedata[0]);
312 #endif
314 void openocd_sleep_prelude(void)
316 cyg_mutex_unlock(&httpstate.jim_lock);
319 void openocd_sleep_postlude(void)
321 cyg_mutex_lock(&httpstate.jim_lock);
324 void format(void)
326 #ifdef CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1
327 diag_printf("Formatting JFFS2...\n");
329 cyg_io_handle_t handle;
331 Cyg_ErrNo err;
332 err = cyg_io_lookup(CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, &handle);
333 if (err != ENOERR)
335 diag_printf("Flash Error cyg_io_lookup: %d\n", err);
336 reboot();
339 cyg_uint32 len;
340 cyg_io_flash_getconfig_devsize_t ds;
341 len = sizeof(ds);
342 err = cyg_io_get_config(handle, CYG_IO_GET_CONFIG_FLASH_DEVSIZE, &ds, &len);
343 if (err != ENOERR)
345 diag_printf("Flash error cyg_io_get_config %d\n", err);
346 reboot();
349 cyg_io_flash_getconfig_erase_t e;
350 len = sizeof(e);
352 e.offset = 0;
353 e.len = ds.dev_size;
355 diag_printf("Formatting 0x%08x bytes\n", (int)ds.dev_size);
356 err = cyg_io_get_config(handle, CYG_IO_GET_CONFIG_FLASH_ERASE, &e, &len);
357 if (err != ENOERR)
359 diag_printf("Flash erase error %d offset 0x%08x\n", err, e.err_address);
360 reboot();
363 diag_printf("Flash formatted successfully\n");
364 #endif
366 reboot();
369 static int zylinjtag_Jim_Command_format_jffs2(Jim_Interp *interp, int argc,
370 Jim_Obj * const *argv)
372 if (argc != 1)
374 return JIM_ERR;
377 format();
378 for (;;)
382 static int zylinjtag_Jim_Command_threads(Jim_Interp *interp, int argc,
383 Jim_Obj * const *argv)
385 cyg_handle_t thread = 0;
386 cyg_uint16 id = 0;
387 Jim_Obj *threads = Jim_NewListObj(interp, NULL, 0);
389 /* Loop over the threads, and generate a table row for
390 * each.
392 while (cyg_thread_get_next(&thread, &id))
394 Jim_Obj *threadObj = Jim_NewListObj(interp, NULL, 0);
396 cyg_thread_info info;
397 char *state_string;
399 cyg_thread_get_info(thread, id, &info);
401 if (info.name == NULL)
402 info.name = "<no name>";
404 Jim_ListAppendElement(interp, threadObj, Jim_NewStringObj(interp,
405 info.name, strlen(info.name)));
407 /* Translate the state into a string.
409 if (info.state == 0)
410 state_string = "RUN";
411 else if (info.state & 0x04)
412 state_string = "SUSP";
413 else
414 switch (info.state & 0x1b)
416 case 0x01:
417 state_string = "SLEEP";
418 break;
419 case 0x02:
420 state_string = "CNTSLEEP";
421 break;
422 case 0x08:
423 state_string = "CREATE";
424 break;
425 case 0x10:
426 state_string = "EXIT";
427 break;
428 default:
429 state_string = "????";
430 break;
433 Jim_ListAppendElement(interp, threadObj, Jim_NewStringObj(interp,
434 state_string, strlen(state_string)));
436 Jim_ListAppendElement(interp, threadObj, Jim_NewIntObj(interp, id));
437 Jim_ListAppendElement(interp, threadObj, Jim_NewIntObj(interp,
438 info.set_pri));
439 Jim_ListAppendElement(interp, threadObj, Jim_NewIntObj(interp,
440 info.cur_pri));
442 Jim_ListAppendElement(interp, threads, threadObj);
444 Jim_SetResult(interp, threads);
446 return JIM_OK;
449 static int zylinjtag_Jim_Command_log(Jim_Interp *interp, int argc,
450 Jim_Obj * const *argv)
452 Jim_Obj *tclOutput = Jim_NewStringObj(interp, "", 0);
454 if (logCount >= logSize)
456 Jim_AppendString(httpstate.jim_interp, tclOutput, logBuffer + logCount
457 % logSize, logSize - logCount % logSize);
459 Jim_AppendString(httpstate.jim_interp, tclOutput, logBuffer, writePtr);
461 Jim_SetResult(interp, tclOutput);
462 return JIM_OK;
465 static int zylinjtag_Jim_Command_reboot(Jim_Interp *interp, int argc,
466 Jim_Obj * const *argv)
468 reboot();
469 return JIM_OK;
472 static void zylinjtag_startNetwork(void)
474 // Bring TCP/IP up immediately before we're ready to accept commands.
476 // That is as soon as a PING responds, we're accepting telnet sessions.
477 #if defined(CYGPKG_NET_FREEBSD_STACK)
478 phi_init_all_network_interfaces();
479 #else
480 lwip_init();
481 #endif
482 if (!eth0_up)
484 diag_printf("Network not up and running\n");
485 exit(-1);
488 /* very first thing we want is a reboot capability */
489 reboot_port();
491 #if defined(CYGPKG_NET_FREEBSD_STACK)
492 /*start TFTP*/
493 tftpd_start(69, &fileops);
494 #endif
496 cyg_httpd_init_tcl_interpreter();
498 Jim_CreateCommand(httpstate.jim_interp, "log", zylinjtag_Jim_Command_log,
499 NULL, NULL);
500 Jim_CreateCommand(httpstate.jim_interp, "zy1000_reboot",
501 zylinjtag_Jim_Command_reboot, NULL, NULL);
502 Jim_CreateCommand(httpstate.jim_interp, "threads",
503 zylinjtag_Jim_Command_threads, NULL, NULL);
504 Jim_CreateCommand(httpstate.jim_interp, "format_jffs2",
505 zylinjtag_Jim_Command_format_jffs2, NULL, NULL);
507 cyg_httpd_start();
509 webRunning = true;
511 diag_printf("Web server running\n");
513 int s;
514 struct ifreq ifr;
515 s = socket(AF_INET, SOCK_DGRAM, 0);
516 if (s >= 0)
518 strcpy(ifr.ifr_name, "eth0");
519 int res;
520 res = ioctl(s, SIOCGIFHWADDR, &ifr);
521 close(s);
523 if (res < 0)
525 diag_printf("Can't obtain MAC address\n");
526 reboot();
530 sprintf(hwaddr, "%02x:%02x:%02x:%02x:%02x:%02x",
531 (int) ((unsigned char *) &ifr.ifr_hwaddr.sa_data)[0],
532 (int) ((unsigned char *) &ifr.ifr_hwaddr.sa_data)[1],
533 (int) ((unsigned char *) &ifr.ifr_hwaddr.sa_data)[2],
534 (int) ((unsigned char *) &ifr.ifr_hwaddr.sa_data)[3],
535 (int) ((unsigned char *) &ifr.ifr_hwaddr.sa_data)[4],
536 (int) ((unsigned char *) &ifr.ifr_hwaddr.sa_data)[5]);
538 discover_message
539 = alloc_printf("ZY1000 Zylin JTAG debugger MAC %s", hwaddr);
541 discover_launch();
544 static void print_exception_handler(cyg_addrword_t data, cyg_code_t exception,
545 cyg_addrword_t info)
547 writeLog = false;
548 serialLog = true;
549 char *infoStr = "unknown";
550 switch (exception)
552 #ifdef CYGNUM_HAL_VECTOR_UNDEF_INSTRUCTION
553 case CYGNUM_HAL_VECTOR_UNDEF_INSTRUCTION:
554 infoStr = "undefined instruction";
555 break;
556 case CYGNUM_HAL_VECTOR_SOFTWARE_INTERRUPT:
557 infoStr = "software interrupt";
558 break;
559 case CYGNUM_HAL_VECTOR_ABORT_PREFETCH:
560 infoStr = "abort prefetch";
561 break;
562 case CYGNUM_HAL_VECTOR_ABORT_DATA:
563 infoStr = "abort data";
564 break;
565 #endif
566 default:
567 break;
570 diag_printf("Exception: %08x(%s) %08x\n", exception, infoStr, info);
572 diag_printf("Dumping log\n---\n");
573 if (logCount >= logSize)
575 diag_write(logBuffer + logCount % logSize, logSize - logCount % logSize);
577 diag_write(logBuffer, writePtr);
579 diag_printf("---\nLogdump complete.\n");
580 diag_printf("Exception: %08x(%s) %08x\n", exception, infoStr, info);
581 diag_printf("\n---\nRebooting\n");
582 HAL_PLATFORM_RESET();
586 #ifdef CYGNUM_HAL_VECTOR_UNDEF_INSTRUCTION
587 static void setHandler(cyg_code_t exception)
589 cyg_exception_handler_t *old_handler;
590 cyg_addrword_t old_data;
592 cyg_exception_set_handler(exception, print_exception_handler, 0,
593 &old_handler, &old_data);
595 #endif
597 static cyg_thread zylinjtag_uart_thread_object;
598 static cyg_handle_t zylinjtag_uart_thread_handle;
599 static char uart_stack[4096];
601 static char forwardBuffer[1024]; // NB! must be smaller than a TCP/IP packet!!!!!
602 static char backwardBuffer[1024];
604 void setNoDelay(int session, int flag)
606 #if 1
607 // This decreases latency dramatically for e.g. GDB load which
608 // does not have a sliding window protocol
610 // Can cause *lots* of TCP/IP packets to be sent and it would have
611 // to be enabled/disabled on the fly to avoid the CPU being
612 // overloaded...
613 setsockopt(session, /* socket affected */
614 IPPROTO_TCP, /* set option at TCP level */
615 TCP_NODELAY, /* name of option */
616 (char *) &flag, /* the cast is historical
617 cruft */
618 sizeof(int)); /* length of option value */
619 #endif
622 #define TEST_TCPIP() 0
624 #if TEST_TCPIP
625 struct
627 int req;
628 int actual;
629 int req2;
630 int actual2;
631 } tcpipSent[512 * 1024];
632 int cur;
633 #endif
635 static void zylinjtag_uart(cyg_addrword_t data)
637 int so_reuseaddr_option = 1;
639 int fd;
640 if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
642 LOG_ERROR("error creating socket: %s", strerror(errno));
643 exit(-1);
646 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void*) &so_reuseaddr_option,
647 sizeof(int));
649 struct sockaddr_in sin;
650 unsigned int address_size;
651 address_size = sizeof(sin);
652 memset(&sin, 0, sizeof(sin));
653 sin.sin_family = AF_INET;
654 sin.sin_addr.s_addr = INADDR_ANY;
655 sin.sin_port = htons(5555);
657 if (bind(fd, (struct sockaddr *) &sin, sizeof(sin)) == -1)
659 LOG_ERROR("couldn't bind to socket: %s", strerror(errno));
660 exit(-1);
663 if (listen(fd, 1) == -1)
665 LOG_ERROR("couldn't listen on socket: %s", strerror(errno));
666 exit(-1);
668 // socket_nonblock(fd);
671 for (;;)
673 int session = accept(fd, (struct sockaddr *) &sin, &address_size);
674 if (session < 0)
676 continue;
679 setNoDelay(session, 1);
680 int oldopts = fcntl(session, F_GETFL, 0);
681 fcntl(session, F_SETFL, oldopts | O_NONBLOCK); //
683 int serHandle = open(ZY1000_SER_DEV, O_RDWR | O_NONBLOCK);
684 if (serHandle < 0)
686 close(session);
687 continue;
690 #ifdef CYGPKG_PROFILE_GPROF
691 start_profile();
692 #endif
693 size_t actual = 0;
694 size_t actual2 = 0;
695 size_t pos, pos2;
696 pos = 0;
697 pos2 = 0;
698 #if TEST_TCPIP
699 cur = 0;
700 #endif
701 for (;;)
703 fd_set write_fds;
704 fd_set read_fds;
705 FD_ZERO(&write_fds);
706 FD_ZERO(&read_fds);
707 int fd_max = -1;
708 FD_SET(session, &read_fds);
709 fd_max = session;
710 FD_SET(serHandle, &read_fds);
711 if (serHandle > fd_max)
713 fd_max = serHandle;
715 /* Wait... */
717 cyg_thread_delay(5); // 50ms fixed delay to wait for data to be sent/received
718 if ((actual == 0) && (actual2 == 0))
720 int retval = select(fd_max + 1, &read_fds, NULL, NULL, NULL);
721 if (retval <= 0)
723 break;
727 if (actual2 <= 0)
729 memset(backwardBuffer, 's', sizeof(backwardBuffer));
730 int t;
731 t = read(serHandle, backwardBuffer,
732 sizeof(backwardBuffer));
733 actual2 = t;
734 if (t < 0)
736 if (errno != EAGAIN)
738 goto closeSession;
740 actual2 = 0;
742 pos2 = 0;
745 size_t y = 0;
746 if (actual2 > 0)
748 int written = write(session, backwardBuffer + pos2, actual2);
749 if (written <= 0)
750 goto closeSession;
751 actual2 -= written;
752 pos2 += written;
753 y = written;
756 if (FD_ISSET(session, &read_fds)
757 && (sizeof(forwardBuffer) > actual))
759 // NB! Here it is important that we empty the TCP/IP read buffer
760 // to make transmission tick right
761 memmove(forwardBuffer, forwardBuffer + pos, actual);
762 pos = 0;
763 int t;
764 // this will block if there is no data at all
765 t = read_socket(session, forwardBuffer + actual,
766 sizeof(forwardBuffer) - actual);
767 if (t <= 0)
769 goto closeSession;
771 actual += t;
774 int y2 = 0;
775 if (actual > 0)
777 /* Do not put things into the serial buffer if it has something to send
778 * as that can cause a single byte to be sent at the time.
782 int written = write(serHandle, forwardBuffer + pos, actual);
783 if (written < 0)
785 if (errno != EAGAIN)
787 goto closeSession;
789 // The serial buffer is full
790 written = 0;
792 else
794 actual -= written;
795 pos += written;
797 y2 = written;
799 #if TEST_TCPIP
800 if (cur < 1024)
802 tcpipSent[cur].req = x;
803 tcpipSent[cur].actual = y;
804 tcpipSent[cur].req2 = x2;
805 tcpipSent[cur].actual2 = y2;
806 cur++;
808 #endif
810 closeSession: close(session);
811 close(serHandle);
813 #if TEST_TCPIP
814 int i;
815 for (i = 0; i < 1024; i++)
817 diag_printf("%d %d %d %d\n", tcpipSent[i].req, tcpipSent[i].actual,
818 tcpipSent[i].req2, tcpipSent[i].actual2);
821 #endif
823 close(fd);
827 void startUart(void)
829 cyg_thread_create(1, zylinjtag_uart, (cyg_addrword_t) 0, "uart thread",
830 (void *) uart_stack, sizeof(uart_stack),
831 &zylinjtag_uart_thread_handle, &zylinjtag_uart_thread_object);
832 cyg_thread_set_priority(zylinjtag_uart_thread_handle, 1); // low priority as it sits in a busy loop
833 cyg_thread_resume(zylinjtag_uart_thread_handle);
836 static int zylinjtag_Jim_Command_uart(Jim_Interp *interp, int argc,
837 Jim_Obj * const *argv)
839 static int current_baud = 38400;
840 if (argc == 1)
842 command_print(cmd_ctx, "%d", current_baud);
843 return JIM_OK;
845 else if (argc != 2)
847 return JIM_ERR;
850 long new_baudrate;
851 if (Jim_GetLong(interp, argv[1], &new_baudrate) != JIM_OK)
852 return JIM_ERR;
854 current_baud = new_baudrate;
856 int baud;
857 switch (current_baud)
859 case 9600:
860 baud = CYGNUM_SERIAL_BAUD_9600;
861 break;
862 case 19200:
863 baud = CYGNUM_SERIAL_BAUD_19200;
864 break;
865 case 38400:
866 baud = CYGNUM_SERIAL_BAUD_38400;
867 break;
868 case 57600:
869 baud = CYGNUM_SERIAL_BAUD_57600;
870 break;
871 case 115200:
872 baud = CYGNUM_SERIAL_BAUD_115200;
873 break;
874 case 230400:
875 baud = CYGNUM_SERIAL_BAUD_230400;
876 break;
877 default:
878 command_print(cmd_ctx, "unsupported baudrate");
879 return ERROR_INVALID_ARGUMENTS;
882 cyg_serial_info_t buf;
883 cyg_uint32 len = 1;
884 //get existing serial configuration
885 len = sizeof(cyg_serial_info_t);
886 int err;
887 cyg_io_handle_t serial_handle;
889 err = cyg_io_lookup(ZY1000_SER_DEV, &serial_handle);
890 if (err != ENOERR)
892 LOG_ERROR("Could not open serial port\n");
893 return JIM_ERR;
896 err = cyg_io_get_config(serial_handle,
897 CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN, &buf, &len);
898 err = cyg_io_get_config(serial_handle, CYG_IO_GET_CONFIG_SERIAL_INFO, &buf,
899 &len);
900 if (err != ENOERR)
902 LOG_ERROR("Failed to get serial port settings %d", err);
903 return JIM_ERR;
905 buf.baud = baud;
907 err = cyg_io_set_config(serial_handle, CYG_IO_SET_CONFIG_SERIAL_INFO, &buf,
908 &len);
909 if (err != ENOERR)
911 LOG_ERROR("Failed to set serial port settings %d", err);
912 return JIM_ERR;
915 return JIM_OK;
918 bool logAllToSerial = false;
921 int boolParam(char *var);
924 static const char *zylin_config_dir="/config/settings";
926 static int add_default_dirs(void)
928 add_script_search_dir(zylin_config_dir);
929 add_script_search_dir("/rom/lib/openocd");
930 add_script_search_dir("/rom");
931 return ERROR_OK;
934 int main(int argc, char *argv[])
936 /* ramblockdevice will be the same address every time. The deflate app uses a buffer 16mBytes out, so we
937 * need to allocate towards the end of the heap. */
939 #ifdef CYGNUM_HAL_VECTOR_UNDEF_INSTRUCTION
940 setHandler(CYGNUM_HAL_VECTOR_UNDEF_INSTRUCTION);
941 setHandler(CYGNUM_HAL_VECTOR_ABORT_PREFETCH);
942 setHandler(CYGNUM_HAL_VECTOR_ABORT_DATA);
943 #endif
945 int err;
947 atexit(keep_webserver);
949 diag_init_putc(_zylinjtag_diag_write_char);
950 // We want this in the log.
951 diag_printf("Zylin ZY1000.\n");
953 err = mount("", "/ram", "ramfs");
954 if (err < 0)
956 diag_printf("unable to mount ramfs\n");
958 chdir("/ram");
960 char address[16];
961 sprintf(address, "%p", &filedata[0]);
962 err = mount(address, "/rom", "romfs");
963 if (err < 0)
965 diag_printf("unable to mount /rom\n");
968 err = mount("", "/log", "logfs");
969 if (err < 0)
971 diag_printf("unable to mount logfs\n");
974 err = mount("", "/tftp", "tftpfs");
975 if (err < 0)
977 diag_printf("unable to mount logfs\n");
980 log = fopen("/log/log", "w");
981 if (log == NULL)
983 diag_printf("Could not open log file /ram/log\n");
984 exit(-1);
988 copydir("/rom", "/ram/cgi");
990 err = mount("/dev/flash1", "/config", "jffs2");
991 if (err < 0)
993 diag_printf("unable to mount jffs2, falling back to ram disk..\n");
994 err = mount("", "/config", "ramfs");
995 if (err < 0)
997 diag_printf("unable to mount /config as ramdisk.\n");
998 reboot();
1001 else
1003 /* are we using a ram disk instead of a flash disk? This is used
1004 * for ZY1000 live demo...
1006 * copy over flash disk to ram block device
1008 if (boolParam("ramdisk"))
1010 diag_printf("Unmounting /config from flash and using ram instead\n");
1011 err = umount("/config");
1012 if (err < 0)
1014 diag_printf("unable to unmount jffs\n");
1015 reboot();
1018 err = mount("/dev/flash1", "/config2", "jffs2");
1019 if (err < 0)
1021 diag_printf("unable to mount jffs\n");
1022 reboot();
1025 err = mount("", "/config", "ramfs");
1026 if (err < 0)
1028 diag_printf("unable to mount ram block device\n");
1029 reboot();
1032 // copydir("/config2", "/config");
1033 copyfile("/config2/ip", "/config/ip");
1034 copydir("/config2/settings", "/config/settings");
1036 umount("/config2");
1040 mkdir(zylin_config_dir, 0777);
1041 char *dirname = alloc_printf("%s/target", zylin_config_dir);
1042 mkdir(dirname, 0777);
1043 free(dirname);
1044 dirname = alloc_printf("%s/board", zylin_config_dir);
1045 mkdir(dirname, 0777);
1046 free(dirname);
1047 dirname = alloc_printf("%s/event", zylin_config_dir);
1048 mkdir(dirname, 0777);
1049 free(dirname);
1051 logAllToSerial = boolParam("logserial");
1053 // We need the network & web server in case there is something wrong with
1054 // the config files that invoke exit()
1055 zylinjtag_startNetwork();
1057 /* we're going to access the jim interpreter from here on... */
1058 openocd_sleep_postlude();
1059 startUart();
1061 add_default_dirs();
1063 /* initialize commandline interface */
1064 struct command_context * cmd_ctx;
1065 struct command_context *setup_command_handler(Jim_Interp *interp);
1066 cmd_ctx = setup_command_handler(httpstate.jim_interp);
1067 command_set_output_handler(cmd_ctx, configuration_output_handler, NULL);
1068 command_context_mode(cmd_ctx, COMMAND_CONFIG);
1070 if (ioutil_init(cmd_ctx) != ERROR_OK)
1071 return EXIT_FAILURE;
1073 #ifdef CYGPKG_PROFILE_GPROF
1074 Jim_CreateCommand(httpstate.jim_interp, "zy1000_profile", zylinjtag_Jim_Command_profile,
1075 NULL, NULL);
1076 #endif
1078 Jim_CreateCommand(httpstate.jim_interp, "uart", zylinjtag_Jim_Command_uart, NULL, NULL);
1081 log_init();
1083 set_log_output(cmd_ctx, log);
1085 LOG_DEBUG("log init complete");
1087 // diag_printf("Executing config files\n");
1089 if (logAllToSerial)
1091 diag_printf(
1092 "%s/logserial = 1 => sending log output to serial port using \"debug_level 3\" as default.\n", zylin_config_dir);
1093 command_run_line(cmd_ctx, "debug_level 3");
1096 command_run_linef(cmd_ctx, "script /rom/openocd.cfg");
1098 int ret;
1099 ret = server_init(cmd_ctx);
1100 if (ERROR_OK != ret)
1101 return EXIT_FAILURE;
1103 /* we MUST always run the init command as it will launch telnet sessions */
1104 command_run_line(cmd_ctx, "init");
1106 // FIX!!! Yuk!
1107 // diag_printf() is really invoked from many more places than we trust it
1108 // not to cause instabilities(e.g. invoking fputc() from an interrupt is *BAD*).
1110 // Disabling it here is safe and gives us enough logged debug output for now. Crossing
1111 // fingers that it doesn't cause any crashes.
1112 diag_printf("Init complete, GDB & telnet servers launched.\n");
1113 command_set_output_handler(cmd_ctx,
1114 zy1000_configuration_output_handler_log, NULL);
1115 if (!logAllToSerial)
1117 serialLog = false;
1120 /* handle network connections */
1121 server_loop(cmd_ctx);
1122 openocd_sleep_prelude();
1124 /* shut server down */
1125 server_quit();
1127 /* free commandline interface */
1128 command_done(cmd_ctx);
1129 umount("/config");
1131 exit(0);
1132 for (;;)
1136 cyg_int32 cyg_httpd_exec_cgi_tcl(char *file_name);
1137 cyg_int32 homeForm(CYG_HTTPD_STATE *p)
1139 cyg_httpd_exec_cgi_tcl("/ram/cgi/index.tcl");
1140 return 0;
1143 CYG_HTTPD_HANDLER_TABLE_ENTRY(root_label, "/", homeForm);
1145 CYG_HTTPD_MIME_TABLE_ENTRY(text_mime_label, "text", "text/plain");
1146 CYG_HTTPD_MIME_TABLE_ENTRY(bin_mime_label, "bin", "application/octet-stream");
1148 #include <pkgconf/system.h>
1149 #include <pkgconf/hal.h>
1150 #include <pkgconf/kernel.h>
1151 #include <pkgconf/io_fileio.h>
1152 #include <pkgconf/fs_rom.h>
1154 #include <cyg/kernel/ktypes.h> // base kernel types
1155 #include <cyg/infra/cyg_trac.h> // tracing macros
1156 #include <cyg/infra/cyg_ass.h> // assertion macros
1157 #include <cyg/fileio/fileio.h>
1158 #include <cyg/kernel/kapi.h>
1159 #include <cyg/infra/diag.h>
1161 //==========================================================================
1162 // Eventually we want to eXecute In Place from the ROM in a protected
1163 // environment, so we'll need executables to be aligned to a boundary
1164 // suitable for MMU protection. A suitable boundary would be the 4k
1165 // boundary in all the CPU architectures I am currently aware of.
1167 // Forward definitions
1169 // Filesystem operations
1170 static int tftpfs_mount(cyg_fstab_entry *fste, cyg_mtab_entry *mte);
1171 static int tftpfs_umount(cyg_mtab_entry *mte);
1172 static int tftpfs_open(cyg_mtab_entry *mte, cyg_dir dir, const char *name,
1173 int mode, cyg_file *fte);
1174 static int tftpfs_fo_read(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio);
1175 static int tftpfs_fo_write(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio);
1177 // File operations
1178 static int tftpfs_fo_fsync(struct CYG_FILE_TAG *fp, int mode);
1179 static int tftpfs_fo_close(struct CYG_FILE_TAG *fp);
1180 static int tftpfs_fo_lseek(struct CYG_FILE_TAG *fp, off_t *apos, int whence);
1182 //==========================================================================
1183 // Filesystem table entries
1185 // -------------------------------------------------------------------------
1186 // Fstab entry.
1187 // This defines the entry in the filesystem table.
1188 // For simplicity we use _FILESYSTEM synchronization for all accesses since
1189 // we should never block in any filesystem operations.
1190 #if 1
1191 FSTAB_ENTRY(tftpfs_fste, "tftpfs", 0,
1192 CYG_SYNCMODE_NONE,
1193 tftpfs_mount,
1194 tftpfs_umount,
1195 tftpfs_open,
1196 (cyg_fsop_unlink *)cyg_fileio_erofs,
1197 (cyg_fsop_mkdir *)cyg_fileio_erofs,
1198 (cyg_fsop_rmdir *)cyg_fileio_erofs,
1199 (cyg_fsop_rename *)cyg_fileio_erofs,
1200 (cyg_fsop_link *)cyg_fileio_erofs,
1201 (cyg_fsop_opendir *)cyg_fileio_erofs,
1202 (cyg_fsop_chdir *)cyg_fileio_erofs,
1203 (cyg_fsop_stat *)cyg_fileio_erofs,
1204 (cyg_fsop_getinfo *)cyg_fileio_erofs,
1205 (cyg_fsop_setinfo *)cyg_fileio_erofs);
1206 #endif
1208 // -------------------------------------------------------------------------
1209 // mtab entry.
1210 // This defines a single ROMFS loaded into ROM at the configured address
1212 // MTAB_ENTRY(rom_mte, // structure name
1213 // "/rom", // mount point
1214 // "romfs", // FIlesystem type
1215 // "", // hardware device
1216 // (CYG_ADDRWORD) CYGNUM_FS_ROM_BASE_ADDRESS // Address in ROM
1217 //);
1220 // -------------------------------------------------------------------------
1221 // File operations.
1222 // This set of file operations are used for normal open files.
1224 static cyg_fileops tftpfs_fileops =
1225 { tftpfs_fo_read, tftpfs_fo_write, tftpfs_fo_lseek,
1226 (cyg_fileop_ioctl *) cyg_fileio_erofs, cyg_fileio_seltrue,
1227 tftpfs_fo_fsync, tftpfs_fo_close,
1228 (cyg_fileop_fstat *) cyg_fileio_erofs,
1229 (cyg_fileop_getinfo *) cyg_fileio_erofs,
1230 (cyg_fileop_setinfo *) cyg_fileio_erofs, };
1232 // -------------------------------------------------------------------------
1233 // tftpfs_mount()
1234 // Process a mount request. This mainly finds root for the
1235 // filesystem.
1237 static int tftpfs_mount(cyg_fstab_entry *fste, cyg_mtab_entry *mte)
1239 return ENOERR;
1242 static int tftpfs_umount(cyg_mtab_entry *mte)
1244 return ENOERR;
1247 struct Tftp
1249 int write;
1250 int readFile;
1251 cyg_uint8 *mem;
1252 int actual;
1253 char *server;
1254 char *file;
1257 static void freeTftp(struct Tftp *t)
1259 if (t == NULL)
1260 return;
1261 if (t->mem)
1262 free(t->mem);
1263 if (t->server)
1264 free(t->server);
1265 if (t->file)
1266 free(t->file);
1267 free(t);
1270 static const int tftpMaxSize = 8192 * 1024;
1271 static int tftpfs_open(cyg_mtab_entry *mte, cyg_dir dir, const char *name,
1272 int mode, cyg_file *file)
1274 struct Tftp *tftp;
1275 tftp = malloc(sizeof(struct Tftp));
1276 if (tftp == NULL)
1277 return EMFILE;
1278 memset(tftp, 0, sizeof(struct Tftp));
1280 file->f_flag |= mode & CYG_FILE_MODE_MASK;
1281 file->f_type = CYG_FILE_TYPE_FILE;
1282 file->f_ops = &tftpfs_fileops;
1283 file->f_offset = 0;
1284 file->f_data = 0;
1285 file->f_xops = 0;
1287 tftp->mem = malloc(tftpMaxSize);
1288 if (tftp->mem == NULL)
1290 freeTftp(tftp);
1291 return EMFILE;
1294 char *server = strchr(name, '/');
1295 if (server == NULL)
1297 freeTftp(tftp);
1298 return EMFILE;
1301 tftp->server = malloc(server - name + 1);
1302 if (tftp->server == NULL)
1304 freeTftp(tftp);
1305 return EMFILE;
1307 strncpy(tftp->server, name, server - name);
1308 tftp->server[server - name] = 0;
1310 tftp->file = strdup(server + 1);
1311 if (tftp->file == NULL)
1313 freeTftp(tftp);
1314 return EMFILE;
1317 file->f_data = (CYG_ADDRWORD) tftp;
1319 return ENOERR;
1322 static int fetchTftp(struct Tftp *tftp)
1324 if (!tftp->readFile)
1326 int err;
1327 tftp->actual = tftp_client_get(tftp->file, tftp->server, 0, tftp->mem,
1328 tftpMaxSize, TFTP_OCTET, &err);
1330 if (tftp->actual < 0)
1332 return EMFILE;
1334 tftp->readFile = 1;
1336 return ENOERR;
1339 // -------------------------------------------------------------------------
1340 // tftpfs_fo_write()
1341 // Read data from file.
1343 static int tftpfs_fo_read(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio)
1345 struct Tftp *tftp = (struct Tftp *) fp->f_data;
1347 if (fetchTftp(tftp) != ENOERR)
1348 return EMFILE;
1350 int i;
1351 off_t pos = fp->f_offset;
1352 int resid = 0;
1353 for (i = 0; i < uio->uio_iovcnt; i++)
1355 cyg_iovec *iov = &uio->uio_iov[i];
1356 char *buf = (char *) iov->iov_base;
1357 off_t len = iov->iov_len;
1359 if (len + pos > tftp->actual)
1361 len = tftp->actual - pos;
1363 resid += iov->iov_len - len;
1365 memcpy(buf, tftp->mem + pos, len);
1366 pos += len;
1369 uio->uio_resid = resid;
1370 fp->f_offset = pos;
1372 return ENOERR;
1375 static int tftpfs_fo_write(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio)
1377 struct Tftp *tftp = (struct Tftp *) fp->f_data;
1379 int i;
1380 off_t pos = fp->f_offset;
1381 int resid = 0;
1382 for (i = 0; i < uio->uio_iovcnt; i++)
1384 cyg_iovec *iov = &uio->uio_iov[i];
1385 char *buf = (char *) iov->iov_base;
1386 off_t len = iov->iov_len;
1388 if (len + pos > tftpMaxSize)
1390 len = tftpMaxSize - pos;
1392 resid += iov->iov_len - len;
1394 memcpy(tftp->mem + pos, buf, len);
1395 pos += len;
1398 uio->uio_resid = resid;
1399 fp->f_offset = pos;
1401 tftp->write = 1;
1403 return ENOERR;
1406 static int tftpfs_fo_fsync(struct CYG_FILE_TAG *fp, int mode)
1408 int error = ENOERR;
1409 return error;
1412 // -------------------------------------------------------------------------
1413 // romfs_fo_close()
1414 // Close a file. We just clear out the data pointer.
1416 static int tftpfs_fo_close(struct CYG_FILE_TAG *fp)
1418 struct Tftp *tftp = (struct Tftp *) fp->f_data;
1419 int error = ENOERR;
1421 if (tftp->write)
1423 tftp_client_put(tftp->file, tftp->server, 0, tftp->mem, fp->f_offset,
1424 TFTP_OCTET, &error);
1427 freeTftp(tftp);
1428 fp->f_data = 0;
1429 return error;
1432 // -------------------------------------------------------------------------
1433 // romfs_fo_lseek()
1434 // Seek to a new file position.
1436 static int tftpfs_fo_lseek(struct CYG_FILE_TAG *fp, off_t *apos, int whence)
1438 struct Tftp *tftp = (struct Tftp *) fp->f_data;
1439 off_t pos = *apos;
1441 if (fetchTftp(tftp) != ENOERR)
1442 return EMFILE;
1444 switch (whence)
1446 case SEEK_SET:
1447 // Pos is already where we want to be.
1448 break;
1450 case SEEK_CUR:
1451 // Add pos to current offset.
1452 pos += fp->f_offset;
1453 break;
1455 case SEEK_END:
1456 // Add pos to file size.
1457 pos += tftp->actual;
1458 break;
1460 default:
1461 return EINVAL;
1464 // Check that pos is still within current file size, or at the
1465 // very end.
1466 if (pos < 0 || pos > tftp->actual)
1467 return EINVAL;
1469 // All OK, set fp offset and return new position.
1470 *apos = fp->f_offset = pos;
1472 return ENOERR;
1475 void usleep(int us)
1477 if (us > 10000)
1478 cyg_thread_delay(us / 10000 + 1);
1479 else
1480 HAL_DELAY_US(us);
1483 // Chunked version.
1484 cyg_int32 show_log_entry(CYG_HTTPD_STATE *phttpstate)
1486 cyg_httpd_start_chunked("text");
1487 if (logCount >= logSize)
1489 cyg_httpd_write_chunked(logBuffer + logCount % logSize, logSize
1490 - logCount % logSize);
1492 cyg_httpd_write_chunked(logBuffer, writePtr);
1493 cyg_httpd_end_chunked();
1494 return -1;
1497 CYG_HTTPD_HANDLER_TABLE_ENTRY(show_log, "/ram/log", show_log_entry);
1499 // Filesystem operations
1500 static int logfs_mount(cyg_fstab_entry *fste, cyg_mtab_entry *mte);
1501 static int logfs_umount(cyg_mtab_entry *mte);
1502 static int logfs_open(cyg_mtab_entry *mte, cyg_dir dir, const char *name,
1503 int mode, cyg_file *fte);
1504 static int logfs_fo_write(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio);
1506 // File operations
1507 static int logfs_fo_fsync(struct CYG_FILE_TAG *fp, int mode);
1508 static int logfs_fo_close(struct CYG_FILE_TAG *fp);
1510 #include <cyg/io/devtab.h>
1512 //==========================================================================
1513 // Filesystem table entries
1515 // -------------------------------------------------------------------------
1516 // Fstab entry.
1517 // This defines the entry in the filesystem table.
1518 // For simplicity we use _FILESYSTEM synchronization for all accesses since
1519 // we should never block in any filesystem operations.
1520 FSTAB_ENTRY(logfs_fste, "logfs", 0,
1521 CYG_SYNCMODE_FILE_FILESYSTEM | CYG_SYNCMODE_IO_FILESYSTEM,
1522 logfs_mount,
1523 logfs_umount,
1524 logfs_open,
1525 (cyg_fsop_unlink *)cyg_fileio_erofs,
1526 (cyg_fsop_mkdir *)cyg_fileio_erofs,
1527 (cyg_fsop_rmdir *)cyg_fileio_erofs,
1528 (cyg_fsop_rename *)cyg_fileio_erofs,
1529 (cyg_fsop_link *)cyg_fileio_erofs,
1530 (cyg_fsop_opendir *)cyg_fileio_erofs,
1531 (cyg_fsop_chdir *)cyg_fileio_erofs,
1532 (cyg_fsop_stat *)cyg_fileio_erofs,
1533 (cyg_fsop_getinfo *)cyg_fileio_erofs,
1534 (cyg_fsop_setinfo *)cyg_fileio_erofs);
1536 // -------------------------------------------------------------------------
1537 // File operations.
1538 // This set of file operations are used for normal open files.
1540 static cyg_fileops logfs_fileops =
1541 { (cyg_fileop_read *) cyg_fileio_erofs, (cyg_fileop_write *) logfs_fo_write,
1542 (cyg_fileop_lseek *) cyg_fileio_erofs,
1543 (cyg_fileop_ioctl *) cyg_fileio_erofs, cyg_fileio_seltrue,
1544 logfs_fo_fsync, logfs_fo_close, (cyg_fileop_fstat *) cyg_fileio_erofs,
1545 (cyg_fileop_getinfo *) cyg_fileio_erofs,
1546 (cyg_fileop_setinfo *) cyg_fileio_erofs, };
1548 // -------------------------------------------------------------------------
1549 // logfs_mount()
1550 // Process a mount request. This mainly finds root for the
1551 // filesystem.
1553 static int logfs_mount(cyg_fstab_entry *fste, cyg_mtab_entry *mte)
1555 return ENOERR;
1558 static int logfs_umount(cyg_mtab_entry *mte)
1560 return ENOERR;
1563 static int logfs_open(cyg_mtab_entry *mte, cyg_dir dir, const char *name,
1564 int mode, cyg_file *file)
1566 file->f_flag |= mode & CYG_FILE_MODE_MASK;
1567 file->f_type = CYG_FILE_TYPE_FILE;
1568 file->f_ops = &logfs_fileops;
1569 file->f_offset = 0;
1570 file->f_data = 0;
1571 file->f_xops = 0;
1572 return ENOERR;
1575 // -------------------------------------------------------------------------
1576 // logfs_fo_write()
1577 // Write data to file.
1579 static int logfs_fo_write(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio)
1581 int i;
1582 for (i = 0; i < uio->uio_iovcnt; i++)
1584 cyg_iovec *iov = &uio->uio_iov[i];
1585 char *buf = (char *) iov->iov_base;
1586 off_t len = iov->iov_len;
1588 diag_write(buf, len);
1590 uio->uio_resid = 0;
1592 return ENOERR;
1594 static int logfs_fo_fsync(struct CYG_FILE_TAG *fp, int mode)
1596 return ENOERR;
1599 // -------------------------------------------------------------------------
1600 // romfs_fo_close()
1601 // Close a file. We just clear out the data pointer.
1603 static int logfs_fo_close(struct CYG_FILE_TAG *fp)
1605 return ENOERR;
1608 int loadFile(const char *fileName, void **data, int *len);
1610 /* boolean parameter stored on config */
1611 int boolParam(char *var)
1613 bool result = false;
1614 char *name = alloc_printf("%s/%s", zylin_config_dir, var);
1615 if (name == NULL)
1616 return result;
1618 void *data;
1619 int len;
1620 if (loadFile(name, &data, &len) == ERROR_OK)
1622 if (len > 1)
1623 len = 1;
1624 result = strncmp((char *) data, "1", len) == 0;
1625 free(data);
1627 free(name);
1628 return result;