Newer
Older
#ifdef CYGPKG_PROFILE_GPROF
register_command(cmd_ctx, NULL, "ecosboard_profile", eCosBoard_handle_eCosBoard_profile_command,
COMMAND_ANY, NULL);
#endif

oharboe
committed
register_command(cmd_ctx, NULL, "uart", handle_uart_command, COMMAND_ANY,
"uart <baud> - forward uart on port 5555");
int errVal;
errVal = log_init(cmd_ctx);
if (errVal != ERROR_OK)
{
diag_printf("log_init() failed %d\n", errVal);
exit(-1);
}
set_log_output(cmd_ctx, log);
LOG_DEBUG("log init complete");
// diag_printf("Executing config files\n");
if (logAllToSerial)
{

oharboe
committed
diag_printf(
"%s/logserial=1 => sending log output to serial port using \"debug_level 3\" as default.\n", zylin_config_dir);
command_run_line(cmd_ctx, "debug_level 3");
}

oharboe
committed
command_run_linef(cmd_ctx, "script /rom/openocd.cfg");
// FIX!!! Yuk!
// diag_printf() is really invoked from many more places than we trust it
// not to cause instabilities(e.g. invoking fputc() from an interrupt is *BAD*).
//
// Disabling it here is safe and gives us enough logged debug output for now. Crossing
// fingers that it doesn't cause any crashes.
diag_printf("Init complete, GDB & telnet servers launched.\n");

oharboe
committed
command_set_output_handler(cmd_ctx,
zy1000_configuration_output_handler_log, NULL);
if (!logAllToSerial)
{
serialLog = false;
}
/* handle network connections */
server_loop(cmd_ctx);
openocd_sleep_prelude();
/* shut server down */
server_quit();
/* free commandline interface */
command_done(cmd_ctx);
umount("/config");
exit(0);

oharboe
committed
for (;;)
;

oharboe
committed
cyg_int32 cyg_httpd_exec_cgi_tcl(char *file_name);
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
cyg_int32 homeForm(CYG_HTTPD_STATE *p)
{
cyg_httpd_exec_cgi_tcl("/ram/cgi/index.tcl");
return 0;
}
CYG_HTTPD_HANDLER_TABLE_ENTRY(root_label, "/", homeForm);
CYG_HTTPD_MIME_TABLE_ENTRY(text_mime_label, "text", "text/plain");
CYG_HTTPD_MIME_TABLE_ENTRY(bin_mime_label, "bin", "application/octet-stream");
#include <pkgconf/system.h>
#include <pkgconf/hal.h>
#include <pkgconf/kernel.h>
#include <pkgconf/io_fileio.h>
#include <pkgconf/fs_rom.h>
#include <cyg/kernel/ktypes.h> // base kernel types
#include <cyg/infra/cyg_trac.h> // tracing macros
#include <cyg/infra/cyg_ass.h> // assertion macros
#include <cyg/fileio/fileio.h>
#include <cyg/kernel/kapi.h>
#include <cyg/infra/diag.h>
//==========================================================================
// Eventually we want to eXecute In Place from the ROM in a protected
// environment, so we'll need executables to be aligned to a boundary
// suitable for MMU protection. A suitable boundary would be the 4k
// boundary in all the CPU architectures I am currently aware of.
// Forward definitions
// Filesystem operations
static int tftpfs_mount(cyg_fstab_entry *fste, cyg_mtab_entry *mte);
static int tftpfs_umount(cyg_mtab_entry *mte);
static int tftpfs_open(cyg_mtab_entry *mte, cyg_dir dir, const char *name,
int mode, cyg_file *fte);
static int tftpfs_fo_read(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio);
static int tftpfs_fo_write(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio);
// File operations
static int tftpfs_fo_fsync(struct CYG_FILE_TAG *fp, int mode);
static int tftpfs_fo_close(struct CYG_FILE_TAG *fp);
static int tftpfs_fo_lseek(struct CYG_FILE_TAG *fp, off_t *apos, int whence);
//==========================================================================
// Filesystem table entries
// -------------------------------------------------------------------------
// Fstab entry.
// This defines the entry in the filesystem table.
// For simplicity we use _FILESYSTEM synchronization for all accesses since
// we should never block in any filesystem operations.
#if 1
FSTAB_ENTRY( tftpfs_fste, "tftpfs", 0,
CYG_SYNCMODE_NONE,
tftpfs_mount,
tftpfs_umount,
tftpfs_open,
(cyg_fsop_unlink *)cyg_fileio_erofs,
(cyg_fsop_mkdir *)cyg_fileio_erofs,
(cyg_fsop_rmdir *)cyg_fileio_erofs,
(cyg_fsop_rename *)cyg_fileio_erofs,
(cyg_fsop_link *)cyg_fileio_erofs,
(cyg_fsop_opendir *)cyg_fileio_erofs,
(cyg_fsop_chdir *)cyg_fileio_erofs,
(cyg_fsop_stat *)cyg_fileio_erofs,
(cyg_fsop_getinfo *)cyg_fileio_erofs,
(cyg_fsop_setinfo *)cyg_fileio_erofs);
#endif
// -------------------------------------------------------------------------
// mtab entry.
// This defines a single ROMFS loaded into ROM at the configured address
//
// MTAB_ENTRY( rom_mte, // structure name
// "/rom", // mount point
// "romfs", // FIlesystem type
// "", // hardware device
// (CYG_ADDRWORD) CYGNUM_FS_ROM_BASE_ADDRESS // Address in ROM
// );
// -------------------------------------------------------------------------
// File operations.
// This set of file operations are used for normal open files.
static cyg_fileops tftpfs_fileops =

