Norflash driver Implementation Analysis of uclinux2.6 (bf561) (9): Driver usage

Source: Internet
Author: User

At the end of the norflash driver load, there are several statements: If (ezkit561_mtd) {ezkit561_mtd-> owner = this_module; return handler (ezkit561_mtd, ezkit561_parts, ezkit561_part_count );} use add_mtd_partitions (Drivers/MTD/mtdpart. c) The function can add corresponding partitions to the partition table of the system. In this way, when you need to read and write the partitions, you can find the corresponding MTD and call its function to complete the corresponding operations. /** This function, given a master MTD object and a partition table, creates * and registers slave MTD objects which are bound to the master according to * The partition definitions. * (Q: shocould we register the master MTD object as well ?) */INT add_mtd_partitions (struct mtd_info * master, const struct mtd_partition * parts, int nbparts) {struct mtd_part * slave; u_int32_t cur_offset = 0; int I; printk (kern_notice "creating % d MTD partitions on/" % S/":/N", nbparts, master-> name); for (I = 0; I <nbparts; I ++) {/* allocate the partition structure */Slave = kmalloc (sizeof (* slave), gfp_kernel); If (! Slave) {printk ("Memory Allocation Error while creating partitions for/" % S/"/N", master-> name); del_mtd_partitions (master); Return-enomem ;} memset (slave, 0, sizeof (* slave);/* Add to partition list, however, the mtd_partitions linked list only deletes the allocated struct when the slave allocation fails. It does not affect other parts of the system! */List_add (& slave-> list, & mtd_partitions);/* set up the MTD object for this partition */slave-> MTD. type = Master-> type ;... If (parts [I]. MTDP) {/* store the Object Pointer (caller may or may not register it */* parts [I]. MTDP = & slave-> MTD; slave-> registered = 0;} else {/* register our partition */add_mtd_device (& slave-> MTD ); slave-> registered = 1 ;}} return 0 ;}at the end of the function, you can use add_mtd_device to add an MTD struct to the pointer array of mtd_table, in this way, you can see/dev/mtdblock0,/dev/mtdblock1 ,... This is a device. Because it is an array, the largest array element # define max_mtd_devices 16 is defined in the system, so it is only mtdblock15 at most.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.