--- zzzz-none-000/linux-2.4.17/drivers/block/rd.c 2001-12-21 17:41:53.000000000 +0000 +++ sangam-fb-322/linux-2.4.17/drivers/block/rd.c 2004-11-24 13:23:44.000000000 +0000 @@ -1,15 +1,15 @@ /* * ramdisk.c - Multiple RAM disk driver - gzip-loading version - v. 0.8 beta. - * - * (C) Chad Page, Theodore Ts'o, et. al, 1995. + * + * (C) Chad Page, Theodore Ts'o, et. al, 1995. * * This RAM disk is designed to have filesystems created on it and mounted - * just like a regular floppy disk. - * + * just like a regular floppy disk. + * * It also does something suggested by Linus: use the buffer cache as the * RAM disk data. This makes it possible to dynamically allocate the RAM disk - * buffer - with some consequences I have to deal with as I write this. - * + * buffer - with some consequences I have to deal with as I write this. + * * This code is based on the original ramdisk.c, written mostly by * Theodore Ts'o (TYT) in 1991. The code was largely rewritten by * Chad Page to use the buffer cache to store the RAM disk data in @@ -33,7 +33,7 @@ * * Added initrd: Werner Almesberger & Hans Lermen, Feb '96 * - * 4/25/96 : Made RAM disk size a parameter (default is now 4 MB) + * 4/25/96 : Made RAM disk size a parameter (default is now 4 MB) * - Chad Page * * Add support for fs images split across >1 disk, Paul Gortmaker, Mar '98 @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -65,8 +66,15 @@ #include #include +#if defined(CONFIG_TI_FILESYSTEM) +#include +extern char *prom_getenv(char *name); +#endif /* CONFIG_TI_FILESYSTEM */ + + extern void wait_for_keypress(void); + /* * 35 has been officially registered as the RAMDISK major number, but * so is the original MAJOR number of 1. We're using 1 in @@ -77,20 +85,29 @@ #include /* The RAM disk size is now a parameter */ -#define NUM_RAMDISKS 16 /* This cannot be overridden (yet) */ +#define NUM_RAMDISKS 16 /* This cannot be overridden (yet) */ #ifndef MODULE /* We don't have to load RAM disks or gunzip them in a module. */ #define RD_LOADER #define BUILD_CRAMDISK +#if defined(CONFIG_TI_FILESYSTEM) +static void tirg_load_image(int); +typedef unsigned char uch; +static char *input_data; +static uch *flash; +static char *fs_ptr_s; +static int ticrd_load(uch *indata, struct file *outfp); void rd_load(void); +#else /* !CONFIG_TI_FILESYSTEM*/ static int crd_load(struct file *fp, struct file *outfp); +#endif /* CONFIG_TI_FILESYSTEM */ #ifdef CONFIG_BLK_DEV_INITRD static int initrd_users; -#endif -#endif +#endif /* CONFIG_BLK_DEV_INITRD */ +#endif /* !MODULE */ /* Various static variables go here. Most are used only in the RAM disk code. */ @@ -106,7 +123,7 @@ * Parameters for the boot-loading of the RAM disk. These are set by * init/main.c (from arguments to the kernel command line) or from the * architecture-specific setup routine (from the stored boot sector - * information). + * information). */ int rd_size = CONFIG_BLK_DEV_RAM_SIZE; /* Size of the RAM disks */ /* @@ -127,6 +144,7 @@ int rd_doload; /* 1 = load RAM disk, 0 = don't load */ int rd_prompt = 1; /* 1 = prompt for RAM disk, 0 = don't prompt */ int rd_image_start; /* starting block # of image */ + #ifdef CONFIG_BLK_DEV_INITRD unsigned long initrd_start, initrd_end; int mount_initrd = 1; /* zero if initrd should not be mounted */ @@ -184,7 +202,7 @@ __setup("ramdisk_size=", ramdisk_size2); __setup("ramdisk_blocksize=", ramdisk_blocksize); -#endif +#endif /* CONFIG_BLK_DEV_INITRD */ /* * Copyright (C) 2000 Linus Torvalds. @@ -321,7 +339,7 @@ if (minor >= NUM_RAMDISKS) goto fail; - + offset = sbh->b_rsector << 9; len = sbh->b_size; @@ -343,14 +361,14 @@ fail: sbh->b_end_io(sbh,0); return 0; -} +} static int rd_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { int error = -EINVAL; unsigned int minor; - if (!inode || !inode->i_rdev) + if (!inode || !inode->i_rdev) goto out; minor = MINOR(inode->i_rdev); @@ -424,7 +442,7 @@ release: initrd_release, }; -#endif +#endif /* CONFIG_BLK_DEV_INITRD */ static int rd_open(struct inode * inode, struct file * filp) @@ -438,7 +456,7 @@ filp->f_op = &initrd_fops; return 0; } -#endif +#endif /* CONFIG_BLK_DEV_INITRD */ if (unit >= NUM_RAMDISKS) return -ENXIO; @@ -481,7 +499,7 @@ blksize_size[MAJOR_NR] = NULL; blk_size[MAJOR_NR] = NULL; } -#endif +#endif /* MODULE */ /* This is the registration and initialization section of the RAM disk driver */ int __init rd_init (void) @@ -522,7 +540,7 @@ #ifdef CONFIG_BLK_DEV_INITRD /* We ought to separate initrd operations here */ register_disk(NULL, MKDEV(MAJOR_NR,INITRD_MINOR), 1, &rd_bd_op, rd_size<<1); -#endif +#endif /* CONFIG_BLK_DEV_INITRD */ hardsect_size[MAJOR_NR] = rd_hardsec; /* Size of the RAM disk blocks */ blksize_size[MAJOR_NR] = rd_blocksizes; /* Avoid set_blocksize() check */ @@ -539,7 +557,7 @@ #ifdef MODULE module_init(rd_init); module_exit(rd_cleanup); -#endif +#endif /* MODULE */ /* loadable module support */ MODULE_PARM (rd_size, "1i"); @@ -551,7 +569,104 @@ /* End of non-loading portions of the RAM disk driver */ -#ifdef RD_LOADER +#ifdef RD_LOADER +#if defined(CONFIG_TI_FILESYSTEM) +static void __init tirg_load_image(int unit) +{ + struct inode *out_inode; + struct file outfile; + struct dentry out_dentry; + mm_segment_t fs; + kdev_t ram_device; + int nblocks; + char *fs_ptr_s; + + ram_device = MKDEV(MAJOR_NR, unit); + + if ((out_inode = get_empty_inode()) == NULL) + return; + memset(&outfile, 0, sizeof(outfile)); + memset(&out_dentry, 0, sizeof(out_dentry)); + outfile.f_mode = 3; /* read/write */ + outfile.f_dentry = &out_dentry; + out_dentry.d_inode = out_inode; + outfile.f_op = &def_blk_fops; + init_special_inode(out_inode, S_IFBLK | S_IRUSR | S_IWUSR, + kdev_t_to_nr(ram_device)); + + if (blkdev_open(out_inode, &outfile) != 0) + goto free_inode; + + fs = get_fs(); + set_fs(KERNEL_DS); + + nblocks = 0; + + if (nblocks == 0) { + +#ifdef BUILD_CRAMDISK + /* get base address of flash file system from environment */ + fs_ptr_s = prom_getenv("linux_fs_start"); + if(fs_ptr_s == NULL) + { + printk("RAMDISK ERROR: linux_fs_start not set in enviroment memory\n"); + goto free_inode; + } + + else + flash = simple_strtol(fs_ptr_s,NULL,0); + + if(!flash) + { + printk("RAMDISK ERROR: Invalid linux_fs_start\n"); + goto free_inode; + } + + + printk("Loading compressed image TI RG (0x%x) \n",flash); + + if (ticrd_load(flash, &outfile) == 0) /* Need to enter address of flash image */ + goto successful_load; + +#else /* !BUILD_CRAMDISK */ + printk(KERN_NOTICE /* The rest of this is for non-compressed img */ + "RAMDISK: Kernel does not support compressed " + "RAM disk images\n"); + +#endif /* BUILD_CRAMDISK */ + goto done; + } + + +successful_load: + printk("Ram Disk successfully loaded with TI-RG image \n"); + ROOT_DEV = MKDEV(MAJOR_NR, unit); + if (ROOT_DEVICE_NAME != NULL) strcpy (ROOT_DEVICE_NAME, "rd/0"); + +done: + set_fs(fs); + return; + +free_inode: + iput(out_inode); + + +} /* tirg_load_image()*/ + +void __init rd_load(void) +{ + tirg_load_image(0); +} + +void __init rd_load_secondary(void) +{ + tirg_load_image(1); +} + + +#else /* !CONFIG_TI_FILESYSTEM */ + + /* * This routine tries to find a RAM disk image to load, and returns the * number of blocks to read for a non-compressed image, 0 if the image @@ -563,14 +678,16 @@ * ext2 * romfs * gzip + * squashfs */ -static int __init +static int __init identify_ramdisk_image(kdev_t device, struct file *fp, int start_block) { const int size = 512; struct minix_super_block *minixsb; struct ext2_super_block *ext2sb; struct romfs_super_block *romfsb; + struct squashfs_super_block *squashfsb; int nblocks = -1; unsigned char *buf; @@ -581,6 +698,7 @@ minixsb = (struct minix_super_block *) buf; ext2sb = (struct ext2_super_block *) buf; romfsb = (struct romfs_super_block *) buf; + squashfsb = (struct squashfs_super_block *) buf; memset(buf, 0xe5, size); /* @@ -589,7 +707,7 @@ if (fp->f_op->llseek) fp->f_op->llseek(fp, start_block * BLOCK_SIZE, 0); fp->f_pos = start_block * BLOCK_SIZE; - + fp->f_op->read(fp, buf, size, &fp->f_pos); /* @@ -613,6 +731,15 @@ goto done; } + /* squashfs is at block zero too */ + if (squashfsb->s_magic == SQUASHFS_MAGIC) { + printk(KERN_NOTICE + "RAMDISK: squashfs filesystem found at block %d\n", + start_block); + nblocks = (squashfsb->bytes_used+BLOCK_SIZE-1)>>BLOCK_SIZE_BITS; + goto done; + } + /* * Read block 1 to test for minix and ext2 superblock */ @@ -621,7 +748,7 @@ fp->f_pos = (start_block+1) * BLOCK_SIZE; fp->f_op->read(fp, buf, size, &fp->f_pos); - + /* Try minix */ if (minixsb->s_magic == MINIX_SUPER_MAGIC || minixsb->s_magic == MINIX_SUPER_MAGIC2) { @@ -644,11 +771,11 @@ printk(KERN_NOTICE "RAMDISK: Couldn't find valid RAM disk image starting at %d.\n", start_block); - + done: if (fp->f_op->llseek) fp->f_op->llseek(fp, start_block * BLOCK_SIZE, 0); - fp->f_pos = start_block * BLOCK_SIZE; + fp->f_pos = start_block * BLOCK_SIZE; kfree(buf); return nblocks; @@ -670,7 +797,7 @@ unsigned short devblocks = 0; #if !defined(CONFIG_ARCH_S390) && !defined(CONFIG_PPC_ISERIES) char rotator[4] = { '|' , '/' , '-' , '\\' }; -#endif +#endif /* !CONFIG_ARCH_S390 && !CONFIG_PPC_ISERIES */ ram_device = MKDEV(MAJOR_NR, unit); if ((inode = get_empty_inode()) == NULL) @@ -702,7 +829,7 @@ fs = get_fs(); set_fs(KERNEL_DS); - + nblocks = identify_ramdisk_image(device, &infile, offset); if (nblocks < 0) goto done; @@ -711,11 +838,11 @@ #ifdef BUILD_CRAMDISK if (crd_load(&infile, &outfile) == 0) goto successful_load; -#else +#else /* !BUILD_CRAMDISK */ printk(KERN_NOTICE "RAMDISK: Kernel does not support compressed " "RAM disk images\n"); -#endif +#endif /* BUILD_CRAMDISK */ goto done; } @@ -730,7 +857,7 @@ nblocks, rd_length[unit] >> BLOCK_SIZE_BITS); goto done; } - + /* * OK, time to copy in the data */ @@ -746,14 +873,14 @@ #ifdef CONFIG_BLK_DEV_INITRD if (MAJOR(device) == MAJOR_NR && MINOR(device) == INITRD_MINOR) devblocks = nblocks; -#endif +#endif /* CONFIG_BLK_DEV_INITRD */ if (devblocks == 0) { printk(KERN_ERR "RAMDISK: could not determine device size\n"); goto done; } - printk(KERN_NOTICE "RAMDISK: Loading %d blocks [%d disk%s] into ram disk... ", + printk(KERN_NOTICE "RAMDISK: Loading %d blocks [%d disk%s] into ram disk... ", nblocks, ((nblocks-1)/devblocks)+1, nblocks>devblocks ? "s" : ""); for (i=0; i < nblocks; i++) { if (i && (i % devblocks == 0)) { @@ -779,7 +906,7 @@ printk("%c\b", rotator[rotate & 0x3]); rotate++; } -#endif +#endif /* !CONFIG_ARCH_S390 && !CONFIG_PPC_ISERIES */ } printk("done.\n"); kfree(buf); @@ -796,7 +923,7 @@ iput(out_inode); set_fs(fs); return; -free_inodes: /* free inodes on error */ +free_inodes: /* free inodes on error */ iput(out_inode); infile.f_op->release(inode, &infile); free_inode: @@ -805,7 +932,7 @@ #ifdef CONFIG_MAC_FLOPPY int swim3_fd_eject(int devnum); -#endif +#endif /* CONFIG_MAC_FLOPPY */ static void __init rd_load_disk(int n) { @@ -816,7 +943,10 @@ if (MAJOR(ROOT_DEV) != FLOPPY_MAJOR #ifdef CONFIG_BLK_DEV_INITRD && MAJOR(real_root_dev) != FLOPPY_MAJOR -#endif +#endif /* CONFIG_BLK_DEV_INITRD */ +#ifdef CONFIG_MTD_BLOCK + && MAJOR(ROOT_DEV) != 31 +#endif /* CONFIG_MTD_BLOCK */ ) return; @@ -841,12 +971,20 @@ void __init rd_load(void) { +#if defined(CONFIG_TI_FILESYSTEM) + tirg_load_image(0); +#else rd_load_disk(0); +#endif /* CONFIG_TI_FILESYSTEM */ } void __init rd_load_secondary(void) { +#if defined(CONFIG_TI_FILESYSTEM) + tirg_load_image(1); +#else rd_load_disk(1); +#endif /* CONFIG_TI_FILESYSTEM */ } #ifdef CONFIG_BLK_DEV_INITRD @@ -854,10 +992,12 @@ { rd_load_image(MKDEV(MAJOR_NR, INITRD_MINOR),rd_image_start,0); } -#endif +#endif /* CONFIG_BLK_DEV_INITRD */ +#endif /* CONFIG_TI_FILESYSTEM */ #endif /* RD_LOADER */ + #ifdef BUILD_CRAMDISK /* @@ -870,7 +1010,15 @@ #define memzero(s, n) memset ((s), 0, (n)) #endif +#if defined(CONFIG_TI_FILESYSTEM) +/*nothing*/ +#else typedef unsigned char uch; +static unsigned insize; /* valid bytes in inbuf */ +static struct file *crd_infp; +#endif /* CONFIG_TI_FILESYSTEM */ + +static uch *inbuf; typedef unsigned short ush; typedef unsigned long ulg; @@ -878,18 +1026,23 @@ #define WSIZE 0x8000 /* window size--must be a power of two, and */ /* at least 32K for zip's deflate method */ -static uch *inbuf; + static uch *window; -static unsigned insize; /* valid bytes in inbuf */ + static unsigned inptr; /* index of next byte to be processed in inbuf */ static unsigned outcnt; /* bytes in output buffer */ static int exit_code; static long bytes_out; -static struct file *crd_infp, *crd_outfp; +static struct file *crd_outfp; +#if defined(CONFIG_TI_FILESYSTEM) +uch get_byte(void); +#else #define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf()) - +#endif /* CONFIG_TI_FILESYSTEM */ + + /* Diagnostic functions (stubbed out) */ #define Assert(cond,msg) #define Trace(x) @@ -900,7 +1053,12 @@ #define STATIC static +#if defined(CONFIG_TI_FILESYSTEM) +/*nothing*/ +#else static int fill_inbuf(void); +#endif /* CONFIG_TI_FILESYSTEM */ + static void flush_window(void); static void *malloc(int size); static void free(void *where); @@ -928,7 +1086,21 @@ { } +#if defined(CONFIG_TI_FILESYSTEM) +uch get_byte(void) +{ + uch c; + + c = *input_data; + input_data++; + + return(c); +} +#endif /* CONFIG_TI_FILESYSTEM */ +#if defined(CONFIG_TI_FILESYSTEM) +/*nothing*/ +#else /* =========================================================================== * Fill the input buffer. This is called only when the buffer is empty * and at least one byte is really needed. @@ -936,7 +1108,7 @@ static int __init fill_inbuf(void) { if (exit_code) return -1; - + insize = crd_infp->f_op->read(crd_infp, inbuf, INBUFSIZ, &crd_infp->f_pos); if (insize == 0) return -1; @@ -945,6 +1117,9 @@ return inbuf[0]; } +#endif /* CONFIG_TI_FILESYSTEM*/ + + /* =========================================================================== * Write the output window window[0..outcnt-1] and update crc and bytes_out. @@ -953,10 +1128,15 @@ static void __init flush_window(void) { ulg c = crc; /* temporary variable */ - unsigned n; + unsigned n, written; uch *in, ch; - - crd_outfp->f_op->write(crd_outfp, window, outcnt, &crd_outfp->f_pos); + + written = crd_outfp->f_op->write(crd_outfp, window, outcnt, &crd_outfp->f_pos); + if (written != outcnt && exit_code == 0) { + printk(KERN_ERR "RAMDISK: incomplete write (ramdisk too small?) " + "(%d != %d)\n", written, outcnt); + exit_code = 1; + } in = window; for (n = 0; n < outcnt; n++) { ch = *in++; @@ -973,7 +1153,39 @@ exit_code = 1; } -static int __init +#if defined(CONFIG_TI_FILESYSTEM) +static int __init +ticrd_load(uch *indata, struct file *outfp) +{ + int result; + outcnt = 0; /* bytes in output buffer */ + exit_code = 0; + bytes_out = 0; + crc = (ulg)0xffffffffL; /* shift register contents */ + + input_data = indata; + crd_outfp = outfp; + inbuf = kmalloc(INBUFSIZ, GFP_KERNEL); + if (inbuf == 0){ + printk(KERN_ERR "RAMDISK: Couldn't allocate gzip buffer\n"); + return -1; + } + window = kmalloc(WSIZE, GFP_KERNEL); + if (window == 0) { + printk(KERN_ERR "RAMDISK: Couldn't allocate gzip window\n"); + kfree(inbuf); + return -1; + } + makecrc(); + result = gunzip(); + kfree(inbuf); + kfree(window); + return result; +} + +#else /* !CONFIG_TI_FILESYSTEM*/ + +static int __init crd_load(struct file * fp, struct file *outfp) { int result; @@ -1005,5 +1217,14 @@ return result; } +#endif /* CONFIG_TI_FILESYSTEM*/ #endif /* BUILD_CRAMDISK */ + + + + + + + +