Bug 8106 - mkfs.jffs2 uses the --pagesize parameter incorrectly
Summary: mkfs.jffs2 uses the --pagesize parameter incorrectly
Status: RESOLVED FIXED
Alias: None
Product: buildroot
Classification: Unclassified
Component: Other (show other bugs)
Version: 2015.02
Hardware: All All
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-15 06:24 UTC by Michał Leśniewski
Modified: 2015-05-22 09:37 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michał Leśniewski 2015-05-15 06:24:50 UTC
Buildbot is able to generate the output image in different formats, one of them is JFFS2.  The image is created as usual using the mkfs.jffs2 tool.  As the JFFS2 system is intended for use with mtd devices, the tool allows specifying the parameters of the flash memory, to which the image will be written.

Now in buildroot's config one can choose the type of flash, for which the JFFS2 image will be generated.  This are the BR2_TARGET_ROOTFS_JFFS2_NANDFLASH_* configuration variables.  Selecting one of them sets BR2_TARGET_ROOTFS_JFFS2_EBSIZE and BR2_TARGET_ROOTFS_JFFS2_PAGESIZE values.

BR2_TARGET_ROOTFS_JFFS2_EBSIZE is the erase block size.  It should match the erase block size of the flash memory that will store the image.  This value is later used as a parameter to mkfs.jffs2 (the --eraseblock option).  This one is used correctly. 

The BR2_TARGET_ROOTFS_JFFS2_PAGESIZE variable is set to the flash memory page size.  During the build it is used as the value of the --pagesize parameter for mkfs.jffs2.

It turns out, that the --pagesize parameter of mkfs.jffs2 has nothing to do with the NAND page size.  It should be set to the virtual memory management page size of the target system.  In most cases this should be set to 4K, which is the default value used if --pagesize is not supplied. 

Please consult the mkfs.jffs2 manual page (and the --help output) for details.
Comment 1 Thomas Petazzoni 2015-05-15 13:41:38 UTC
Wow, thanks for this bug report! It seems you are absolutely correct, and I actually learned with your bug report that the --pagesize option is for the virtual memory page size, not the NAND page size.

Do you think you can cook a patch to address this problem?

One issue is that Buildroot has no idea what is the virtual memory page size on the target system. I would suggest to just not pass any --pagesize option, and leave the default of 4 KB, since this is what the vast majority of systems are using.

And I'm pretty sure that if you use --pagesize 4K on a system that uses 8 KB or 64 KB pages, it will continue to work fine.
Comment 2 Michał Leśniewski 2015-05-22 07:45:33 UTC
I read a bit about the JFFS2 file system and looked at the JFFS2 code in the Linux kernel.  It looks like setting the --pagesize parameter value to the exact size of the virtual memory page would give the best results (best compression ratio).  However, setting a smaller --pagesize value should work fine, just as you wrote before. 

Anyway, I prepared a patch and sent it to the mailing list (http://lists.busybox.net/pipermail/buildroot/2015-May/128576.html).
Comment 3 Peter Korsgaard 2015-05-22 09:37:18 UTC
Committed as e3904a890de2a74c290675fdb90324a6ed83e633, thanks!