oharboe
committed
{ tftpfs_fo_read, tftpfs_fo_write, tftpfs_fo_lseek,
(cyg_fileop_ioctl *) cyg_fileio_erofs, cyg_fileio_seltrue,
tftpfs_fo_fsync, tftpfs_fo_close,
(cyg_fileop_fstat *) cyg_fileio_erofs,
(cyg_fileop_getinfo *) cyg_fileio_erofs,

oharboe
committed
(cyg_fileop_setinfo *) cyg_fileio_erofs, };
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
// -------------------------------------------------------------------------
// tftpfs_mount()
// Process a mount request. This mainly finds root for the
// filesystem.
static int tftpfs_mount(cyg_fstab_entry *fste, cyg_mtab_entry *mte)
{
return ENOERR;
}
static int tftpfs_umount(cyg_mtab_entry *mte)
{
return ENOERR;
}
struct Tftp
{
int write;
int readFile;
cyg_uint8 *mem;
int actual;
char *server;
char *file;
};
static void freeTftp(struct Tftp *t)
{
if (t == NULL)
return;
if (t->mem)
free(t->mem);
if (t->server)
free(t->server);
if (t->file)
free(t->file);
free(t);
}
static const int tftpMaxSize = 8192 * 1024;
static int tftpfs_open(cyg_mtab_entry *mte, cyg_dir dir, const char *name,
int mode, cyg_file *file)
{
struct Tftp *tftp;
tftp = malloc(sizeof(struct Tftp));
if (tftp == NULL)
return EMFILE;
memset(tftp, 0, sizeof(struct Tftp));
file->f_flag |= mode & CYG_FILE_MODE_MASK;
file->f_type = CYG_FILE_TYPE_FILE;
file->f_ops = &tftpfs_fileops;
file->f_offset = 0;
file->f_data = 0;
file->f_xops = 0;
tftp->mem = malloc(tftpMaxSize);
if (tftp->mem == NULL)
{
freeTftp(tftp);
return EMFILE;
}
char *server = strchr(name, '/');
if (server == NULL)
{
freeTftp(tftp);
return EMFILE;
}
tftp->server = malloc(server - name + 1);
if (tftp->server == NULL)
{
freeTftp(tftp);
return EMFILE;
}
strncpy(tftp->server, name, server - name);
tftp->server[server - name] = 0;
tftp->file = strdup(server + 1);
if (tftp->file == NULL)
{
freeTftp(tftp);
return EMFILE;
}
file->f_data = (CYG_ADDRWORD) tftp;
return ENOERR;
}
static int fetchTftp(struct Tftp *tftp)
{
if (!tftp->readFile)
{
int err;

oharboe
committed
tftp->actual = tftp_client_get(tftp->file, tftp->server, 0, tftp->mem,
tftpMaxSize, TFTP_OCTET, &err);
if (tftp->actual < 0)
{
return EMFILE;
}
tftp->readFile = 1;
}
return ENOERR;
}
// -------------------------------------------------------------------------
// tftpfs_fo_write()
// Read data from file.

