10 Replies Latest reply on Jul 24, 2019 7:20 AM by GernotH_31

    write partition(s) to F-RAM fm25v01a-g

    ArRi_4326921

      Hello folks,

       

      I am currently working on an embedded linux module based on Raspbian mounting on-board the F-RAM in the object :

       

      https://www.cypress.com/part/fm25v01a-g

       

      So as suggested here :

       

      F-RAM Support under Linux – KBA223028

       

      and here :

       

      where can I find FM25V02 FRAM Linux Driver

       

      I place this entry for the FRAM in the spi-nor.c source file of my kernel

      { "fm25v01a",  INFO(0x7f7f7f, 0, 16, 1024, 0) },

      since the overall size of the memory is 16K. So, after cross-building the module and reloading at the next boot, I am able to the device with

      $ cat /proc/mtd

      dev:    size erasesize  name

      mtd0: 00080000 00000200 "spi0.1"

      so the next step I try is to use fdisk to create a partition as usual (my choice of filesystem type is FAT12) but when i try to write the changes I can't simply do it...any pointers for that ?

       

      $ fdisk /dev/mtd0   

       

      Welcome to fdisk (util-linux 2.29.2).

      Changes will remain in memory only, until you decide to write them.

      Be careful before using the write command.

       

      Device does not contain a recognized partition table.

      Created a new DOS disklabel with disk identifier 0x5638c96c.

       

      Command (m for help): p

      Disk /dev/mtd0: 0 B, 0 bytes, 0 sectors

      Units: sectors of 1 * 512 = 512 bytes

      Sector size (logical/physical): 512 bytes / 512 bytes

      I/O size (minimum/optimal): 512 bytes / 512 bytes

      Disklabel type: dos

      Disk identifier: 0x5638c96c

       

      Command (m for help): n

      Partition type

         p   primary (0 primary, 0 extended, 4 free)

         e   extended (container for logical partitions)

      Select (default p): p

      Partition number (1-4, default 1):

      First sector (1-4294967295, default 1):

      Last sector, +sectors or +size{K,M,G,T,P} (1-4294967294, default 4294967294): +5K

       

      Created a new partition 1 of type 'Linux' and of size 5.5 KiB.

       

      Command (m for help): t

      Selected partition 1

      Partition type (type L to list all types): 1

      Changed type of partition 'Linux' to 'FAT12'.

       

      Command (m for help): w

      The partition table has been altered.

      /dev/mtd0: close device failed: Invalid argument

       

      thanks in advance !

       

                 Arturo

        • 1. Re: write partition(s) to F-RAM fm25v01a-g
          GernotH_31

          Hi Arturo,

           

          you cannot partition a mtd with fdisk like you do with a hard disk, this is not supported. However, what you can do is, you can define mtd partitions as usual and then run a FAT on just one mtd partition.

           

          It is preferable to define the F-RAM sector layout with 512 bytes sectors. This way it nicely corresponds to the usual 512 bytes sectors of disks. Then you can run a FAT as follows.

           

          Best regards,

          Gernot

           

          # cat /proc/mtd

          dev: size   erasesize  name

          mtd0: 00080000 00000200 "spi0.0"

          # mkfs.vfat /dev/mtdblock0

          mkfs.fat 3.0.28 (2015-05-16)

          unable to get drive geometry, using default 255/63

          # mount -t vfat /dev/mtdblock0 /tt

          # echo "Hello world!" > /tt/hello.txt

          # umount /tt

          # mount -t vfat /dev/mtdblock0 /tt

          # ls -l /tt

          total 2

          -rwxr-xr-x 1 root root 13 Feb  5 11:13 hello.txt

          • 2. Re: write partition(s) to F-RAM fm25v01a-g
            ArRi_4326921

            Hello Gernot,

             

             

            I just run this command :

             

            # mkfs.vfat /dev/mtd0  

            mkfs.fat 4.1 (2017-01-24)

            mkfs.vfat: unable to discover size of /dev/mtd0

            since in my case the device is /dev/mtd0 but I get that message error, any pointers ?

             

            # ls -l /dev/ | grep mtd

            crw------- 1 root root     90,   0 Jun 28 10:51 mtd0

            crw------- 1 root root     90,   1 Jun 28 10:51 mtd0ro

             

            this are just the mounted devices belonging to the mtd group.

             

                       Kind Regards

            • 3. Re: write partition(s) to F-RAM fm25v01a-g
              GernotH_31

              Hi Arturo,

               

              you need to enable the mtdblock driver in the kernel configuration menu. Afterwards, you should get both /dev/mtdx character devices and /dev/mtdblockx block devices.

               

              Best regards,

              Gernot

              • 4. Re: write partition(s) to F-RAM fm25v01a-g
                ArRi_4326921

                I have gone further....after manually loading the mtdblock.ko kernel module finally the device /dev/mtdblock0 pops up but I am unable to format the filesytem as you suggested :

                 

                # cat /proc/mtd

                dev: size erasesize name

                mtd0: 00004000 00000010 "spi0.1"

                 

                # mkfs.vfat /dev/mtdblock0

                mkfs.fat 4.1 (2017-01-24)

                attribute "partition" not found

                mkfs.vfat: Device partition expected, not making filesystem on entire device '/dev/mtdblock0' (use -I to override)

                 

                # mkfs.vfat -I /dev/mtdblock0

                mkfs.fat 4.1 (2017-01-24)

                attribute "partition" not found

                mkfs.vfat: Attempting to create a too large filesystem

                any pointers ?

                • 5. Re: write partition(s) to F-RAM fm25v01a-g
                  GernotH_31

                  Your mtd size/erasesize does not look good. eraseisize seems to be set to 0x10=16!? Can you set the erasesize to 512 (0x200) and check again?

                  • 6. Re: write partition(s) to F-RAM fm25v01a-g
                    ArRi_4326921

                    The FRAM has an overall size of 16K, hence my spi-nor.c entry :

                     

                    https://www.cypress.com/part/fm25v01a-gload&usg=AOvVaw1S3e-YB5-BR7JEZgCLtE5Y

                     

                    more information about it

                     

                    root@aranciarty:~# mtdinfo --map /dev/mtd0

                    mtd0

                    Name:                           spi0.1

                    Type:                           nor

                    Eraseblock size:                16 bytes

                    Amount of eraseblocks:          1024 (16384 bytes, 16.0 KiB)

                    Minimum input/output unit size: 1 byte

                    Sub-page size:                  1 byte

                    Character device major/minor:   90:0

                    Bad blocks are allowed:         false

                    Device is writable:             true

                    Eraseblock map:

                    maybe declaring one of these arguments :

                     

                    #define SECT_4K BIT(0) /* SPINOR_OP_BE_4K works uniformly */

                    #define SPI_NOR_NO_ERASE BIT(1) /* No erase command needed */

                    #define SST_WRITE BIT(2) /* use SST byte programming */

                    #define SPI_NOR_NO_FR BIT(3) /* Can't do fastread */

                    #define SECT_4K_PMC BIT(4) /* SPINOR_OP_BE_4K_PMC works uniformly */

                    #define SPI_NOR_DUAL_READ BIT(5) /* Flash supports Dual Read */

                    #define SPI_NOR_QUAD_READ BIT(6) /* Flash supports Quad Read */

                    #define USE_FSR BIT(7) /* use flag status register */

                    #define SPI_NOR_HAS_LOCK BIT(8) /* Flash supports lock/unlock via SR */

                    #define SPI_NOR_HAS_TB BIT(9) /*

                    * Flash SR has Top/Bottom (TB) protect

                    * bit. Must be used with

                    * SPI_NOR_HAS_LOCK.

                    */

                    #define SPI_S3AN BIT(10) /*

                    * Xilinx Spartan 3AN In-System Flash

                    * (MFR cannot be used for probing

                    * because it has the same value as

                    * ATMEL flashes)

                    */

                    #define SPI_NOR_4B_OPCODES BIT(11) /*

                    * Use dedicated 4byte address op codes

                    * to support memory size above 128Mib.

                    */

                    #define NO_CHIP_ERASE BIT(12) /* Chip does not support chip erase */

                    #define SPI_NOR_SKIP_SFDP BIT(13) /* Skip parsing of SFDP tables */

                    #define USE_CLSR BIT(14) /* use CLSR command */

                    might solve it ?

                    • 7. Re: write partition(s) to F-RAM fm25v01a-g
                      ArRi_4326921

                      Hello GernotH,

                       

                      I rebuilt the module with this entries :

                      { "fm25v01a",  INFO(0x7f7f7f, 0, 512, 32, 0) },

                      or, as an alternative :

                      { "fm25v01a",    INFO(0x7f7f7f, 0, 512, 32, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_HAS_LOCK) },

                      so getting this output :

                      # mtdinfo -a

                      Count of MTD devices:          1

                      Present MTD devices:            mtd0

                      Sysfs interface supported:      yes

                       

                      mtd0

                      Name:                          spi0.1

                      Type:                          nor

                      Eraseblock size:                512 bytes

                      Amount of eraseblocks:          32 (16384 bytes, 16.0 KiB)

                      Minimum input/output unit size: 1 byte

                      Sub-page size:                  1 byte

                      Character device major/minor:  90:0

                      Bad blocks are allowed:        false

                      Device is writable:            true

                      but the error still persists....any idea ?

                       

                      BTW, which is your on-board FRAM and above all which are your kernel modifications ? It may help me a lot understanding the issue....

                       

                                Thanks in advance

                      • 8. Re: write partition(s) to F-RAM fm25v01a-g
                        GernotH_31

                        Another detail you need to consider is that this device requires 2 address bytes! This is different from the 3 or 4 address bytes that are usually used for flash memories in the driver. There are special macros available to specify that.

                         

                        I have ordered some parts and will take a closer look at this when I have got them. Will keep you posted!

                         

                        --Gernot

                        • 9. Re: write partition(s) to F-RAM fm25v01a-g
                          ArRi_4326921

                          Hello Gernot,

                           

                          thank you for all the effort you are putting into this issue. I have really appreciated it.....looking forward to hear back from you as soon as you move on this behaviour.

                           

                          Thank you very much again !

                           

                          --Arturo

                          • 10. Re: write partition(s) to F-RAM fm25v01a-g
                            GernotH_31

                            Hi Arturo,

                             

                            I have got samples now and checked the situation. Using the Cypress SPI memories driver (with support for 2 address bytes), I can reproduce the situation:

                             

                            # ./mkfs.vfat  /dev/mtdblock0                                                                        

                            mkfs.fat 4.1 (2017-01-24)                                                                                       

                            mkfs.vfat: Attempting to create a too large filesystem

                             

                            After analyzing the mkfs source code (mkfs.fat.c), I think the F-RAM device is too small for a FAT file system. This device has just 16 kByte, i.e. just 32 sectors of 512 bytes each. This is much less than a floppy disk had in the early days. FAT makes clusters of sectors and uses 2 FAT tables.

                             

                            So I think you will have to move to a larger F-RAM density if you want to run a FAT on the device. I might run some tests here to find out the exact limit if you want.

                             

                            Best regards,

                            Gernot