Esempio n. 1
0
static int __init init_mtdram(void)
{
	void *addr;
	int err;

	if (!total_size)
		return -EINVAL;

	/* Allocate some memory */
	mtd_info = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
	if (!mtd_info)
		return -ENOMEM;

	addr = vmalloc(MTDRAM_TOTAL_SIZE);
	if (!addr) {
		kfree(mtd_info);
		mtd_info = NULL;
		return -ENOMEM;
	}
	err = mtdram_init_device(mtd_info, addr, MTDRAM_TOTAL_SIZE, "mtdram test device");
	if (err) {
		vfree(addr);
		kfree(mtd_info);
		mtd_info = NULL;
		return err;
	}
	memset(mtd_info->priv, 0xff, MTDRAM_TOTAL_SIZE);
	return err;
}
Esempio n. 2
0
int __init init_mtdram(void)
{
  void *addr;
  int err;
  /* Allocate some memory */
   mtd_info = (struct mtd_info *)kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
   if (!mtd_info)
     return -ENOMEM;

  addr = vmalloc(MTDRAM_TOTAL_SIZE);
  if (!addr) {
    DEBUG(MTD_DEBUG_LEVEL1, 
          "Failed to vmalloc memory region of size %ld\n", 
          (long)MTDRAM_TOTAL_SIZE);
    kfree(mtd_info);
    mtd_info = NULL;
    return -ENOMEM;
  }
  err = mtdram_init_device(mtd_info, addr, 
                           MTDRAM_TOTAL_SIZE, "mtdram test device");
  if (err) 
  {
    vfree(addr);
    kfree(mtd_info);
    mtd_info = NULL;
    return err;
  }
  memset(mtd_info->priv, 0xff, MTDRAM_TOTAL_SIZE);
  return err;
}
Esempio n. 3
0
static int __init init_mtdram(void)
{
    void *addr;
    int err;
    /* Allocate some memory */
    mtd_info = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
    if (!mtd_info)
        return -ENOMEM;

    addr = ioremap(CONFIG_MTDRAM_ABS_POS, MTDRAM_TOTAL_SIZE);
    if (!addr) {
        DEBUG(MTD_DEBUG_LEVEL1,
              "Failed to ioremap) memory region of size %ld at ABS_POS:%ld\n",
              (long)MTDRAM_TOTAL_SIZE, (long)CONFIG_MTDRAM_ABS_POS);
        kfree(mtd_info);
        mtd_info = NULL;
        return -ENOMEM;
    }
    err = mtdram_init_device(mtd_info, addr,
                             MTDRAM_TOTAL_SIZE, "mtdram test device");
    if (err)
    {
        iounmap(addr);
        kfree(mtd_info);
        mtd_info = NULL;
        return err;
    }
    memset(mtd_info->priv, 0xff, MTDRAM_TOTAL_SIZE);
    return err;
}
Esempio n. 4
0
void flash_init(void)
{
	struct dentry dentry = { .d_name  = "mtd1" };

	printk("Creating MTD device %s\n", dentry.d_name);
	if (mtdram_init_device(&mtd1, &_binary_sda1_start, 1024,
				dentry.d_name))
		printk("error: mtdram init device failed\n");
	add_mtd_device(&mtd1, dentry.d_name);
}

int main()
{
	int fd;
	char buffer[128];

	/* printk("filesystem at %p\n", &_binary_sda1_start); */
	/* dump_romfs_info(&_binary_sda1_start); */

	flash_init();
	mount("/dev/mtd1", "/dev/flash", "romfs", 0, 0);

	/* Lorem ipsum dolor sit amet, consectetur adipiscing elit. */
	fd = open("/dev/flash/lorem.txt", 0);
	if (fd < 0) {
		printk("error: failed to open /home/lorem.txt\n");
		TEST_EXIT(1);
	}

	memset(buffer, 0, 128);
	read(fd, buffer, 11);
	printk("read(): %s\n", buffer);
	if (strcmp(buffer, "Lorem ipsum"))
		TEST_EXIT(1);

	memset(buffer, 0, 128);
	read(fd, buffer, 10);
	printk("read(): %s\n", buffer);
	if (strcmp(buffer, " dolor sit"))
		TEST_EXIT(1);

	memset(buffer, 0, 128);
	read(fd, buffer, 18);
	printk("read(): %s\n", buffer);
	if (strcmp(buffer, " amet, consectetur"))
		TEST_EXIT(1);

	/* rewind the file */
	lseek(fd, 0, SEEK_SET);
	memset(buffer, 0, 128);
	read(fd, buffer, 11);
	printk("read(): %s\n", buffer);
	if (strcmp(buffer, "Lorem ipsum"))
		TEST_EXIT(1);

	TEST_EXIT(0);
}
Esempio n. 5
0
void flash_init(void)
{
	struct dentry dentry = { .d_name  = "mtd1" };

	printk("Creating MTD device %s\n", dentry.d_name);
	if (mtdram_init_device(&mtd1, &_binary_sda1_start, 1024,
				dentry.d_name))
		printk("error: mtdram init device failed\n");
	add_mtd_device(&mtd1, dentry.d_name);
}

