rendered paste body#include <asm/io.h>
#include <linux/init.h>
#include <linux/mtd/map.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#define WINDOW_ADDR 0xBFC00000 /* Start address of the flash */
#define REDBOOT_FIS_DIRECTORY /* Address of the RedBoot FIS directory */
#define WINDOW_SIZE 0x400000 /* Size of flash */
#define BUSWIDTH 2 /* Buswidth */
extern int boot_loader_type; /* For RedBoot / CFE detection */
extern int parse_redboot_partitions(struct mtd_info *master, struct mtd_partition **pparts, unsigned long fis_origin);
static struct mtd_partition *parsed_parts;
static void __exit bcm963xx_mtd_cleanup(void);
static struct mtd_info *bcm963xx_mtd_info;
static struct map_info bcm963xx_map = {
.name = "bcm963xx",
.size = WINDOW_SIZE,
.bankwidth = BUSWIDTH,
.phys = WINDOW_ADDR,
};
static struct mtd_partition bcm963xx_parts[] = {
{ name: "bootloader", size: 0, offset: 0, mask_flags: MTD_WRITEABLE },
{ name: "rootfs", size: 0, offset: 0},
{ name: "jffs2", size: 5 * 0x10000, offset: 57*0x10000}
};
static int __init bcm963xx_mtd_init(void)
{
printk("bcm963xx: 0x%08x at 0x%08x\n", WINDOW_SIZE, WINDOW_ADDR);
bcm963xx_map.virt = ioremap_nocache(WINDOW_ADDR, WINDOW_SIZE);
if (!bcm963xx_map.virt) {
printk("bcm963xx: Failed to ioremap\n");
return -EIO;
}
simple_map_init(&bcm963xx_map);
bcm963xx_mtd_info = do_map_probe("cfi_probe", &bcm963xx_map);
if (bcm963xx_mtd_info) {
bcm963xx_mtd_info->owner = THIS_MODULE;
int parsed_nr_parts = 0;
char * part_type;
#ifdef CONFIG_MTD_REDBOOT_PARTS
if (parsed_nr_parts == 0) {
int ret = parse_redboot_partitions(bcm963xx_mtd_info, &parsed_parts, (unsigned long)(0xBEBF0000));
if (ret > 0) {
part_type = "RedBoot";
parsed_nr_parts = ret;
}
}
#endif
add_mtd_partitions(bcm963xx_mtd_info, parsed_parts, sizeof(*parsed_parts) / sizeof(struct mtd_partition));
return 0;
}
iounmap(bcm963xx_map.virt);
return -ENXIO;
}
static void __exit bcm963xx_mtd_cleanup(void)
{
if (bcm963xx_mtd_info) {
del_mtd_partitions(bcm963xx_mtd_info);
map_destroy(bcm963xx_mtd_info);
}
if (bcm963xx_map.virt) {
iounmap(bcm963xx_map.virt);
bcm963xx_map.virt = 0;
}
}
module_init(bcm963xx_mtd_init);
module_exit(bcm963xx_mtd_cleanup);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Felix Fietkau");