oharboe
committed
static int tftpfs_fo_read(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio)
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
{
struct Tftp *tftp = (struct Tftp *) fp->f_data;
if (fetchTftp(tftp) != ENOERR)
return EMFILE;
int i;
off_t pos = fp->f_offset;
int resid = 0;
for (i = 0; i < uio->uio_iovcnt; i++)
{
cyg_iovec *iov = &uio->uio_iov[i];
char *buf = (char *) iov->iov_base;
off_t len = iov->iov_len;
if (len + pos > tftp->actual)
{
len = tftp->actual - pos;
}
resid += iov->iov_len - len;
memcpy(buf, tftp->mem + pos, len);
pos += len;
}
uio->uio_resid = resid;
fp->f_offset = pos;
return ENOERR;
}

oharboe
committed
static int tftpfs_fo_write(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio)
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
{
struct Tftp *tftp = (struct Tftp *) fp->f_data;
int i;
off_t pos = fp->f_offset;
int resid = 0;
for (i = 0; i < uio->uio_iovcnt; i++)
{
cyg_iovec *iov = &uio->uio_iov[i];
char *buf = (char *) iov->iov_base;
off_t len = iov->iov_len;
if (len + pos > tftpMaxSize)
{
len = tftpMaxSize - pos;
}
resid += iov->iov_len - len;
memcpy(tftp->mem + pos, buf, len);
pos += len;
}
uio->uio_resid = resid;
fp->f_offset = pos;
tftp->write = 1;
return ENOERR;
}

oharboe
committed
static int tftpfs_fo_fsync(struct CYG_FILE_TAG *fp, int mode)
{
int error = ENOERR;
return error;
}
// -------------------------------------------------------------------------
// romfs_fo_close()
// Close a file. We just clear out the data pointer.
static int tftpfs_fo_close(struct CYG_FILE_TAG *fp)
{
struct Tftp *tftp = (struct Tftp *) fp->f_data;
int error = ENOERR;
if (tftp->write)
{

oharboe
committed
tftp_client_put(tftp->file, tftp->server, 0, tftp->mem, fp->f_offset,
TFTP_OCTET, &error);
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
}
freeTftp(tftp);
fp->f_data = 0;
return error;
}
// -------------------------------------------------------------------------
// romfs_fo_lseek()
// Seek to a new file position.
static int tftpfs_fo_lseek(struct CYG_FILE_TAG *fp, off_t *apos, int whence)
{
struct Tftp *tftp = (struct Tftp *) fp->f_data;
off_t pos = *apos;
if (fetchTftp(tftp) != ENOERR)
return EMFILE;
switch (whence)
{
case SEEK_SET:
// Pos is already where we want to be.
break;
case SEEK_CUR:
// Add pos to current offset.
pos += fp->f_offset;
break;
case SEEK_END:
// Add pos to file size.
pos += tftp->actual;
break;
default:
return EINVAL;
}
// Check that pos is still within current file size, or at the
// very end.
if (pos < 0 || pos > tftp->actual)
return EINVAL;
// All OK, set fp offset and return new position.
*apos = fp->f_offset = pos;
return ENOERR;
}
void usleep(int us)
{
if (us > 10000)
cyg_thread_delay(us / 10000 + 1);
else
HAL_DELAY_US(us);
}
// Chunked version.

oharboe
committed
cyg_int32 show_log_entry(CYG_HTTPD_STATE *phttpstate)
{
cyg_httpd_start_chunked("text");
if (logCount >= logSize)
{

oharboe
committed
cyg_httpd_write_chunked(logBuffer + logCount % logSize, logSize
- logCount % logSize);
}
cyg_httpd_write_chunked(logBuffer, writePtr);
cyg_httpd_end_chunked();
return -1;
}
CYG_HTTPD_HANDLER_TABLE_ENTRY(show_log, "/ram/log", show_log_entry);
// Filesystem operations
static int logfs_mount(cyg_fstab_entry *fste, cyg_mtab_entry *mte);
static int logfs_umount(cyg_mtab_entry *mte);
static int logfs_open(cyg_mtab_entry *mte, cyg_dir dir, const char *name,
int mode, cyg_file *fte);