int main()
{
	int fd;
	const char filename[] = "/dev/flash/foo/bar/lorem";
	char buffer[32];

	/* printk("filesystem at %p\n", &_binary_sda1_start); */
	/* dump_romfs_info(&_binary_sda1_start); */

	flash_init();
	mount("/dev/mtd1", "/dev/flash", "romfs", 0, 0);

	/* Lorem ipsum dolor sit amet, consectetur adipiscing elit. */
	fd = open(filename, 0);
	if (fd < 0) {
		printk("error: failed to open %s\n", filename);
		TEST_EXIT(1);
	}

	memset(buffer, 0, 32);
	if (read(fd, buffer, 11) != 11)
		TEST_EXIT(1);
	if (strcmp(buffer, "Lorem ipsum"))
		TEST_EXIT(1);

	memset(buffer, 0, 32);
	if (read(fd, buffer, 10) != 10)
		TEST_EXIT(1);
	if (strcmp(buffer, " dolor sit"))
		TEST_EXIT(1);

	close(fd);

	TEST_EXIT(0);
}
Esempio n. 6
0
void flash_init(void)
{
	struct dentry dentry = { .d_name  = "mtd1" };

	printk("Creating MTD device %s\n", dentry.d_name);
	if (mtdram_init_device(&mtd1, &_binary_sda1_start, 4096,
				dentry.d_name))
		printk("error: mtdram init device failed\n");
	add_mtd_device(&mtd1, dentry.d_name);
}

int main()
{
	flash_init();
	mount("/dev/mtd1", "/dev/flash", "romfs", 0, 0);

	/* execve does not return in POSIX standard */
	if (execve("/dev/flash/a.out", 0, 0))
		TEST_EXIT(1);
	sched_yield();

	TEST_EXIT(0);
}
/*
 * Probe the flash chip(s) and, if it succeeds, read the partition-table
 * and register the partitions with MTD.
 */
