📄 flash.patch
字号:
+ diff -u linux-2.2.13/drivers/char/Config.in.FLASH.ORIG linux-2.2.13/drivers/char/Config.in--- linux-2.2.13/drivers/char/Config.in.FLASH.ORIG Tue Oct 19 22:31:56 1999+++ linux-2.2.13/drivers/char/Config.in Mon Oct 25 00:46:03 1999@@ -111,6 +111,11 @@ bool 'Tadpole ANA H8 Support' CONFIG_H8 fi +bool '/dev/flash' CONFIG_FLASH+if [ "$CONFIG_FLASH" = "y" ]; then+ bool ' AMD flash chip support' CONFIG_AMD_FLASH+fi+ mainmenu_option next_comment comment 'Video For Linux' + diff -u linux-2.2.13/drivers/char/Makefile.FLASH.ORIG linux-2.2.13/drivers/char/Makefile--- linux-2.2.13/drivers/char/Makefile.FLASH.ORIG Tue Oct 19 22:31:57 1999+++ linux-2.2.13/drivers/char/Makefile Mon Oct 25 00:47:44 1999@@ -334,6 +334,13 @@ endif endif +ifeq ($(CONFIG_FLASH),y)+LX_OBJS += flash.o+ ifeq ($(CONFIG_AMD_FLASH),y)+ LX_OBJS += amd_flash.o+ endif+endif+ ifeq ($(CONFIG_BUS_I2C),y) L_I2C=y else+ diff -u linux-2.2.13/drivers/char/mem.c.FLASH.ORIG linux-2.2.13/drivers/char/mem.c--- linux-2.2.13/drivers/char/mem.c.FLASH.ORIG Tue Oct 19 22:33:16 1999+++ linux-2.2.13/drivers/char/mem.c Sat Jan 8 23:45:05 2000@@ -16,6 +16,7 @@ #include <linux/init.h> #include <linux/joystick.h> #include <linux/i2c.h>+#include <linux/flash.h> #include <linux/capability.h> #include <asm/uaccess.h>@@ -645,6 +646,9 @@ lp_m68k_init(); #endif misc_init();+#ifdef CONFIG_FLASH+ flash_init();+#endif #ifdef CONFIG_SOUND soundcore_init(); #ifdef CONFIG_SOUND_OSS + diff -u linux-2.2.13/include/linux/major.h.FLASH.ORIG linux-2.2.13/include/linux/major.h--- linux-2.2.13/include/linux/major.h.FLASH.ORIG Tue Oct 19 23:30:25 1999+++ linux-2.2.13/include/linux/major.h Mon Oct 25 00:52:21 1999@@ -82,6 +83,8 @@ #define IDE4_MAJOR 56 #define IDE5_MAJOR 57++#define FLASH_MAJOR 60 /* in experimental/local area 60-63 */ #define SCSI_DISK1_MAJOR 65 #define SCSI_DISK2_MAJOR 66+ diff -u linux-2.2.13/include/linux/flash.h.FLASH.ORIG linux-2.2.13/include/linux/flash.h--- linux-2.2.13/include/linux/flash.h.FLASH.ORIG Tue May 5 22:32:27 1998+++ linux-2.2.13/include/linux/flash.h Sun Dec 19 20:00:56 1999@@ -0,0 +1,171 @@+#ifndef _LINUX_FLASH_H+#define _LINUX_FLASH_H++/*+ * /usr/include/linux/flash.h Version 0.1+ *+ * Copyright (C) 1999 Alexander Larsson (alla@lysator.liu.se or alex@signum.se)+ */++/*+ * This program is free software; you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation; either version 2 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with this program; if not, write to the Free Software+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA+ */++#include <asm/ioctl.h>+#include <asm/byteorder.h>++typedef struct flash_info_t {+ u_int size; /* Total size of flash array in bytes. */+ u_int bitwidth; /* Bit width of individual chips. */+ u_int chip_config; /* What chip configuration is used, 1 chip, 2 chips etc. */+ u_int num_regions; /* Number of regions with equal sized sectors */+} flash_info_t;++typedef struct flash_region_info_t {+ u_long offset;+ u_int sector_size; /* What size are the erase zones (in bytes) */+ u_int num_sectors;+} flash_region_info_t;++typedef struct erase_info_t {+ u_long offset;+ u_long size;+} erase_info_t;++/* IOCTL:s */+#define FLASHGETINFO _IOR('F', 1, flash_info_t)+#define FLASHGETREGIONINFO _IOR('F', 2, flash_region_info_t)+#define FLASHERASE _IOW('F', 3, erase_info_t)++#ifdef __KERNEL__++/* Defines used by CFI (Common Flash Interface) */+#define CFI_QRY_OFFSET 0x10+#define CFI_PRIMARY_VENDOR_ID_OFFSET 0x13+#define CFI_PRIMARY_QUERY_TABLE_OFFSET 0x15+#define CFI_ALT_VENDOR_ID_OFFSET 0x17+#define CFI_ALT_QUERY_TABLE_OFFSET 0x19++#define CFI_DEVICE_SIZE_OFFSET 0x27+#define CFI_NUM_ERASE_BLOCKS_OFFSET 0x2C+#define CFI_ERASE_REGION_INFO_OFFSET 0x2D++#define CFI_QUERY_CMD 0x98+#define CFI_QUERY_OFFSET 0x55++#define CFI_VENDOR_NONE 0x0000+#define CFI_VENDOR_INTEL_SHARP_EXTENDED 0x0001+#define CFI_VENDOR_AMD_FUJITSU_STANDARD 0x0002+#define CFI_VENDOR_INTEL_STANDARD 0x0003+#define CFI_VENDOR_AMD_FUJITSU_EXTENDED 0x0004+#define CFI_VENDOR_MITSUBISHI_STANDARD 0x0100+#define CFI_VENDOR_MITSUBISHI_EXTENDED 0x0101+#define CFI_VENDOR_RESERVED 0xffff++extern inline u_short cfi_read_short(char *baseptr, int offset, int chip,+ int bit_width, int chip_cfg)+{+ /* bit_width: 0 => 8 bit total width, 1 => 16 bit, 2 => 32 bit */+ /* chip_config: 0 => 1 chip, 1 => 2 chip, 2 => 4 chip */+ u_short res;+ volatile u_char *ptr;++ ptr = &baseptr[offset<<bit_width];++ ptr += chip<<bit_width; /* chip offset */+#ifdef __BIG_ENDIAN+ ptr += (1<<bit_width)-1; /* byte offset */+#endif+ res = (ptr[1] << 8) | ptr[0];++ return res;+}++extern inline u_int cfi_read_int(char *baseptr, int offset, int chip,+ int bit_width, int chip_cfg)+{+ /* bit_width: 0 => 8 bit total width, 1 => 16 bit, 2 => 32 bit */+ /* chip_config: 0 => 1 chip, 1 => 2 chip, 2 => 4 chip */+ u_int res;+ volatile u_char *ptr;++ ptr = &baseptr[offset<<bit_width];++ ptr += chip<<bit_width; /* chip offset */++#ifdef __BIG_ENDIAN+ ptr += (1<<bit_width)-1; /* byte offset */+#endif++ res =+ ((u_int)ptr[3*4]<<24) |+ ((u_int)ptr[2*4]<<16) |+ ((u_int)ptr[1*4]<< 8) |+ ((u_int)ptr[0*4]<< 0) ;+ return res;+}+++extern inline u_char cfi_read_char(char *baseptr, int offset, int chip,+ int bit_width)+{+ volatile u_char *ptr;++ ptr = &baseptr[offset<<bit_width];+#ifdef __BIG_ENDIAN+ return ptr[chip+1];+#else /* little_endian */+ return ptr[chip];+#endif+}++/* Interface for generic flash chips */+typedef struct flash_device_info {+ struct flash_device_ops *ops; /* link to device_ops */+ struct flash_device_info *next; /* next device_info for this major */+ void *handle; /* driver-dependent data */+ kdev_t dev; /* device number for char device */++ int num_regions;+ flash_region_info_t *region; /* Always stored in order */+} flash_device_info_t;++struct flash_device_ops {+ int (*read) (struct flash_device_info *,+ char *, size_t, off_t, int);+ int (*write) (struct flash_device_info *,+ const char *, size_t, off_t, int);+ int (*erase_sector) (struct flash_device_info *,+ off_t, size_t);+ /* Can erase several consecutive sectors. */+ int (*protect_sector) (struct flash_device_info *,+ off_t, size_t, int);+ int (*get_info) (struct flash_device_info *, flash_info_t *);+};+++extern int register_flash(struct flash_device_info *fdi);+extern int unregister_flash(struct flash_device_info *fdi);++extern void flash_init(void);+extern flash_device_info_t *flash_devices;++/* Some utility routines: */+extern int flash_on_sector_boundaries(struct flash_device_info *fdi,+ off_t offset, size_t count);++#endif /* End of kernel only stuff */++#endif /* _LINUX_FLASH_H */+ diff -u linux-2.2.13/drivers/char/flash.c.FLASH.ORIG linux-2.2.13/drivers/char/flash.c--- linux-2.2.13/drivers/char/flash.c.FLASH.ORIG Tue Jan 11 00:33:56 2000+++ linux-2.2.13/drivers/char/flash.c Mon Jan 10 23:26:50 2000@@ -0,0 +1,563 @@+/*+ * linux/drivers/char/flash.c Version 0.1+ *+ * Copyright (C) 1999 Alexander Larsson (alla@lysator.liu.se or alex@signum.se)+ */++/*+ * This program is free software; you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation; either version 2 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with this program; if not, write to the Free Software+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA+ */++#include <linux/config.h>+#include <linux/module.h>+#include <linux/fs.h>+#include <linux/major.h>+#include <linux/types.h>+#include <linux/errno.h>+#include <linux/kernel.h>+#include <linux/malloc.h>+#include <linux/init.h>+#include <linux/flash.h>++#include <asm/byteorder.h>+#include <asm/uaccess.h>+#include <asm/io.h>+#include <asm/residual.h>+#include <asm/residual.h>++#undef DEBUGFLASH++#ifdef DEBUGFLASH+#define DEBUG(args...) printk(args)+#else+#define DEBUG(args...)+#endif++flash_device_info_t *flash_devices = NULL;+static int next_minor = 0;+++#define MAKE_TWO(byte) (((u_short)byte)<<8 | byte)+#define MAKE_FOUR(byte) (((u_int)byte)<<24 | byte<<16 | byte<<8 | byte)+++int register_flash(struct flash_device_info *fdi)+{+ fdi->dev = MKDEV(FLASH_MAJOR, next_minor++);+ fdi->next = flash_devices;+ flash_devices = fdi;++ printk("registered flash device /dev/flash%d\n", MINOR(fdi->dev));++ return 0;+}++int unregister_flash(struct flash_device_info *unreg)+{+ struct flash_device_info *fdi, *prev;++ prev = NULL;+ fdi = flash_devices;+ while (fdi != NULL && fdi != unreg) {+ prev = fdi;+ fdi = fdi->next;+ }++ if (fdi == NULL)+ return -1;++ if (prev)+ prev->next = fdi->next;+ else+ flash_devices = fdi->next;++ printk("unregistered flash device\n");++ return 0;+}++static loff_t flash_lseek(struct file * file, loff_t offset, int orig)+{+ switch (orig) {+ case 0:+ file->f_pos = offset;+ return file->f_pos;+ case 1:+ file->f_pos += offset;+ return file->f_pos;+ default:+ return -EINVAL;+ }+}++static u_long end_of_flash(struct flash_device_info *fdi)+{+ flash_region_info_t *last_region;++ last_region = &fdi->region[fdi->num_regions-1];++ return last_region->offset ++ last_region->sector_size*last_region->num_sectors;+}++/*+ * This funcion reads the flash memory.+ */+static ssize_t flash_read(struct file * file, char * buf,+ size_t count, loff_t *ppos)+{+ struct flash_device_info *fdi = file->private_data;+ unsigned long p = *ppos;+ unsigned long end_flash;+ int res;++ end_flash = end_of_flash(fdi);++ if (p >= end_flash)+ return 0;++ if (count > end_flash - p)+ count = end_flash - p;++ res = (*fdi->ops->read)(fdi, buf, count, p, 1);++ if (res)+ return res;++ *ppos += count;+ return count;+}++static ssize_t flash_write(struct file * file, const char * buf,+ size_t count, loff_t *ppos)+{+ struct flash_device_info *fdi = file->private_data;+ unsigned long p = *ppos;+ unsigned long end_flash;+ int res;++ end_flash = end_of_flash(fdi);++ if (p >= end_flash)+ return (-ENOSPC);++ if (count > end_flash - p)+ count = end_flash - p;+++ if (flash_on_sector_boundaries(fdi, p, count)) {+ /* On a sector boundary => Erase the sectors */+ res = (*fdi->ops->erase_sector)(fdi, p, count);+ if (res)+ return res;+ }++ res = (*fdi->ops->write)(fdi, buf, count, p, 1);+ if (res) {+ return res;+ }++ *ppos += count;+ return count;+}++static int flash_ioctl(struct inode * inode, struct file *filp,+ unsigned int cmd, unsigned long arg)+{+ struct flash_device_info *fdi = filp->private_data;+ erase_info_t erase_info;+ int ret;++ switch (cmd) {+ case FLASHGETINFO:+ ret = (*fdi->ops->get_info)(fdi, (flash_info_t *)arg);+ return ret;+ break;+ case FLASHGETREGIONINFO:+ ret = copy_to_user((char *)arg, fdi->region,+ sizeof(flash_region_info_t)*fdi->num_regions);+ if (ret)+ return -EFAULT;+ return 0;+ break;+ case FLASHERASE:+ ret = copy_from_user(&erase_info, (erase_info_t *)arg, sizeof(erase_info_t));+ if (ret)+ return ret;+ ret = (*fdi->ops->erase_sector)(fdi, erase_info.offset, erase_info.size);+ return ret;+ break;+ default:+ return -EINVAL;+ }+ return -EINVAL;+}+
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -