source: trunk/target/linux/generic/patches-2.6.37/400-rootfs_split.patch @ 27007

Last change on this file since 27007 was 27007, checked in by florian, 6 years ago

[kernel] fix mtd warnings

Fixes for the following warnings:

drivers/mtd/devices/block2mtd.c: In function '_open_bdev':
drivers/mtd/devices/block2mtd.c:272:3: warning: ISO C90 forbids mixed declarations and code
drivers/mtd/devices/block2mtd.c: In function 'add_device':
drivers/mtd/devices/block2mtd.c:399:13: warning: assignment discards qualifiers from pointer target type

In the case of 442-block2mtd_probe.patch, it's not until the insertion of a executable statement before the definition that causes a warning, so I've chosen to resolve the issue here by splitting the definition and the initialization into a definition and a statement (and assignment) instead.

Signed-off-by: Philip Prindeville <philipp@…>

File size: 9.1 KB
  • drivers/mtd/Kconfig

    a b config MTD_PARTITIONS 
    5353          devices. Partitioning on NFTL 'devices' is a different - that's the 
    5454          'normal' form of partitioning used on a block device. 
    5555 
     56config MTD_ROOTFS_ROOT_DEV 
     57        bool "Automatically set 'rootfs' partition to be root filesystem" 
     58        depends on MTD_PARTITIONS 
     59        default y 
     60 
     61config MTD_ROOTFS_SPLIT 
     62        bool "Automatically split 'rootfs' partition for squashfs" 
     63        depends on MTD_PARTITIONS 
     64        default y 
     65 
    5666config MTD_REDBOOT_PARTS 
    5767        tristate "RedBoot partition table parsing" 
    5868        depends on MTD_PARTITIONS 
  • drivers/mtd/mtdpart.c

    a b  
    2929#include <linux/kmod.h> 
    3030#include <linux/mtd/mtd.h> 
    3131#include <linux/mtd/partitions.h> 
     32#include <linux/root_dev.h> 
     33#include <linux/magic.h> 
    3234#include <linux/err.h> 
    3335 
    3436/* Our partition linked list */ 
    struct mtd_part { 
    4850 * the pointer to that structure with this macro. 
    4951 */ 
    5052#define PART(x)  ((struct mtd_part *)(x)) 
    51  
     53#define IS_PART(mtd) (mtd->read == part_read) 
    5254 
    5355/* 
    5456 * MTD methods which simply translate the effective address and pass through 
    int mtd_del_partition(struct mtd_info *m 
    618620} 
    619621EXPORT_SYMBOL_GPL(mtd_del_partition); 
    620622 
     623#ifdef CONFIG_MTD_ROOTFS_SPLIT 
     624#define ROOTFS_SPLIT_NAME "rootfs_data" 
     625#define ROOTFS_REMOVED_NAME "<removed>" 
     626 
     627struct squashfs_super_block { 
     628        __le32 s_magic; 
     629        __le32 pad0[9]; 
     630        __le64 bytes_used; 
     631}; 
     632 
     633 
     634static int split_squashfs(struct mtd_info *master, int offset, int *split_offset) 
     635{ 
     636        struct squashfs_super_block sb; 
     637        int len, ret; 
     638 
     639        ret = master->read(master, offset, sizeof(sb), &len, (void *) &sb); 
     640        if (ret || (len != sizeof(sb))) { 
     641                printk(KERN_ALERT "split_squashfs: error occured while reading " 
     642                        "from \"%s\"\n", master->name); 
     643                return -EINVAL; 
     644        } 
     645 
     646        if (SQUASHFS_MAGIC != le32_to_cpu(sb.s_magic) ) { 
     647                printk(KERN_ALERT "split_squashfs: no squashfs found in \"%s\"\n", 
     648                        master->name); 
     649                *split_offset = 0; 
     650                return 0; 
     651        } 
     652 
     653        if (le64_to_cpu((sb.bytes_used)) <= 0) { 
     654                printk(KERN_ALERT "split_squashfs: squashfs is empty in \"%s\"\n", 
     655                        master->name); 
     656                *split_offset = 0; 
     657                return 0; 
     658        } 
     659 
     660        len = (u32) le64_to_cpu(sb.bytes_used); 
     661        len += (offset & 0x000fffff); 
     662        len +=  (master->erasesize - 1); 
     663        len &= ~(master->erasesize - 1); 
     664        len -= (offset & 0x000fffff); 
     665        *split_offset = offset + len; 
     666 
     667        return 0; 
     668} 
     669 
     670static int split_rootfs_data(struct mtd_info *master, struct mtd_info *rpart, const struct mtd_partition *part) 
     671{ 
     672        struct mtd_partition *dpart; 
     673        struct mtd_part *slave = NULL; 
     674        struct mtd_part *spart; 
     675        int ret, split_offset = 0; 
     676 
     677        spart = PART(rpart); 
     678        ret = split_squashfs(master, spart->offset, &split_offset); 
     679        if (ret) 
     680                return ret; 
     681 
     682        if (split_offset <= 0) 
     683                return 0; 
     684 
     685        dpart = kmalloc(sizeof(*part)+sizeof(ROOTFS_SPLIT_NAME)+1, GFP_KERNEL); 
     686        if (dpart == NULL) { 
     687                printk(KERN_INFO "split_squashfs: no memory for partition \"%s\"\n", 
     688                        ROOTFS_SPLIT_NAME); 
     689                return -ENOMEM; 
     690        } 
     691 
     692        memcpy(dpart, part, sizeof(*part)); 
     693        strcpy((char *)&dpart[1], ROOTFS_SPLIT_NAME); 
     694        dpart->name = (unsigned char *)&dpart[1]; 
     695 
     696        dpart->size = rpart->size - (split_offset - spart->offset); 
     697        dpart->offset = split_offset; 
     698 
     699        if (dpart == NULL) 
     700                return 1; 
     701 
     702        printk(KERN_INFO "mtd: partition \"%s\" created automatically, ofs=%llX, len=%llX \n", 
     703                ROOTFS_SPLIT_NAME, dpart->offset, dpart->size); 
     704 
     705        slave = allocate_partition(master, dpart, 0, split_offset); 
     706        if (IS_ERR(slave)) 
     707                return PTR_ERR(slave); 
     708        mutex_lock(&mtd_partitions_mutex); 
     709        list_add(&slave->list, &mtd_partitions); 
     710        mutex_unlock(&mtd_partitions_mutex); 
     711 
     712        add_mtd_device(&slave->mtd); 
     713 
     714        rpart->split = &slave->mtd; 
     715 
     716        return 0; 
     717} 
     718 
     719static int refresh_rootfs_split(struct mtd_info *mtd) 
     720{ 
     721        struct mtd_partition tpart; 
     722        struct mtd_part *part; 
     723        char *name; 
     724        //int index = 0; 
     725        int offset, size; 
     726        int ret; 
     727 
     728        part = PART(mtd); 
     729 
     730        /* check for the new squashfs offset first */ 
     731        ret = split_squashfs(part->master, part->offset, &offset); 
     732        if (ret) 
     733                return ret; 
     734 
     735        if ((offset > 0) && !mtd->split) { 
     736                printk(KERN_INFO "%s: creating new split partition for \"%s\"\n", __func__, mtd->name); 
     737                /* if we don't have a rootfs split partition, create a new one */ 
     738                tpart.name = (char *) mtd->name; 
     739                tpart.size = mtd->size; 
     740                tpart.offset = part->offset; 
     741 
     742                return split_rootfs_data(part->master, &part->mtd, &tpart); 
     743        } else if ((offset > 0) && mtd->split) { 
     744                /* update the offsets of the existing partition */ 
     745                size = mtd->size + part->offset - offset; 
     746 
     747                part = PART(mtd->split); 
     748                part->offset = offset; 
     749                part->mtd.size = size; 
     750                printk(KERN_INFO "%s: %s partition \"" ROOTFS_SPLIT_NAME "\", offset: 0x%06x (0x%06x)\n", 
     751                        __func__, (!strcmp(part->mtd.name, ROOTFS_SPLIT_NAME) ? "updating" : "creating"), 
     752                        (u32) part->offset, (u32) part->mtd.size); 
     753                name = kmalloc(sizeof(ROOTFS_SPLIT_NAME) + 1, GFP_KERNEL); 
     754                strcpy(name, ROOTFS_SPLIT_NAME); 
     755                part->mtd.name = name; 
     756        } else if ((offset <= 0) && mtd->split) { 
     757                printk(KERN_INFO "%s: removing partition \"%s\"\n", __func__, mtd->split->name); 
     758 
     759                /* mark existing partition as removed */ 
     760                part = PART(mtd->split); 
     761                name = kmalloc(sizeof(ROOTFS_SPLIT_NAME) + 1, GFP_KERNEL); 
     762                strcpy(name, ROOTFS_REMOVED_NAME); 
     763                part->mtd.name = name; 
     764                part->offset = 0; 
     765                part->mtd.size = 0; 
     766        } 
     767 
     768        return 0; 
     769} 
     770#endif /* CONFIG_MTD_ROOTFS_SPLIT */ 
     771 
    621772/* 
    622773 * This function, given a master MTD object and a partition table, creates 
    623774 * and registers slave MTD objects which are bound to the master according to 
    int add_mtd_partitions(struct mtd_info * 
    633784{ 
    634785        struct mtd_part *slave; 
    635786        uint64_t cur_offset = 0; 
    636         int i; 
     787        int i, ret; 
    637788 
    638789        printk(KERN_NOTICE "Creating %d MTD partitions on \"%s\":\n", nbparts, master->name); 
    639790 
    int add_mtd_partitions(struct mtd_info * 
    648799 
    649800                add_mtd_device(&slave->mtd); 
    650801 
     802                if (!strcmp(parts[i].name, "rootfs")) { 
     803#ifdef CONFIG_MTD_ROOTFS_ROOT_DEV 
     804                        if (ROOT_DEV == 0) { 
     805                                printk(KERN_NOTICE "mtd: partition \"rootfs\" " 
     806                                        "set to be root filesystem\n"); 
     807                                ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, slave->mtd.index); 
     808                        } 
     809#endif 
     810#ifdef CONFIG_MTD_ROOTFS_SPLIT 
     811                        ret = split_rootfs_data(master, &slave->mtd, &parts[i]); 
     812                        /* if (ret == 0) 
     813                         *      j++; */ 
     814#endif 
     815                } 
     816 
    651817                cur_offset = slave->offset + slave->mtd.size; 
    652818        } 
    653819 
    int add_mtd_partitions(struct mtd_info * 
    655821} 
    656822EXPORT_SYMBOL(add_mtd_partitions); 
    657823 
     824int refresh_mtd_partitions(struct mtd_info *mtd) 
     825{ 
     826        int ret = 0; 
     827 
     828        if (IS_PART(mtd)) { 
     829                struct mtd_part *part; 
     830                struct mtd_info *master; 
     831 
     832                part = PART(mtd); 
     833                master = part->master; 
     834                if (master->refresh_device) 
     835                        ret = master->refresh_device(master); 
     836        } 
     837 
     838        if (!ret && mtd->refresh_device) 
     839                ret = mtd->refresh_device(mtd); 
     840 
     841#ifdef CONFIG_MTD_ROOTFS_SPLIT 
     842        if (!ret && IS_PART(mtd) && !strcmp(mtd->name, "rootfs")) 
     843                refresh_rootfs_split(mtd); 
     844#endif 
     845 
     846        return 0; 
     847} 
     848EXPORT_SYMBOL_GPL(refresh_mtd_partitions); 
     849 
    658850static DEFINE_SPINLOCK(part_parser_lock); 
    659851static LIST_HEAD(part_parsers); 
    660852 
  • drivers/mtd/mtdchar.c

    a b static int mtd_ioctl(struct file *file, 
    841841                file->f_pos = 0; 
    842842                break; 
    843843        } 
     844#ifdef CONFIG_MTD_PARTITIONS 
     845        case MTDREFRESH: 
     846        { 
     847                ret = refresh_mtd_partitions(mtd); 
     848                break; 
     849        } 
     850#endif 
    844851 
    845852        case OTPGETREGIONCOUNT: 
    846853        case OTPGETREGIONINFO: 
  • include/linux/mtd/mtd.h

    a b struct nand_ecclayout { 
    125125        struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES_LARGE]; 
    126126}; 
    127127 
     128struct mtd_info; 
    128129struct mtd_info { 
    129130        u_char type; 
    130131        uint32_t flags; 
    struct mtd_info { 
    266267        struct device dev; 
    267268        int usecount; 
    268269 
     270        int (*refresh_device)(struct mtd_info *mtd); 
     271        struct mtd_info *split; 
     272 
    269273        /* If the driver is something smart, like UBI, it may need to maintain 
    270274         * its own reference counting. The below functions are only for driver. 
    271275         * The driver may register its callbacks. These callbacks are not 
  • include/linux/mtd/partitions.h

    a b  
    3434 * erasesize aligned (e.g. use MTDPART_OFS_NEXTBLK). 
    3535 */ 
    3636 
     37struct mtd_partition; 
    3738struct mtd_partition { 
    38         char *name;                     /* identifier string */ 
     39        const char *name;               /* identifier string */ 
    3940        uint64_t size;                  /* partition size */ 
    4041        uint64_t offset;                /* offset within the master MTD space */ 
    4142        uint32_t mask_flags;            /* master MTD flags to mask out for this partition */ 
    4243        struct nand_ecclayout *ecclayout;       /* out of band layout for this partition (NAND only) */ 
     44        int (*refresh_partition)(struct mtd_info *); 
    4345}; 
    4446 
    4547#define MTDPART_OFS_NXTBLK      (-2) 
    struct mtd_info; 
    5153 
    5254int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int); 
    5355int del_mtd_partitions(struct mtd_info *); 
     56int refresh_mtd_partitions(struct mtd_info *); 
    5457 
    5558/* 
    5659 * Functions dealing with the various ways of partitioning the space 
  • include/mtd/mtd-abi.h

    a b struct otp_info { 
    127127#define MEMWRITEOOB64           _IOWR('M', 21, struct mtd_oob_buf64) 
    128128#define MEMREADOOB64            _IOWR('M', 22, struct mtd_oob_buf64) 
    129129#define MEMISLOCKED             _IOR('M', 23, struct erase_info_user) 
     130#define MTDREFRESH              _IO('M', 23) 
    130131 
    131132/* 
    132133 * Obsolete legacy interface. Keep it in order not to break userspace 
Note: See TracBrowser for help on using the repository browser.