This is the mail archive of the
ecos-patches@sourceware.org
mailing list for the eCos project.
FlashV2 conflict
- From: Gary Thomas <gary at mlbassoc dot com>
- To: eCos patches <ecos-patches at ecos dot sourceware dot org>
- Date: Fri, 06 Apr 2007 09:17:46 -0600
- Subject: FlashV2 conflict
There are some things in RedBoot (fs/fileio.c) which aren't
quite right when built using the trunk. In particular, there
is use of CYGPKG_IO_FLASH_BLOCK_DEVICE_LEGACY which seems to
be only on the FLASHv2 branch.
What's the best way to fix this? The attached patches make
file I/O to JFFS2 work on the trunk again for me.
--
------------------------------------------------------------
Gary Thomas | Consulting for the
MLB Associates | Embedded world
------------------------------------------------------------
Index: redboot/current/src/fs/fileio.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/fs/fileio.c,v
retrieving revision 1.7
diff -u -5 -p -r1.7 fileio.c
--- redboot/current/src/fs/fileio.c 20 Jul 2006 20:27:47 -0000 1.7
+++ redboot/current/src/fs/fileio.c 6 Apr 2007 15:10:18 -0000
@@ -73,12 +73,12 @@
#include <cyg/infra/cyg_ass.h> // assertion macros
//==========================================================================
// Define table boundaries
-CYG_HAL_TABLE_BEGIN( __FS_cmds_TAB__, FS_cmds);
-CYG_HAL_TABLE_END( __FS_cmds_TAB_END__, FS_cmds);
+CYG_HAL_TABLE_BEGIN(__FS_cmds_TAB__, FS_cmds);
+CYG_HAL_TABLE_END(__FS_cmds_TAB_END__, FS_cmds);
extern struct cmd __FS_cmds_TAB__[], __FS_cmds_TAB_END__;
//==========================================================================
@@ -106,11 +106,11 @@ static struct
//==========================================================================
static void do_mount(int argc, char *argv[]);
static void do_umount(int argc, char *argv[]);
-#ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE_LEGACY
+#ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE
#define FLASHPART "[-f <partition>] "
#else
#define FLASHPART
#endif
@@ -136,20 +136,20 @@ do_mount(int argc, char *argv[])
char *dev_str = "<undefined>", *type_str, *mp_str;
bool dev_set = false, type_set = false;
struct option_info opts[3];
int err, num_opts = 2;
int i,m=0; /* Set to 0 to silence warning */
-#ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE_LEGACY
+#ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE
char *part_str;
bool part_set = false;
#endif
init_opts(&opts[0], 'd', true, OPTION_ARG_TYPE_STR,
(void *)&dev_str, &dev_set, "device");
init_opts(&opts[1], 't', true, OPTION_ARG_TYPE_STR,
(void *)&type_str, &type_set, "fstype");
-#ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE_LEGACY
+#ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE
init_opts(&opts[2], 'f', true, OPTION_ARG_TYPE_STR,
(void *)&part_str, &part_set, "partition");
num_opts++;
#endif
@@ -161,20 +161,19 @@ do_mount(int argc, char *argv[])
if (!type_set) {
err_printf("fs mount: Must specify file system type\n");
return;
}
- if( mp_str == 0 )
+ if (mp_str == 0)
mp_str = "/";
- if( mount_count >= MAX_MOUNTS )
- {
+ if (mount_count >= MAX_MOUNTS) {
err_printf("fs mount: Maximum number of mounts exceeded\n");
return;
}
-#ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE_LEGACY
+#ifdef CYGPKG_IO_FLASH_BLOCK_DEVICE
if (part_set) {
int len;
cyg_io_handle_t h;
if (dev_set && strcmp(dev_str, CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1)) {
@@ -185,52 +184,46 @@ do_mount(int argc, char *argv[])
dev_str = CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1;
len = strlen(part_str);
err = cyg_io_lookup(dev_str, &h);
if (err < 0) {
- err_printf("fs mount: cyg_io_lookup of \"%s\" returned %d\n", err);
+ err_printf("fs mount: cyg_io_lookup of \"%s\" returned %d\n", dev_str, err);
return;
}
err = cyg_io_set_config(h, CYG_IO_SET_CONFIG_FLASH_FIS_NAME,
- part_str, &len);
+ part_str, (cyg_uint32 *)&len);
if (err < 0) {
diag_printf("fs mount: FIS partition \"%s\" not found\n",
part_str);
return;
}
}
#endif
- for( i = 0; i < MAX_MOUNTS; i++ )
- {
- if( mounts[i].mp_str[0] != '\0' )
- {
- if( strcmp(mounts[i].dev_str, dev_str ) == 0 )
- {
+ for (i = 0; i < MAX_MOUNTS; i++) {
+ if (mounts[i].mp_str[0] != '\0') {
+ if (strcmp(mounts[i].dev_str, dev_str) == 0) {
err_printf("fs mount: Device %s already mounted\n",dev_str);
return;
}
}
else
m = i;
}
- strcpy( mounts[m].mp_str, mp_str );
- strcpy( mounts[m].dev_str, dev_str );
- strcpy( mounts[m].type_str, type_str );
+ strcpy(mounts[m].mp_str, mp_str);
+ strcpy(mounts[m].dev_str, dev_str);
+ strcpy(mounts[m].type_str, type_str);
err = mount(mounts[m].dev_str, mounts[m].mp_str, mounts[m].type_str);
- if (err)
- {
+ if (err) {
err_printf("fs mount: mount(%s,%s,%s) failed %d\n", dev_str, mp_str, type_str, errno);
mounts[m].mp_str[0] = '\0'; // mount failed so don't let it appear mounted
- }
- else
- {
- if( mount_count == 0 )
- chdir( "/" );
+ } else {
+ if (mount_count == 0)
+ chdir("/");
mount_count++;
}
}
//==========================================================================
@@ -240,44 +233,40 @@ do_umount(int argc, char *argv[])
{
char *dir_str;
int err;
int i;
- if( mount_count == 0 )
- {
+ if (mount_count == 0) {
err_printf("fs: No filesystems mounted\n");
return;
- }
+ }
if (!scan_opts(argc, argv, 1, NULL, 0, &dir_str, OPTION_ARG_TYPE_STR, "mountpoint"))
return;
- if( dir_str == 0 )
+ if (dir_str == 0)
dir_str = "/";
- for( i = 0; i < MAX_MOUNTS; i++ )
- {
- if( strcmp(mounts[i].mp_str, dir_str ) == 0 )
+ for (i = 0; i < MAX_MOUNTS; i++) {
+ if (strcmp(mounts[i].mp_str, dir_str) == 0)
break;
}
- if( i == MAX_MOUNTS )
- {
+ if (i == MAX_MOUNTS) {
err_printf("fs unmount: unknown mountpoint %s\n",dir_str);
return;
}
- err = umount (dir_str);
+ err = umount(dir_str);
if (err)
err_printf("fs umount: unmount failed %d\n", errno);
- else
- {
+ else {
mounts[i].mp_str[0] = '\0';
mount_count--;
- if( mount_count == 0 )
- chdir( "/" );
+ if (mount_count == 0)
+ chdir("/");
}
}
//==========================================================================
@@ -294,34 +283,32 @@ do_list(int argc, char * argv[])
char filename[PATH_MAX];
char cwd[PATH_MAX];
struct stat sbuf;
int err;
- if( mount_count == 0 )
- {
+ if (mount_count == 0) {
err_printf("fs: No filesystems mounted\n");
return;
}
if (!scan_opts(argc, argv, 1, NULL, 0, &dir_str, OPTION_ARG_TYPE_STR, "directory"))
return;
- if( dir_str == 0 )
- {
+ if (dir_str == 0) {
dir_str = getcwd(cwd, sizeof(cwd));
}
dirp = opendir(dir_str);
- if (dirp==NULL) {
+ if (dirp == NULL) {
err_printf("fs list: no such directory %s\n",dir_str);
return;
}
for (;;) {
struct dirent *entry = readdir(dirp);
- if( entry == NULL )
+ if (entry == NULL)
break;
strcpy(filename, dir_str);
strcat(filename, "/");
strcat(filename, entry->d_name);
@@ -340,11 +327,11 @@ do_list(int argc, char * argv[])
diag_printf("%s%s%s", // Ho, humm, have to hard code the shifts
rwx[(sbuf.st_mode & S_IRWXU) >> 16],
rwx[(sbuf.st_mode & S_IRWXG) >> 19],
rwx[(sbuf.st_mode & S_IRWXO) >> 22]);
diag_printf(" %2d size %6d %s\n",
- sbuf.st_nlink,sbuf.st_size,
+ sbuf.st_nlink, (int)sbuf.st_size,
entry->d_name);
}
closedir(dirp);
return;
@@ -365,26 +352,24 @@ static void
do_mkdir(int argc, char * argv[])
{
char *dir_str;
int err;
- if( mount_count == 0 )
- {
- err_printf("fs: No filesystems mounted\n");
- return;
- }
+ if (mount_count == 0) {
+ err_printf("fs: No filesystems mounted\n");
+ return;
+ }
if (!scan_opts(argc, argv, 1, NULL, 0, &dir_str, OPTION_ARG_TYPE_STR, "directory") ||
- dir_str == NULL)
- {
+ dir_str == NULL) {
fs_usage("invalid arguments");
return;
}
- err = mkdir( dir_str, 0 );
+ err = mkdir(dir_str, 0);
- if( err != 0 )
+ if (err != 0)
err_printf("fs mkdir: failed to create directory %s\n",dir_str);
}
local_cmd_entry("mkdir",
"create directory",
@@ -399,26 +384,24 @@ static void
do_deldir(int argc, char * argv[])
{
char *dir_str;
int err;
- if( mount_count == 0 )
- {
- err_printf("fs: No filesystems mounted\n");
- return;
- }
+ if (mount_count == 0) {
+ err_printf("fs: No filesystems mounted\n");
+ return;
+ }
if (!scan_opts(argc, argv, 1, NULL, 0, &dir_str, OPTION_ARG_TYPE_STR, "directory") ||
- dir_str == NULL)
- {
+ dir_str == NULL) {
fs_usage("invalid arguments");
return;
}
- err = rmdir( dir_str );
+ err = rmdir(dir_str);
- if( err != 0 )
+ if (err != 0)
err_printf("fs deldir: failed to remove directory %s\n",dir_str);
}
local_cmd_entry("deldir",
"delete directory",
@@ -433,26 +416,24 @@ static void
do_del(int argc, char * argv[])
{
char *name_str = NULL;
int err;
- if( mount_count == 0 )
- {
- err_printf("fs: No filesystems mounted\n");
- return;
- }
+ if (mount_count == 0) {
+ err_printf("fs: No filesystems mounted\n");
+ return;
+ }
if (!scan_opts(argc, argv, 1, NULL, 0, &name_str, OPTION_ARG_TYPE_STR, "file") ||
- name_str == NULL)
- {
+ name_str == NULL) {
fs_usage("invalid arguments");
return;
}
- err = unlink( name_str );
+ err = unlink(name_str);
- if( err != 0 )
+ if (err != 0)
err_printf("fs del: failed to delete file %s\n",name_str);
}
local_cmd_entry("del",
"delete file",
@@ -465,23 +446,23 @@ local_cmd_entry("del",
static void
do_move(int argc, char * argv[])
{
int err;
- __externC int rename( const char *oldname, const char *newname );
- if( mount_count == 0 )
- {
+ __externC int rename(const char *oldname, const char *newname);
+
+ if (mount_count == 0) {
err_printf("fs: No filesystems mounted\n");
return;
}
- if( argc != 3 )
+ if (argc != 3)
fs_usage("bad arguments to move command\n");
- err = rename( argv[1], argv[2] );
+ err = rename(argv[1], argv[2]);
- if( err != 0 )
+ if (err != 0)
err_printf("fs move: failed to move file %s to %s\n",argv[1],argv[2]);
}
local_cmd_entry("move",
"move file",
@@ -496,25 +477,24 @@ static void
do_cd(int argc, char * argv[])
{
char *dir_str;
int err;
- if( mount_count == 0 )
- {
- err_printf("fs: No filesystems mounted\n");
- return;
- }
+ if (mount_count == 0) {
+ err_printf("fs: No filesystems mounted\n");
+ return;
+ }
if (!scan_opts(argc, argv, 1, NULL, 0, &dir_str, OPTION_ARG_TYPE_STR, "directory"))
return;
- if( dir_str == NULL )
+ if (dir_str == NULL)
dir_str = "/";
- err = chdir( dir_str );
+ err = chdir(dir_str);
- if( err != 0 )
+ if (err != 0)
err_printf("fs cd: failed to change directory %s\n",dir_str);
}
local_cmd_entry("cd",
"change directory",
@@ -535,36 +515,33 @@ do_write(int argc, char * argv[])
unsigned long length = 0;
bool mem_addr_set = false;
bool length_set = false;
int fd;
- if( mount_count == 0 )
- {
- err_printf("fs: No filesystems mounted\n");
- return;
- }
+ if (mount_count == 0) {
+ err_printf("fs: No filesystems mounted\n");
+ return;
+ }
- init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
- (void *)&mem_addr, (bool *)&mem_addr_set, "memory base address");
- init_opts(&opts[1], 'l', true, OPTION_ARG_TYPE_NUM,
- (void *)&length, (bool *)&length_set, "image length");
+ init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
+ (void *)&mem_addr, (bool *)&mem_addr_set, "memory base address");
+ init_opts(&opts[1], 'l', true, OPTION_ARG_TYPE_NUM,
+ (void *)&length, (bool *)&length_set, "image length");
if (!scan_opts(argc, argv, 1, opts, 2, &name_str, OPTION_ARG_TYPE_STR, "file name") ||
- name_str == NULL)
- {
+ name_str == NULL) {
fs_usage("invalid arguments");
return;
}
// diag_printf("load_address %08x %08x\n",load_address,load_address_end);
// diag_printf("ram %08x %08x\n",ram_start, ram_end);
// diag_printf("file name %08x >%s<\n",name_str,name_str);
if (!mem_addr_set &&
(load_address >= (CYG_ADDRESS)ram_start) &&
- ((load_address_end) < (CYG_ADDRESS)ram_end))
- {
+ ((load_address_end) < (CYG_ADDRESS)ram_end)) {
mem_addr = load_address;
mem_addr_set = true;
if (!length_set)
{
length = load_address_end - load_address;
@@ -572,30 +549,26 @@ do_write(int argc, char * argv[])
// maybe get length from existing file size if no loaded
// image?
}
}
- fd = open( name_str, O_WRONLY|O_CREAT|O_TRUNC );
-
- if( fd < 0 )
- {
- err_printf("fs write: Cannot open %s\n", name_str );
+ fd = open(name_str, O_WRONLY|O_CREAT|O_TRUNC);
+ if (fd < 0) {
+ err_printf("fs write: Cannot open %s\n", name_str);
return;
}
-// diag_printf("write %08x %08x\n",mem_addr, length );
+// diag_printf("write %08x %08x\n",mem_addr, length);
- err = write( fd, (void *)mem_addr, length );
-
- if( err != length )
- {
+ err = write(fd, (void *)mem_addr, length);
+ if (err != length) {
err_printf("fs write: failed to write to file %d(%d) %d\n",err,length,errno);
}
- err = close( fd );
+ err = close(fd);
- if( err != 0 )
+ if (err != 0)
err_printf("fs write: close failed\n");
}
local_cmd_entry("write",
"write data to file",
@@ -616,45 +589,39 @@ do_info(int argc, char * argv[])
{
cyg_bool found = false;
cyg_fstab_entry *f;
cyg_devtab_entry_t *t;
- for( f = &cyg_fstab[0] ; f != &cyg_fstab_end; f++ )
- {
- if( !found )
- {
+ for (f = &cyg_fstab[0] ; f != &cyg_fstab_end; f++) {
+ if (!found) {
diag_printf("Filesystems available:\n");
found = true;
}
diag_printf("%s\n",f->name);
}
found = false;
- for (t = &__DEVTAB__[0]; t != &__DEVTAB_END__; t++)
- {
- if( (t->status & CYG_DEVTAB_STATUS_BLOCK) == 0 ||
- (t->status & CYG_DEVTAB_STATUS_AVAIL) == 0 )
+ for (t = &__DEVTAB__[0]; t != &__DEVTAB_END__; t++) {
+ if ((t->status & CYG_DEVTAB_STATUS_BLOCK) == 0 ||
+ (t->status & CYG_DEVTAB_STATUS_AVAIL) == 0)
continue;
- if( !found )
- {
+ if (!found) {
diag_printf("\nDevices available:\n");
found = true;
}
diag_printf("%s\n",t->name);
}
- if( mount_count != 0 )
- {
+ if (mount_count != 0) {
int i;
diag_printf("\nMounted filesystems:\n");
diag_printf(" Device Filesystem Mounted on\n");
- for( i = 0; i < MAX_MOUNTS; i++ )
- {
- if( mounts[i].mp_str[0] != '\0' )
+ for (i = 0; i < MAX_MOUNTS; i++) {
+ if (mounts[i].mp_str[0] != '\0')
diag_printf("%32s %10s %s\n", mounts[i].dev_str, mounts[i].type_str, mounts[i].mp_str);
}
}
}
@@ -674,10 +641,11 @@ do_fs(int argc, char *argv[])
if (argc < 2) {
fs_usage("too few arguments");
return;
}
+
if ((cmd = cmd_search(__FS_cmds_TAB__, &__FS_cmds_TAB_END__,
argv[1])) != (struct cmd *)0) {
(cmd->fun)(argc-1, argv+1);
return;
}
@@ -699,15 +667,14 @@ static int fd;
externC int
fileio_stream_open(connection_info_t *info, int *err)
{
char *filename = info->filename;
- if( mount_count == 0 )
- {
- diag_printf("fs: No filesystems mounted\n");
- return -1;
- }
+ if (mount_count == 0) {
+ diag_printf("fs: No filesystems mounted\n");
+ return -1;
+ }
fd = open(filename, O_RDONLY);
if (fd < 0) {
diag_printf("fs: Open failed, error %d\n", errno);
return -1;