oharboe
committed
static int logfs_fo_write(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio);
// File operations
static int logfs_fo_fsync(struct CYG_FILE_TAG *fp, int mode);
static int logfs_fo_close(struct CYG_FILE_TAG *fp);
#include <cyg/io/devtab.h>
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
//==========================================================================
// Filesystem table entries
// -------------------------------------------------------------------------
// Fstab entry.
// This defines the entry in the filesystem table.
// For simplicity we use _FILESYSTEM synchronization for all accesses since
// we should never block in any filesystem operations.
FSTAB_ENTRY( logfs_fste, "logfs", 0,
CYG_SYNCMODE_FILE_FILESYSTEM|CYG_SYNCMODE_IO_FILESYSTEM,
logfs_mount,
logfs_umount,
logfs_open,
(cyg_fsop_unlink *)cyg_fileio_erofs,
(cyg_fsop_mkdir *)cyg_fileio_erofs,
(cyg_fsop_rmdir *)cyg_fileio_erofs,
(cyg_fsop_rename *)cyg_fileio_erofs,
(cyg_fsop_link *)cyg_fileio_erofs,
(cyg_fsop_opendir *)cyg_fileio_erofs,
(cyg_fsop_chdir *)cyg_fileio_erofs,
(cyg_fsop_stat *)cyg_fileio_erofs,
(cyg_fsop_getinfo *)cyg_fileio_erofs,
(cyg_fsop_setinfo *)cyg_fileio_erofs);
// -------------------------------------------------------------------------
// File operations.
// This set of file operations are used for normal open files.
static cyg_fileops logfs_fileops =

oharboe
committed
{ (cyg_fileop_read *) cyg_fileio_erofs, (cyg_fileop_write *) logfs_fo_write,
(cyg_fileop_lseek *) cyg_fileio_erofs,

oharboe
committed
(cyg_fileop_ioctl *) cyg_fileio_erofs, cyg_fileio_seltrue,
logfs_fo_fsync, logfs_fo_close, (cyg_fileop_fstat *) cyg_fileio_erofs,
(cyg_fileop_getinfo *) cyg_fileio_erofs,

oharboe
committed
(cyg_fileop_setinfo *) cyg_fileio_erofs, };
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
// -------------------------------------------------------------------------
// logfs_mount()
// Process a mount request. This mainly finds root for the
// filesystem.
static int logfs_mount(cyg_fstab_entry *fste, cyg_mtab_entry *mte)
{
return ENOERR;
}
static int logfs_umount(cyg_mtab_entry *mte)
{
return ENOERR;
}
static int logfs_open(cyg_mtab_entry *mte, cyg_dir dir, const char *name,
int mode, cyg_file *file)
{
file->f_flag |= mode & CYG_FILE_MODE_MASK;
file->f_type = CYG_FILE_TYPE_FILE;
file->f_ops = &logfs_fileops;
file->f_offset = 0;
file->f_data = 0;
file->f_xops = 0;
return ENOERR;
}
// -------------------------------------------------------------------------
// logfs_fo_write()
// Write data to file.

oharboe
committed
static int logfs_fo_write(struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio)
{
int i;
for (i = 0; i < uio->uio_iovcnt; i++)
{
cyg_iovec *iov = &uio->uio_iov[i];
char *buf = (char *) iov->iov_base;
off_t len = iov->iov_len;
diag_write(buf, len);
}
uio->uio_resid = 0;
return ENOERR;
}

oharboe
committed
static int logfs_fo_fsync(struct CYG_FILE_TAG *fp, int mode)
{
return ENOERR;
}
// -------------------------------------------------------------------------
// romfs_fo_close()
// Close a file. We just clear out the data pointer.
static int logfs_fo_close(struct CYG_FILE_TAG *fp)
{
return ENOERR;
}