static int __init init_axis_flash(void)
{
	struct mtd_info *main_mtd;
	struct mtd_info *aux_mtd = NULL;
	int err = 0;
	int pidx = 0;
	struct partitiontable_head *ptable_head = NULL;
	struct partitiontable_entry *ptable;
	int ptable_ok = 0;
	static char page[PAGESIZE];
	size_t len;
	int ram_rootfs_partition = -1; /* -1 => no RAM rootfs partition */
	int part;

	/* We need a root fs. If it resides in RAM, we need to use an
	 * MTDRAM device, so it must be enabled in the kernel config,
	 * but its size must be configured as 0 so as not to conflict
	 * with our usage.
	 */
#if !defined(CONFIG_MTD_MTDRAM) || (CONFIG_MTDRAM_TOTAL_SIZE != 0) || (CONFIG_MTDRAM_ABS_POS != 0)
	if (!romfs_in_flash && !nand_boot) {
		printk(KERN_EMERG "axisflashmap: Cannot create an MTD RAM "
		       "device; configure CONFIG_MTD_MTDRAM with size = 0!\n");
		panic("This kernel cannot boot from RAM!\n");
	}
#endif

#ifndef CONFIG_ETRAX_VCS_SIM
	main_mtd = flash_probe();
	if (main_mtd)
		printk(KERN_INFO "%s: 0x%08x bytes of NOR flash memory.\n",
		       main_mtd->name, main_mtd->size);

#ifdef CONFIG_ETRAX_NANDFLASH
	aux_mtd = crisv32_nand_flash_probe();
	if (aux_mtd)
		printk(KERN_INFO "%s: 0x%08x bytes of NAND flash memory.\n",
			aux_mtd->name, aux_mtd->size);

#ifdef CONFIG_ETRAX_NANDBOOT
	{
		struct mtd_info *tmp_mtd;

		printk(KERN_INFO "axisflashmap: Set to boot from NAND flash, "
		       "making NAND flash primary device.\n");
		tmp_mtd = main_mtd;
		main_mtd = aux_mtd;
		aux_mtd = tmp_mtd;
	}
#endif /* CONFIG_ETRAX_NANDBOOT */
#endif /* CONFIG_ETRAX_NANDFLASH */

	if (!main_mtd && !aux_mtd) {
		/* There's no reason to use this module if no flash chip can
		 * be identified. Make sure that's understood.
		 */
		printk(KERN_INFO "axisflashmap: Found no flash chip.\n");
	}

#if 0 /* Dump flash memory so we can see what is going on */
	if (main_mtd) {
		int sectoraddr, i;
		for (sectoraddr = 0; sectoraddr < 2*65536+4096;
				sectoraddr += PAGESIZE) {
			main_mtd->read(main_mtd, sectoraddr, PAGESIZE, &len,
				page);
			printk(KERN_INFO
			       "Sector at %d (length %d):\n",
			       sectoraddr, len);
			for (i = 0; i < PAGESIZE; i += 16) {
				printk(KERN_INFO
				       "%02x %02x %02x %02x "
				       "%02x %02x %02x %02x "
				       "%02x %02x %02x %02x "
				       "%02x %02x %02x %02x\n",
				       page[i] & 255, page[i+1] & 255,
				       page[i+2] & 255, page[i+3] & 255,
				       page[i+4] & 255, page[i+5] & 255,
				       page[i+6] & 255, page[i+7] & 255,
				       page[i+8] & 255, page[i+9] & 255,
				       page[i+10] & 255, page[i+11] & 255,
				       page[i+12] & 255, page[i+13] & 255,
				       page[i+14] & 255, page[i+15] & 255);
			}
		}
	}
#endif

	if (main_mtd) {
		main_mtd->owner = THIS_MODULE;
		axisflash_mtd = main_mtd;

		loff_t ptable_sector = CONFIG_ETRAX_PTABLE_SECTOR;

		/* First partition (rescue) is always set to the default. */
		pidx++;
#ifdef CONFIG_ETRAX_NANDBOOT
		/* We know where the partition table should be located,
		 * it will be in first good block after that.
		 */
		int blockstat;
		do {
			blockstat = main_mtd->block_isbad(main_mtd,
				ptable_sector);
			if (blockstat < 0)
				ptable_sector = 0; /* read error */
			else if (blockstat)
				ptable_sector += main_mtd->erasesize;
		} while (blockstat && ptable_sector);
#endif
		if (ptable_sector) {
			main_mtd->read(main_mtd, ptable_sector, PAGESIZE,
				&len, page);
			ptable_head = &((struct partitiontable *) page)->head;
		}

#if 0 /* Dump partition table so we can see what is going on */
		printk(KERN_INFO
		       "axisflashmap: flash read %d bytes at 0x%08x, data: "
		       "%02x %02x %02x %02x %02x %02x %02x %02x\n",
		       len, CONFIG_ETRAX_PTABLE_SECTOR,
		       page[0] & 255, page[1] & 255,
		       page[2] & 255, page[3] & 255,
		       page[4] & 255, page[5] & 255,
		       page[6] & 255, page[7] & 255);
		printk(KERN_INFO
		       "axisflashmap: partition table offset %d, data: "
		       "%02x %02x %02x %02x %02x %02x %02x %02x\n",
		       PARTITION_TABLE_OFFSET,
		       page[PARTITION_TABLE_OFFSET+0] & 255,
		       page[PARTITION_TABLE_OFFSET+1] & 255,
		       page[PARTITION_TABLE_OFFSET+2] & 255,
		       page[PARTITION_TABLE_OFFSET+3] & 255,
		       page[PARTITION_TABLE_OFFSET+4] & 255,
		       page[PARTITION_TABLE_OFFSET+5] & 255,
		       page[PARTITION_TABLE_OFFSET+6] & 255,
		       page[PARTITION_TABLE_OFFSET+7] & 255);
#endif
	}

	if (ptable_head && (ptable_head->magic == PARTITION_TABLE_MAGIC)
	    && (ptable_head->size <
		(MAX_PARTITIONS * sizeof(struct partitiontable_entry) +
		PARTITIONTABLE_END_MARKER_SIZE))
	    && (*(unsigned long*)((void*)ptable_head + sizeof(*ptable_head) +
				  ptable_head->size -
				  PARTITIONTABLE_END_MARKER_SIZE)
		== PARTITIONTABLE_END_MARKER)) {
		/* Looks like a start, sane length and end of a
		 * partition table, lets check csum etc.
		 */
		struct partitiontable_entry *max_addr =
			(struct partitiontable_entry *)
			((unsigned long)ptable_head + sizeof(*ptable_head) +
			 ptable_head->size);
		unsigned long offset = CONFIG_ETRAX_PTABLE_SECTOR;
		unsigned char *p;
		unsigned long csum = 0;

		ptable = (struct partitiontable_entry *)
			((unsigned long)ptable_head + sizeof(*ptable_head));

		/* Lets be PARANOID, and check the checksum. */
		p = (unsigned char*) ptable;

		while (p <= (unsigned char*)max_addr) {
			csum += *p++;
			csum += *p++;
			csum += *p++;
			csum += *p++;
		}
		ptable_ok = (csum == ptable_head->checksum);

		/* Read the entries and use/show the info.  */
		printk(KERN_INFO "axisflashmap: "
		       "Found a%s partition table at 0x%p-0x%p.\n",
		       (ptable_ok ? " valid" : "n invalid"), ptable_head,
		       max_addr);

		/* We have found a working bootblock.  Now read the
		 * partition table.  Scan the table.  It ends with 0xffffffff.
		 */
		while (ptable_ok
		       && ptable->offset != PARTITIONTABLE_END_MARKER
		       && ptable < max_addr
		       && pidx < MAX_PARTITIONS - 1) {

			axis_partitions[pidx].offset = offset + ptable->offset;
#ifdef CONFIG_ETRAX_NANDFLASH
			if (main_mtd->type == MTD_NANDFLASH) {
				axis_partitions[pidx].size =
					(((ptable+1)->offset ==
					  PARTITIONTABLE_END_MARKER) ?
					  main_mtd->size :
					  ((ptable+1)->offset + offset)) -
					(ptable->offset + offset);

			} else
#endif /* CONFIG_ETRAX_NANDFLASH */
				axis_partitions[pidx].size = ptable->size;
#ifdef CONFIG_ETRAX_NANDBOOT
			/* Save partition number of jffs2 ro partition.
			 * Needed if RAM booting or root file system in RAM.
			 */
			if (!nand_boot &&
			    ram_rootfs_partition < 0 && /* not already set */
			    ptable->type == PARTITION_TYPE_JFFS2 &&
			    (ptable->flags & PARTITION_FLAGS_READONLY_MASK) ==
				PARTITION_FLAGS_READONLY)
				ram_rootfs_partition = pidx;
#endif /* CONFIG_ETRAX_NANDBOOT */
			pidx++;
			ptable++;
		}
	}

	/* Decide whether to use default partition table. */
	/* Only use default table if we actually have a device (main_mtd) */

	struct mtd_partition *partition = &axis_partitions[0];
	if (main_mtd && !ptable_ok) {
		memcpy(axis_partitions, axis_default_partitions,
		       sizeof(axis_default_partitions));
		pidx = NUM_DEFAULT_PARTITIONS;
		ram_rootfs_partition = DEFAULT_ROOTFS_PARTITION_NO;
	}

	/* Add artificial partitions for rootfs if necessary */
	if (romfs_in_flash) {
		/* rootfs is in directly accessible flash memory = NOR flash.
		   Add an overlapping device for the rootfs partition. */
		printk(KERN_INFO "axisflashmap: Adding partition for "
		       "overlapping root file system image\n");
		axis_partitions[pidx].size = romfs_length;
		axis_partitions[pidx].offset = romfs_start - FLASH_CACHED_ADDR;
		axis_partitions[pidx].name = "romfs";
		axis_partitions[pidx].mask_flags |= MTD_WRITEABLE;
		ram_rootfs_partition = -1;
		pidx++;
	} else if (romfs_length && !nand_boot) {
		/* romfs exists in memory, but not in flash, so must be in RAM.
		 * Configure an MTDRAM partition. */
		if (ram_rootfs_partition < 0) {
			/* None set yet, put it at the end */
			ram_rootfs_partition = pidx;
			pidx++;
		}
		printk(KERN_INFO "axisflashmap: Adding partition for "
		       "root file system image in RAM\n");
		axis_partitions[ram_rootfs_partition].size = romfs_length;
		axis_partitions[ram_rootfs_partition].offset = romfs_start;
		axis_partitions[ram_rootfs_partition].name = "romfs";
		axis_partitions[ram_rootfs_partition].mask_flags |=
			MTD_WRITEABLE;
	}

#ifdef CONFIG_ETRAX_AXISFLASHMAP_MTD0WHOLE
	if (main_mtd) {
		main_partition.size = main_mtd->size;
		err = mtd_device_register(main_mtd, &main_partition, 1);
		if (err)
			panic("axisflashmap: Could not initialize "
			      "partition for whole main mtd device!\n");
	}
#endif

	/* Now, register all partitions with mtd.
	 * We do this one at a time so we can slip in an MTDRAM device
	 * in the proper place if required. */

	for (part = 0; part < pidx; part++) {
		if (part == ram_rootfs_partition) {
			/* add MTDRAM partition here */
			struct mtd_info *mtd_ram;

			mtd_ram = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
			if (!mtd_ram)
				panic("axisflashmap: Couldn't allocate memory "
				      "for mtd_info!\n");
			printk(KERN_INFO "axisflashmap: Adding RAM partition "
			       "for rootfs image.\n");
			err = mtdram_init_device(mtd_ram,
						 (void *)partition[part].offset,
						 partition[part].size,
						 partition[part].name);
			if (err)
				panic("axisflashmap: Could not initialize "
				      "MTD RAM device!\n");
			/* JFFS2 likes to have an erasesize. Keep potential
			 * JFFS2 rootfs happy by providing one. Since image
			 * was most likely created for main mtd, use that
			 * erasesize, if available. Otherwise, make a guess. */
			mtd_ram->erasesize = (main_mtd ? main_mtd->erasesize :
				CONFIG_ETRAX_PTABLE_SECTOR);
		} else {
			err = mtd_device_register(main_mtd, &partition[part],
						  1);
			if (err)
				panic("axisflashmap: Could not add mtd "
					"partition %d\n", part);
		}
	}
#endif /* CONFIG_EXTRAX_VCS_SIM */

#ifdef CONFIG_ETRAX_VCS_SIM
	/* For simulator, always use a RAM partition.
	 * The rootfs will be found after the kernel in RAM,
	 * with romfs_start and romfs_end indicating location and size.
	 */
	struct mtd_info *mtd_ram;

	mtd_ram = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
	if (!mtd_ram) {
		panic("axisflashmap: Couldn't allocate memory for "
		      "mtd_info!\n");
	}

	printk(KERN_INFO "axisflashmap: Adding RAM partition for romfs, "
	       "at %u, size %u\n",
	       (unsigned) romfs_start, (unsigned) romfs_length);

	err = mtdram_init_device(mtd_ram, (void *)romfs_start,
				 romfs_length, "romfs");
	if (err) {
		panic("axisflashmap: Could not initialize MTD RAM "
		      "device!\n");
	}
#endif /* CONFIG_EXTRAX_VCS_SIM */

#ifndef CONFIG_ETRAX_VCS_SIM
	if (aux_mtd) {
		aux_partition.size = aux_mtd->size;
		err = mtd_device_register(aux_mtd, &aux_partition, 1);
		if (err)
			panic("axisflashmap: Could not initialize "
			      "aux mtd device!\n");

	}
#endif /* CONFIG_EXTRAX_VCS_SIM */

	return err;
}
Esempio n. 8
0
/*
 * Probe the flash chip(s) and, if it succeeds, read the partition-table
 * and register the partitions with MTD.
 */
