diff options
Diffstat (limited to 'ubi-utils/sort-me-out')
-rw-r--r-- | ubi-utils/sort-me-out/Makefile | 91 | ||||
-rw-r--r-- | ubi-utils/sort-me-out/README | 41 | ||||
-rw-r--r-- | ubi-utils/sort-me-out/bin2nand.c | 366 | ||||
-rwxr-xr-x | ubi-utils/sort-me-out/bin2nand2bin_test.sh | 216 | ||||
-rw-r--r-- | ubi-utils/sort-me-out/f128_nand_sample.cfg | 38 | ||||
-rw-r--r-- | ubi-utils/sort-me-out/f64_nor_sample.cfg | 39 | ||||
-rwxr-xr-x | ubi-utils/sort-me-out/inject_biterror.pl | 94 | ||||
-rw-r--r-- | ubi-utils/sort-me-out/nand2bin.c | 493 | ||||
-rw-r--r-- | ubi-utils/sort-me-out/nandcorr.c | 95 | ||||
-rw-r--r-- | ubi-utils/sort-me-out/nandecc.c | 159 | ||||
-rw-r--r-- | ubi-utils/sort-me-out/nandecc.h | 29 | ||||
-rw-r--r-- | ubi-utils/sort-me-out/pdd.txt | 16 | ||||
-rwxr-xr-x | ubi-utils/sort-me-out/run_all.sh | 101 | ||||
-rw-r--r-- | ubi-utils/sort-me-out/test.cfg | 23 | ||||
-rwxr-xr-x | ubi-utils/sort-me-out/ubi_test.sh | 328 | ||||
-rwxr-xr-x | ubi-utils/sort-me-out/ubi_tools_test.sh | 252 | ||||
-rw-r--r-- | ubi-utils/sort-me-out/ubicrc32.pl | 74 | ||||
-rw-r--r-- | ubi-utils/sort-me-out/unubi_test.sh | 105 |
18 files changed, 2560 insertions, 0 deletions
diff --git a/ubi-utils/sort-me-out/Makefile b/ubi-utils/sort-me-out/Makefile new file mode 100644 index 0000000..b8e3c96 --- /dev/null +++ b/ubi-utils/sort-me-out/Makefile @@ -0,0 +1,91 @@ +# +# Makefile +# +# Testcase for UBI pfi update. +# +# Author: Frank Haverkamp <haverkam@de.ibm.com> +# + +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:../perl:.. + +dd = dd +sed = sed +bin2nand = bin2nand +ubigen = ubigen +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: help + +help: + @echo "Testcases for the UBI/NAND manufacturing tool-chain" + @echo "---------------------------------------------------------------" + @echo " make mif_test - Generate a mif (manufacturing " + @echo " image file)." + @echo " make bin2nand2bin_test - Create binary with ECC information" + @echo " in the OOB area. Test ECC generation" + @echo " and correction." + +mif_test: $(compl_pfi) $(compl_nand2048_mif) + +bin2nand2bin_test: + chmod a+x ./bin2nand2bin_test.sh + chmod a+x ./inject_biterror.pl + ./bin2nand2bin_test.sh + +$(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 +# +# 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 *~ testblock* oob.bin + +distclean: clean + $(RM) *.bin *.mif *.oob *.img diff --git a/ubi-utils/sort-me-out/README b/ubi-utils/sort-me-out/README index 8ca9bdc..4018567 100644 --- a/ubi-utils/sort-me-out/README +++ b/ubi-utils/sort-me-out/README @@ -7,3 +7,44 @@ This directory contains various stuff that has to be cleaned up and sorted out. * ubigen.c: this utility adds UBI headers to an image file, but does not generate the volume table. It is probably useless, but one might find it interesting, so we do not drop it so far and keep here. + +* bin2nand2bin_test.sh: tests nand2bin and bin2nand utilities. Should probably + go to some tests/tools-tests or something. the nand2bin and bin2nand + utilities themselves have nothing to do to UBI in general and should not sit + in ubi-utils. Should be moved somewhere like mtd-utils.git/nand-tools/ + +* f64_nor_sample.cfg, f128_nand_sample.cfg: just exampe of configuration files + for the mkpfi utility. Not too useful without any documentation. Some pfi + configuration file format documentation has to be added to mkpfi man page and + these files should probably be added there. + +* pdd.txt: not sure what is it, this is probably something specific to the + setup which is used by IBM guys (Frank, Andreas, Josh). This is probably not + of general interest and should go away. + +* run_all.sh: runns "all" test. + +* ubicrc32.pl: probably redundand as we already have a C ubicrc32 utility. + +* ubi_test.sh: some UBI testing script, should go to + mtd-utils.git/tests/ubi-tests. + +* unubi_test.sh: tests the "unubi" utility, should go somewhere like + tests/tools-tests + +* inject_biterror.pl: injects a bit error to a binary image. Does not relate to + UBI and should go to mtd-utils.git/nand-tools/ or something + +* Makefile: previously was sitting at ubi-tools/scripts and prepared fake image + files for test scripts. + +* test.cfg: mkpfi configuration file for ubi_tools_test.sh + +* ubi_tools_test.sh: similar to unubi_test.sh + +* nand2bin.c, bin2nand.c: useful utilities which should go to + mtd-utils.git/nand-tools/ + +* nandecc.c, nandecc.h: needed to compile nand2bin and bin2nand + +* nandcorr.c: seems to be unused diff --git a/ubi-utils/sort-me-out/bin2nand.c b/ubi-utils/sort-me-out/bin2nand.c new file mode 100644 index 0000000..83f50cc --- /dev/null +++ b/ubi-utils/sort-me-out/bin2nand.c @@ -0,0 +1,366 @@ +/* + * Copyright (c) International Business Machines Corp., 2007 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Author: Oliver Lohmann + */ + +/* + * Create a flashable NAND image from a binary image + * + * History: + * 1.0 Initial release (tglx) + * 1.1 Understands hex and dec input parameters (tglx) + * 1.2 Generates separated OOB data, if needed. (oloh) + * 1.3 Padds data/oob to a given size. (oloh) + * 1.4 Removed argp because we want to use uClibc. + * 1.5 Minor cleanup + * 1.6 Written variable not initialized (-j did not work) (haver) + * 1.7 Made NAND ECC layout configurable (haver) + */ + +#include <unistd.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <fcntl.h> +#include <getopt.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <errno.h> + +#include "error.h" +#include "config.h" +#include "nandecc.h" +#include "ecclayouts.h" + +#define PROGRAM_VERSION "1.7" + +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) + +#define CHECK_ENDP(option, endp) do { \ + if (*endp) { \ + fprintf(stderr, \ + "Parse error option \'%s\'. " \ + "No correct numeric value.\n" \ + , option); \ + exit(EXIT_FAILURE); \ + } \ +} while(0) + +typedef enum action_t { + ACT_NORMAL = 0x00000001, +} action_t; + +#define PAGESIZE 2048 +#define PADDING 0 /* 0 means, do not adjust anything */ +#define BUFSIZE 4096 + +static char doc[] = "\nVersion: " PROGRAM_VERSION "\n" + "bin2nand - a tool for adding OOB information to a " + "binary input file.\n"; + +static const char *optionsstr = +" -c, --copyright Print copyright informatoin.\n" +" -j, --padding=<num> Padding in Byte/Mi/ki. Default = no padding\n" +" -l, --ecc-placement=<MTD,IBM> OOB placement scheme (default is IBM).\n" +" -p, --pagesize=<num> Pagesize in Byte/Mi/ki. Default = 2048\n" +" -o, --output=<fname> Output filename. Interleaved Data/OOB if\n" +" output-oob not specified.\n" +" -q, --output-oob=<fname> Write OOB data in separate file.\n" +" -?, --help Give this help list\n" +" --usage Give a short usage message\n" +" -V, --version Print program version\n"; + +static const char *usage = +"Usage: bin2nand [-c?V] [-j <num>] [-p <num>] [-o <fname>] [-q <fname>]\n" +" [--copyright] [--padding=<num>] [--pagesize=<num>]\n" +" [--output=<fname>] [--output-oob=<fname>] [--help] [--usage]\n" +" [--version]\n"; + +struct option long_options[] = { + { .name = "copyright", .has_arg = 0, .flag = NULL, .val = 'c' }, + { .name = "padding", .has_arg = 1, .flag = NULL, .val = 'j' }, + { .name = "pagesize", .has_arg = 1, .flag = NULL, .val = 'p' }, + { .name = "output", .has_arg = 1, .flag = NULL, .val = 'o' }, + { .name = "output-oob", .has_arg = 1, .flag = NULL, .val = 'q' }, + { .name = "ecc-layout", .has_arg = 1, .flag = NULL, .val = 'l' }, + { .name = "help", .has_arg = 0, .flag = NULL, .val = '?' }, + { .name = "usage", .has_arg = 0, .flag = NULL, .val = 0 }, + { .name = "version", .has_arg = 0, .flag = NULL, .val = 'V' }, + { NULL, 0, NULL, 0} +}; + +#define __unused __attribute__((unused)) +static const char copyright [] __unused = "Copyright IBM Corp. 2007"; + +struct args { + action_t action; + + size_t pagesize; + size_t oobsize; + size_t padding; + + FILE* fp_in; + const char *file_out_data; /* Either: Data and OOB interleaved + or plain data */ + const char *file_out_oob; /* OOB Data only. */ + struct nand_ecclayout *nand_oob; + + /* special stuff needed to get additional arguments */ + char *arg1; + char **options; /* [STRING...] */ +}; + + +static int ustrtoull(const char *cp, char **endp, unsigned int base) +{ + unsigned long long res = strtoull(cp, endp, base); + + switch (**endp) { + case 'G': + res *= 1024; + case 'M': + res *= 1024; + case 'k': + case 'K': + res *= 1024; + /* "Ki", "ki", "Mi" or "Gi" are to be used. */ + if ((*endp)[1] == 'i') + (*endp) += 2; + } + return res; +} + +static int +parse_opt(int argc, char **argv, struct args *args) +{ + const char *ecc_layout = NULL; + unsigned int i, oob_idx = 0; + char* endp; + + while (1) { + int key; + + key = getopt_long(argc, argv, "cj:l:p:o:q:?V", long_options, NULL); + if (key == -1) + break; + + switch (key) { + case 'p': /* pagesize */ + args->pagesize = (size_t) + ustrtoull(optarg, &endp, 0); + CHECK_ENDP("p", endp); + break; + case 'j': /* padding */ + args->padding = (size_t) + ustrtoull(optarg, &endp, 0); + CHECK_ENDP("j", endp); + break; + case 'o': /* output */ + args->file_out_data = optarg; + break; + case 'q': /* output oob */ + args->file_out_oob = optarg; + break; + case 'l': /* --ecc-layout=<...> */ + ecc_layout = optarg; + break; + case '?': /* help */ + printf("%s%s", doc, optionsstr); + exit(0); + break; + case 'V': + printf("%s\n", PROGRAM_VERSION); + exit(0); + break; + case 'c': + printf("%s\n", copyright); + exit(0); + default: + printf("%s", usage); + exit(-1); + } + } + + if (optind < argc) { + args->fp_in = fopen(argv[optind++], "rb"); + if ((args->fp_in) == NULL) { + err_quit("Cannot open file %s for input\n", + argv[optind++]); + } + } + + switch (args->pagesize) { + case 512: args->oobsize = 16; oob_idx = 0; break; + case 2048: args->oobsize = 64; oob_idx = 1; break; + default: + err_msg("Unsupported page size: %d\n", args->pagesize); + return -EINVAL; + } + + /* Figure out correct oob layout if it differs from default */ + if (ecc_layout) { + for (i = 0; i < ARRAY_SIZE(oob_placement); i++) + if (strcmp(ecc_layout, oob_placement[i].name) == 0) + args->nand_oob = + oob_placement[i].nand_oob[oob_idx]; + } + return 0; +} + +static int +process_page(struct args *args, uint8_t *buf, FILE *fp_data, FILE *fp_oob, + size_t *written) +{ + int eccpoi; + size_t i; + uint8_t oobbuf[64]; + uint8_t ecc_code[3] = { 0, }; /* temp */ + + /* Calculate ECC for each subpage of 256 bytes */ + memset(oobbuf, 0xff, sizeof(oobbuf)); + for (eccpoi = 0, i = 0; i < args->pagesize; i += 256, eccpoi += 3) { + int j; + nand_calculate_ecc(&buf[i], ecc_code); + for (j = 0; j < 3; j++) + oobbuf[args->nand_oob->eccpos[eccpoi + j]] = ecc_code[j]; + } + + /* write data */ + *written += fwrite(buf, 1, args->pagesize, fp_data); + + /* either separate oob or interleave with data */ + if (fp_oob) { + i = fwrite(oobbuf, 1, args->oobsize, fp_oob); + if (ferror(fp_oob)) { + err_msg("IO error\n"); + return -EIO; + } + } + else { + i = fwrite(oobbuf, 1, args->oobsize, fp_data); + if (ferror(fp_data)) { + err_msg("IO error\n"); + return -EIO; + } + } + + return 0; +} + +int main (int argc, char** argv) +{ + int rc = -1; + int res = 0; + size_t written = 0, read; + struct args args = { + .action = ACT_NORMAL, + .pagesize = PAGESIZE, + .padding = PADDING, + .fp_in = NULL, + .file_out_data = NULL, + .file_out_oob = NULL, + .nand_oob = &ibm_nand_oob_64, + }; + + FILE* fp_out_data = stdout; + FILE* fp_out_oob = NULL; + + parse_opt(argc, argv, &args); + + uint8_t* buf = calloc(1, BUFSIZE); + if (!buf) { + err_quit("Cannot allocate page buffer.\n"); + } + + if (!args.fp_in) { + err_msg("No input image specified!\n"); + goto err; + } + + if (args.file_out_data) { + fp_out_data = fopen(args.file_out_data, "wb"); + if (fp_out_data == NULL) { + err_sys("Cannot open file %s for output\n", + args.file_out_data); + goto err; + } + } + + if (args.file_out_oob) { + fp_out_oob = fopen(args.file_out_oob, "wb"); + if (fp_out_oob == NULL) { + err_sys("Cannot open file %s for output\n", + args.file_out_oob); + goto err; + } + } + + + while(1) { + read = fread(buf, 1, args.pagesize, args.fp_in); + if (feof(args.fp_in) && read == 0) + break; + + if (read < args.pagesize) { + err_msg("Image not page aligned\n"); + goto err; + } + + if (ferror(args.fp_in)) { + err_msg("Read error\n"); + goto err; + } + + res = process_page(&args, buf, fp_out_data, fp_out_oob, + &written); + if (res != 0) + goto err; + } + + while (written < args.padding) { + memset(buf, 0xff, args.pagesize); + res = process_page(&args, buf, fp_out_data, fp_out_oob, + &written); + if (res != 0) + goto err; + } + + rc = 0; +err: + free(buf); + + if (args.fp_in) + fclose(args.fp_in); + + if (fp_out_oob) + fclose(fp_out_oob); + + if (fp_out_data && fp_out_data != stdout) + fclose(fp_out_data); + + if (rc != 0) { + err_msg("Error during conversion. rc: %d\n", rc); + if (args.file_out_data) + remove(args.file_out_data); + if (args.file_out_oob) + remove(args.file_out_oob); + } + return rc; +} diff --git a/ubi-utils/sort-me-out/bin2nand2bin_test.sh b/ubi-utils/sort-me-out/bin2nand2bin_test.sh new file mode 100755 index 0000000..51f048c --- /dev/null +++ b/ubi-utils/sort-me-out/bin2nand2bin_test.sh @@ -0,0 +1,216 @@ +#!/bin/sh +# +# Version: 1.1 +# Author: Frank Haverkamp <haver@vnet.ibm.com> +# +# Testcase for nand2bin and bin2nand. Generate testdata and inject +# biterrors. Convert data back and compare with original data. +# +# Conversion: +# bin -> bin2nand -> mif -> nand2bin -> img +# + +inject_biterror=./inject_biterror.pl +pagesize=2048 +oobsize=64 + +# Create test data +dd if=/dev/urandom of=testblock.bin bs=131072 count=1 + +for layout in IBM MTD ; do + echo "*** Simple test with $layout layout ..." + + echo -n "Convert bin to mif ... " + bin2nand -l$layout --pagesize=${pagesize} -o testblock.mif testblock.bin + if [ $? -ne "0" ]; then + echo "failed!" + exit 1 + else + echo "ok" + fi + + echo -n "Convert mif to bin ... " + nand2bin -l$layout --pagesize=${pagesize} -o testblock.img testblock.mif + if [ $? -ne "0" ]; then + echo "failed!" + exit 1 + else + echo "ok" + fi + + echo -n "Comparing data ... " + diff testblock.bin testblock.img + if [ $? -ne "0" ]; then + echo "failed!" + exit 1 + else + echo "ok" + fi +done + +echo "*** Test conversion without bitflips ..." + +echo -n "Convert bin to mif ... " +bin2nand --pagesize=${pagesize} -o testblock.mif testblock.bin +if [ $? -ne "0" ]; then + echo "failed!" + exit 1 +else + echo "ok" +fi + +echo -n "Convert mif to bin ... " +nand2bin --pagesize=${pagesize} -o testblock.img testblock.mif +if [ $? -ne "0" ]; then + echo "failed!" + exit 1 +else + echo "ok" +fi + +echo -n "Comparing data ... " +diff testblock.bin testblock.img +if [ $? -ne "0" ]; then + echo "failed!" + exit 1 +else + echo "ok" +fi + +echo "*** Test conversion with uncorrectable ECC erors ..." +echo -n "Inject biterror at offset $ioffs ... " +${inject_biterror} --offset=0 --bitmask=0x81 \ + --input=testblock.mif \ + --output=testblock_bitflip.mif +if [ $? -ne "0" ]; then + echo "failed!" + exit 1 +else + echo "ok" +fi + +echo "Convert mif to bin ... " +rm testblock.img +nand2bin --correct-ecc --pagesize=${pagesize} -o testblock.img \ + testblock_bitflip.mif +if [ $? -ne "0" ]; then + echo "failed!" + exit 1 +else + echo "ok" +fi + +echo -n "Comparing data, must fail due to uncorrectable ECC ... " +diff testblock.bin testblock.img +if [ $? -ne "0" ]; then + echo "ok" # Must fail! +else + echo "failed!" + exit 1 +fi + +echo "*** Test bitflips in data ... " +for offs in `seq 0 255` ; do + + cp testblock.mif testblock_bitflip.mif + + for xoffs in 0 256 512 768 ; do + let ioffs=$offs+$xoffs + + cp testblock_bitflip.mif testblock_bitflip_tmp.mif + echo -n "Inject biterror at offset $ioffs ... " + ${inject_biterror} --offset=${ioffs} --bitmask=0x01 \ + --input=testblock_bitflip_tmp.mif \ + --output=testblock_bitflip.mif + if [ $? -ne "0" ]; then + echo "failed!" + exit 1 + else + echo "ok" + fi + done + + echo "Convert mif to bin ... " + rm testblock.img + nand2bin --correct-ecc --pagesize=${pagesize} -o testblock.img \ + testblock_bitflip.mif + if [ $? -ne "0" ]; then + echo "failed!" + exit 1 + else + echo "ok" + fi + + echo -n "Comparing data ... " + diff testblock.bin testblock.img + if [ $? -ne "0" ]; then + hexdump testblock.bin > testblock.bin.txt + hexdump testblock.img > testblock.img.txt + echo "Use tkdiff testblock.bin.txt testblock.img.txt to compare" + echo "failed!" + exit 1 + else + echo "ok" + fi + + # Without correction + echo "Convert mif to bin ... " + rm testblock.img + nand2bin --pagesize=${pagesize} -o testblock.img \ + testblock_bitflip.mif + if [ $? -ne "0" ]; then + echo "failed!" + exit 1 + else + echo "ok" + fi + + echo -n "Comparing data must differ, correction is disabled ... " + diff testblock.bin testblock.img + if [ $? -ne "0" ]; then + echo "ok" # must fail + else + echo "failed!" + exit 1 + fi +done + +echo "*** Test bitflips in OOB data ... " +for offs in `seq 0 $oobsize` ; do + + let ioffs=$pagesize+$offs + + echo -n "Inject biterror at offset $ioffs ... " + ${inject_biterror} --offset=${ioffs} --bitmask=0x01 \ + --input=testblock.mif \ + --output=testblock_bitflip.mif + if [ $? -ne "0" ]; then + echo "failed!" + exit 1 + else + echo "ok" + fi + + echo "Convert mif to bin ... " + rm testblock.img + nand2bin --correct-ecc --pagesize=${pagesize} -o testblock.img \ + testblock_bitflip.mif + if [ $? -ne "0" ]; then + echo "failed!" + exit 1 + else + echo "ok" + fi + + echo -n "Comparing data ... " + diff testblock.bin testblock.img + if [ $? -ne "0" ]; then + hexdump testblock.bin > testblock.bin.txt + hexdump testblock.img > testblock.img.txt + echo "Use tkdiff testblock.bin.txt testblock.img.txt to compare" + echo "failed!" + exit 1 + else + echo "ok" + fi +done diff --git a/ubi-utils/sort-me-out/f128_nand_sample.cfg b/ubi-utils/sort-me-out/f128_nand_sample.cfg new file mode 100644 index 0000000..bb62600 --- /dev/null +++ b/ubi-utils/sort-me-out/f128_nand_sample.cfg @@ -0,0 +1,38 @@ +[targets] +complete=ipl,spl,bootenv,kernel,rootfs +bootcode=spl,bootenv + +# Build sections +[ipl] +image=ipl.bin +raw_starts=0x00000000 +raw_total_size=128kiB + +[spl] +image=u-boot.bin +ubi_ids=2,3 +ubi_size=2MiB +ubi_type=static +ubi_names=spl_0,spl_1 + +[bootenv] +bootenv_file=bootenv_complete.txt +ubi_ids=4,5 +ubi_size=128kiB +ubi_type=static +ubi_names=bootenv_0,bootenv_1 + +[kernel] +image=vmlinux.bin +ubi_ids=6,7 +ubi_size=6MiB +ubi_type=static +ubi_names=kernel_0,kernel_1 + +[rootfs] +image=rootfs.bin +ubi_ids=8,9 +ubi_alignment=2kiB +ubi_size=16MiB +ubi_type=dynamic +ubi_names=rootfs_0,rootfs_1 diff --git a/ubi-utils/sort-me-out/f64_nor_sample.cfg b/ubi-utils/sort-me-out/f64_nor_sample.cfg new file mode 100644 index 0000000..889d4c2 --- /dev/null +++ b/ubi-utils/sort-me-out/f64_nor_sample.cfg @@ -0,0 +1,39 @@ +[targets] +complete=ipl,spl,bootenv,kernel,rootfs +bootcode=spl,bootenv +rootfs=rootfs + +# Build sections +[ipl] +image=ipl.bin +raw_starts=0x02FE0000, 0x03FE0000 +raw_total_size=128kiB + +[spl] +image=u-boot.bin +ubi_ids=2,3 +ubi_size=2MiB +ubi_type=static +ubi_names=spl_0,spl_1 + +[bootenv] +bootenv_file=bootenv_complete.txt +ubi_ids=4,5 +ubi_size=128kiB +ubi_type=static +ubi_names=bootenv_0,bootenv_1 + +[kernel] +image=vmlinux.bin +ubi_ids=6,7 +ubi_size=6MiB +ubi_type=static +ubi_names=kernel_0,kernel_1 + +[rootfs] +image=rootfs.bin +ubi_ids=8,9 +ubi_alignment=2kiB +ubi_size=16128kiB +ubi_type=dynamic +ubi_names=rootfs_0,rootfs_1 diff --git a/ubi-utils/sort-me-out/inject_biterror.pl b/ubi-utils/sort-me-out/inject_biterror.pl new file mode 100755 index 0000000..b4a862a --- /dev/null +++ b/ubi-utils/sort-me-out/inject_biterror.pl @@ -0,0 +1,94 @@ +#!/usr/bin/perl -w +# +# 2007 Frank Haverkamp <haver@vnet.ibm.com> +# +# Program for bit-error injection. I am sure that perl experts do it +# in 1 line. Please let me know how it is done right ;-). +# + +use strict; +use warnings; +use Getopt::Long; +use Pod::Usage; + +my $i; +my $help; +my $result; +my $offset = 0; +my $bitmask = 0x01; +my $in = "input.mif"; +my $out = "output.mif"; + +$result = GetOptions ("offset=i" => \$offset, # numeric + "bitmask=o" => \$bitmask, # numeric + "input=s" => \$in, # string + "output=s" => \$out, # string + "help|?" => \$help) or pod2usage(2); + +pod2usage(1) if $help; + +my $buf; + +open(my $in_fh, "<", $in) + or die "Cannot open file $in: $!"; +binmode $in_fh; + +open(my $out_fh, ">", $out) or + die "Cannot open file $out: $!"; +binmode $out_fh; + +$i = 0; +while (sysread($in_fh, $buf, 1)) { + + $buf = pack('C', unpack('C', $buf) ^ $bitmask) if ($i == $offset); + syswrite($out_fh, $buf, 1) or + die "Cannot write to offset $offset: $!"; + $i++; +} + +close $in_fh; +close $out_fh; + +__END__ + +=head1 NAME + +inject_biterrors.pl + +=head1 SYNOPSIS + +inject_biterror.pl [options] + +=head1 OPTIONS + +=over 8 + +=item B<--help> + +Print a brief help message and exits. + +=item B<--offset>=I<offset> + +Byte-offset where bit-error should be injected. + +=item B<--bitmask>=I<bitmask> + +Bit-mask where to inject errors in the byte. + +=item B<--input>=I<input-file> + +Input file. + +=item B<--output>=I<output-file> + +Output file. + +=back + +=head1 DESCRIPTION + +B<inject_biterrors.pl> will read the given input file and inject +biterrors at the I<offset> specified. The location of the biterrors +are defined by the I<bitmask> parameter. + +=cut diff --git a/ubi-utils/sort-me-out/nand2bin.c b/ubi-utils/sort-me-out/nand2bin.c new file mode 100644 index 0000000..8c95b27 --- /dev/null +++ b/ubi-utils/sort-me-out/nand2bin.c @@ -0,0 +1,493 @@ +/* + * Copyright (c) International Business Machines Corp., 2006, 2007 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Author: Frank Haverkamp + * + * An utility to decompose NAND images and strip OOB off. Not yet finished ... + * + * 1.2 Removed argp because we want to use uClibc. + * 1.3 Minor cleanup + * 1.4 Fixed OOB output file + * 1.5 Added verbose output and option to set blocksize. + * Added split block mode for more convenient analysis. + * 1.6 Fixed ECC error detection and correction. + * 1.7 Made NAND ECC layout configurable, the holes which were previously + * filled with 0x00 are untouched now and will be 0xff just like MTD + * behaves when writing the oob (haver) + */ + +#include <config.h> +#include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdint.h> +#include <getopt.h> +#include <stdarg.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/ioctl.h> +#include <sys/stat.h> +#include <sys/types.h> + +#include "config.h" +#include "nandecc.h" +#include "ecclayouts.h" + +#define PROGRAM_VERSION "1.7" + +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) +#define MAXPATH 1024 +#define MIN(x,y) ((x)<(y)?(x):(y)) + +struct args { + const char *oob_file; + const char *output_file; + size_t pagesize; + size_t oobsize; + int bad_marker_offs_in_oob; + size_t blocksize; + int split_blocks; + size_t in_len; /* size of input file */ + int correct_ecc; + struct nand_ecclayout *nand_oob; + + /* special stuff needed to get additional arguments */ + char *arg1; + char **options; /* [STRING...] */ +}; + +static struct args myargs = { + .output_file = "data.bin", + .oob_file = "oob.bin", + .pagesize = 2048, + .blocksize = 128 * 1024, + .nand_oob = &ibm_nand_oob_64, + .in_len = 0, + .split_blocks = 0, + .correct_ecc = 0, + .arg1 = NULL, + .options = NULL, +}; + +static char doc[] = "\nVersion: " PROGRAM_VERSION "\n" + "nand2bin - split data and OOB.\n"; + +static const char *optionsstr = +" -l, --ecc-placement=<MTD,IBM> OOB placement scheme (default is IBM).\n" +" -o, --output=<output> Data output file\n" +" -O, --oob=<oob> OOB output file\n" +" -p, --pagesize=<pagesize> NAND pagesize\n" +" -b, --blocksize=<blocksize> NAND blocksize\n" +" -s, --split-blocks generate binaries for each block\n" +" -e, --correct-ecc Correct data according to ECC info\n" +" -v, --verbose verbose output\n" +" -?, --help Give this help list\n" +" --usage Give a short usage message\n"; + +static const char *usage = +"Usage: nand2bin [-?] [-o <output>] [-O <oob>] [-p <pagesize>]\n" +" [--output=<output>] [--oob=<oob>] [--pagesize=<pagesize>] [--help]\n" +" [--usage] input.mif\n"; + +static int verbose = 0; + +static struct option long_options[] = { + { .name = "ecc-layout", .has_arg = 1, .flag = NULL, .val = 'l' }, + { .name = "output", .has_arg = 1, .flag = NULL, .val = 'o' }, + { .name = "oob", .has_arg = 1, .flag = NULL, .val = 'O' }, + { .name = "pagesize", .has_arg = 1, .flag = NULL, .val = 'p' }, + { .name = "blocksize", .has_arg = 1, .flag = NULL, .val = 'b' }, + { .name = "split-blocks", .has_arg = 0, .flag = NULL, .val = 's' }, + { .name = "correct-ecc", .has_arg = 0, .flag = NULL, .val = 'e' }, + { .name = "verbose", .has_arg = 0, .flag = NULL, .val = 'v' }, + { .name = "help", .has_arg = 0, .flag = NULL, .val = '?' }, + { .name = "usage", .has_arg = 0, .flag = NULL, .val = 0 }, + { NULL, 0, NULL, 0} +}; + +/* + * str_to_num - Convert string into number and cope with endings like + * k, K, kib, KiB for kilobyte + * m, M, mib, MiB for megabyte + */ +static uint32_t str_to_num(char *str) +{ + char *s = str; + ulong num = strtoul(s, &s, 0); + + if (*s != '\0') { + if (strcmp(s, "KiB") == 0) + num *= 1024; + else if (strcmp(s, "MiB") == 0) + num *= 1024*1024; + else { + fprintf(stderr, "WARNING: Wrong number format " + "\"%s\", check your paramters!\n", str); + } + } + return num; +} + +/* + * @brief Parse the arguments passed into the test case. + * + * @param argc The number of arguments + * @param argv The argument list + * @param args Pointer to program args structure + * + * @return error + * + */ +static int parse_opt(int argc, char **argv, struct args *args) +{ + unsigned int i, oob_idx = 0; + const char *ecc_layout = NULL; + + while (1) { + int key; + + key = getopt_long(argc, argv, "b:el:o:O:p:sv?", long_options, NULL); + if (key == -1) + break; + + switch (key) { + case 'b': /* --blocksize<blocksize> */ + args->blocksize = str_to_num(optarg); + break; + case 'e': /* --correct-ecc */ + args->correct_ecc = 1; + break; + case 'l': /* --ecc-layout=<...> */ + ecc_layout = optarg; + break; + case 'o': /* --output=<output.bin> */ + args->output_file = optarg; + break; + case 'O': /* --oob=<oob.bin> */ + args->oob_file = optarg; + break; + case 'p': /* --pagesize<pagesize> */ + args->pagesize = str_to_num(optarg); + break; + case 's': /* --split-blocks */ + args->split_blocks = 1; + break; + case 'v': /* --verbose */ + verbose++; + break; + case 'V': + printf("%s\n", PROGRAM_VERSION); + exit(0); + break; + case '?': /* help */ + printf("Usage: nand2bin [OPTION...] input.mif\n"); + printf("%s%s", doc, optionsstr); + printf("\nReport bugs to %s\n", + PACKAGE_BUGREPORT); + exit(0); + break; + default: + printf("%s", usage); + exit(-1); + } + } + + if (optind < argc) + args->arg1 = argv[optind++]; + + switch (args->pagesize) { + case 512: + args->oobsize = 16; + args->bad_marker_offs_in_oob = 5; + oob_idx = 0; + break; + case 2048: + args->oobsize = 64; + args->bad_marker_offs_in_oob = 0; + oob_idx = 1; + break; + default: + fprintf(stderr, "Unsupported page size: %d\n", args->pagesize); + return -EINVAL; + } + + /* Figure out correct oob layout if it differs from default */ + if (ecc_layout) { + for (i = 0; i < ARRAY_SIZE(oob_placement); i++) + if (strcmp(ecc_layout, oob_placement[i].name) == 0) + args->nand_oob = + oob_placement[i].nand_oob[oob_idx]; + } + return 0; +} + +/* + * We must only compare the relevant bytes in the OOB area. All other + * bytes can be ignored. The information we need to do this is in + * nand_oob. + */ +static int oob_cmp(struct nand_ecclayout *nand_oob, uint8_t *oob, + uint8_t *calc_oob) +{ + unsigned int i; + for (i = 0; i < nand_oob->eccbytes; i++) + if (oob[nand_oob->eccpos[i]] != calc_oob[nand_oob->eccpos[i]]) + return 1; + return 0; +} + +static inline void hexdump(FILE *fp, const uint8_t *buf, ssize_t size) +{ + int k; + + for (k = 0; k < size; k++) { + fprintf(fp, "%02x ", buf[k]); + if ((k & 15) == 15) + fprintf(fp, "\n"); + } +} + +static int process_page(struct args *args, uint8_t *buf, uint8_t *oobbuf) +{ + size_t i, j; + int eccpoi; + uint8_t ecc_code[3] = { 0, }; /* temp */ + + /* Calculate ECC */ + memset(oobbuf, 0xff, args->oobsize); + for (eccpoi = 0, i = 0; i < args->pagesize; i += 256, eccpoi += 3) { + nand_calculate_ecc(&buf[i], ecc_code); + for (j = 0; j < 3; j++) + oobbuf[args->nand_oob->eccpos[eccpoi + j]] = ecc_code[j]; + } + return 0; +} + +static int decompose_image(struct args *args, FILE *in_fp, + FILE *bin_fp, FILE *oob_fp) +{ + unsigned int i, eccpoi; + int read, rc, page = 0; + uint8_t *buf = malloc(args->pagesize); + uint8_t *oob = malloc(args->oobsize); + uint8_t *calc_oob = malloc(args->oobsize); + uint8_t *calc_buf = malloc(args->pagesize); + uint8_t *page_buf; + int pages_per_block = args->blocksize / args->pagesize; + int badpos = args->bad_marker_offs_in_oob; + uint8_t ecc_code[3] = { 0, }; /* temp */ + uint8_t calc_ecc_code[3] = { 0, }; /* temp */ + + if (!buf || !oob || !calc_oob || !calc_buf) + exit(EXIT_FAILURE); + + while (!feof(in_fp)) { + /* read page by page */ + read = fread(buf, 1, args->pagesize, in_fp); + if (ferror(in_fp)) { + fprintf(stderr, "I/O Error."); + exit(EXIT_FAILURE); + } + if (read != (ssize_t)args->pagesize) + break; + + read = fread(oob, 1, args->oobsize, in_fp); + if (ferror(in_fp)) { + fprintf(stderr, "I/O Error."); + exit(EXIT_FAILURE); + } + + page_buf = buf; /* default is unmodified data */ + + if ((page == 0 || page == 1) && (oob[badpos] != 0xff)) { + if (verbose) + printf("Block %d is bad\n", + page / pages_per_block); + goto write_data; + } + if (args->correct_ecc) + page_buf = calc_buf; + + process_page(args, buf, calc_oob); + memcpy(calc_buf, buf, args->pagesize); + + if (verbose && oob_cmp(args->nand_oob, oob, calc_oob) != 0) { + printf("\nECC compare mismatch found at block %d page %d!\n", + page / pages_per_block, page % pages_per_block); + + printf("Read out OOB Data:\n"); + hexdump(stdout, oob, args->oobsize); + + printf("Calculated OOB Data:\n"); + hexdump(stdout, calc_oob, args->oobsize); + } + + /* Do correction on subpage base */ + for (i = 0, eccpoi = 0; i < args->pagesize; i += 256, eccpoi += 3) { + int j; + + for (j = 0; j < 3; j++) { + ecc_code[j] = oob[args->nand_oob->eccpos[eccpoi + j]]; + calc_ecc_code[j] = + calc_oob[args->nand_oob->eccpos[eccpoi + j]]; + } + rc = nand_correct_data(calc_buf + i, ecc_code, + calc_ecc_code); + if (rc == -1) + fprintf(stdout, "Uncorrectable ECC error at " + "block %d page %d/%d\n", + page / pages_per_block, + page % pages_per_block, i / 256); + else if (rc > 0) + fprintf(stdout, "Correctable ECC error at " + "block %d page %d/%d\n", + page / pages_per_block, + page % pages_per_block, i / 256); + } + + write_data: + rc = fwrite(page_buf, 1, args->pagesize, bin_fp); + if (ferror(bin_fp)) { + fprintf(stderr, "I/O Error."); + exit(EXIT_FAILURE); + } + rc = fwrite(oob, 1, args->oobsize, oob_fp); + if (ferror(bin_fp)) { + fprintf(stderr, "I/O Error."); + exit(EXIT_FAILURE); + } + + page++; + } + free(calc_buf); + free(calc_oob); + free(oob); + free(buf); + return 0; +} + +static int split_blocks(struct args *args, FILE *in_fp) +{ + uint8_t *buf; + int pages_per_block = args->blocksize / args->pagesize; + int block_len = pages_per_block * (args->pagesize + args->oobsize); + int blocks = args->in_len / block_len; + char bname[256] = { 0, }; + int badpos = args->bad_marker_offs_in_oob; + int bad_blocks = 0, i, bad_block = 0; + ssize_t rc; + FILE *b; + + buf = malloc(block_len); + if (!buf) { + perror("Not enough memory"); + exit(EXIT_FAILURE); + } + + for (i = 0; i < blocks; i++) { + rc = fread(buf, 1, block_len, in_fp); + if (rc != block_len) { + fprintf(stderr, "cannot read enough data!\n"); + exit(EXIT_FAILURE); + } + + /* do block analysis */ + bad_block = 0; + if ((buf[args->pagesize + badpos] != 0xff) || + (buf[2 * args->pagesize + args->oobsize + badpos] != 0xff)) { + bad_blocks++; + bad_block = 1; + } + if ((verbose && bad_block) || (verbose > 1)) { + printf("-- (block %d oob of page 0 and 1)\n", i); + hexdump(stdout, buf + args->pagesize, args->oobsize); + printf("--\n"); + hexdump(stdout, buf + 2 * args->pagesize + + args->oobsize, args->oobsize); + } + + /* write complete block out */ + snprintf(bname, sizeof(bname) - 1, "%s.%d", args->arg1, i); + b = fopen(bname, "w+"); + if (!b) { + perror("Cannot open file"); + exit(EXIT_FAILURE); + } + rc = fwrite(buf, 1, block_len, b); + if (rc != block_len) { + fprintf(stderr, "could not write all data!\n"); + exit(EXIT_FAILURE); + } + fclose(b); + } + + free(buf); + if (bad_blocks || verbose) + fprintf(stderr, "%d blocks, %d bad blocks\n", + blocks, bad_blocks); + return 0; +} + +int +main(int argc, char *argv[]) +{ + FILE *in, *bin = NULL, *oob = NULL; + struct stat file_info; + + parse_opt(argc, argv, &myargs); + + if (!myargs.arg1) { + fprintf(stderr, "Please specify input file!\n"); + exit(EXIT_FAILURE); + } + + if (lstat(myargs.arg1, &file_info) != 0) { + perror("Cannot fetch file size from input file.\n"); + exit(EXIT_FAILURE); + } + myargs.in_len = file_info.st_size; + + in = fopen(myargs.arg1, "r"); + if (!in) { + perror("Cannot open file"); + exit(EXIT_FAILURE); + } + + if (myargs.split_blocks) { + split_blocks(&myargs, in); + goto out; + } + + bin = fopen(myargs.output_file, "w+"); + if (!bin) { + perror("Cannot open file"); + exit(EXIT_FAILURE); + } + oob = fopen(myargs.oob_file, "w+"); + if (!oob) { + perror("Cannot open file"); + exit(EXIT_FAILURE); + } + decompose_image(&myargs, in, bin, oob); + + out: + if (in) fclose(in); + if (bin) fclose(bin); + if (oob) fclose(oob); + exit(EXIT_SUCCESS); +} diff --git a/ubi-utils/sort-me-out/nandcorr.c b/ubi-utils/sort-me-out/nandcorr.c new file mode 100644 index 0000000..caa07e2 --- /dev/null +++ b/ubi-utils/sort-me-out/nandcorr.c @@ -0,0 +1,95 @@ +/* + * Copyright (c) International Business Machines Corp., 2006 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* + * ECC algorithm for NAND FLASH. Detects and corrects 1 bit errors in + * a 256 bytes of data. + * + * Reimplement by Thomas Gleixner after staring long enough at the + * mess in drivers/mtd/nand/nandecc.c + * + */ + +#include "nandecc.h" + +static int countbits(uint32_t byte) +{ + int res = 0; + + for (;byte; byte >>= 1) + res += byte & 0x01; + return res; +} + +/** + * @dat: data which should be corrected + * @read_ecc: ecc information read from flash + * @calc_ecc: calculated ecc information from the data + * @return: number of corrected bytes + * or -1 when no correction is possible + */ +int nand_correct_data(uint8_t *dat, const uint8_t *read_ecc, + const uint8_t *calc_ecc) +{ + uint8_t s0, s1, s2; + + /* + * Do error detection + * + * Be careful, the index magic is due to a pointer to a + * uint32_t. + */ + s0 = calc_ecc[0] ^ read_ecc[0]; + s1 = calc_ecc[1] ^ read_ecc[1]; + s2 = calc_ecc[2] ^ read_ecc[2]; + + if ((s0 | s1 | s2) == 0) + return 0; + + /* Check for a single bit error */ + if( ((s0 ^ (s0 >> 1)) & 0x55) == 0x55 && + ((s1 ^ (s1 >> 1)) & 0x55) == 0x55 && + ((s2 ^ (s2 >> 1)) & 0x54) == 0x54) { + + uint32_t byteoffs, bitnum; + + byteoffs = (s1 << 0) & 0x80; + byteoffs |= (s1 << 1) & 0x40; + byteoffs |= (s1 << 2) & 0x20; + byteoffs |= (s1 << 3) & 0x10; + + byteoffs |= (s0 >> 4) & 0x08; + byteoffs |= (s0 >> 3) & 0x04; + byteoffs |= (s0 >> 2) & 0x02; + byteoffs |= (s0 >> 1) & 0x01; + + bitnum = (s2 >> 5) & 0x04; + bitnum |= (s2 >> 4) & 0x02; + bitnum |= (s2 >> 3) & 0x01; + + dat[byteoffs] ^= (1 << bitnum); + + return 1; + } + + if(countbits(s0 | ((uint32_t)s1 << 8) | ((uint32_t)s2 <<16)) == 1) + return 1; + + return -1; +} + diff --git a/ubi-utils/sort-me-out/nandecc.c b/ubi-utils/sort-me-out/nandecc.c new file mode 100644 index 0000000..71660ef --- /dev/null +++ b/ubi-utils/sort-me-out/nandecc.c @@ -0,0 +1,159 @@ +/* + * This file contains an ECC algorithm from Toshiba that detects and + * corrects 1 bit errors in a 256 byte block of data. + * + * drivers/mtd/nand/nand_ecc.c + * + * Copyright (C) 2000-2004 Steven J. Hill (sjhill@realitydiluted.com) + * Toshiba America Electronics Components, Inc. + * + * This file is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 or (at your option) any + * later version. + * + * This file is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this file; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * As a special exception, if other files instantiate templates or use + * macros or inline functions from these files, or you compile these + * files and link them with other works to produce a work based on these + * files, these files do not by themselves cause the resulting work to be + * covered by the GNU General Public License. However the source code for + * these files must still be made available in accordance with section (3) + * of the GNU General Public License. + * + * This exception does not invalidate any other reasons why a work based on + * this file might be covered by the GNU General Public License. + */ + +#include "nandecc.h" + +/* + * Pre-calculated 256-way 1 byte column parity + */ +static const uint8_t nand_ecc_precalc_table[] = { + 0x00, 0x55, 0x56, 0x03, 0x59, 0x0c, 0x0f, 0x5a, + 0x5a, 0x0f, 0x0c, 0x59, 0x03, 0x56, 0x55, 0x00, + 0x65, 0x30, 0x33, 0x66, 0x3c, 0x69, 0x6a, 0x3f, + 0x3f, 0x6a, 0x69, 0x3c, 0x66, 0x33, 0x30, 0x65, + 0x66, 0x33, 0x30, 0x65, 0x3f, 0x6a, 0x69, 0x3c, + 0x3c, 0x69, 0x6a, 0x3f, 0x65, 0x30, 0x33, 0x66, + 0x03, 0x56, 0x55, 0x00, 0x5a, 0x0f, 0x0c, 0x59, + 0x59, 0x0c, 0x0f, 0x5a, 0x00, 0x55, 0x56, 0x03, + 0x69, 0x3c, 0x3f, 0x6a, 0x30, 0x65, 0x66, 0x33, + 0x33, 0x66, 0x65, 0x30, 0x6a, 0x3f, 0x3c, 0x69, + 0x0c, 0x59, 0x5a, 0x0f, 0x55, 0x00, 0x03, 0x56, + 0x56, 0x03, 0x00, 0x55, 0x0f, 0x5a, 0x59, 0x0c, + 0x0f, 0x5a, 0x59, 0x0c, 0x56, 0x03, 0x00, 0x55, + 0x55, 0x00, 0x03, 0x56, 0x0c, 0x59, 0x5a, 0x0f, + 0x6a, 0x3f, 0x3c, 0x69, 0x33, 0x66, 0x65, 0x30, + 0x30, 0x65, 0x66, 0x33, 0x69, 0x3c, 0x3f, 0x6a, + 0x6a, 0x3f, 0x3c, 0x69, 0x33, 0x66, 0x65, 0x30, + 0x30, 0x65, 0x66, 0x33, 0x69, 0x3c, 0x3f, 0x6a, + 0x0f, 0x5a, 0x59, 0x0c, 0x56, 0x03, 0x00, 0x55, + 0x55, 0x00, 0x03, 0x56, 0x0c, 0x59, 0x5a, 0x0f, + 0x0c, 0x59, 0x5a, 0x0f, 0x55, 0x00, 0x03, 0x56, + 0x56, 0x03, 0x00, 0x55, 0x0f, 0x5a, 0x59, 0x0c, + 0x69, 0x3c, 0x3f, 0x6a, 0x30, 0x65, 0x66, 0x33, + 0x33, 0x66, 0x65, 0x30, 0x6a, 0x3f, 0x3c, 0x69, + 0x03, 0x56, 0x55, 0x00, 0x5a, 0x0f, 0x0c, 0x59, + 0x59, 0x0c, 0x0f, 0x5a, 0x00, 0x55, 0x56, 0x03, + 0x66, 0x33, 0x30, 0x65, 0x3f, 0x6a, 0x69, 0x3c, + 0x3c, 0x69, 0x6a, 0x3f, 0x65, 0x30, 0x33, 0x66, + 0x65, 0x30, 0x33, 0x66, 0x3c, 0x69, 0x6a, 0x3f, + 0x3f, 0x6a, 0x69, 0x3c, 0x66, 0x33, 0x30, 0x65, + 0x00, 0x55, 0x56, 0x03, 0x59, 0x0c, 0x0f, 0x5a, + 0x5a, 0x0f, 0x0c, 0x59, 0x03, 0x56, 0x55, 0x00 +}; + +/** + * nand_trans_result - [GENERIC] create non-inverted ECC + * @reg2: line parity reg 2 + * @reg3: line parity reg 3 + * @ecc_code: ecc + * + * Creates non-inverted ECC code from line parity + */ +static void nand_trans_result(uint8_t reg2, uint8_t reg3, + uint8_t *ecc_code) +{ + uint8_t a, b, i, tmp1, tmp2; + + /* Initialize variables */ + a = b = 0x80; + tmp1 = tmp2 = 0; + + /* Calculate first ECC byte */ + for (i = 0; i < 4; i++) { + if (reg3 & a) /* LP15,13,11,9 --> ecc_code[0] */ + tmp1 |= b; + b >>= 1; + if (reg2 & a) /* LP14,12,10,8 --> ecc_code[0] */ + tmp1 |= b; + b >>= 1; + a >>= 1; + } + + /* Calculate second ECC byte */ + b = 0x80; + for (i = 0; i < 4; i++) { + if (reg3 & a) /* LP7,5,3,1 --> ecc_code[1] */ + tmp2 |= b; + b >>= 1; + if (reg2 & a) /* LP6,4,2,0 --> ecc_code[1] */ + tmp2 |= b; + b >>= 1; + a >>= 1; + } + + /* Store two of the ECC bytes */ + ecc_code[1] = tmp1; + ecc_code[0] = tmp2; +} + +/** + * nand_calculate_ecc - [NAND Interface] Calculate 3 byte ECC code for + * 256 byte block + * + * @dat: raw data + * @ecc_code: buffer for ECC + */ +int nand_calculate_ecc(const uint8_t *dat, uint8_t *ecc_code) +{ + uint8_t idx, reg1, reg2, reg3; + int j; + + /* Initialize variables */ + reg1 = reg2 = reg3 = 0; + ecc_code[0] = ecc_code[1] = ecc_code[2] = 0; + + /* Build up column parity */ + for(j = 0; j < 256; j++) { + + /* Get CP0 - CP5 from table */ + idx = nand_ecc_precalc_table[dat[j]]; + reg1 ^= (idx & 0x3f); + + /* All bit XOR = 1 ? */ + if (idx & 0x40) { + reg3 ^= (uint8_t) j; + reg2 ^= ~((uint8_t) j); + } + } + + /* Create non-inverted ECC code from line parity */ + nand_trans_result(reg2, reg3, ecc_code); + + /* Calculate final ECC code */ + ecc_code[0] = ~ecc_code[0]; + ecc_code[1] = ~ecc_code[1]; + ecc_code[2] = ((~reg1) << 2) | 0x03; + return 0; +} diff --git a/ubi-utils/sort-me-out/nandecc.h b/ubi-utils/sort-me-out/nandecc.h new file mode 100644 index 0000000..bcf1982 --- /dev/null +++ b/ubi-utils/sort-me-out/nandecc.h @@ -0,0 +1,29 @@ +#ifndef _NAND_ECC_H +#define _NAND_ECC_H +/* + * Copyright (c) International Business Machines Corp., 2006 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * NAND ecc functions + */ + +#include <stdint.h> + +int nand_calculate_ecc(const uint8_t *dat, uint8_t *ecc_code); +int nand_correct_data(uint8_t *dat, const uint8_t *read_ecc, + const uint8_t *calc_ecc); + +#endif diff --git a/ubi-utils/sort-me-out/pdd.txt b/ubi-utils/sort-me-out/pdd.txt new file mode 100644 index 0000000..a3ad915 --- /dev/null +++ b/ubi-utils/sort-me-out/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 diff --git a/ubi-utils/sort-me-out/run_all.sh b/ubi-utils/sort-me-out/run_all.sh new file mode 100755 index 0000000..040bcbd --- /dev/null +++ b/ubi-utils/sort-me-out/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 <mtd device number>" + 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/sort-me-out/test.cfg b/ubi-utils/sort-me-out/test.cfg new file mode 100644 index 0000000..0b5ec48 --- /dev/null +++ b/ubi-utils/sort-me-out/test.cfg @@ -0,0 +1,23 @@ +[targets] +test_complete=spl,kernel,rootfs + +[spl] +image=test_u-boot.bin +ubi_ids=10,11 +ubi_size=1MiB +ubi_type=static +ubi_names=test_spl_0,test_spl_1 + +[kernel] +image=test_vmlinux.bin +ubi_ids=12,13 +ubi_size=2MiB +ubi_type=static +ubi_names=test_kernel_0,test_kernel_1 + +[rootfs] +image=test_rootfs.bin +ubi_ids=14,15 +ubi_size=2MiB +ubi_type=dynamic +ubi_names=test_rootfs_0,test_rootfs_1 diff --git a/ubi-utils/sort-me-out/ubi_test.sh b/ubi-utils/sort-me-out/ubi_test.sh new file mode 100755 index 0000000..73e4b19 --- /dev/null +++ b/ubi-utils/sort-me-out/ubi_test.sh @@ -0,0 +1,328 @@ +#!/bin/sh +# +# UBI Volume creation/deletion/write/read test script +# +# Written in shell language to reduce dependencies to more sophisticated +# interpreters, which may not be available on some stupid platforms. +# +# Author: Frank Haverkamp <haver@vnet.ibm.com> +# +# 1.0 Initial version +# 1.1 Use ubiupdatevol instead of ubiwritevol +# + +VERSION="1.1" + +export PATH=$PATH:~/bin:/usr/local/bin:/home/dedekind/work/prj/ubi/tools/flashutils/bin/ + +UBIMKVOL=ubimkvol +UBIRMVOL=ubirmvol +UBIUPDATEVOL=ubiupdatevol + +# 128 KiB 131072 +# 256 KiB 262144 +# 512 KiB 524288 + +SIZE_512K=524288 +SIZE_1M=1310720 + +SELF=$0 +MINVOL=10 +MAXVOL=12 + +# +# To have a standardized output I define the following function to be +# used when a test was ok or when it failed. +# +failed () +{ + echo "FAILED" +} + +passed () +{ + echo "PASSED" +} + +# +# Print sucess message. Consider to exit with zero as return code. +# +exit_success () +{ + echo "SUCCESS" + exit 0 +} + +# +# Print failure message. Consider to exit with non zero return code. +# +exit_failure () +{ + echo "FAILED" + exit 1 +} + +############################################################################### +# +# START +# +############################################################################### + +fix_sysfs_issue () +{ + echo -n "*** Fixing the sysfs issue with the /dev nodes ... " + + minor=0 + major=`grep ubi0 /proc/devices | sed -e 's/\(.*\) ubi0/\1/'` + + rm -rf /dev/ubi0 + mknod /dev/ubi0 c $major 0 + + for minor in `seq 0 $MAXVOL`; do + ### echo " mknod /dev/ubi0_$minor c $major $(($minor + 1))" + rm -rf /dev/ubi0_$minor + mknod /dev/ubi0_$minor c $major $(($minor + 1)) + done + passed +} + +# delete_volume - Delete a volume. If it does not exist, do not try +# to delete it. +# @id: volume id +# +delete_volume () +{ + volume=$1 + + ### FIXME broken sysfs!!!! + if [ -e /sys/class/ubi/$volume -o -e /sys/class/ubi/ubi0/$volume -o -e /sys/class/ubi/ubi0_$volume ]; then + + echo -n "*** Truncate volume if it exists ... " + $UBIUPDATEVOL -d0 -n$volume -t + if [ $? -ne "0" ] ; then + exit_failure + fi + passed + + echo -n "*** Delete volume if it exists ... " + $UBIRMVOL -d0 -n$volume + if [ $? -ne "0" ] ; then + exit_failure + fi + passed + fi +} + +mkvol_rmvol_test () +{ + type=$1 + +### Test if volume delete on non-existing volumes fails nicely + + for i in `seq $MINVOL $MAXVOL`; do + echo "*** Delete if exist or not $i ... " + + delete_volume $i + passed + done + +### Now deleting volumes must fail + + for i in `seq $MINVOL $MAXVOL`; do + echo "*** Trying to delete non existing UBI Volume $i ... " + + $UBIRMVOL -d0 -n$i + if [ $? -eq "0" ] ; then + exit_failure + fi + passed + done + +### Test if volume creation works ok + + for i in `seq $MINVOL $MAXVOL`; do + echo "*** Creating UBI Volume $i ... " + echo " $UBIMKVOL -d0 -n$i -t$type -NNEW$i -s $SIZE_512K" + + $UBIMKVOL -d0 -n$i -t$type -N"NEW$i" -s $SIZE_512K + if [ $? -ne "0" ] ; then + exit_failure + fi + passed + done + +### Now deleting volumes must be ok + + for i in `seq $MINVOL $MAXVOL`; do + echo "*** Trying to delete UBI Volume $i ... " + + $UBIRMVOL -d0 -n$i + if [ $? -ne "0" ] ; then + exit_failure + fi + passed + done + +### Now allocate too large volume + + echo -n "*** Try to create too large volume" + $UBIMKVOL -d0 -n$MINVOL -t$type -N"NEW$MINVOL" -s 800000000 + if [ $? -eq "0" ] ; then + exit_failure + fi + passed +} + +# writevol_test - Tests volume creation and writing data to it. +# +# @size: Size of random data to write +# @type: Volume type static or dynamic +# +writevol_test () +{ + size=$1 + type=$2 + + echo "*** Write volume test with size $size" + +### Make sure that volume exist, delete existing volume, create new + + delete_volume $MINVOL + + echo -n "*** Try to create volume ... " + $UBIMKVOL -d0 -n$MINVOL -t$type -N"NEW$MINVOL" -s $SIZE_1M + if [ $? -ne "0" ] ; then + exit_failure + fi + passed + +### Try to create same volume again + echo -n "*** Try to create some volume again, this must fail ... " + $UBIMKVOL -d0 -n$MINVOL -t$type -N"NEW$MINVOL" -s $SIZE_1M + if [ $? -eq "0" ] ; then + exit_failure + fi + passed + +### Now create test data, write it, read it, compare it + echo -n "*** Create test data ... " + dd if=/dev/urandom of=testdata.bin bs=$size count=1 + if [ $? -ne "0" ] ; then + exit_failure + fi + passed + + echo "*** Now writing data to volume ... " + # sleep 5 + ls -l testdata.bin + echo " $UBIUPDATEVOL -d0 -n$MINVOL testdata.bin" + $UBIUPDATEVOL -d0 -n$MINVOL testdata.bin + if [ $? -ne "0" ] ; then + exit_failure + fi + passed + + if [ $type = "static" ] ; then + echo "*** Download data with cat ... " + cat /dev/ubi0_$MINVOL > readdata.bin + if [ $? -ne "0" ] ; then + exit_failure + fi + passed + else + echo "*** Download data with dd bs=1 ... " + dd if=/dev/ubi0_$MINVOL of=readdata.bin bs=$size count=1 + if [ $? -ne "0" ] ; then + exit_failure + fi + passed + + # Size 1 does not work with this test ... + # + #echo "*** Download data with dd bs=$size ... " + #dd if=/dev/ubi0_$MINVOL of=readdata2.bin bs=$size count=1 + #if [ $? -ne "0" ] ; then + # exit_failure + #fi + #passed + + #echo -n "*** Comparing data (1) ... " + #cmp readdata.bin readdata2.bin + #if [ $? -ne "0" ] ; then + # exit_failure + #fi + #passed + fi + + echo -n "*** Comparing data ... " + cmp readdata.bin testdata.bin + if [ $? -ne "0" ] ; then + exit_failure + fi + passed +} + +echo "***********************************************************************" +echo "* UBI Testing starts now ... *" +echo "* Good luck! *" +echo "***********************************************************************" + +# Set to zero if not running on example hardware +grep ubi /proc/devices > /dev/null +if [ $? -ne "0" ]; then + echo "No UBI found in /proc/devices! I am broken!" + exit_failure +fi + +# Set to zero if not running on example hardware +grep 1142 /proc/cpuinfo > /dev/null +if [ $? -eq "0" ]; then + echo "Running on example hardware" + mount -o remount,rw / / + sleep 1 + fix_sysfs_issue +else + echo "Running on Artems hardware" +fi + +echo "***********************************************************************" +echo "* mkvol/rmvol testing for static volumes ... *" +echo "***********************************************************************" + +mkvol_rmvol_test static + +echo "***********************************************************************" +echo "* mkvol/rmvol testing for dynamic volumes ... *" +echo "***********************************************************************" + +mkvol_rmvol_test dynamic + +echo "***********************************************************************" +echo "* write to static volumes ... *" +echo "***********************************************************************" + +# 10 Erase blocks = (128 KiB - 64 * 2) * 10 +# = 1309440 bytes +# 128 KiB 131072 +# 256 KiB 262144 +# 512 KiB 524288 + +for size in 262144 131073 131072 2048 1 4096 12800 31313 ; do + writevol_test $size static +done + +echo "***********************************************************************" +echo "* write to dynamic volumes ... *" +echo "***********************************************************************" +echo "VERSION: $VERSION" + +for size in 131073 131072 2048 1 4096 12800 31313 262144 ; do + writevol_test $size dynamic +done + +echo "***********************************************************************" +echo "* Congratulations, no errors found! *" +echo "* Have fun with your cool UBI system! *" +echo "***********************************************************************" + +exit_success diff --git a/ubi-utils/sort-me-out/ubi_tools_test.sh b/ubi-utils/sort-me-out/ubi_tools_test.sh new file mode 100755 index 0000000..7f121f1 --- /dev/null +++ b/ubi-utils/sort-me-out/ubi_tools_test.sh @@ -0,0 +1,252 @@ +#!/bin/sh +# +# UBI Volume creation/deletion/write/read test script. +# Uses our flash update tools and the associated toolchain for flash +# image creation. +# +# Written in shell language to reduce dependencies to more sophisticated +# interpreters, which may not be available on some stupid platforms. +# +# Author: Frank Haverkamp <haver@vnet.ibm.com> +# +# 1.0 Initial version +# + +VERSION="1.0" + +export PATH=$PATH:~/bin:/usr/local/bin:/home/dedekind/work/prj/ubi/tools/flashutils/bin/ + +UBIMKVOL=ubimkvol +UBIRMVOL=ubirmvol +UBIWRITEVOL=ubiupdatevol +PFIFLASH=pfiflash +CMP=cmp + +MAXVOL=32 + +test_pfi=test_complete.pfi +real_pfi=example_complete.pfi + +# 128 KiB 131072 +# 256 KiB 262144 +# 512 KiB 524288 + +# +# To have a standardized output I define the following function to be +# used when a test was ok or when it failed. +# +failed () +{ + echo "FAILED" +} + +passed () +{ + echo "PASSED" +} + +# +# Print sucess message. Consider to exit with zero as return code. +# +exit_success () +{ + echo "SUCCESS" + exit 0 +} + +# +# Print failure message. Consider to exit with non zero return code. +# +exit_failure () +{ + echo "FAILED" + exit 1 +} + +############################################################################### +# +# START +# +############################################################################### + +fix_sysfs_issue () +{ + echo -n "*** Fixing the sysfs issue with the /dev nodes ... " + + minor=0 + major=`grep ubi0 /proc/devices | sed -e 's/\(.*\) ubi0/\1/'` + + rm -rf /dev/ubi0 + mknod /dev/ubi0 c $major 0 + + for minor in `seq 0 $MAXVOL`; do + ### echo " mknod /dev/ubi0_$minor c $major $(($minor + 1))" + rm -rf /dev/ubi0_$minor + mknod /dev/ubi0_$minor c $major $(($minor + 1)) + done + passed +} + +# delete_volume - Delete a volume. If it does not exist, do not try +# to delete it. +# @id: volume id +# +delete_volume () +{ + volume=$1 + + ### FIXME broken sysfs!!!! + if [ -e /sys/class/ubi/$volume -o -e /sys/class/ubi/ubi0/$volume -o -e /sys/class/ubi/ubi0_$volume ]; then + + echo -n "*** Truncate volume if it exists ... " + $UBIWRITEVOL -d0 -n$volume -t + if [ $? -ne "0" ] ; then + exit_failure + fi + passed + + echo -n "*** Delete volume if it exists ... " + $UBIRMVOL -d0 -n$volume + if [ $? -ne "0" ] ; then + exit_failure + fi + passed + fi +} + +echo "***********************************************************************" +echo "* UBI Tools Testing starts now ... *" +echo "* Good luck! *" +echo "***********************************************************************" + +# Set to zero if not running on example hardware +grep ubi /proc/devices > /dev/null +if [ $? -ne "0" ]; then + echo "No UBI found in /proc/devices! I am broken!" + exit_failure +fi + +# Set to zero if not running on example hardware +grep 1142 /proc/cpuinfo > /dev/null +if [ $? -eq "0" ]; then + echo "Running on example hardware" + mount -o remount,rw / / + sleep 1 + fix_sysfs_issue +else + echo "Running on other hardware" +fi + +### Test basic stuff +pfiflash_basic () +{ + echo "Calling pfiflash with test-data ... " + echo " $PFIFLASH $test_pfi" + $PFIFLASH $test_pfi + if [ $? -ne "0" ]; then + echo "Uhhh something went wrong!" + exit_failure + fi + passed + + echo "Testing if data is correct 10 and 11 ... " + $CMP /dev/ubi0_10 /dev/ubi0_11 + if [ $? -ne "0" ]; then + echo "Mirrored volumes not equal!" + exit_failure + fi + passed + + echo "Comparing against original data ... " + $CMP /dev/ubi0_10 test_u-boot.bin + if [ $? -ne "0" ]; then + echo "Compared volume not equal!" + exit_failure + fi + passed + + echo "Testing if data is correct 12 and 13 ... " + $CMP /dev/ubi0_12 /dev/ubi0_13 + if [ $? -ne "0" ]; then + echo "Mirrored volumes not equal!" + exit_failure + fi + passed + + echo "Comparing against original data ... " + $CMP /dev/ubi0_12 test_vmlinux.bin + if [ $? -ne "0" ]; then + echo "Compared volume not equal!" + exit_failure + fi + passed + + echo "Testing if data is correct 14 and 15 ... " + $CMP /dev/ubi0_14 /dev/ubi0_15 + if [ $? -ne "0" ]; then + echo "Mirrored volumes not equal!" + exit_failure + fi + passed +} + +### Test each and everything +pfiflash_advanced () +{ + if [ -e example_complete.pfi ]; then + echo "Calling pfiflash with real data ... " + $PFIFLASH -p overwrite --complete example_complete.pfi + if [ $? -ne "0" ]; then + echo "Uhhh something went wrong!" + exit_failure + fi + passed + + echo "Testing if data is correct 2 and 3 ... " + $CMP /dev/ubi0_2 /dev/ubi0_3 + if [ $? -ne "0" ]; then + echo "Mirrored volumes not equal!" + exit_failure + fi + passed + + echo "Comparing against original data ... " + $CMP /dev/ubi0_2 u-boot.bin + if [ $? -ne "0" ]; then + echo "Compared volume not equal!" + exit_failure + fi + passed + + echo "Testing if data is correct 6 and 7 ... " + $CMP /dev/ubi0_6 /dev/ubi0_7 + if [ $? -ne "0" ]; then + echo "Mirrored volumes not equal!" + exit_failure + fi + passed + + echo "Comparing against original data ... " + $CMP /dev/ubi0_6 vmlinux.bin + if [ $? -ne "0" ]; then + echo "Compared volume not equal!" + exit_failure + fi + passed + fi +} + +echo "***********************************************************************" +echo "* Testing pfiflash ... *" +echo "***********************************************************************" +echo "VERSION: $VERSION" + +pfiflash_basic +pfiflash_advanced + +echo "***********************************************************************" +echo "* Congratulations, no errors found! *" +echo "* Have fun with your cool UBI system! *" +echo "***********************************************************************" + +exit_success diff --git a/ubi-utils/sort-me-out/ubicrc32.pl b/ubi-utils/sort-me-out/ubicrc32.pl new file mode 100644 index 0000000..92711cb --- /dev/null +++ b/ubi-utils/sort-me-out/ubicrc32.pl @@ -0,0 +1,74 @@ +#!/usr/bin/perl -w + +# Subroutine crc32(): Calculates the CRC on a given string. + +{ + my @table = (); + + # @brief Calculate CRC32 for a given string. + sub crc32 + { + unless (@table) { + # Initialize the CRC table + my $poly = 0xEDB88320; + @table = (); + + for my $i (0..255) { + my $c = $i; + + for my $j (0..7) { + $c = ($c & 1) ? (($c >> 1) ^ $poly) : ($c >> 1); + } + $table[$i] = $c; + } + } + my $s = shift; # string to calculate the CRC for + my $crc = shift; # CRC start value + + defined($crc) + or $crc = 0xffffffff; # Default CRC start value + + for (my $i = 0; $i < length($s); $i++) { + $crc = $table[($crc ^ ord(substr($s, $i, 1))) & 0xff] + ^ ($crc >> 8); + } + return $crc; + } +} + +sub crc32_on_file +{ + my $file = shift; + + my $crc32 = crc32(''); + my $buf = ''; + my $ret = 0; + + while ($ret = read($file, $buf, 8192)) { + $crc32 = crc32($buf, $crc32); + } + defined($ret) + or return undef; + printf("0x%x\n", $crc32); +} + + +# Main routine: Calculate the CRCs on the given files and print the +# results. + +{ + if (@ARGV) { + while (my $path = shift) { + my $file; + open $file, "<", $path + or die "Error opening '$path'.\n"; + + &crc32_on_file($file) + or die "Error reading from '$path'.\n"; + close $file; + } + } else { + &crc32_on_file(\*STDIN) + or die "Error reading from stdin.\n"; + } +} diff --git a/ubi-utils/sort-me-out/unubi_test.sh b/ubi-utils/sort-me-out/unubi_test.sh new file mode 100644 index 0000000..40dc2e2 --- /dev/null +++ b/ubi-utils/sort-me-out/unubi_test.sh @@ -0,0 +1,105 @@ +#!/bin/sh +# +# Use raw NAND data, extract UBI image and apply tool to it. +# Test basic functionality. +# +# 2007 Frank Haverkamp <haver@vnet.ibm.com> +# + +version=1.1 + +image=data.mif +oob=oob.bin +data=data.bin +pagesize=2048 +volmax=31 +datadir=unubi_data + +# general arguments e.g. debug enablement +# unubi_args="-D" + +echo "------------------------------------------------------------------------" +echo "Testcase: ${0} Version: ${version}" +echo "------------------------------------------------------------------------" +echo "Testing nand2bin ..." +echo " Input: ${image}" +echo " Data: ${data}" +echo " OOB: ${oob}" +echo " Pagesize: ${pagesize}" +nand2bin --pagesize ${pagesize} -o ${data} -O ${oob} ${image} +echo + +echo "------------------------------------------------------------------------" +echo "Testing unubi ..." +echo "------------------------------------------------------------------------" +unubi --version +echo + +echo "------------------------------------------------------------------------" +echo "Trying to extract first ${volmax} volumes ..." +echo "------------------------------------------------------------------------" +mkdir -p ${datadir}/volumes +for v in `seq 0 ${volmax}` ; do + unubi ${unubi_args} -r${v} -d${datadir}/volumes ${data} + echo -n "." +done +echo "ok" +ls -l ${datadir}/volumes +echo + +echo "------------------------------------------------------------------------" +echo "Extracting graphics ..." +echo "------------------------------------------------------------------------" +unubi -a -d${datadir} ${data} +echo "Use gnuplot to display:" +ls ${datadir}/*.plot +ls ${datadir}/*.data +echo + +echo "------------------------------------------------------------------------" +echo "eb-split" +echo "------------------------------------------------------------------------" +unubi -e -d${datadir}/eb-split ${data} +ls -l ${datadir}/eb-split +echo + +echo "------------------------------------------------------------------------" +echo "vol-split" +echo "------------------------------------------------------------------------" +unubi -v -d${datadir}/vol-split ${data} +ls -l ${datadir}/vol-split +echo +echo "The generated images contain only the data (126KiB in our " +echo "case) not including the UBI erase count and volume info " +echo "header. For dynamic volumes the data should be the full " +echo "126KiB. Unubi cannot know how much of the data is valid. " +echo + +echo "------------------------------------------------------------------------" +echo "!vol-split" +echo "------------------------------------------------------------------------" +unubi -V -d${datadir}/vol-split! ${data} +ls -l ${datadir}/vol-split\! +echo +echo "The generated images contain the full block data of 128KiB " +echo "including the UBI erase count and volume information header." +echo + +echo "------------------------------------------------------------------------" +echo "Extracting volume info table ..." +echo "------------------------------------------------------------------------" +unubi -i -d${datadir} ${data} +echo "I strongly hope that empty ubi blocks are filled with 0xff! " +echo + +echo "------------------------------------------------------------------------" +echo "Table 0" +echo "------------------------------------------------------------------------" +cat ${datadir}/vol_info_table0 +echo + +echo "------------------------------------------------------------------------" +echo "Table 1" +echo "------------------------------------------------------------------------" +cat ${datadir}/vol_info_table1 +echo |