2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2007 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
7 * Created by Charles Manning <charles@aleph1.co.uk>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
15 * yaffscfg.c The configuration for the "direct" use of yaffs.
17 * This is set up for u-boot.
19 * This version now uses the ydevconfig mechanism to set up partitions.
28 #include "yaffs_packedtags2.h"
29 #include "yaffs_mtdif.h"
30 #include "yaffs_mtdif2.h"
37 unsigned yaffs_trace_mask = 0x0; /* Disable logging */
38 static int yaffs_errno = 0;
42 void *yaffsfs_malloc(size_t x)
47 void yaffsfs_free(void *x)
52 void yaffsfs_SetError(int err)
54 //Do whatever to set error
58 int yaffsfs_GetLastError(void)
64 int yaffsfs_GetError(void)
69 void yaffsfs_Lock(void)
73 void yaffsfs_Unlock(void)
77 __u32 yaffsfs_CurrentTime(void)
82 void *yaffs_malloc(size_t size)
87 void yaffs_free(void *ptr)
92 void yaffsfs_LocalInitialisation(void)
94 // Define locking semaphore.
97 extern nand_info_t nand_info[];
100 void cmd_yaffs_devconfig(char *_mp, int flash_dev, int start_block, int end_block)
102 struct mtd_info *mtd = NULL;
103 struct yaffs_dev *dev;
106 dev = calloc(1, sizeof(*dev));
109 mtd = &nand_info[flash_dev];
115 if(end_block < start_block)
116 end_block = mtd->size / mtd->erasesize;
118 memset(dev, 0, sizeof(*dev));
119 dev->param.name = mp;
120 dev->driver_context = mtd;
121 dev->param.start_block = start_block;
122 dev->param.end_block = end_block;
123 dev->param.chunks_per_block = mtd->erasesize / mtd->writesize;
124 dev->param.total_bytes_per_chunk = mtd->writesize;
125 dev->param.is_yaffs2 = 1;
126 dev->param.use_nand_ecc = 1;
127 dev->param.n_reserved_blocks = 5;
128 dev->param.inband_tags = 0;
129 dev->param.n_caches = 10;
130 dev->param.write_chunk_tags_fn = nandmtd2_WriteChunkWithTagsToNAND;
131 dev->param.read_chunk_tags_fn = nandmtd2_ReadChunkWithTagsFromNAND;
132 dev->param.erase_fn = nandmtd_EraseBlockInNAND;
133 dev->param.initialise_flash_fn = nandmtd_InitialiseNAND;
134 dev->param.bad_block_fn = nandmtd2_MarkNANDBlockBad;
135 dev->param.query_block_fn = nandmtd2_QueryNANDBlock;
137 yaffs_add_device(dev);
142 void make_a_file(char *yaffsName,char bval,int sizeOfFile)
146 unsigned char buffer[100];
148 outh = yaffs_open(yaffsName, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
151 printf("Error opening file: %d\n", outh);
155 memset(buffer,bval,100);
162 yaffs_write(outh,buffer,i);
164 } while (sizeOfFile > 0);
170 void read_a_file(char *fn)
176 h = yaffs_open(fn, O_RDWR,0);
179 printf("File not found\n");
183 while(yaffs_read(h,&b,1)> 0)
197 void cmd_yaffs_mount(char *mp)
199 int retval = yaffs_mount(mp);
201 printf("Error mounting %s, return value: %d\n", mp, yaffsfs_GetError());
205 void cmd_yaffs_umount(char *mp)
207 if( yaffs_unmount(mp) == -1)
208 printf("Error umounting %s, return value: %d\n", mp, yaffsfs_GetError());
211 void cmd_yaffs_write_file(char *yaffsName,char bval,int sizeOfFile)
213 make_a_file(yaffsName,bval,sizeOfFile);
217 void cmd_yaffs_read_file(char *fn)
223 void cmd_yaffs_mread_file(char *fn, char *addr)
230 printf ("Copy %s to 0x%p... ", fn, addr);
231 h = yaffs_open(fn, O_RDWR,0);
234 printf("File not found\n");
238 yaffs_read(h,addr,(int)s.st_size);
239 printf("\t[DONE]\n");
245 void cmd_yaffs_mwrite_file(char *fn, char *addr, int size)
249 outh = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
252 printf("Error opening file: %d\n", outh);
255 yaffs_write(outh,addr,size);
261 void cmd_yaffs_ls(const char *mountpt, int longlist)
266 struct yaffs_stat stat;
269 d = yaffs_opendir(mountpt);
273 printf("opendir failed\n");
277 for(i = 0; (de = yaffs_readdir(d)) != NULL; i++)
281 sprintf(tempstr, "%s/%s", mountpt, de->d_name);
282 yaffs_stat(tempstr, &stat);
283 printf("%-25s\t%7ld\n",de->d_name, stat.st_size);
287 printf("%s\n",de->d_name);
294 void cmd_yaffs_mkdir(const char *dir)
296 int retval = yaffs_mkdir(dir, 0);
299 printf("yaffs_mkdir returning error: %d\n", retval);
302 void cmd_yaffs_rmdir(const char *dir)
304 int retval = yaffs_rmdir(dir);
307 printf("yaffs_rmdir returning error: %d\n", retval);
310 void cmd_yaffs_rm(const char *path)
312 int retval = yaffs_unlink(path);
315 printf("yaffs_unlink returning error: %d\n", retval);
318 void cmd_yaffs_mv(const char *oldPath, const char *newPath)
320 int retval = yaffs_rename(newPath, oldPath);
323 printf("yaffs_unlink returning error: %d\n", retval);