static int __init init_axis_flash(void)
{
	struct mtd_info *mymtd;
	int err = 0;
	int pidx = 0;
	struct partitiontable_head *ptable_head = NULL;
	struct partitiontable_entry *ptable;
	int use_default_ptable = 1; /* Until proven otherwise. */
	const char *pmsg = KERN_INFO "  /dev/flash%d at 0x%08x, size 0x%08x\n";
	static char page[512];
	size_t len;

#ifndef CONFIG_ETRAXFS_SIM
	mymtd = flash_probe();
	mymtd->read(mymtd, CONFIG_ETRAX_PTABLE_SECTOR, 512, &len, page);
	ptable_head = (struct partitiontable_head *)(page + PARTITION_TABLE_OFFSET);

	if (!mymtd) {
		/* There's no reason to use this module if no flash chip can
		 * be identified. Make sure that's understood.
		 */
		printk(KERN_INFO "axisflashmap: Found no flash chip.\n");
	} else {
		printk(KERN_INFO "%s: 0x%08x bytes of flash memory.\n",
		       mymtd->name, mymtd->size);
		axisflash_mtd = mymtd;
	}

	if (mymtd) {
		mymtd->owner = THIS_MODULE;
	}
	pidx++;  /* First partition is always set to the default. */

	if (ptable_head && (ptable_head->magic == PARTITION_TABLE_MAGIC)
	    && (ptable_head->size <
		(MAX_PARTITIONS * sizeof(struct partitiontable_entry) +
		PARTITIONTABLE_END_MARKER_SIZE))
	    && (*(unsigned long*)((void*)ptable_head + sizeof(*ptable_head) +
				  ptable_head->size -
				  PARTITIONTABLE_END_MARKER_SIZE)
		== PARTITIONTABLE_END_MARKER)) {
		/* Looks like a start, sane length and end of a
		 * partition table, lets check csum etc.
		 */
		int ptable_ok = 0;
		struct partitiontable_entry *max_addr =
			(struct partitiontable_entry *)
			((unsigned long)ptable_head + sizeof(*ptable_head) +
			 ptable_head->size);
		unsigned long offset = CONFIG_ETRAX_PTABLE_SECTOR;
		unsigned char *p;
		unsigned long csum = 0;

		ptable = (struct partitiontable_entry *)
			((unsigned long)ptable_head + sizeof(*ptable_head));

		/* Lets be PARANOID, and check the checksum. */
		p = (unsigned char*) ptable;

		while (p <= (unsigned char*)max_addr) {
			csum += *p++;
			csum += *p++;
			csum += *p++;
			csum += *p++;
		}
		ptable_ok = (csum == ptable_head->checksum);

		/* Read the entries and use/show the info.  */
		printk(KERN_INFO " Found a%s partition table at 0x%p-0x%p.\n",
		       (ptable_ok ? " valid" : "n invalid"), ptable_head,
		       max_addr);

		/* We have found a working bootblock.  Now read the
		 * partition table.  Scan the table.  It ends when
		 * there is 0xffffffff, that is, empty flash.
		 */
		while (ptable_ok
		       && ptable->offset != 0xffffffff
		       && ptable < max_addr
		       && pidx < MAX_PARTITIONS) {

			axis_partitions[pidx].offset = offset + ptable->offset + (crisv32_nand_boot ? 16384 : 0);
			axis_partitions[pidx].size = ptable->size;

			printk(pmsg, pidx, axis_partitions[pidx].offset,
			       axis_partitions[pidx].size);
			pidx++;
			ptable++;
		}
		use_default_ptable = !ptable_ok;
	}

	if (romfs_in_flash) {
		/* Add an overlapping device for the root partition (romfs). */

		axis_partitions[pidx].name = "romfs";
		if (crisv32_nand_boot) {
			char* data = kmalloc(1024, GFP_KERNEL);
			int len;
			int offset = crisv32_nand_cramfs_offset & ~(1024-1);
			char* tmp;

			mymtd->read(mymtd, offset, 1024, &len, data);
			tmp = &data[crisv32_nand_cramfs_offset % 512];
			axis_partitions[pidx].size = *(unsigned*)(tmp + 4);
			axis_partitions[pidx].offset = crisv32_nand_cramfs_offset;
			kfree(data);
		} else {
			axis_partitions[pidx].size = romfs_length;
			axis_partitions[pidx].offset = romfs_start - FLASH_CACHED_ADDR;
		}

		axis_partitions[pidx].mask_flags |= MTD_WRITEABLE;

		printk(KERN_INFO
                       " Adding readonly flash partition for romfs image:\n");
		printk(pmsg, pidx, axis_partitions[pidx].offset,
		       axis_partitions[pidx].size);
		pidx++;
	}

        if (mymtd) {
		if (use_default_ptable) {
			printk(KERN_INFO " Using default partition table.\n");
			err = add_mtd_partitions(mymtd, axis_default_partitions,
						 NUM_DEFAULT_PARTITIONS);
		} else {
			err = add_mtd_partitions(mymtd, axis_partitions, pidx);
		}

		if (err) {
			panic("axisflashmap could not add MTD partitions!\n");
		}
	}
/* CONFIG_EXTRAXFS_SIM */
#endif

	if (!romfs_in_flash) {
		/* Create an RAM device for the root partition (romfs). */

#if !defined(CONFIG_MTD_MTDRAM) || (CONFIG_MTDRAM_TOTAL_SIZE != 0) || (CONFIG_MTDRAM_ABS_POS != 0)
		/* No use trying to boot this kernel from RAM. Panic! */
		printk(KERN_EMERG "axisflashmap: Cannot create an MTD RAM "
		       "device due to kernel (mis)configuration!\n");
		panic("This kernel cannot boot from RAM!\n");
#else
		struct mtd_info *mtd_ram;

		mtd_ram = (struct mtd_info *)kmalloc(sizeof(struct mtd_info),
						     GFP_KERNEL);
		if (!mtd_ram) {
			panic("axisflashmap couldn't allocate memory for "
			      "mtd_info!\n");
		}

		printk(KERN_INFO " Adding RAM partition for romfs image:\n");
		printk(pmsg, pidx, romfs_start, romfs_length);

		err = mtdram_init_device(mtd_ram, (void*)romfs_start,
		                         romfs_length, "romfs");
		if (err) {
			panic("axisflashmap could not initialize MTD RAM "
			      "device!\n");
		}
#endif
	}

	return err;
}
Esempio n. 9
0
static int __init init_axis_flash(void)
{
	struct mtd_info *mymtd;
	int err = 0;
	int pidx = 0;
	struct partitiontable_head *ptable_head = NULL;
	struct partitiontable_entry *ptable;
	int use_default_ptable = 1; 
	const char pmsg[] = "  /dev/flash%d at 0x%08x, size 0x%08x\n";

	if (!(mymtd = flash_probe())) {
		printk(KERN_INFO "axisflashmap: Found no flash chip.\n");
	} else {
		printk(KERN_INFO "%s: 0x%08x bytes of flash memory.\n",
		       mymtd->name, mymtd->size);
		axisflash_mtd = mymtd;
	}

	if (mymtd) {
		mymtd->owner = THIS_MODULE;
		ptable_head = (struct partitiontable_head *)(FLASH_CACHED_ADDR +
			      CONFIG_ETRAX_PTABLE_SECTOR +
			      PARTITION_TABLE_OFFSET);
	}
	pidx++;  

	if (ptable_head && (ptable_head->magic == PARTITION_TABLE_MAGIC)
	    && (ptable_head->size <
		(MAX_PARTITIONS * sizeof(struct partitiontable_entry) +
		PARTITIONTABLE_END_MARKER_SIZE))
	    && (*(unsigned long*)((void*)ptable_head + sizeof(*ptable_head) +
				  ptable_head->size -
				  PARTITIONTABLE_END_MARKER_SIZE)
		== PARTITIONTABLE_END_MARKER)) {
		int ptable_ok = 0;
		struct partitiontable_entry *max_addr =
			(struct partitiontable_entry *)
			((unsigned long)ptable_head + sizeof(*ptable_head) +
			 ptable_head->size);
		unsigned long offset = CONFIG_ETRAX_PTABLE_SECTOR;
		unsigned char *p;
		unsigned long csum = 0;

		ptable = (struct partitiontable_entry *)
			((unsigned long)ptable_head + sizeof(*ptable_head));

		
		p = (unsigned char*) ptable;

		while (p <= (unsigned char*)max_addr) {
			csum += *p++;
			csum += *p++;
			csum += *p++;
			csum += *p++;
		}
		ptable_ok = (csum == ptable_head->checksum);

		
		printk(KERN_INFO " Found a%s partition table at 0x%p-0x%p.\n",
		       (ptable_ok ? " valid" : "n invalid"), ptable_head,
		       max_addr);

		while (ptable_ok
		       && ptable->offset != 0xffffffff
		       && ptable < max_addr
		       && pidx < MAX_PARTITIONS) {

			axis_partitions[pidx].offset = offset + ptable->offset;
			axis_partitions[pidx].size = ptable->size;

			printk(pmsg, pidx, axis_partitions[pidx].offset,
			       axis_partitions[pidx].size);
			pidx++;
			ptable++;
		}
		use_default_ptable = !ptable_ok;
	}

	if (romfs_in_flash) {
		

		axis_partitions[pidx].name = "romfs";
		axis_partitions[pidx].size = romfs_length;
		axis_partitions[pidx].offset = romfs_start - FLASH_CACHED_ADDR;
		axis_partitions[pidx].mask_flags |= MTD_WRITEABLE;

		printk(KERN_INFO
                       " Adding readonly flash partition for romfs image:\n");
		printk(pmsg, pidx, axis_partitions[pidx].offset,
		       axis_partitions[pidx].size);
		pidx++;
	}

#ifdef CONFIG_ETRAX_AXISFLASHMAP_MTD0WHOLE
	if (mymtd) {
		main_partition.size = mymtd->size;
		err = mtd_device_register(mymtd, &main_partition, 1);
		if (err)
			panic("axisflashmap: Could not initialize "
			      "partition for whole main mtd device!\n");
	}
#endif

        if (mymtd) {
		if (use_default_ptable) {
			printk(KERN_INFO " Using default partition table.\n");
			err = mtd_device_register(mymtd,
						  axis_default_partitions,
						  NUM_DEFAULT_PARTITIONS);
		} else {
			err = mtd_device_register(mymtd, axis_partitions,
						  pidx);
		}

		if (err)
			panic("axisflashmap could not add MTD partitions!\n");
	}

	if (!romfs_in_flash) {
		

#if !defined(CONFIG_MTD_MTDRAM) || (CONFIG_MTDRAM_TOTAL_SIZE != 0) || (CONFIG_MTDRAM_ABS_POS != 0)
		
		printk(KERN_EMERG "axisflashmap: Cannot create an MTD RAM "
		       "device due to kernel (mis)configuration!\n");
		panic("This kernel cannot boot from RAM!\n");
#else
		struct mtd_info *mtd_ram;

		mtd_ram = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
		if (!mtd_ram)
			panic("axisflashmap couldn't allocate memory for "
			      "mtd_info!\n");

		printk(KERN_INFO " Adding RAM partition for romfs image:\n");
		printk(pmsg, pidx, (unsigned)romfs_start,
			(unsigned)romfs_length);

		err = mtdram_init_device(mtd_ram,
			(void *)romfs_start,
			romfs_length,
			"romfs");
		if (err)
			panic("axisflashmap could not initialize MTD RAM "
			      "device!\n");
#endif
	}
	return err;
}
Esempio n. 10
0
static int __init init_axis_flash(void)
{
	struct mtd_info *main_mtd;
	struct mtd_info *aux_mtd = NULL;
	int err = 0;
	int pidx = 0;
	struct partitiontable_head *ptable_head = NULL;
	struct partitiontable_entry *ptable;
	int ptable_ok = 0;
	static char page[PAGESIZE];
	size_t len;
	int ram_rootfs_partition = -1; 
	int part;

#if !defined(CONFIG_MTD_MTDRAM) || (CONFIG_MTDRAM_TOTAL_SIZE != 0) || (CONFIG_MTDRAM_ABS_POS != 0)
	if (!romfs_in_flash && !nand_boot) {
		printk(KERN_EMERG "axisflashmap: Cannot create an MTD RAM "
		       "device; configure CONFIG_MTD_MTDRAM with size = 0!\n");
		panic("This kernel cannot boot from RAM!\n");
	}
#endif

#ifndef CONFIG_ETRAX_VCS_SIM
	main_mtd = flash_probe();
	if (main_mtd)
		printk(KERN_INFO "%s: 0x%08x bytes of NOR flash memory.\n",
		       main_mtd->name, main_mtd->size);

#ifdef CONFIG_ETRAX_NANDFLASH
	aux_mtd = crisv32_nand_flash_probe();
	if (aux_mtd)
		printk(KERN_INFO "%s: 0x%08x bytes of NAND flash memory.\n",
			aux_mtd->name, aux_mtd->size);

#ifdef CONFIG_ETRAX_NANDBOOT
	{
		struct mtd_info *tmp_mtd;

		printk(KERN_INFO "axisflashmap: Set to boot from NAND flash, "
		       "making NAND flash primary device.\n");
		tmp_mtd = main_mtd;
		main_mtd = aux_mtd;
		aux_mtd = tmp_mtd;
	}
#endif 
#endif 

	if (!main_mtd && !aux_mtd) {
		printk(KERN_INFO "axisflashmap: Found no flash chip.\n");
	}

#if 0 
	if (main_mtd) {
		int sectoraddr, i;
		for (sectoraddr = 0; sectoraddr < 2*65536+4096;
				sectoraddr += PAGESIZE) {
			main_mtd->read(main_mtd, sectoraddr, PAGESIZE, &len,
				page);
			printk(KERN_INFO
			       "Sector at %d (length %d):\n",
			       sectoraddr, len);
			for (i = 0; i < PAGESIZE; i += 16) {
				printk(KERN_INFO
				       "%02x %02x %02x %02x "
				       "%02x %02x %02x %02x "
				       "%02x %02x %02x %02x "
				       "%02x %02x %02x %02x\n",
				       page[i] & 255, page[i+1] & 255,
				       page[i+2] & 255, page[i+3] & 255,
				       page[i+4] & 255, page[i+5] & 255,
				       page[i+6] & 255, page[i+7] & 255,
				       page[i+8] & 255, page[i+9] & 255,
				       page[i+10] & 255, page[i+11] & 255,
				       page[i+12] & 255, page[i+13] & 255,
				       page[i+14] & 255, page[i+15] & 255);
			}
		}
	}
#endif

	if (main_mtd) {
		main_mtd->owner = THIS_MODULE;
		axisflash_mtd = main_mtd;

		loff_t ptable_sector = CONFIG_ETRAX_PTABLE_SECTOR;

		
		pidx++;
#ifdef CONFIG_ETRAX_NANDBOOT
		int blockstat;
		do {
			blockstat = mtd_block_isbad(main_mtd, ptable_sector);
			if (blockstat < 0)
				ptable_sector = 0; 
			else if (blockstat)
				ptable_sector += main_mtd->erasesize;
		} while (blockstat && ptable_sector);
#endif
		if (ptable_sector) {
			mtd_read(main_mtd, ptable_sector, PAGESIZE, &len,
				 page);
			ptable_head = &((struct partitiontable *) page)->head;
		}

#if 0 
		printk(KERN_INFO
		       "axisflashmap: flash read %d bytes at 0x%08x, data: "
		       "%02x %02x %02x %02x %02x %02x %02x %02x\n",
		       len, CONFIG_ETRAX_PTABLE_SECTOR,
		       page[0] & 255, page[1] & 255,
		       page[2] & 255, page[3] & 255,
		       page[4] & 255, page[5] & 255,
		       page[6] & 255, page[7] & 255);
		printk(KERN_INFO
		       "axisflashmap: partition table offset %d, data: "
		       "%02x %02x %02x %02x %02x %02x %02x %02x\n",
		       PARTITION_TABLE_OFFSET,
		       page[PARTITION_TABLE_OFFSET+0] & 255,
		       page[PARTITION_TABLE_OFFSET+1] & 255,
		       page[PARTITION_TABLE_OFFSET+2] & 255,
		       page[PARTITION_TABLE_OFFSET+3] & 255,
		       page[PARTITION_TABLE_OFFSET+4] & 255,
		       page[PARTITION_TABLE_OFFSET+5] & 255,
		       page[PARTITION_TABLE_OFFSET+6] & 255,
		       page[PARTITION_TABLE_OFFSET+7] & 255);
#endif
	}

	if (ptable_head && (ptable_head->magic == PARTITION_TABLE_MAGIC)
	    && (ptable_head->size <
		(MAX_PARTITIONS * sizeof(struct partitiontable_entry) +
		PARTITIONTABLE_END_MARKER_SIZE))
	    && (*(unsigned long*)((void*)ptable_head + sizeof(*ptable_head) +
				  ptable_head->size -
				  PARTITIONTABLE_END_MARKER_SIZE)
		== PARTITIONTABLE_END_MARKER)) {
		struct partitiontable_entry *max_addr =
			(struct partitiontable_entry *)
			((unsigned long)ptable_head + sizeof(*ptable_head) +
			 ptable_head->size);
		unsigned long offset = CONFIG_ETRAX_PTABLE_SECTOR;
		unsigned char *p;
		unsigned long csum = 0;

		ptable = (struct partitiontable_entry *)
			((unsigned long)ptable_head + sizeof(*ptable_head));

		
		p = (unsigned char*) ptable;

		while (p <= (unsigned char*)max_addr) {
			csum += *p++;
			csum += *p++;
			csum += *p++;
			csum += *p++;
		}
		ptable_ok = (csum == ptable_head->checksum);

		
		printk(KERN_INFO "axisflashmap: "
		       "Found a%s partition table at 0x%p-0x%p.\n",
		       (ptable_ok ? " valid" : "n invalid"), ptable_head,
		       max_addr);

		while (ptable_ok
		       && ptable->offset != PARTITIONTABLE_END_MARKER
		       && ptable < max_addr
		       && pidx < MAX_PARTITIONS - 1) {

			axis_partitions[pidx].offset = offset + ptable->offset;
#ifdef CONFIG_ETRAX_NANDFLASH
			if (main_mtd->type == MTD_NANDFLASH) {
				axis_partitions[pidx].size =
					(((ptable+1)->offset ==
					  PARTITIONTABLE_END_MARKER) ?
					  main_mtd->size :
					  ((ptable+1)->offset + offset)) -
					(ptable->offset + offset);

			} else
#endif 
				axis_partitions[pidx].size = ptable->size;
#ifdef CONFIG_ETRAX_NANDBOOT
			if (!nand_boot &&
			    ram_rootfs_partition < 0 && 
			    ptable->type == PARTITION_TYPE_JFFS2 &&
			    (ptable->flags & PARTITION_FLAGS_READONLY_MASK) ==
				PARTITION_FLAGS_READONLY)
				ram_rootfs_partition = pidx;
#endif 
			pidx++;
			ptable++;
		}
	}

	
	

	struct mtd_partition *partition = &axis_partitions[0];
	if (main_mtd && !ptable_ok) {
		memcpy(axis_partitions, axis_default_partitions,
		       sizeof(axis_default_partitions));
		pidx = NUM_DEFAULT_PARTITIONS;
		ram_rootfs_partition = DEFAULT_ROOTFS_PARTITION_NO;
	}

	
	if (romfs_in_flash) {
		printk(KERN_INFO "axisflashmap: Adding partition for "
		       "overlapping root file system image\n");
		axis_partitions[pidx].size = romfs_length;
		axis_partitions[pidx].offset = romfs_start - FLASH_CACHED_ADDR;
		axis_partitions[pidx].name = "romfs";
		axis_partitions[pidx].mask_flags |= MTD_WRITEABLE;
		ram_rootfs_partition = -1;
		pidx++;
	} else if (romfs_length && !nand_boot) {
		if (ram_rootfs_partition < 0) {
			
			ram_rootfs_partition = pidx;
			pidx++;
		}
		printk(KERN_INFO "axisflashmap: Adding partition for "
		       "root file system image in RAM\n");
		axis_partitions[ram_rootfs_partition].size = romfs_length;
		axis_partitions[ram_rootfs_partition].offset = romfs_start;
		axis_partitions[ram_rootfs_partition].name = "romfs";
		axis_partitions[ram_rootfs_partition].mask_flags |=
			MTD_WRITEABLE;
	}

#ifdef CONFIG_ETRAX_AXISFLASHMAP_MTD0WHOLE
	if (main_mtd) {
		main_partition.size = main_mtd->size;
		err = mtd_device_register(main_mtd, &main_partition, 1);
		if (err)
			panic("axisflashmap: Could not initialize "
			      "partition for whole main mtd device!\n");
	}
#endif


	for (part = 0; part < pidx; part++) {
		if (part == ram_rootfs_partition) {
			
			struct mtd_info *mtd_ram;

			mtd_ram = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
			if (!mtd_ram)
				panic("axisflashmap: Couldn't allocate memory "
				      "for mtd_info!\n");
			printk(KERN_INFO "axisflashmap: Adding RAM partition "
			       "for rootfs image.\n");
			err = mtdram_init_device(mtd_ram,
						 (void *)partition[part].offset,
						 partition[part].size,
						 partition[part].name);
			if (err)
				panic("axisflashmap: Could not initialize "
				      "MTD RAM device!\n");
			mtd_ram->erasesize = (main_mtd ? main_mtd->erasesize :
				CONFIG_ETRAX_PTABLE_SECTOR);
		} else {
			err = mtd_device_register(main_mtd, &partition[part],
						  1);
			if (err)
				panic("axisflashmap: Could not add mtd "
					"partition %d\n", part);
		}
	}
#endif 

#ifdef CONFIG_ETRAX_VCS_SIM
	struct mtd_info *mtd_ram;

	mtd_ram = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
	if (!mtd_ram) {
		panic("axisflashmap: Couldn't allocate memory for "
		      "mtd_info!\n");
	}

	printk(KERN_INFO "axisflashmap: Adding RAM partition for romfs, "
	       "at %u, size %u\n",
	       (unsigned) romfs_start, (unsigned) romfs_length);

	err = mtdram_init_device(mtd_ram, (void *)romfs_start,
				 romfs_length, "romfs");
	if (err) {
		panic("axisflashmap: Could not initialize MTD RAM "
		      "device!\n");
	}
#endif 

#ifndef CONFIG_ETRAX_VCS_SIM
	if (aux_mtd) {
		aux_partition.size = aux_mtd->size;
		err = mtd_device_register(aux_mtd, &aux_partition, 1);
		if (err)
			panic("axisflashmap: Could not initialize "
			      "aux mtd device!\n");

	}
#endif 

	return err;
}