From f175083413f0f94de88def865eeb65e465ded389 Mon Sep 17 00:00:00 2001 From: Frank Haverkamp Date: Wed, 14 Jun 2006 11:53:59 +0200 Subject: UBI - Unsorted Block Images UBI (Latin: "where?") manages multiple logical volumes on a single flash device, specifically supporting NAND flash devices. UBI provides a flexible partitioning concept which still allows for wear-levelling across the whole flash device. In a sense, UBI may be compared to the Logical Volume Manager (LVM). Whereas LVM maps logical sector numbers to physical HDD sector numbers, UBI maps logical eraseblocks to physical eraseblocks. More information may be found in the UBI design documentation: ubidesign.pdf. Which can be found here: http://www.linux-mtd.infradead.org/doc/ubi.html Partitioning/Re-partitioning An UBI volume occupies a certain number of erase blocks. This is limited by a configured maximum volume size, which could also be viewed as the partition size. Each individual UBI volume's size can be changed independently of the other UBI volumes, provided that the sum of all volume sizes doesn't exceed a certain limit. UBI supports dynamic volumes and static volumes. Static volumes are read-only and their contents are protected by CRC check sums. Bad eraseblocks handling UBI transparently handles bad eraseblocks. When a physical eraseblock becomes bad, it is substituted by a good physical eraseblock, and the user does not even notice this. Scrubbing On a NAND flash bit flips can occur on any write operation, sometimes also on read. If bit flips persist on the device, at first they can still be corrected by ECC, but once they accumulate, correction will become impossible. Thus it is best to actively scrub the affected eraseblock, by first copying it to a free eraseblock and then erasing the original. The UBI layer performs this type of scrubbing under the covers, transparently to the UBI volume users. Erase Counts UBI maintains an erase count header per eraseblock. This frees higher-level layers (like file systems) from doing this and allows for centralized erase count management instead. The erase counts are used by the wear-levelling algorithm in the UBI layer. The algorithm itself is exchangeable. Booting from NAND For booting directly from NAND flash the hardware must at least be capable of fetching and executing a small portion of the NAND flash. Some NAND flash controllers have this kind of support. They usually limit the window to a few kilobytes in erase block 0. This "initial program loader" (IPL) must then contain sufficient logic to load and execute the next boot phase. Due to bad eraseblocks, which may be randomly scattered over the flash device, it is problematic to store the "secondary program loader" (SPL) statically. Also, due to bit-flips it may become corrupted over time. UBI allows to solve this problem gracefully by storing the SPL in a small static UBI volume. UBI volumes vs. static partitions UBI volumes are still very similar to static MTD partitions: * both consist of eraseblocks (logical eraseblocks in case of UBI volumes, and physical eraseblocks in case of static partitions; * both support three basic operations - read, write, erase. But UBI volumes have the following advantages over traditional static MTD partitions: * there are no eraseblock wear-leveling constraints in case of UBI volumes, so the user should not care about this; * there are no bit-flips and bad eraseblocks in case of UBI volumes. So, UBI volumes may be considered as flash devices with relaxed restrictions. Where can it be found? Documentation, kernel code and applications can be found in the MTD gits. What are the applications for? The applications help to create binary flash images for two purposes: pfi files (partial flash images) for in-system update of UBI volumes, and plain binary images, with or without OOB data in case of NAND, for a manufacturing step. Furthermore some tools are/and will be created that allow flash content analysis after a system has crashed. Who did UBI? The original ideas, where UBI is based on, were developed by Andreas Arnez, Frank Haverkamp and Thomas Gleixner. Josh W. Boyer and some others were involved too. The implementation of the kernel layer was done by Artem B. Bityutskiy. The user-space applications and tools were written by Oliver Lohmann with contributions from Frank Haverkamp, Andreas Arnez, and Artem. Joern Engel contributed a patch which modifies JFFS2 so that it can be run on a UBI volume. Thomas Gleixner did modifications to the NAND layer and also some to JFFS2 to make it work. Signed-off-by: Frank Haverkamp --- ubi-utils/scripts/Makefile | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 ubi-utils/scripts/Makefile (limited to 'ubi-utils/scripts/Makefile') diff --git a/ubi-utils/scripts/Makefile b/ubi-utils/scripts/Makefile new file mode 100644 index 0000000..6d014ea --- /dev/null +++ b/ubi-utils/scripts/Makefile @@ -0,0 +1,57 @@ +# +# Makefile +# +# Testcase for UBI pfi update. +# +# Author: Frank Haverkamp +# + +card = test +mkpfi_cfg = test.cfg + +# +# Some default values you might want to overwrite. Try it if you need +# it and add more if needed. Note that no real sanity checking is done +# on those values. If you do it wrong your card has no valid PDD data. +# + +PATH := $(PATH):/opt/ppc/usr/bin + +dd = dd +sed = sed +bin2nand = bin2nand +ubigen = ubigen +mkpfi = mkpfi +pfi2bin = pfi2bin + +vmlinux_bin ?= test_vmlinux.bin +rootfs_bin ?= test_rootfs.bin +spl_bin ?= test_u-boot.bin + +compl ?= $(card)_complete +compl_pfi ?= $(compl).pfi + +all: $(compl_pfi) + +$(compl_pfi): $(vmlinux_bin) $(rootfs_bin) $(spl_bin) + $(mkpfi) -c $(mkpfi_cfg) + +# +# Default data +# +# If the binary data is not available in the current working directory +# we try to create symlinks to our test data. +# +$(vmlinux_bin) $(rootfs_bin) $(spl_bin): + @echo + @echo "No $@ found, will use defaults !" + @echo + @echo "OR press CTRL-C to provide your own $@" && \ + sleep 1 && \ + $(dd) if=/dev/urandom of=$@ bs=1M count=1 + +clean: + $(RM) *.pfi *~ + +distclean: clean + $(RM) *.bin -- cgit v1.2.3 From b366fb2eb4fa3b72766e25550b5643928e581c91 Mon Sep 17 00:00:00 2001 From: Frank Haverkamp Date: Wed, 21 Jun 2006 15:28:37 +0200 Subject: [MTD] UBI: Enhanced example for testing. Signed-off-by: Frank Haverkamp --- ubi-utils/scripts/Makefile | 26 ++++++++++++++++++++++---- ubi-utils/scripts/pdd.txt | 16 ++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 ubi-utils/scripts/pdd.txt (limited to 'ubi-utils/scripts/Makefile') diff --git a/ubi-utils/scripts/Makefile b/ubi-utils/scripts/Makefile index 6d014ea..e8850fd 100644 --- a/ubi-utils/scripts/Makefile +++ b/ubi-utils/scripts/Makefile @@ -21,21 +21,39 @@ dd = dd sed = sed bin2nand = bin2nand ubigen = ubigen -mkpfi = mkpfi -pfi2bin = pfi2bin +mkpfi = mkpfi -v +pfi2bin = pfi2bin -v vmlinux_bin ?= test_vmlinux.bin rootfs_bin ?= test_rootfs.bin spl_bin ?= test_u-boot.bin +pdd_txt ?= pdd.txt + +flashtype ?= nand +pagesize ?= 2048 compl ?= $(card)_complete compl_pfi ?= $(compl).pfi +compl_img ?= $(compl).img + +compl_nand2048_mif=$(compl).$(flashtype)$(pagesize).mif +compl_nand2048_img=$(compl).$(flashtype)$(pagesize).img -all: $(compl_pfi) +all: $(compl_pfi) $(compl_nand2048_mif) $(compl_pfi): $(vmlinux_bin) $(rootfs_bin) $(spl_bin) $(mkpfi) -c $(mkpfi_cfg) +# Binary data and out of band data (OOB) +# +$(compl_nand2048_mif): $(compl_img) + $(bin2nand) -p $(pagesize) -o $(compl_nand2048_mif) $< + +# Binary data only +# +$(compl_img): $(compl_pfi) + $(pfi2bin) -j $(pdd_txt) -o $@ $< + # # Default data # @@ -54,4 +72,4 @@ clean: $(RM) *.pfi *~ distclean: clean - $(RM) *.bin + $(RM) *.bin *.mif *.oob *.img diff --git a/ubi-utils/scripts/pdd.txt b/ubi-utils/scripts/pdd.txt new file mode 100644 index 0000000..a3ad915 --- /dev/null +++ b/ubi-utils/scripts/pdd.txt @@ -0,0 +1,16 @@ +pdd=flash_type,flash_size,flash_eraseblock_size,flash_page_size,card_serialnumber,card_type,ethaddr,eth1addr,eth0,eth1,total,card_hardwarelevel +pdd_preserve=ethaddr,eth1addr,card_serialnumber +# To be personalized +ethaddr=00:04:34:56:78:9A +eth1addr=00:04:34:56:78:9B +card_serialnumber=SN0 +# Static for this card type +total=102M +card_type=nand_driven_testcard +card_hardwarelevel=0 +eth0=bcm5222,eth0,0 +eth1=bcm5222,eth0,1 +flash_type=NAND +flash_size=0x08000000 +flash_eraseblock_size=0x00020000 +flash_page_size=0x00000800 -- cgit v1.2.3 From 842f19e7a67e0dd9ca53d1760fb8b3f2c94ab826 Mon Sep 17 00:00:00 2001 From: Adrian Hunter Date: Wed, 21 Mar 2007 11:54:35 +0200 Subject: UBI-Utils: Add a run_all.sh script Signed-off-by: Adrian Hunter --- ubi-utils/scripts/Makefile | 2 +- ubi-utils/scripts/run_all.sh | 101 ++++++++++++++++++++++++++++++++++++ ubi-utils/scripts/ubi_jffs2_test.sh | 3 +- 3 files changed, 103 insertions(+), 3 deletions(-) create mode 100755 ubi-utils/scripts/run_all.sh mode change 100644 => 100755 ubi-utils/scripts/ubi_jffs2_test.sh (limited to 'ubi-utils/scripts/Makefile') diff --git a/ubi-utils/scripts/Makefile b/ubi-utils/scripts/Makefile index e8850fd..ebd9bc6 100644 --- a/ubi-utils/scripts/Makefile +++ b/ubi-utils/scripts/Makefile @@ -15,7 +15,7 @@ mkpfi_cfg = test.cfg # on those values. If you do it wrong your card has no valid PDD data. # -PATH := $(PATH):/opt/ppc/usr/bin +PATH := $(PATH):/opt/ppc/usr/bin:../perl:.. dd = dd sed = sed diff --git a/ubi-utils/scripts/run_all.sh b/ubi-utils/scripts/run_all.sh new file mode 100755 index 0000000..040bcbd --- /dev/null +++ b/ubi-utils/scripts/run_all.sh @@ -0,0 +1,101 @@ +#!/bin/sh + +exit_success () +{ + echo "UBI Utils Test Scripts - SUCCESS!" + exit 0 +} + +exit_failure () +{ + echo $1 + echo "UBI Utils Test Scripts - FAILED!" + exit 1 +} + +echo UBI Utils Test Scripts + +devno=$1 +logfile=temp-test-log.txt + +if test -z "$devno"; +then + echo "Usage is $0 " + exit 1 +fi + +cwd=`pwd` || exit_failure "pwd failed" + +log="${cwd}/${logfile}" + +PATH=$PATH:$cwd:.. + +cat /dev/null > $log || exit_failure "Failed to create $log" + +echo "Setting up for jffs2_test.sh" | tee -a $log + +avail=`cat /sys/class/ubi/ubi${devno}/avail_eraseblocks` +size=`cat /sys/class/ubi/ubi${devno}/eraseblock_size` + +bytes=`expr $avail \* $size` + +ubimkvol -d$devno -s$bytes -n0 -Njtstvol || exit_failure "ubimkvol failed" + +mkdir -p /mnt/test_file_system || exit_failure "mkdir failed" + +mtd=`cat /proc/mtd | grep jtstvol | cut -d: -f1` + +if test -z "$mtd"; +then + exit_failure "mtd device not found" +fi + +mount -t jffs2 $mtd /mnt/test_file_system || exit_failure "mount failed" + +cd /mnt/test_file_system || exit_failure "cd failed" + +echo Running jffs2_test.sh | tee -a $log + +jffs2_test.sh >> $log 2>&1 || exit_failure "jffs2_test.sh failed" + +rm -f * + +cd $cwd || exit_failure "cd failed" + +umount /mnt/test_file_system || exit_failure "umount failed" + +ubirmvol -d$devno -n0 || exit_failure "ubirmvol failed" + +major=`cat /sys/class/ubi/ubi${devno}/dev | cut -d: -f1` + +for minor in `seq 0 32`; do + if test ! -e /dev/ubi${devno}_$minor ; + then + mknod /dev/ubi${devno}_$minor c $major $(($minor + 1)) + fi +done + +rm -f testdata.bin readdata.bin + +echo Running ubi_jffs2_test.sh | tee -a $log + +ubi_jffs2_test.sh >> $log 2>&1 || exit_failure "ubi_jffs2_test.sh failed" + +echo Running ubi_test.sh | tee -a $log + +ubi_test.sh >> $log 2>&1 || exit_failure "ubi_test.sh failed" + +for minor in `seq 0 32`; do + if test -e /sys/class/ubi/ubi${devno}/$minor; + then + ubirmvol -d$devno -n$minor || exit_failure "ubirmvol failed" + fi +done + +echo Running ubi_tools_test.sh | tee -a $log + +ubi_tools_test.sh >> $log 2>&1 || exit_failure "ubi_tools_test failed" + +rm -f $log + +exit_success diff --git a/ubi-utils/scripts/ubi_jffs2_test.sh b/ubi-utils/scripts/ubi_jffs2_test.sh old mode 100644 new mode 100755 index 4d97431..883903d --- a/ubi-utils/scripts/ubi_jffs2_test.sh +++ b/ubi-utils/scripts/ubi_jffs2_test.sh @@ -216,8 +216,7 @@ writevol_test () jffs2_torture () { - rm -f $TLOG - touch $TLOG + cat /dev/null > TLOG echo "*** Torture test ... " -- cgit v1.2.3