@@ -420,11 +420,248 @@ or via command line arguments):
420420 $ dd if=/dev/mtd6 of=tmp_read.txt bs=num count=1 # read to num bytes to flash
421421 $ diff tmp_read.txt tmp_write.txt # should be NULL
422422
423+ .. note ::
424+
425+ Make sure UBIFS filesystem is enabled in the kernel (refer to `this
426+ section <#enabling-qspi-driver-configurations> `__ for more information).
427+
428+ .. linux_ubifs_start
429+
430+ .. rubric :: Unsorted Block Image File System (UBIFS)
431+ :name: linux-ubifs
432+
433+ UBIFS is a flash file system for unmanaged flash memory devices. UBIFS works on
434+ top of an UBI layer, which is itself on top of MTD (Memory Technology Device)
435+ layer. UBI + UBIFS takes care of wear leveling, bad-block management, etc.
436+
423437.. rubric :: Using UBIFS on flash
424438 :name: using-ubifs-on-flash
425439
426- Make sure UBIFS filesystem is enabled in the kernel (refer to `this
427- section <#enabling-qspi-driver-configurations> `__ for more information).
440+ .. rubric :: Required Software for UBI image creation
441+ :name: linux-required-software-ubifs
442+
443+ Building a UBI File System requires two applications, :command: `ubinize ` and
444+ :command: `mkfs.ubifs `. Both are both provided by ``mtd-utils `` package.
445+
446+ .. code-block :: console
447+
448+ $ sudo apt-get install mtd-utils
449+
450+ .. rubric :: Building a UBI File System image
451+ :name: linux-building-ubi-file-system
452+
453+ Step 1: Create a directory containing the files and directories for the file
454+ system. It is important that the directory size is smaller than the ``rootfs ``
455+ partition in the flash.
456+
457+ Step 2: Create a file named :file: `ubinize.cfg ` and add the contents below.
458+
459+ .. code-block :: text
460+
461+ [ubifs]
462+ mode=ubi
463+ image=rootfs.ubifs
464+ vol_id=0
465+ vol_type=dynamic
466+ vol_name=rootfs
467+ vol_flags=autoresize
468+
469+ .. linux_ubifs_end
470+
471+ .. linux_args_detail_start
472+
473+ .. rubric :: mkfs.ubifs
474+ :name: linux-mkfs-ubifs
475+
476+ :command: `mkfs.ubifs ` is used to create UBI File System image, which is
477+ specifically generated for a flash memory device, like Serial NOR, NAND and
478+ Parallel NAND.
479+
480+ Syntax
481+
482+ .. code-block :: console
483+
484+ mkfs.ubifs -r <root_dir> -o <output_image> [options]
485+
486+ Some key options to use:
487+
488+ 1. ``-m <min_io_size> ``: specifies the minimum I/O size (in bytes) of the flash
489+ device.
490+
491+ 2. ``-e <leb_size> ``: specifies the logical eraseblock (LEB) size, which is the
492+ usable portion of an eraseblock in UBI (physical eraseblock - UBI overhead)
493+
494+ 3. ``-c <max_leb> ``: specifies the maximum number of logical eraseblocks (LEBs) the
495+ filesystem can use.
496+
497+ 4. ``-x <compression> ``: specifies the compression method to use. Default is
498+ ``zlib ``
499+
500+ 5. ``-F ``: used to force the filesystem to "fixup" all the free space which it
501+ is going to use. Note, this flag makes the first mount very slow, because
502+ the "free space fixup" procedure takes time.
503+
504+ For more details:
505+
506+ .. code-block :: console
507+
508+ mkfs.ubifs --help
509+
510+ .. rubric :: ubinize
511+ :name: linux-ubinize
512+
513+ :command: `ubinize ` is used to create UBI image for one or more UBIFS images.
514+
515+ .. code-block :: console
516+
517+ ubinize [options] -o <output_image> <configuration_file>
518+
519+ Some key options to use:
520+
521+ 1. ``-m <min_io_size> ``: specifies the minimum I/O size (in bytes) of the flash
522+ device.
523+
524+ 2. ``-p <peb_size> ``: specifies the physical eraseblock size, which is the
525+ total size of an eraseblock in the flash device.
526+
527+ 3. ``-s <sub_page_size> ``: specifies the sub-page size. Usually equivalent to
528+ the minimum I/O size.
529+
530+ 4. ``-O <vid_hdr_offset> ``: specifies the offset of the VID (Volume Identifier)
531+ header within the physical eraseblock.
532+
533+ For more details:
534+
535+ .. code-block :: console
536+
537+ ubinize --help
538+
539+ .. linux_args_detail_end
540+
541+ .. ifconfig :: CONFIG_part_variant in ('AM64X')
542+
543+ Step 3: Generate .ubifs image
544+
545+ .. code-block :: console
546+
547+ $ mkfs.ubifs -r /path/to/directory -o rootfs.ubifs -m 16 -e 262016 -c 219
548+
549+ Step 4: Generate .ubi image
550+
551+ .. code-block :: console
552+
553+ $ ubinize -o rootfs.ubi -m 16 -p 262144 -s 16 -O 64 ubinize.cfg
554+
555+ .. ifconfig :: CONFIG_part_variant in ('AM62X')
556+
557+ Step 3: Generate .ubifs image
558+
559+ For OSPI NOR:
560+
561+ .. code-block :: console
562+
563+ $ mkfs.ubifs -r /path/to/directory -o rootfs.ubifs -m 16 -e 262016 -c 219
564+
565+ For OSPI NAND:
566+
567+ .. code-block :: console
568+
569+ $ mkfs.ubifs -r /path/to/directory -o rootfs.ubifs -m 2048 -e 126976 -c 743
570+
571+ Step 4: Generate .ubi image
572+
573+ For OSPI NOR:
574+
575+ .. code-block :: console
576+
577+ $ ubinize -o rootfs.ubi -m 16 -p 262144 -s 16 -O 64 ubinize.cfg
578+
579+ For OSPI NAND:
580+
581+ .. code-block :: console
582+
583+ $ ubinize -o rootfs.ubi -m 2048 -p 131072 -s 2048 -O 2048 ubinize.cfg
584+
585+ .. ifconfig :: CONFIG_part_variant in ('AM62AX')
586+
587+ Step 3: Generate .ubifs image
588+
589+ .. code-block :: console
590+
591+ $ mkfs.ubifs -r /path/to/directory -o rootfs.ubifs -m 2048 -e 126976 -c 743
592+
593+ Step 4: Generate .ubi image
594+
595+ .. code-block :: console
596+
597+ $ ubinize -o rootfs.ubi -m 2048 -p 131072 -s 2048 -O 2048 ubinize.cfg
598+
599+ .. ifconfig :: CONFIG_part_variant in ('AM62PX', 'J7200')
600+
601+ Step 3: Generate .ubifs image
602+
603+ .. code-block :: console
604+
605+ $ mkfs.ubifs -r /path/to/directory -o rootfs.ubifs -m 16 -e 262016 -c 219
606+
607+ Step 4: Generate .ubi image
608+
609+ .. code-block :: console
610+
611+ $ ubinize -o rootfs.ubi -m 16 -p 262144 -s 16 -O 64 ubinize.cfg
612+
613+ .. ifconfig :: CONFIG_part_variant in ('J721E')
614+
615+ Step 3: Generate .ubifs image
616+
617+ .. code-block :: console
618+
619+ $ mkfs.ubifs -r /path/to/directory -o rootfs.ubifs <MKUBIFS ARGS>
620+
621+ Step 4: Generate .ubi image
622+
623+ .. code-block :: console
624+
625+ $ ubinize -o rootfs.ubi <UBINIZE ARGS> ubinize.cfg
626+
627+ .. ifconfig :: CONFIG_part_variant in ('J721S2', 'J784S4', 'J742S2', 'J722S')
628+
629+ Step 3: Generate .ubifs image
630+
631+ For OSPI NOR:
632+
633+ .. code-block :: console
634+
635+ $ mkfs.ubifs -r /path/to/directory -o rootfs.ubifs -m 16 -e 262016 -c 219
636+
637+ For OSPI NAND:
638+
639+ .. code-block :: console
640+
641+ $ mkfs.ubifs -r /path/to/directory -o rootfs.ubifs -m 4096 -e 253952 -c 369
642+
643+ Step 4: Generate .ubi image
644+
645+ For OSPI NOR:
646+
647+ .. code-block :: console
648+
649+ $ ubinize -o rootfs.ubi -m 16 -p 262144 -s 16 -O 64 ubinize.cfg
650+
651+ For OSPI NAND:
652+
653+ .. code-block :: console
654+
655+ $ ubinize -o rootfs.ubi -m 16 -p 262144 -s 4096 -O 4096 ubinize.cfg
656+
657+ Step 5: Flash rootfs.ubi to ``ospi.rootfs `` or ``ospi_nand.rootfs `` partition
658+ in the flash
659+
660+ .. code-block :: console
661+
662+ # EVM Linux
663+
664+ $ ubiformat -f rootfs.ubi /dev/mtdX
428665
429666 .. code-block :: console
430667
0 commit comments