diff options
author | Frank Haverkamp <haver@vnet.ibm.com> | 2006-06-21 14:26:02 +0200 |
---|---|---|
committer | Frank Haverkamp <haver@vnet.ibm.com> | 2006-10-31 15:06:06 +0100 |
commit | 6ccd7242c4c1404dafb64cd937adc3c65ce02385 (patch) | |
tree | 5a2833912e91c6f3f0d99b72d9dede35dc9c1ae2 /ubi-utils/src | |
parent | f175083413f0f94de88def865eeb65e465ded389 (diff) |
[MTD] UBI: Removed automake, autoconf, added ubi userspace headers.
Signed-off-by: Frank Haverkamp <haver@vnet.ibm.com>
Diffstat (limited to 'ubi-utils/src')
-rw-r--r-- | ubi-utils/src/bin2nand.c (renamed from ubi-utils/src/bin2nand/bin2nand.c) | 73 | ||||
-rw-r--r-- | ubi-utils/src/bin2nand/nandecc.h | 11 | ||||
-rw-r--r-- | ubi-utils/src/bootenv.c (renamed from ubi-utils/src/libbootenv/bootenv.c) | 18 | ||||
-rw-r--r-- | ubi-utils/src/bootenv.h | 415 | ||||
-rw-r--r-- | ubi-utils/src/config.h | 28 | ||||
-rw-r--r-- | ubi-utils/src/crc32.c (renamed from ubi-utils/src/libcrc32/crc32.c) | 0 | ||||
-rw-r--r-- | ubi-utils/src/crc32.h | 36 | ||||
-rw-r--r-- | ubi-utils/src/error.c (renamed from ubi-utils/src/liberror/error.c) | 0 | ||||
-rw-r--r-- | ubi-utils/src/error.h | 84 | ||||
-rw-r--r-- | ubi-utils/src/example_ubi.h | 28 | ||||
-rw-r--r-- | ubi-utils/src/hashmap.c (renamed from ubi-utils/src/libbootenv/hashmap.c) | 0 | ||||
-rw-r--r-- | ubi-utils/src/hashmap.h (renamed from ubi-utils/src/libbootenv/hashmap.h) | 0 | ||||
-rw-r--r-- | ubi-utils/src/libpfiflash.c (renamed from ubi-utils/src/libpfiflash/pfiflash.c) | 12 | ||||
-rw-r--r-- | ubi-utils/src/libubi.c (renamed from ubi-utils/src/libubi/libubi.c) | 0 | ||||
-rw-r--r-- | ubi-utils/src/libubi_int.h (renamed from ubi-utils/src/libubi/libubi_int.h) | 6 | ||||
-rw-r--r-- | ubi-utils/src/libubi_sysfs.c (renamed from ubi-utils/src/libubi/libubi_sysfs.c) | 5 | ||||
-rw-r--r-- | ubi-utils/src/libubi_sysfs.h (renamed from ubi-utils/src/libubi/libubi_sysfs.h) | 0 | ||||
-rw-r--r-- | ubi-utils/src/libubigen.c (renamed from ubi-utils/src/libubigen/ubigen.c) | 2 | ||||
-rw-r--r-- | ubi-utils/src/libubimirror.c (renamed from ubi-utils/src/libubimirror/ubimirror.c) | 6 | ||||
-rw-r--r-- | ubi-utils/src/list.c (renamed from ubi-utils/src/liblist/list.c) | 0 | ||||
-rw-r--r-- | ubi-utils/src/list.h | 56 | ||||
-rw-r--r-- | ubi-utils/src/mkbootenv.c (renamed from ubi-utils/src/mkbootenv/mkbootenv.c) | 0 | ||||
-rw-r--r-- | ubi-utils/src/mkpfi/f128_nand_sample.cfg | 38 | ||||
-rw-r--r-- | ubi-utils/src/mkpfi/f64_nor_sample.cfg | 39 | ||||
-rwxr-xr-x | ubi-utils/src/mkpfi/mkpfi | 723 | ||||
-rw-r--r-- | ubi-utils/src/nand2bin.c (renamed from ubi-utils/src/nand2bin/nand2bin.c) | 9 | ||||
-rw-r--r-- | ubi-utils/src/nandcorr.c (renamed from ubi-utils/src/nand2bin/nandcorr.c) | 0 | ||||
-rw-r--r-- | ubi-utils/src/nandecc.c (renamed from ubi-utils/src/bin2nand/nandecc.c) | 0 | ||||
-rw-r--r-- | ubi-utils/src/nandecc.h | 28 | ||||
-rw-r--r-- | ubi-utils/src/pddcustomize.c (renamed from ubi-utils/src/pddcustomize/pddcustomize.c) | 0 | ||||
-rw-r--r-- | ubi-utils/src/peb.c (renamed from ubi-utils/src/libpeb/peb.c) | 0 | ||||
-rw-r--r-- | ubi-utils/src/peb.h | 41 | ||||
-rw-r--r-- | ubi-utils/src/pfi.c (renamed from ubi-utils/src/libpfi/pfi.c) | 0 | ||||
-rw-r--r-- | ubi-utils/src/pfi.h | 244 | ||||
-rw-r--r-- | ubi-utils/src/pfi2bin.c (renamed from ubi-utils/src/pfi2bin/pfi2bin.c) | 0 | ||||
-rw-r--r-- | ubi-utils/src/pfiflash.c (renamed from ubi-utils/src/pfiflash/pfiflash.c) | 2 | ||||
-rw-r--r-- | ubi-utils/src/pfiflash.h | 62 | ||||
-rw-r--r-- | ubi-utils/src/reader.c (renamed from ubi-utils/src/libreader/reader.c) | 14 | ||||
-rw-r--r-- | ubi-utils/src/reader.h | 84 | ||||
-rw-r--r-- | ubi-utils/src/ubicrc32.c (renamed from ubi-utils/src/ubicrc32/ubicrc32.c) | 0 | ||||
-rwxr-xr-x | ubi-utils/src/ubicrc32/ubicrc32.pl | 74 | ||||
-rw-r--r-- | ubi-utils/src/ubigen.c (renamed from ubi-utils/src/ubigen/ubigen_main.c) | 0 | ||||
-rw-r--r-- | ubi-utils/src/ubigen.h | 149 | ||||
-rw-r--r-- | ubi-utils/src/ubiinfo/ubiflash.h | 185 | ||||
-rw-r--r-- | ubi-utils/src/ubiinfo/ubiinfo.c | 406 | ||||
-rw-r--r-- | ubi-utils/src/ubiinfo/ubiipl.h | 87 | ||||
-rw-r--r-- | ubi-utils/src/ubimirror.c (renamed from ubi-utils/src/ubimirror/ubimirror.c) | 0 | ||||
-rw-r--r-- | ubi-utils/src/ubimirror.h | 66 | ||||
-rw-r--r-- | ubi-utils/src/ubimkvol.c (renamed from ubi-utils/src/ubimkvol/ubimkvol.c) | 9 | ||||
-rw-r--r-- | ubi-utils/src/ubirmvol.c (renamed from ubi-utils/src/ubirmvol/ubirmvol.c) | 4 | ||||
-rw-r--r-- | ubi-utils/src/ubiupdatevol.c (renamed from ubi-utils/src/ubiwritevol/ubiwritevol.c) | 6 | ||||
-rw-r--r-- | ubi-utils/src/unubi.c (renamed from ubi-utils/src/unubi/unubi.c) | 11 |
52 files changed, 1425 insertions, 1636 deletions
diff --git a/ubi-utils/src/bin2nand/bin2nand.c b/ubi-utils/src/bin2nand.c index 5224e3b..168f7dd 100644 --- a/ubi-utils/src/bin2nand/bin2nand.c +++ b/ubi-utils/src/bin2nand.c @@ -23,11 +23,9 @@ * * 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) - * */ #include <unistd.h> @@ -77,33 +75,48 @@ static const char copyright [] __attribute__((unused)) = "FIXME: insert license type."; /* FIXME */ static struct argp_option options[] = { - { name: "copyright", key: 'c', arg: NULL, flags: 0, - doc: "Print copyright information.", - group: 1 }, - - { name: "pagesize", key: 'p', arg: "<num>", flags: 0, - doc: "Pagesize in Byte/Mi/ki. Default: 2048", - group: 1 }, - - { name: "padding", key: 'j', arg: "<num>", flags: 0, - doc: "Padding in Byte/Mi/ki. Default: no padding", - group: 1 }, - - /* Output options */ - { name: NULL, key: 0, arg: NULL, flags: 0, - doc: "Output settings:", - group: 2 }, - - { name: "output", key: 'o', arg: "<fname>", flags: 0, - doc: "Output filename. Interleaved Data/OOB if output-oob not " + { .name = "copyright", + .key = 'c', + .arg = NULL, + .flags = 0, + .doc = "Print copyright information.", + .group = 1 }, + + { .name = "pagesize", + .key = 'p', + .arg = "<num>", + .flags = 0, + .doc = "Pagesize in Byte/Mi/ki. Default = 2048", + .group = 1 }, + + { .name = "padding", + .key = 'j', + .arg = "<num>", + .flags = 0, + .doc = "Padding in Byte/Mi/ki. Default = no padding", + .group = 1 }, + + { .name = "output", + .key = 'o', + .arg = "<fname>", + .flags = 0, + .doc = "Output filename. Interleaved Data/OOB if output-oob not " "specified.", - group: 2 }, - - { name: "output-oob", key: 'q', arg: "<fname>", flags: 0, - doc: "Write OOB data in separate file.", - group: 2 }, - - { name: NULL, key: 0, arg: NULL, flags: 0, doc: NULL, group: 0 }, + .group = 2 }, + + { .name = "output-oob", + .key = 'q', + .arg = "<fname>", + .flags = 0, + .doc = "Write OOB data in separate file.", + .group = 2 }, + + { .name = NULL, + .key = 0, + .arg = NULL, + .flags = 0, + .doc = NULL, + .group = 0 }, }; typedef struct myargs { @@ -254,8 +267,8 @@ int main (int argc, char** argv) .pagesize = PAGESIZE, .padding = PADDING, .fp_in = NULL, - .file_out_data = "", - .file_out_oob = "", + .file_out_data = NULL, + .file_out_oob = NULL, }; FILE* fp_out_data = stdout; diff --git a/ubi-utils/src/bin2nand/nandecc.h b/ubi-utils/src/bin2nand/nandecc.h deleted file mode 100644 index 8ae8a66..0000000 --- a/ubi-utils/src/bin2nand/nandecc.h +++ /dev/null @@ -1,11 +0,0 @@ -/* - * NAND ecc functions - */ -#ifndef _NAND_ECC_H -#define _NAND_ECC_H - -#include <stdint.h> - -extern int nand_calculate_ecc(const uint8_t *dat, uint8_t *ecc_code); - -#endif diff --git a/ubi-utils/src/libbootenv/bootenv.c b/ubi-utils/src/bootenv.c index b6a1191..8871d90 100644 --- a/ubi-utils/src/libbootenv/bootenv.c +++ b/ubi-utils/src/bootenv.c @@ -27,6 +27,7 @@ #include <sys/stat.h> #include <bootenv.h> +#include "config.h" #include "hashmap.h" #include "error.h" @@ -390,7 +391,7 @@ err: static int fill_output_buffer(bootenv_t env, char *buf, size_t buf_size_max, - size_t *written) + size_t *written) { int rc = 0; size_t keys_size, i; @@ -403,7 +404,7 @@ fill_output_buffer(bootenv_t env, char *buf, size_t buf_size_max, goto err; for (i = 0; i < keys_size; i++) { - if (wr > BOOTENV_MAXSIZE) { + if (wr > buf_size_max) { rc = -ENOSPC; goto err; } @@ -412,7 +413,7 @@ fill_output_buffer(bootenv_t env, char *buf, size_t buf_size_max, if (rc != 0) goto err; - wr += snprintf(buf + wr, BOOTENV_MAXSIZE - wr, + wr += snprintf(buf + wr, buf_size_max - wr, "%s=%s", keys[i], val); wr++; /* for \0 */ } @@ -514,7 +515,7 @@ err: } int -bootenv_valid(bootenv_t env) +bootenv_valid(bootenv_t env __unused) { /* @FIXME No sanity check implemented. */ return 0; @@ -574,7 +575,8 @@ err: int bootenv_pdd_keep(bootenv_t env_old, bootenv_t env_new, bootenv_t *env_res, - int *warnings, char *err_buf, size_t err_buf_size) + int *warnings, char *err_buf __unused, + size_t err_buf_size __unused) { bootenv_list_t l_old = NULL; bootenv_list_t l_new = NULL; @@ -683,8 +685,8 @@ err: int bootenv_pdd_overwrite(bootenv_t env_old, bootenv_t env_new, - bootenv_t *env_res, int *warnings, - char *err_buf, size_t err_buf_size) + bootenv_t *env_res, int *warnings __unused, + char *err_buf __unused, size_t err_buf_size __unused) { if ((env_old == NULL) || (env_new == NULL) || (env_res == NULL)) return -EINVAL; @@ -694,7 +696,7 @@ bootenv_pdd_overwrite(bootenv_t env_old, bootenv_t env_new, int bootenv_pdd_merge(bootenv_t env_old, bootenv_t env_new, bootenv_t *env_res, - int *warnings, char *err_buf, size_t err_buf_size) + int *warnings __unused, char *err_buf, size_t err_buf_size) { if ((env_old == NULL) || (env_new == NULL) || (env_res == NULL)) return -EINVAL; diff --git a/ubi-utils/src/bootenv.h b/ubi-utils/src/bootenv.h new file mode 100644 index 0000000..86743ed --- /dev/null +++ b/ubi-utils/src/bootenv.h @@ -0,0 +1,415 @@ +#ifndef __BOOTENV_H__ +#define __BOOTENV_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. + */ + +#include <stdio.h> /* FILE */ +#include <stdint.h> +#include <pfiflash.h> + +/* DOXYGEN DOCUMENTATION */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file bootenv.h + * @author oliloh@de.ibm.com + * @version 1.3 + * + * 1.3 Some renaming + */ + +/** + * @mainpage Usage + * + * @section intro Introduction + * This library provides all functionality to handle with the so-called + * platform description data (PDD) and the bootparameters defined in + * U-Boot. It is able to apply the defined PDD operations in PDD update + * scenarios. For more information about the PDD and bootparameter + * environment "bootenv" confer the PDD documentation. + * + * @section ret Return codes + * This library defines some return codes which will be delivered classified + * as warnings or errors. See the "Defines" section for details and numeric + * values. + * + * @section benv Bootenv format description + * There are two different input formats: + * - text files + * - binary files + * + * @subsection txt Text Files + * Text files have to be specified like: + * @verbatim key1=value1,value2,value7\n key2=value55,value1\n key4=value1\n@endverbatim + * + * @subsection bin Binary files + * Binary files have to be specified like: + * @verbatim<CRC32-bit>key1=value1,value2,value7\0key2=value55,value1\0... @endverbatim + * You can confer the U-Boot documentation for more details. + * + * @section benvlists Bootenv lists format description. + * Values referenced in the preceeding subsection can be + * defined like lists: + * @verbatim value1,value2,value3 @endverbatim + * There are some situation where a conversion of a comma + * seperated list can be useful, e.g. to get a list + * of defined PDD entries. + */ + +#define BOOTENV_MAXSIZE (1024 * 100) /* max 100kiB space for bootenv */ + +/** + * @def BOOTENV_ECRC + * @brief Given binary file is to large. + * @def BOOTENV_EFMT + * @brief Given bootenv section has an invalid format + * @def BOOTENV_EBADENTRY + * @brief Bad entry in the bootenv section. + * @def BOOTENV_EINVAL + * @brief Invalid bootenv defintion. + * @def BOOTENV_ENOPDD + * @brief Given bootenv sectoin has no PDD defintion string (pdd=...). + * @def BOOTENV_EPDDINVAL + * @brief Given bootenv section has an invalid PDD defintion. + * @def BOOTENV_ENOTIMPL + * @brief Functionality not implemented. + * @def BOOTENV_ECOPY + * @brief Bootenv memory copy error + * @def BOOTENV_ENOTFOUND + * @brief Given key has has no value. + * @def BOOTENV_EMAX + * @brief Highest error value. + */ +#define BOOTENV_ETOOBIG 1 +#define BOOTENV_EFMT 2 +#define BOOTENV_EBADENTRY 3 +#define BOOTENV_EINVAL 4 +#define BOOTENV_ENOPDD 5 +#define BOOTENV_EPDDINVAL 6 +#define BOOTENV_ENOTIMPL 7 +#define BOOTENV_ECOPY 8 +#define BOOTENV_ENOTFOUND 9 +#define BOOTENV_EMAX 10 + +/** + * @def BOOTENV_W + * @brief A warning which is handled internally as an error + * but can be recovered by manual effort. + * @def BOOTENV_WPDD_STRING_DIFFERS + * @brief The PDD strings of old and new PDD differ and + * can cause update problems, because new PDD values + * are removed from the bootenv section completely. + */ +#define BOOTENV_W 20 +#define BOOTENV_WPDD_STRING_DIFFERS 21 +#define BOOTENV_WMAX 22 /* highest warning value */ + + +typedef struct bootenv *bootenv_t; + /**< A bootenv library handle. */ + +typedef struct bootenv_list *bootenv_list_t; + /**< A handle for a value list. */ + +typedef int(*pdd_func_t)(bootenv_t, bootenv_t, bootenv_t*, + int*, char*, size_t); + + +/** + * @brief Get a new handle. + * @return 0 + * @return or error + * */ +int bootenv_create(bootenv_t *env); + +/** + * @brief Cleanup structure. + * @param env Bootenv structure which shall be destroyed. + * @return 0 + * @return or error + */ +int bootenv_destroy(bootenv_t *env); + +/** + * @brief Copy a bootenv handle. + * @param in The input bootenv. + * @param out The copied output bootenv. Discards old data. + * @return 0 + * @return or error + */ +int bootenv_copy_bootenv(bootenv_t in, bootenv_t *out); + +/** + * @brief Looks for a value inside the bootenv data. + * @param env Handle to a bootenv structure. + * @param key The key. + * @return NULL key not found + * @return !NULL ptr to value + */ +int bootenv_get(bootenv_t env, const char *key, const char **value); + + +/** + * @brief Looks for a value inside the bootenv data and converts it to num. + * @param env Handle to a bootenv structure. + * @param key The key. + * @param value A pointer to the resulting numerical value + * @return NULL key not found + * @return !NULL ptr to value + */ +int bootenv_get_num(bootenv_t env, const char *key, uint32_t *value); + +/** + * @brief Set a bootenv value by key. + * @param env Handle to a bootenv structure. + * @param key Key. + * @param value Value to set. + * @return 0 + * @return or error + */ +int bootenv_set(bootenv_t env, const char *key, const char *value); + +/** + * @brief Remove the given key (and its value) from a bootenv structure. + * @param env Handle to a bootenv structure. + * @param key Key. + * @return 0 + * @return or error + */ +int bootenv_unset(bootenv_t env, const char *key); + + +/** + * @brief Get a vector of all keys which are currently set + * within a bootenv handle. + * @param env Handle to a bootenv structure. + * @param size The size of the allocated array structure. + * @param sort Flag, if set the vector is sorted ascending. + * @return NULL on error. + * @return !NULL a pointer to the first element the allocated vector. + * @warning Free the allocate memory yourself! + */ +int bootenv_get_key_vector(bootenv_t env, size_t *size, int sort, + const char ***vector); + +/** + * @brief Calculate the size in bytes which are necessary to write the + * current bootenv section in a *binary file. + * @param env bootenv handle. + * @param size The size in bytes of the bootenv handle. + * @return 0 + * @return or ERROR. + */ +int bootenv_size(bootenv_t env, size_t *size); + +/** + * @brief Read a binary bootenv file. + * @param fp File pointer to input stream. + * @param env bootenv handle. + * @param size maximum data size. + * @return 0 + * @return or ERROR. + */ +int bootenv_read(FILE* fp, bootenv_t env, size_t size); + + +/** + * @brief Read bootenv data from an text/ascii file. + * @param fp File pointer to ascii PDD file. + * @param env bootenv handle + * @return 0 + * @return or ERROR. + */ +int bootenv_read_txt(FILE* fp, bootenv_t env); + +/** + * @brief Write a bootenv structure to the given location (binary). + * @param fp Filepointer to binary file. + * @param env Bootenv structure which shall be written. + * @return 0 + * @return or error + */ +int bootenv_write(FILE* fp, bootenv_t env); + +/** + * @brief Write a bootenv structure to the given location (text). + * @param fp Filepointer to text file. + * @param env Bootenv structure which shall be written. + * @return 0 + * @return or error + */ +int bootenv_write_txt(FILE* fp, bootenv_t env); + +/** + * @brief Prototype for a PDD handling funtion + */ + +/** + * @brief The PDD keep operation. + * @param env_old The old bootenv structure. + * @param env_new The new bootenv structure. + * @param env_res The result of PDD keep. + * @param warnings A flag which marks any warnings. + * @return 0 + * @return or error + * @note For a complete documentation about the algorithm confer the + * PDD documentation. + */ +int bootenv_pdd_keep(bootenv_t env_old, bootenv_t env_new, + bootenv_t *env_res, int *warnings, + char *err_buf, size_t err_buf_size); + + +/** + * @brief The PDD merge operation. + * @param env_old The old bootenv structure. + * @param env_new The new bootenv structure. + * @param env_res The result of merge-pdd. + * @param warnings A flag which marks any warnings. + * @return 0 + * @return or error + * @note For a complete documentation about the algorithm confer the + * PDD documentation. + */ +int bootenv_pdd_merge(bootenv_t env_old, bootenv_t env_new, + bootenv_t *env_res, int *warnings, + char *err_buf, size_t err_buf_size); + +/** + * @brief The PDD overwrite operation. + * @param env_old The old bootenv structure. + * @param env_new The new bootenv structure. + * @param env_res The result of overwrite-pdd. + * @param warnings A flag which marks any warnings. + * @return 0 + * @return or error + * @note For a complete documentation about the algorithm confer the + * PDD documentation. + */ +int bootenv_pdd_overwrite(bootenv_t env_new, + bootenv_t env_old, bootenv_t *env_res, int *warnings, + char *err_buf, size_t err_buf_size); + +/** + * @brief Dump a bootenv structure to stdout. (Debug) + * @param env Handle to a bootenv structure. + * @return 0 + * @return or error + */ +int bootenv_dump(bootenv_t env); + +/** + * @brief Validate a bootenv structure. + * @param env Handle to a bootenv structure. + * @return 0 + * @return or error + */ +int bootenv_valid(bootenv_t env); + +/** + * @brief Create a new bootenv list structure. + * @return NULL on error + * @return or a new list handle. + * @note This structure is used to store values in a list. + * A useful addition when handling PDD strings. + */ +int bootenv_list_create(bootenv_list_t *list); + +/** + * @brief Destroy a bootenv list structure + * @param list Handle to a bootenv list structure. + * @return 0 + * @return or error + */ +int bootenv_list_destroy(bootenv_list_t *list); + +/** + * @brief Import a list from a comma seperated string + * @param list Handle to a bootenv list structure. + * @param str Comma seperated string list. + * @return 0 + * @return or error + */ +int bootenv_list_import(bootenv_list_t list, const char *str); + +/** + * @brief Export a list to a string of comma seperated values. + * @param list Handle to a bootenv list structure. + * @return NULL one error + * @return or pointer to a newly allocated string. + * @warning Free the allocated memory by yourself! + */ +int bootenv_list_export(bootenv_list_t list, char **string); + +/** + * @brief Add an item to the list. + * @param list A handle of a list structure. + * @param item An item. + * @return 0 + * @return or error + */ +int bootenv_list_add(bootenv_list_t list, const char *item); + +/** + * @brief Remove an item from the list. + * @param list A handle of a list structure. + * @param item An item. + * @return 0 + * @return or error + */ +int bootenv_list_remove(bootenv_list_t list, const char *item); + +/** + * @brief Check if a given item is in a given list. + * @param list A handle of a list structure. + * @param item An item. + * @return 1 Item is in list. + * @return 0 Item is not in list. + */ +int bootenv_list_is_in(bootenv_list_t list, const char *item); + + +/** + * @brief Convert a list into a vector of all values inside the list. + * @param list Handle to a bootenv structure. + * @param size The size of the allocated vector structure. + * @return 0 + * @return or error + * @warning Free the allocate memory yourself! + */ +int bootenv_list_to_vector(bootenv_list_t list, size_t *size, + const char ***vector); + +/** + * @brief Convert a list into a vector of all values inside the list. + * @param list Handle to a bootenv structure. + * @param size The size of the allocated vector structure. + * @return 0 + * @return or error + * @warning Free the allocate memory yourself! + */ +int bootenv_list_to_num_vector(bootenv_list_t list, size_t *size, + uint32_t **vector); + +#ifdef __cplusplus +} +#endif +#endif /*__BOOTENV_H__ */ diff --git a/ubi-utils/src/config.h b/ubi-utils/src/config.h new file mode 100644 index 0000000..746fa3c --- /dev/null +++ b/ubi-utils/src/config.h @@ -0,0 +1,28 @@ +#ifndef __CONFIG_H__ +#define __CONFIG_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. + * + * Author: Frank Haverkamp + */ + +#define PACKAGE_VERSION "1.0" +#define PACKAGE_BUGREPORT "dedekind@oktetlabs.ru, haver@vnet.ibm.com, or tglx@linutronix.de" + +#define __unused __attribute__((unused)) + +#endif diff --git a/ubi-utils/src/libcrc32/crc32.c b/ubi-utils/src/crc32.c index 666e217..666e217 100644 --- a/ubi-utils/src/libcrc32/crc32.c +++ b/ubi-utils/src/crc32.c diff --git a/ubi-utils/src/crc32.h b/ubi-utils/src/crc32.h new file mode 100644 index 0000000..31362b0 --- /dev/null +++ b/ubi-utils/src/crc32.h @@ -0,0 +1,36 @@ +#ifndef __CRC32_H__ +#define __CRC32_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. + */ + +/* + * Author: Thomas Gleixner + * + * CRC32 functions + * + * Can be compiled as seperate object, but is included into the ipl source + * so gcc can inline the functions. We optimize for size so the omission of + * the function frame is helpful. + * + */ +#include <stdint.h> + +void init_crc32_table(uint32_t *table); +uint32_t clc_crc32(uint32_t *table, uint32_t crc, void *buf, int len); + +#endif /* __CRC32_H__ */ diff --git a/ubi-utils/src/liberror/error.c b/ubi-utils/src/error.c index c8c623c..c8c623c 100644 --- a/ubi-utils/src/liberror/error.c +++ b/ubi-utils/src/error.c diff --git a/ubi-utils/src/error.h b/ubi-utils/src/error.h new file mode 100644 index 0000000..e8d7137 --- /dev/null +++ b/ubi-utils/src/error.h @@ -0,0 +1,84 @@ +#ifndef __ERROR_H__ +#define __ERROR_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. + */ + +#include <stdio.h> + +void error_initlog(const char *logfile); +int read_procfile(FILE *fp_out, const char *procfile); + +void __err_ret(const char *fmt, ...); +void __err_sys(const char *fmt, ...); +void __err_msg(const char *fmt, ...); +void __err_quit(const char *fmt, ...); +void __err_dump(const char *fmt, ...); + +void info_msg(const char *fmt, ...); + +#ifdef DEBUG +#define __loc_msg(str) do { \ + __err_msg("[%s. FILE: %s FUNC: %s LINE: %d]\n", \ + str, __FILE__, __FUNCTION__, __LINE__); \ +} while (0) +#else +#define __loc_msg(str) +#endif + + +#define err_dump(fmt, ...) do { \ + __loc_msg("ErrDump"); \ + __err_dump(fmt, ##__VA_ARGS__); \ +} while (0) + +#define err_quit(fmt, ...) do { \ + __loc_msg("ErrQuit"); \ + __err_quit(fmt, ##__VA_ARGS__); \ +} while (0) + + +#define err_ret(fmt, ...) do { \ + __loc_msg("ErrRet"); \ + __err_ret(fmt, ##__VA_ARGS__); \ +} while (0) + +#define err_sys(fmt, ...) do { \ + __loc_msg("ErrSys"); \ + __err_sys(fmt, ##__VA_ARGS__); \ +} while (0) + +#define err_msg(fmt, ...) do { \ + __loc_msg("ErrMsg"); \ + __err_msg(fmt, ##__VA_ARGS__); \ +} while (0) + +#define log_msg(fmt, ...) do { \ + /* __loc_msg("LogMsg"); */ \ + __err_msg(fmt, ##__VA_ARGS__); \ +} while (0) + +#ifdef DEBUG +#define dbg_msg(fmt, ...) do { \ + __loc_msg("DbgMsg"); \ + __err_msg(fmt, ##__VA_ARGS__); \ +} while (0) +#else +#define dbg_msg(fmt, ...) +#endif + +#endif /* __ERROR_H__ */ diff --git a/ubi-utils/src/example_ubi.h b/ubi-utils/src/example_ubi.h new file mode 100644 index 0000000..23c7b54 --- /dev/null +++ b/ubi-utils/src/example_ubi.h @@ -0,0 +1,28 @@ +#ifndef __EXAMPLE_UBI_H__ +#define __EXAMPLE_UBI_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. + */ + +/** + * Defaults for our cards. + */ +#define EXAMPLE_UBI_DEVICE 0 +#define EXAMPLE_BOOTENV_VOL_ID_1 4 +#define EXAMPLE_BOOTENV_VOL_ID_2 5 + +#endif /* __EXAMPLE_UBI_H__ */ diff --git a/ubi-utils/src/libbootenv/hashmap.c b/ubi-utils/src/hashmap.c index 250f71f..250f71f 100644 --- a/ubi-utils/src/libbootenv/hashmap.c +++ b/ubi-utils/src/hashmap.c diff --git a/ubi-utils/src/libbootenv/hashmap.h b/ubi-utils/src/hashmap.h index 1b13e95..1b13e95 100644 --- a/ubi-utils/src/libbootenv/hashmap.h +++ b/ubi-utils/src/hashmap.h diff --git a/ubi-utils/src/libpfiflash/pfiflash.c b/ubi-utils/src/libpfiflash.c index 0859a22..ed2af3c 100644 --- a/ubi-utils/src/libpfiflash/pfiflash.c +++ b/ubi-utils/src/libpfiflash.c @@ -40,8 +40,9 @@ #include <libubi.h> #include <pfiflash.h> -#include <mtd/ubi-user.h> /* FIXME Is this ok here!!?? */ +//#include <mtd/ubi-user.h> /* FIXME Is this ok here!!?? */ +#include "config.h" #include "ubimirror.h" #include "error.h" #include "reader.h" @@ -158,7 +159,8 @@ my_ubi_mkvol(int devno, int s, pfi_ubi_t u, char *err_buf, size_t err_buf_size) * If the volume does not exist, the function will return success. */ static int -my_ubi_rmvol(int devno, uint32_t id, char *err_buf, size_t err_buf_size) +my_ubi_rmvol(int devno, uint32_t id, + char *err_buf __unused, size_t err_buf_size __unused) { int rc = 0; ubi_lib_t ulib = NULL; @@ -321,7 +323,7 @@ write_bootenv_volume(int devno, uint32_t id, bootenv_t bootenv_old, static int write_normal_volume(int devno, uint32_t id, size_t update_size, FILE* fp_in, - char *err_buf, size_t err_buf_size) + char *err_buf __unused, size_t err_buf_size __unused) { int rc = 0; ubi_lib_t ulib = NULL; @@ -386,7 +388,7 @@ process_ubi_volumes(FILE* pfi, int seqnum, list_t pfi_ubis, foreach(u, ptr, pfi_ubis) { int s = seqnum; - if (seqnum > (u->ids_size - 1)) { + if (seqnum > ((int)u->ids_size - 1)) { s = 0; /* per default use the first */ } u->curr_seqnum = s; @@ -585,7 +587,7 @@ pfiflash(FILE* pfi, int complete, int seqnum, pdd_handling_t pdd_handling, } } - if ((pdd_handling >= 0) && (pdd_handling < PDD_HANDLING_NUM)) { + if (((int)pdd_handling >= 0) && (pdd_handling < PDD_HANDLING_NUM)) { pdd_f = pdd_funcs[pdd_handling]; } else { diff --git a/ubi-utils/src/libubi/libubi.c b/ubi-utils/src/libubi.c index 9b9a793..9b9a793 100644 --- a/ubi-utils/src/libubi/libubi.c +++ b/ubi-utils/src/libubi.c diff --git a/ubi-utils/src/libubi/libubi_int.h b/ubi-utils/src/libubi_int.h index 1640010..ab387f5 100644 --- a/ubi-utils/src/libubi/libubi_int.h +++ b/ubi-utils/src/libubi_int.h @@ -36,17 +36,17 @@ fprintf(stderr, "UBI Library Error at %s: ", __func__); \ fprintf(stderr, fmt, ##__VA_ARGS__); \ fprintf(stderr, "\n"); \ - } while(0) + } while (0) #ifdef UBILIB_DEBUG #define ubi_dbg(fmt, ...) do { \ fprintf(stderr, "UBI Debug: %s: ", __func__); \ fprintf(stderr, fmt, ##__VA_ARGS__); \ fprintf(stderr, "\n"); \ - } while(0) + } while (0) #else -#define ubi_dbg(fmt, ...) +#define ubi_dbg(fmt, ...) do { } while (0) #endif /** diff --git a/ubi-utils/src/libubi/libubi_sysfs.c b/ubi-utils/src/libubi_sysfs.c index f7ecebc..95fd3de 100644 --- a/ubi-utils/src/libubi/libubi_sysfs.c +++ b/ubi-utils/src/libubi_sysfs.c @@ -32,6 +32,7 @@ #include <errno.h> #include <stdarg.h> +#include "config.h" #include "libubi_int.h" int @@ -128,7 +129,7 @@ sysfs_read_dev_subst(const char *patt, unsigned int *major, } static int -sysfs_read_ull(const char *file, unsigned long long *num) +sysfs_read_ull(const char *file __unused, unsigned long long *num __unused) { return 0; } @@ -147,7 +148,7 @@ sysfs_read_ull_subst(const char *patt, unsigned long long *num, int n, ...) } static int -sysfs_read_uint(const char *file, unsigned int *num) +sysfs_read_uint(const char *file __unused, unsigned int *num __unused) { return 0; } diff --git a/ubi-utils/src/libubi/libubi_sysfs.h b/ubi-utils/src/libubi_sysfs.h index 2fb6072..2fb6072 100644 --- a/ubi-utils/src/libubi/libubi_sysfs.h +++ b/ubi-utils/src/libubi_sysfs.h diff --git a/ubi-utils/src/libubigen/ubigen.c b/ubi-utils/src/libubigen.c index 0cfa687..258e555 100644 --- a/ubi-utils/src/libubigen/ubigen.c +++ b/ubi-utils/src/libubigen.c @@ -247,7 +247,7 @@ ubigen_write_broken_update(ubi_info_t u, uint32_t blk) } void -dump_info(ubi_info_t u) +dump_info(ubi_info_t u __unused) { #ifdef DEBUG int err = 0; diff --git a/ubi-utils/src/libubimirror/ubimirror.c b/ubi-utils/src/libubimirror.c index bf6b37c..e5715fc 100644 --- a/ubi-utils/src/libubimirror/ubimirror.c +++ b/ubi-utils/src/libubimirror.c @@ -48,7 +48,7 @@ enum { * Read len number of bytes from fd. * Return 0 on EOF, -1 on error. */ -static ssize_t fill_buffer(int fd, unsigned char *buf, size_t len) +static ssize_t fill_buffer(int fd, unsigned char *buf, ssize_t len) { ssize_t got, have = 0; @@ -65,7 +65,7 @@ static ssize_t fill_buffer(int fd, unsigned char *buf, size_t len) * Write len number of bytes to fd. * Return bytes written (>= 0), -1 on error. */ -static ssize_t flush_buffer(int fd, unsigned char *buf, size_t len) +static ssize_t flush_buffer(int fd, unsigned char *buf, ssize_t len) { ssize_t done, have = 0; @@ -150,7 +150,7 @@ copy_files(int fd_in, int fd_out) } int -ubimirror(uint32_t devno, int seqnum, uint32_t *ids, size_t ids_size, +ubimirror(uint32_t devno, int seqnum, uint32_t *ids, ssize_t ids_size, char *err_buf, size_t err_buf_size) { int rc = 0; diff --git a/ubi-utils/src/liblist/list.c b/ubi-utils/src/list.c index 6eb716b..6eb716b 100644 --- a/ubi-utils/src/liblist/list.c +++ b/ubi-utils/src/list.c diff --git a/ubi-utils/src/list.h b/ubi-utils/src/list.h new file mode 100644 index 0000000..e8452a2 --- /dev/null +++ b/ubi-utils/src/list.h @@ -0,0 +1,56 @@ +#ifndef __LIST_H__ +#define __LIST_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. + * + * Author: Oliver Lohmann + */ + +#include <stdint.h> + +#define foreach(elem, ptr, list) \ + for (elem = list != NULL ? (typeof(elem)) head(list) \ + : NULL, ptr = list; \ + ptr != NULL; \ + ptr = tail(ptr), \ + elem = (typeof(elem)) ptr ? head(ptr) : NULL) + +typedef struct node* list_t; +typedef void* info_t; +typedef int (*free_func_t)(info_t*); +typedef int (*cmp_func_t)(info_t, info_t); +typedef void (*process_func_t)(info_t); + +struct node { + list_t next; + info_t info; +}; + +list_t mk_empty(void); +int is_empty(list_t l); +info_t is_in(cmp_func_t cmp, info_t e, list_t l); +info_t head(list_t l); +list_t tail(list_t l); +list_t remove_head(list_t l); +list_t cons(info_t e, list_t l); +list_t prepend_elem(info_t e, list_t); +list_t append_elem(info_t e, list_t); +list_t remove_all(free_func_t free_func, list_t l); +list_t insert_sorted(cmp_func_t cmp_func, info_t e, list_t l); +void apply(process_func_t process_func, list_t l); + +#endif /* __LIST_H__ */ diff --git a/ubi-utils/src/mkbootenv/mkbootenv.c b/ubi-utils/src/mkbootenv.c index 49ce597..49ce597 100644 --- a/ubi-utils/src/mkbootenv/mkbootenv.c +++ b/ubi-utils/src/mkbootenv.c diff --git a/ubi-utils/src/mkpfi/f128_nand_sample.cfg b/ubi-utils/src/mkpfi/f128_nand_sample.cfg deleted file mode 100644 index e468d9d..0000000 --- a/ubi-utils/src/mkpfi/f128_nand_sample.cfg +++ /dev/null @@ -1,38 +0,0 @@ -[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/src/mkpfi/f64_nor_sample.cfg b/ubi-utils/src/mkpfi/f64_nor_sample.cfg deleted file mode 100644 index fd44e27..0000000 --- a/ubi-utils/src/mkpfi/f64_nor_sample.cfg +++ /dev/null @@ -1,39 +0,0 @@ -[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/src/mkpfi/mkpfi b/ubi-utils/src/mkpfi/mkpfi deleted file mode 100755 index 2cce587..0000000 --- a/ubi-utils/src/mkpfi/mkpfi +++ /dev/null @@ -1,723 +0,0 @@ -#!/usr/bin/perl -# -# 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. -# - -# -# mkpfi -# -# This perl program is assembles PFI files from a config file. -# -# Author: Oliver Lohmann (oliloh@de.ibm.com) -# -use warnings; -use strict; -use lib "/usr/lib/perl5"; # Please change this path as you need it, or - # make a proposal how this could be done - # nicer. -use Getopt::Long; -use Pod::Usage; -use Config::IniFiles; -use File::Temp; - -# ---------------------------------------------------------------------------- -# Versions -our $version : unique = "0.1"; -our $pfi_version : unique = "0x1"; - -# ---------------------------------------------------------------------------- -# Globals -my $verbose = 0; -my $cfg; - -my %opts = (); -my %files = (config => ""); -my @tmp_files; - -my %tools = (ubicrc32 => "ubicrc32"); - -# ---------------------------------------------------------------------------- -# Processing the input sections -# -# The idea is to combine each section entry with a function -# in order to allow some kind of preprocessing for the values -# before they are written into the PFI file. -# This is especially useful to be more verbose and -# user-friendly in the layout file. -# -# All key-function hashes are applied after the general -# validation of the configuration file. -# If any mandatory key is missing in a section the user -# will be informed and the PFI creation process is aborted. -# -# Default keys will be checked for their presence inside the config -# file. If they are missing, they will be generated with appr. values. - -# Mandatory keys for UBI volumes. -my %ubi_keys = ("ubi_ids" => \&check_id_list, - "ubi_size" => \&replace_num, - "ubi_type" => \&replace_type, - "ubi_names" => \&remove_spaces, - "ubi_alignment" => \&replace_num); - -# Mandatory keys for RAW sections. -my %raw_keys = ("raw_starts" => \&expand_starts, - "raw_total_size" => \&replace_num); - -# Common default keys for documentation and control purposes. -my %common_keys = ("flags" => \&replace_num, - "label" => \&do_nothing); - -# Define any defaults here. Values which maintained in this default -# region need not to be specified by the user explicitly. -my %def_ubi_keys = ("ubi_alignment" => [\&set_default, "0x1"]); -my %def_raw_keys = (); -my %def_common_keys = ("flags" => [\&set_default, "0x0"], - "label" => [\&generate_label, ""]); - -# ---------------------------------------------------------------------------- -# Input keys, actually the path to the input data. - -my %input_keys = ("image" => \&do_nothing); - -# Placeholder keys allow the replacement via a special -# purpose function. E.g. the bootenv_file key will be used -# to generate bootenv binary data from an text file and -# replace the bootenv_file key with an image key to handle it -# in the same way in the further creation process. -my %input_placeholder_keys = ("bootenv_file" => \&create_bootenv_image); - -# ---------------------------------------------------------------------------- -# Helper - -# @brief Get current time string. -sub get_date { - my $tmp = scalar localtime; - $tmp =~ s/ /_/g; - return $tmp; -} - -# @brief Print an info message to stdout. -sub INFO($) { - my $str = shift; - - if (!$verbose) { - return; - } - - print STDOUT $str; -} - -# @brief Print an error message to stderr. -sub ERR($) { - my $str = shift; - print STDERR $str; -} - -# @brief Print a warning message to stderr. -sub WARN($) { - my $str = shift; - print STDERR $str; -} - -sub parse_command_line($) { - my $opt = shift; - my $result = GetOptions( "help" => \$$opt{'help'}, - "man" => \$$opt{'man'}, - "config=s" => \$$opt{'config'}, - "verbose" => \$$opt{'verbose'}, - ) or pod2usage(2); - pod2usage(1) if defined ($$opt{help}); - pod2usage(-verbose => 2) if defined ($$opt{man}); - - $verbose = $$opt{verbose} if defined $$opt{verbose}; - - if (!defined $$opt{config}) { - ERR("[ ERROR: No config file specified. Aborting...\n"); - exit 1; - } - -} - -# @brief Check if all needed tools are in PATH. -sub check_tools { - my $err = 0; - my $key; - - foreach $key (keys %tools) { - if (`which $tools{$key}` eq "") { - ERR("\n") if ($err == 0); - ERR("! Please add the tool \'$tools{$key}\' " . - "to your path!\n"); - $err = 1; - } - } - die "[ ERROR: Did not find all needed tools!\n" if $err; -} - -sub open_cfg_file($) { - my $fname = shift; - my $res = new Config::IniFiles( -file => $fname ); - - die "[ ERROR: Cannot load your config file!\n" if (!defined $res); - return $res; -} - -sub set_default($$$$) { - my ($cfg, $section, $parameter, $def_value) = @_; - $cfg->newval($section, $parameter, $def_value); - return; -} - -sub generate_label($$$$) { - my ($cfg, $section, $parameter, $def_value) = @_; - my $new_label = $def_value . $section; - $new_label .= "_" . get_date; - $cfg->newval($section, $parameter, $new_label); - return; -} - -# @brief Converts any num to a unified hex string, i.e the resulting value -# always starts with "0x" and is aligned to 8 hexdigits. -# @return Returns 0 on success, otherwise an error occured. -# -sub any_num_to_hex($$) { - my $val = shift; - my $res = shift; - - # M(iB) - if ($val =~ m/([0-9]+)[Mm][i]?[Bb]?/g) { - $$res = sprintf("0x%08x", $1 * 1024 * 1024); - } - # k(iB) - elsif ($val =~ m/([0-9]+)[kK][i]?[Bb]?/g) { - $$res = sprintf("0x%08x", $1 * 1024); - } - # hex - elsif ($val =~ m/0x?([0-9a-fA-F]+)/g) { - $$res = sprintf("0x%08x", hex $1); - } - # decimal - elsif ($val =~ m/^([0-9]+)$/g) { - $$res = sprintf("0x%08x", $1); - } - else { - $$res = ""; - return -1; - } - - return 0; -} - -sub remove_spaces($$$) { - my ($cfg, $section, $parameter) = @_; - my ($start, @starts, @new_starts); - my $val = $cfg->val($section, $parameter); - my $res; - - $val =~ s/ //g; # spaces - $cfg->newval($section, $parameter, $val); -} - -sub expand_starts($$$) { - my ($cfg, $section, $parameter) = @_; - my ($start, @starts, @new_starts); - my $val = $cfg->val($section, $parameter); - my $res; - - $val =~ s/ //g; # spaces - @starts = split(/,/, $val); - - foreach $start (@starts) { - if (any_num_to_hex($start, \$res) != 0) { - ERR("[ ERROR: [$section]\n"); - ERR("[ Expecting a list of numeric " . - "values for parameter: $parameter\n"); - exit 1; - } - push (@new_starts, $res); - } - $res = join(',', @starts); - - $cfg->newval($section, $parameter, $res); -} - -sub check_id_list($$$) { - my ($cfg, $section, $parameter) = @_; - my $val = $cfg->val($section, $parameter); - my $res; - - if (!($val =~ m/^[0-9]+[,0-9]*/)) { - ERR("[ ERROR: Syntax error in 'ubi_ids' in " . - "section '$section': $val\n"); - ERR("[ Aborting... "); - exit 1; - } -} - -sub replace_type($$$) { - my ($cfg, $section, $parameter) = @_; - my $val = $cfg->val($section, $parameter); - my $res; - - $res = lc($val); - grep {$res eq $_} ('static', 'dynamic') - or die "[ ERROR: Unknown UBI Volume Type in " . - "section '$section': $val\n"; - - $cfg->newval($section, $parameter, $res); -} - - -sub replace_num($$$) { - my ($cfg, $section, $parameter) = @_; - my $val = $cfg->val($section, $parameter); - my $res = ""; - - if (any_num_to_hex($val, \$res) != 0) { - ERR("[ ERROR: [$section]\n"); - ERR("[ Expecting a numeric value " . - "for parameter: $parameter\n"); - exit 1; - } - $cfg->newval($section, $parameter, $res); -} - -sub do_nothing($$$) { - my ($cfg, $section, $parameter) = @_; - return; -} - -sub bootenv_sanity_check($) { - my $env = shift; # hash array containing bootenv - my %pdd = (); - - defined($$env{'pdd'}) or return "'pdd' not defined"; - foreach (split /,/, $$env{'pdd'}) { - defined($$env{$_}) or return "undefined '$_' in pdd"; - $pdd{$_} = 1; - } - - defined $$env{'pdd_preserve'} or - return ""; - foreach (split /,/, $$env{'pdd_preserve'}) { - defined($pdd{$_}) - or return "pdd_preserve field '$_' not in pdd"; - } - return ""; -} - -sub create_bootenv_image($$$) { - my ($cfg, $section, $parameter) = @_; - my $txt_fn = $cfg->val($section, "bootenv_file"); - my $in; - - my %value = (); - my @key = (); - - open $in, "<", $txt_fn - or die "[ ERROR: can't open bootenv file '$txt_fn'.\n"; - while (<$in>) { - next if (/^\s*(\#.*)?$/); # Skip comments/whitespace. - - if (/^(\S+?)\+\=(.*)$/) { - defined($value{$1}) or - die "$txt_fn:$.: error: appending to" . - " non-existent '$1'\n"; - $value{$1} .= $2; - } elsif (/^(\S+?)\=(.*)$/) { - not defined($value{$1}) or - die "$txt_fn:$.: error: trying to" . - " redefine '$1'\n"; - push @key, $1; - $value{$1} = $2; - } else { - die "$txt_fn:$.: error: unrecognized syntax\n"; - } - } - close $in; - - $_ = &bootenv_sanity_check(\%value) - and die "$txt_fn: error: $_\n"; - - my $tmp_file = new File::Temp(); - push (@tmp_files, $tmp_file); - - foreach (@key) { - print $tmp_file "$_=", $value{$_}, "\0"; - } - close $tmp_file; - - $cfg->newval($section, "image", $tmp_file-> filename); -} - -sub process_keys($$$) { - my ($cfg, $section, $keys) = @_; - my @parameters = $cfg->Parameters($section); - my $i; - - for ($i = 0 ; $i < scalar(@parameters) ; $i++ ) { - if (defined($$keys{$parameters[$i]})) { - $$keys{$parameters[$i]}->($cfg, $section, - $parameters[$i]); - } - } - -} - -sub is_in_keylist($$) { - my ($key, $keys) = @_; - my $i; - - for ($i = 0; $i < scalar(@$keys); $i++) { - if ($$keys[$i] eq $key) { - return 1; - } - } - - return 0; -} - -sub check_default_keys($$$) { - my ($cfg, $section, $keys) = @_; - my @parameters = $cfg->Parameters($section); - my $key; - - foreach $key (keys %$keys) { - if (!is_in_keylist($key, \@parameters)) { - $$keys{$key}[0]-> - ($cfg, $section, $key, $$keys{$key}[1]); - } - } - -} - - - -sub check_keys($$$) { - my ($cfg, $section, $keys) = @_; - my @parameters = $cfg->Parameters($section); - my ($i, $key, $err); - - $err = 0; - for ($i = 0 ; $i < scalar(@$keys) ; $i++ ) { - if (!is_in_keylist($$keys[$i], \@parameters)) { - ERR("[ ERROR: [$section]\n") if $err == 0; - $err = 1; - ERR("[ Missing key '$$keys[$i]'\n"); - } - } - - if ($err) { - ERR("[ Aborting...\n"); - exit 1; - } -} - -sub push_pfi_data($$$$$) { - my ($cfg, $section, $pfi_infos, $keys, $mode) = @_; - my ($tmp, $i, $hdr); - - my %pfi_info = (); - $pfi_info{'mode'} = $mode; - $pfi_info{'image'} = $cfg->val($section, "image"); - - # Build the PFI header - $hdr = sprintf("PFI!\n"); - $hdr .= sprintf("version=0x%08x\n", hex $pfi_version); - $hdr .= sprintf("mode=$mode\n"); - - # calculate the size of the binary data part - $tmp = -s $cfg->val($section, "image"); - if (!defined $tmp) { - ERR("[ ERROR: [$section]\n"); - ERR("[ Missing input image: " - . $cfg->val($section, "image") . "\n"); - exit 1; - } - # Check for the image to fit into the given space - my $quota; - if ($mode eq 'raw') { - $quota = oct $cfg->val($section, "raw_total_size"); - } elsif ($mode eq 'ubi') { - $quota = oct $cfg->val($section, "ubi_size"); - } - $tmp <= $quota - or die "[ERROR: image file too big: " . - $cfg->val($section, "image") . "\n"; - $pfi_info{'size'} = $tmp; - - $hdr .= sprintf("size=0x%08x\n", $tmp); - - my $img_file = $cfg->val($section, "image"); - my $crc32 = `$tools{'ubicrc32'} $img_file 2>&1`; - if (any_num_to_hex($crc32, \$tmp) != 0) { - die "[ ERROR: $tools{'ubicrc32'} returned with errors"; - } - $hdr .= sprintf("crc=$tmp\n"); - - - # Process all remaining keys - for ($i = 0; $i < scalar (@$keys); $i++) { - if ($$keys[$i] eq "image") { # special case image input file - if (! -e ($tmp = $cfg->val($section, "image"))) { - ERR("[ ERROR: [$section]\n"); - ERR("[ Cannot find input file $tmp\n"); - exit 1; - } - next; - } - $hdr .= sprintf("%s=%s\n", $$keys[$i], - $cfg->val($section, $$keys[$i])); - } - - $hdr .= sprintf("\n"); # end marker for PFI-header - - $pfi_info{'header'} = $hdr; - - # store in the header list - push @$pfi_infos, \%pfi_info; -} - -sub process_section($$$$$$) { - my ($cfg, $section, $pfi_infos, $custom_keys, - $def_custom_keys, $mode) = @_; - my @keys = (keys %common_keys, keys %$custom_keys); - my @complete_keys = (@keys, keys %input_keys); - - # set defaults if necessary - check_default_keys($cfg, $section, $def_custom_keys); - check_default_keys($cfg, $section, \%def_common_keys); - - # check for placeholders... - process_keys($cfg, $section, \%input_placeholder_keys); - - # VALIDATE layout.cfg entries - check_keys($cfg, $section, \@complete_keys); - - # execute linked functions (if any) - process_keys($cfg, $section, \%common_keys); - process_keys($cfg, $section, $custom_keys); - - push_pfi_data($cfg, $section, $pfi_infos, \@keys, $mode); -} - -sub get_section_info($$) { - my ($cfg, $section) = @_; - my @parameters = $cfg->Parameters($section); - my ($ubi, $raw, $i, @res); - - $ubi = $raw = 0; - for ($i = 0 ; $i < scalar(@parameters) ; $i++ ) { - if ($parameters[$i] =~ m/ubi_/gi) { - $ubi = 1; - @res = (\%ubi_keys, \%def_ubi_keys, "ubi"); - } - if ($parameters[$i] =~ m/raw_/gi) { - $raw = 1; - @res = (\%raw_keys, \%def_raw_keys, "raw"); - } - } - - if (($ubi + $raw) != 1) { # double definition in section - ERR("[ ERROR: Layout error in section '$section'\n"); - exit 1; - } - - return @res; -} - -sub mk_target_list($$) { - my $val = shift; - my $tmp = shift; - my $complete = 0; - - if ($val =~ m/\((.*)\)/g) { - $val = $1; - $complete = 1; - } - $val =~ s/ //g; # spaces - - @$tmp = split(/,/, $val); - - return $complete; -} - -sub copy_bytes($$$) { - my ($in, $out, $to_copy) = @_; - - while ($to_copy) { - my $buf; - my $bufsize = 1024*1024; - - $bufsize < $to_copy or $bufsize = $to_copy; - read($in, $buf, $bufsize) == $bufsize - or die "[ ERROR: Image file shrunk during operation\n"; - print $out $buf; - $to_copy -= $bufsize; - } -} - -sub write_target($$) { - my ($pfi_infos, $target) = @_; - my ($pfi_info); - - INFO("[ Writting target pfi file: '$target.pfi'...\n"); - if (-e "$target.pfi") { - WARN("! Replaced old pfi...\n"); - `rm -f $target.pfi`; - } - open(FILE, ">", "$target.pfi") - or die "[ ERROR: Cannot create output file: $target.pfi\n"; - binmode(FILE); - - # @FIXME sort by mode (first raw, then ubi) - # Currently this ordering is based on a string comparism. :-) - @$pfi_infos = sort {(lc $$a{'mode'}) cmp (lc $$b{'mode'})} @$pfi_infos; - - # Print all headers first - foreach $pfi_info (@$pfi_infos) { - print FILE $$pfi_info{'header'}; - - } - # Print the linked data sections - print FILE "DATA\n"; - foreach $pfi_info (@$pfi_infos) { - open(IMAGE, "<", $$pfi_info{'image'}) - or die "[ ERROR: Cannot open input image: " . - "$$pfi_info{'image'}" . "\n"; - binmode(IMAGE); - ©_bytes(\*IMAGE, \*FILE, $$pfi_info{'size'}); - close(IMAGE) or die "[ ERROR: Cannot close input image: " . - "$$pfi_info{'image'}" . "\n"; - } - close(FILE) or die "[ ERROR: Cannot close output file: $target.pfi\n"; -} - -sub process_config($) { - my $cfg = shift; - my @sections = $cfg->Sections; - my ($i, $j, $keylist, $def_keylist, $mode, $tmp, - @tlist, $complete,@pfi_infos); - - my @parameters = $cfg->Parameters("targets") or - die "[ ERROR: Config file has no 'targets' section!\n"; - - for ($i = 0 ; $i < scalar(@parameters) ; $i++ ) { - INFO("[ Processing target '$parameters[$i]'...\n"); - @pfi_infos = (); - - # get a list of subtargets - $complete = mk_target_list($cfg->val("targets", - $parameters[$i]), \@tlist); - # build all subtargets - for ($j = 0 ; $j < scalar(@tlist) ; $j++ ) { - ($keylist, $def_keylist, $mode) - = get_section_info($cfg, $tlist[$j]); - process_section($cfg, $tlist[$j], - \@pfi_infos, - $keylist, $def_keylist, $mode); - } - - write_target(\@pfi_infos, $parameters[$i]); - } - - INFO("[ Success.\n"); - - -} - -sub clear_files() { - # @FIXME: - # Works implicitly and Fedora seems to have removed - # the cleanup call. Thus for now, inactive. - # File::Temp::cleanup(); -} - -require 5.008_000; # Tested with version 5.8.0. -select STDOUT; $| = 1; # make STDOUT output unbuffered -select STDERR; $| = 1; # make STDERR output unbuffered - -parse_command_line(\%opts); -check_tools; -$cfg = open_cfg_file($opts{config}); -process_config($cfg); -clear_files; - -__END__ - - -=head1 NAME - -mkpfi - Using GetOpt::Long, Pod::Usage, Config::IniFiles - - -=head1 SYNOPSIS - -mkpfi [OPTIONS ...] - - - OPTION - - [--config] [--help] [--man] - - -=head1 ABSTRACT - -Perl script for generating pdd pfi files from given config files. - -=head1 OPTIONS - -=over - -=item B<--help> - -Print out brief help message. - -=item B<--usage> - -Print usage. - -=item B<--config> - -Config input file. - -=item B<--man> - -Print manual page, same as 'perldoc mkpfi'. - -=item B<--verbose> - -Be verbose! - -=back - -=head1 BUGS - -Report via MTD mailing list - - -=head1 SEE ALSO - -http://www.linux-mtd.infradead.org/ - - -=head1 AUTHOR - -Oliver Lohmann (oliloh@de.ibm.com) - -=cut diff --git a/ubi-utils/src/nand2bin/nand2bin.c b/ubi-utils/src/nand2bin.c index a728fb5..a5e8bca 100644 --- a/ubi-utils/src/nand2bin/nand2bin.c +++ b/ubi-utils/src/nand2bin.c @@ -34,6 +34,7 @@ #include <sys/stat.h> #include <sys/types.h> +#include "config.h" #include "nandecc.h" #define MAXPATH 1024 @@ -59,10 +60,10 @@ static struct args myargs = { static error_t parse_opt (int key, char *arg, struct argp_state *state); -const char *argp_program_bug_address = "<haver@vnet.ibm.com>"; +const char *argp_program_bug_address = PACKAGE_BUGREPORT; -static char doc[] = "\nVersion: " VERSION "\n\t" - HOST_OS" "HOST_CPU" at "__DATE__" "__TIME__"\n" +static char doc[] = "\nVersion: " PACKAGE_VERSION "\n\t" + BUILD_OS" "BUILD_CPU" at "__DATE__" "__TIME__"\n" "\nSplit data and OOB.\n"; static struct argp_option options[] = { @@ -197,7 +198,7 @@ static int calc_oobsize(size_t pagesize) } static inline void -hexdump(FILE *fp, const uint8_t *buf, size_t size) +hexdump(FILE *fp, const uint8_t *buf, ssize_t size) { int k; diff --git a/ubi-utils/src/nand2bin/nandcorr.c b/ubi-utils/src/nandcorr.c index 7f1a547..7f1a547 100644 --- a/ubi-utils/src/nand2bin/nandcorr.c +++ b/ubi-utils/src/nandcorr.c diff --git a/ubi-utils/src/bin2nand/nandecc.c b/ubi-utils/src/nandecc.c index 71660ef..71660ef 100644 --- a/ubi-utils/src/bin2nand/nandecc.c +++ b/ubi-utils/src/nandecc.c diff --git a/ubi-utils/src/nandecc.h b/ubi-utils/src/nandecc.h new file mode 100644 index 0000000..fb5d529 --- /dev/null +++ b/ubi-utils/src/nandecc.h @@ -0,0 +1,28 @@ +#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> + +extern int nand_calculate_ecc(const uint8_t *dat, uint8_t *ecc_code); +extern int nand_correct_data(uint8_t *dat, const uint8_t *fail_ecc); + +#endif diff --git a/ubi-utils/src/pddcustomize/pddcustomize.c b/ubi-utils/src/pddcustomize.c index f71d916..f71d916 100644 --- a/ubi-utils/src/pddcustomize/pddcustomize.c +++ b/ubi-utils/src/pddcustomize.c diff --git a/ubi-utils/src/libpeb/peb.c b/ubi-utils/src/peb.c index 08b770f..08b770f 100644 --- a/ubi-utils/src/libpeb/peb.c +++ b/ubi-utils/src/peb.c diff --git a/ubi-utils/src/peb.h b/ubi-utils/src/peb.h new file mode 100644 index 0000000..246bce8 --- /dev/null +++ b/ubi-utils/src/peb.h @@ -0,0 +1,41 @@ +#ifndef __RAW_BLOCK_H__ +#define __RAW_BLOCK_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. + * + * Author: Oliver Lohmann + */ + +#include <stdint.h> +#include <stdio.h> + +typedef struct peb *peb_t; +struct peb { + uint32_t num; /* Physical eraseblock number + * in the RAW file. */ + uint32_t size; /* Data Size (equals physical + * erase block size) */ + uint8_t* data; /* Data buffer */ +}; + +int peb_new(uint32_t peb_num, uint32_t peb_size, peb_t* peb); +int peb_free(peb_t* peb); +int peb_cmp(peb_t peb_1, peb_t peb_2); +int peb_write(FILE* fp_out, peb_t peb); +void peb_dump(FILE* fp_out, peb_t peb); + +#endif /* __RAW_BLOCK_H__ */ diff --git a/ubi-utils/src/libpfi/pfi.c b/ubi-utils/src/pfi.c index c8d5ee4..c8d5ee4 100644 --- a/ubi-utils/src/libpfi/pfi.c +++ b/ubi-utils/src/pfi.c diff --git a/ubi-utils/src/pfi.h b/ubi-utils/src/pfi.h new file mode 100644 index 0000000..8c5cc07 --- /dev/null +++ b/ubi-utils/src/pfi.h @@ -0,0 +1,244 @@ +#ifndef __pfi_h +#define __pfi_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. + */ + +/** + * @file pfi.h + * + * @author Oliver Lohmann <oliloh@de.ibm.com> + * Andreas Arnez <arnez@de.ibm.com> + * Joern Engel <engeljoe@de.ibm.com> + * Frank Haverkamp <haverkam@de.ibm.com> + * + * @brief libpfi will hold all code to create and process pfi + * images. Definitions made in this file are equaly usable for the + * development host and the target system. + * + * @note This header additionally holds the official definitions for + * the pfi headers. + */ + +#include <stdio.h> /* FILE */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Definitions. */ + +#define PFI_HDRVERSION 1 /* current header version */ + +#define PFI_ENOVERSION 1 /* unknown version */ +#define PFI_ENOHEADER 2 /* not a pfi header */ +#define PFI_EINSUFF 3 /* insufficient information */ +#define PFI_EUNDEF 4 /* key not defined */ +#define PFI_ENOMEM 5 /* out of memory */ +#define PFI_EBADTYPE 6 /* bad data type */ +#define PFI_EFILE 7 /* file I/O error: see errno */ +#define PFI_EFILEINVAL 8 /* file format not valid */ +#define PFI_EINVAL 9 /* invalid parameter */ +#define PFI_ERANGE 10 /* invalid range */ +#define PFI_EMODE 11 /* expecting other mode in this header */ +#define PFI_DATA_START 12 /* data section starts */ +#define PFI_EMAX 13 /* should be always larger as the largest + error code */ + +#define PFI_LABEL_LEN 64 /* This is the maximum length for a + PFI header label */ +#define PFI_KEYWORD_LEN 32 /* This is the maximum length for an + entry in the mode and type fields */ + +#define PFI_UBI_MAX_VOLUMES 128 +#define PFI_UBI_VOL_NAME_LEN 127 + +/** + * @brief The pfi header allows to set flags which influence the flashing + * behaviour. + */ +#define PFI_FLAG_PROTECTED 0x00000001 + + +/** + * @brief Handle to pfi header. Used in most of the functions associated + * with pfi file handling. + */ +typedef struct pfi_header *pfi_header; + + +/** + * @brief Initialize a pfi header object. + * + * @param head Pointer to handle. This function allocates memory + * for this data structure. + * @return 0 on success, otherwise: + * PFI_ENOMEM : no memory available for the handle. + */ +int pfi_header_init (pfi_header *head); + + +/** + * @brief Destroy a pfi header object. + * + * @param head handle. head is invalid after calling this function. + * @return 0 always. + */ +int pfi_header_destroy (pfi_header *head); + + +/** + * @brief Add a key/value pair to a pfi header object. + * + * @param head handle. + * @param key pointer to key string. Must be 0 terminated. + * @param value pointer to value string. Must be 0 terminated. + * @return 0 on success, otherwise: + * PFI_EUNDEF : key was not found. + * PFI_ENOMEM : no memory available for the handle. + * PFI_EBADTYPE : value is not an hex string. This happens + * when the key stores an integer and the + * new value is not convertable e.g. not in + * 0xXXXXXXXX format. + */ +int pfi_header_setvalue (pfi_header head, + const char *key, const char *value); + + +/** + * @brief Add a key/value pair to a pfi header object. Provide the + * value as a number. + * + * @param head handle. + * @param key pointer to key string. Must be 0 terminated. + * @param value value to set. + * @return 0 on success, otherwise: + * PFI_EUNDEF : key was not found. + * PFI_EBADTYPE : value is not a string. This happens + * when the key stores a string. + */ +int pfi_header_setnumber (pfi_header head, + const char *key, uint32_t value); + + +/** + * @brief For a given key, return the numerical value stored in a + * pfi header object. + * + * @param head handle. + * @param key pointer to key string. Must be 0 terminated. + * @param value pointer to value. + * @return 0 on success, otherwise: + * PFI_EUNDEF : key was not found. + * PFI_EBADTYPE : stored value is not an integer but a string. + */ +int pfi_header_getnumber (pfi_header head, + const char *key, uint32_t *value); + + +static inline uint32_t +pfi_getnumber(pfi_header head, const char *key) +{ + uint32_t value; + pfi_header_getnumber(head, key, &value); + return value; +} + +/** + * @brief For a given key, return the string value stored in a pfi + * header object. + * + * @param head handle. + * @param key pointer to key string. Must be 0 terminated. + * @param value pointer to value string. Memory must be allocated by the user. + * @return 0 on success, otherwise: + * PFI_EUNDEF : key was not found. + * PFI_EBADTYPE : stored value is not a string but an integer. + */ +int pfi_header_getstring (pfi_header head, + const char *key, char *value, size_t size); + + +/** + * @brief Write a pfi header object into a given file. + * + * @param out output stream. + * @param head handle. + * @return 0 on success, error values otherwise: + * PFI_EINSUFF : not all mandatory fields are filled. + * PFI_ENOHEADER : wrong header version or magic number. + * -E* : see <asm/errno.h>. + */ +int pfi_header_write (FILE *out, pfi_header head); + + +/** + * @brief Read a pfi header object from a given file. + * + * @param in input stream. + * @param head handle. + * @return 0 on success, error values otherwise: + * PFI_ENOVERSION: unknown header version. + * PFI_EFILE : cannot read enough data. + * PFI_ENOHEADER : wrong header version or magic number. + * -E* : see <asm/errno.h>. + * + * If the header verification returned success the user can assume that + * all mandatory fields for a particular version are accessible. Checking + * the return code when calling the get-function for those keys is not + * required in those cases. For optional fields the checking must still be + * done. + */ +int pfi_header_read (FILE *in, pfi_header head); + + +/** + * @brief Display a pfi header in human-readable form. + * + * @param out output stream. + * @param head handle. + * @return always 0. + * + * @note Prints out that it is not implemented and whom you should + * contact if you need it urgently!. + */ +int pfi_header_dump (FILE *out, pfi_header head); + + +/* + * @brief Iterates over a stream of pfi files. The iterator function + * must advance the file pointer in FILE *in to the next pfi + * header. Function exists on feof(in). + * + * @param in input file descriptor, must be open and valid. + * @param func iterator function called when pfi header could be + * read and was validated. The function must return 0 on + * success. + * @return See pfi_header_init and pfi_header_read. + * PFI_EINVAL : func is not valid + * 0 ok. + */ +typedef int (* pfi_read_func)(FILE *in, pfi_header hdr, void *priv_data); + +int pfi_read (FILE *in, pfi_read_func func, void *priv_data); + + +#ifdef __cplusplus +} +#endif + +#endif /* __pfi_h */ diff --git a/ubi-utils/src/pfi2bin/pfi2bin.c b/ubi-utils/src/pfi2bin.c index 6536c19..6536c19 100644 --- a/ubi-utils/src/pfi2bin/pfi2bin.c +++ b/ubi-utils/src/pfi2bin.c diff --git a/ubi-utils/src/pfiflash/pfiflash.c b/ubi-utils/src/pfiflash.c index 18b3aa2..04f62df 100644 --- a/ubi-utils/src/pfiflash/pfiflash.c +++ b/ubi-utils/src/pfiflash.c @@ -155,7 +155,7 @@ parse_opt(int key, char *arg, struct argp_state *state) break; case 'p': args->pdd_handling = get_pdd_handling(arg); - if (args->pdd_handling < 0) { + if ((int)args->pdd_handling < 0) { err_quit("Unknown PDD handling: %s.\n" "Please use either 'keep', 'merge' or" "'overwrite'.\n'"); diff --git a/ubi-utils/src/pfiflash.h b/ubi-utils/src/pfiflash.h new file mode 100644 index 0000000..fc2eede --- /dev/null +++ b/ubi-utils/src/pfiflash.h @@ -0,0 +1,62 @@ +#ifndef __PFIFLASH_H__ +#define __PFIFLASH_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. + */ + +/** + * + * @file pfi.h + * + * @author Oliver Lohmann <oliloh@de.ibm.com> + * + * @brief The pfiflash library offers an interface for using the + * pfiflash * utility. + */ + +#include <stdio.h> /* FILE */ + +#define PFIFLASH_MAX_ERR_BUF_SIZE 1024 + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum pdd_handling_t +{ + PDD_KEEP = 0, + PDD_MERGE, + PDD_OVERWRITE, + PDD_HANDLING_NUM, /* always the last item */ +} pdd_handling_t; /**< Possible PDD handle algorithms. */ + +/** + * @brief Flashes a PFI file to UBI Device 0. + * @param complete [0|1] Do a complete system update. + * @param seqnum Index in a redundant group. + * @param pdd_handling The PDD handling algorithm. + * @param err_buf An error buffer. + * @param err_buf_size Size of the error buffer. + */ +int pfiflash(FILE* pfi, int complete, int seqnum, pdd_handling_t pdd_handling, + char *err_buf, size_t err_buf_size); + +#ifdef __cplusplus +} +#endif + +#endif /* __PFIFLASH_H__ */ diff --git a/ubi-utils/src/libreader/reader.c b/ubi-utils/src/reader.c index c8242df..e4a8ceb 100644 --- a/ubi-utils/src/libreader/reader.c +++ b/ubi-utils/src/reader.c @@ -29,6 +29,7 @@ #include <stdlib.h> #include <errno.h> +#include "config.h" #include "bootenv.h" #include "reader.h" @@ -112,8 +113,13 @@ read_pdd_data(FILE* fp_pdd, pdd_data_t* pdd_data, return rc; } +/** + * FIXME enhance flasing raw PFI content e.g. IPLs for NAND and NOR. + * Here is one of the only places where the flash type and its special + * handling is exposed to the users. + */ int -read_pfi_raw(pfi_header pfi_hd, FILE* fp_pfi, pfi_raw_t* pfi_raw, +read_pfi_raw(pfi_header pfi_hd, FILE* fp_pfi __unused, pfi_raw_t* pfi_raw, const char* label, char* err_buf, size_t err_buf_size) { int rc = 0; @@ -169,8 +175,12 @@ read_pfi_raw(pfi_header pfi_hd, FILE* fp_pfi, pfi_raw_t* pfi_raw, return rc; } +/** + * FIXME Enhance reading raw PFI sections, e.g. IPL. See comment at + * write_pfi_ubi. + */ int -read_pfi_ubi(pfi_header pfi_hd, FILE* fp_pfi, pfi_ubi_t* pfi_ubi, +read_pfi_ubi(pfi_header pfi_hd, FILE* fp_pfi __unused, pfi_ubi_t* pfi_ubi, const char *label, char* err_buf, size_t err_buf_size) { int rc = 0; diff --git a/ubi-utils/src/reader.h b/ubi-utils/src/reader.h new file mode 100644 index 0000000..93c15e3 --- /dev/null +++ b/ubi-utils/src/reader.h @@ -0,0 +1,84 @@ +#ifndef __READER_H__ +#define __READER_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. + * + * Author: Oliver Lohmann + * + * Read Platform Description Data (PDD). + */ + +#include <stdint.h> +#include <stdio.h> + +#include "pfi.h" +#include "bootenv.h" +#include "list.h" + +typedef enum flash_type_t { + NAND_FLASH = 0, + NOR_FLASH, +} flash_type_t; + +typedef struct pdd_data *pdd_data_t; +typedef struct pfi_raw *pfi_raw_t; +typedef struct pfi_ubi *pfi_ubi_t; + +struct pdd_data { + uint32_t flash_size; + uint32_t eb_size; + uint32_t vid_hdr_offset; + flash_type_t flash_type; +}; + +struct pfi_raw { + uint32_t data_size; + uint32_t *starts; + uint32_t starts_size; +}; + +struct pfi_ubi { + uint32_t data_size; + uint32_t alignment; + uint32_t *ids; + uint32_t ids_size; + char **names; + uint32_t names_size; + uint32_t size; + enum { pfi_ubi_dynamic, pfi_ubi_static } type; + int curr_seqnum; /* specifies the seqnum taken in an update, + default: 0 (used by pfiflash, ubimirror) */ +}; + +int read_pdd_data(FILE* fp_pdd, pdd_data_t *pdd_data, + char *err_buf, size_t err_buf_size); +int read_pfi_raw(pfi_header pfi_hd, FILE* fp_pfi, pfi_raw_t *pfi_raw, + const char *label, char *err_buf, size_t err_buf_size); +int read_pfi_ubi(pfi_header pfi_hd, FILE* fp_pfi, pfi_ubi_t *pfi_ubi, + const char *label, char *err_buf, size_t err_buf_size); + +/** + * @brief Reads all pfi headers into list structures, separated by + * RAW and UBI sections. + */ +int read_pfi_headers(list_t *pfi_raws, list_t *pfi_ubis, FILE* fp_pfi, + char* err_buf, size_t err_buf_size); +int free_pdd_data(pdd_data_t *pdd_data); +int free_pfi_raw(pfi_raw_t *raw_pfi); +int free_pfi_ubi(pfi_ubi_t *pfi_ubi); + +#endif /* __READER_H__ */ diff --git a/ubi-utils/src/ubicrc32/ubicrc32.c b/ubi-utils/src/ubicrc32.c index fb4ef49..fb4ef49 100644 --- a/ubi-utils/src/ubicrc32/ubicrc32.c +++ b/ubi-utils/src/ubicrc32.c diff --git a/ubi-utils/src/ubicrc32/ubicrc32.pl b/ubi-utils/src/ubicrc32/ubicrc32.pl deleted file mode 100755 index add5f9d..0000000 --- a/ubi-utils/src/ubicrc32/ubicrc32.pl +++ /dev/null @@ -1,74 +0,0 @@ -#!/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/src/ubigen/ubigen_main.c b/ubi-utils/src/ubigen.c index 8a464dd..8a464dd 100644 --- a/ubi-utils/src/ubigen/ubigen_main.c +++ b/ubi-utils/src/ubigen.c diff --git a/ubi-utils/src/ubigen.h b/ubi-utils/src/ubigen.h new file mode 100644 index 0000000..9e9e8ec --- /dev/null +++ b/ubi-utils/src/ubigen.h @@ -0,0 +1,149 @@ +#ifndef __UBIGEN_H__ +#define __UBIGEN_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. + * + * Author: Frank Haverkamp + * + * An utility to update UBI volumes. + */ + +#include <stdio.h> /* FILE */ +#include <stdint.h> +#include <mtd/ubi-header.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define DEFAULT_BLOCKSIZE (128 * 1024) +#define DEFAULT_PAGESIZE (2*1024) + +#define EUBIGEN_INVALID_TYPE 1 +#define EUBIGEN_INVALID_HDR_OFFSET 2 +#define EUBIGEN_INVALID_ALIGNMENT 3 +#define EUBIGEN_TOO_SMALL_EB 4 +#define EUBIGEN_MAX_ERROR 5 + + +typedef enum action { + NO_ERROR = 0x00000000, + BROKEN_HDR_CRC = 0x00000001, + BROKEN_DATA_CRC = 0x00000002, + BROKEN_DATA_SIZE = 0x00000004, + BROKEN_OMIT_BLK = 0x00000008, + MARK_AS_UPDATE = 0x00000010, +} ubigen_action_t; + +typedef struct ubi_info *ubi_info_t; + +/** + * @brief Initialize the internal CRC32 table. + * @note Necessary because of the used crc32 function in UBI. + * A usage of CRC32, from e.g. zlib will fail. + */ +void ubigen_init(void); + +/** + * @brief Create an ubigen handle. + * @param ... + * @return 0 On sucess. + * else Error. + * @note This parameterlist is ugly. But we have to use + * two big structs and meta information internally, + * filling them would be even uglier. + */ +int ubigen_create(ubi_info_t *u, uint32_t vol_id, uint8_t vol_type, + uint32_t eb_size, uint64_t ec, uint32_t alignment, + uint8_t version, uint32_t vid_hdr_offset, + uint8_t compat_flag, size_t data_size, + FILE* fp_in, FILE* fp_out); + +/** + * @brief Destroy an ubigen handle. + * @param u Handle to free. + * @return 0 On success. + * else Error. + */ +int ubigen_destroy(ubi_info_t *u); + +/** + * @brief Get number of total logical EBs, necessary for the + * complete storage of data in the handle. + * @param u The handle. + * @return 0 On success. + * else Error. + */ +int ubigen_get_leb_total(ubi_info_t u, size_t* total); + +/** + * @brief Get the size in bytes of one logical EB in the handle. + * @param u The handle. + * @return 0 On success. + * else Error. + */ +int ubigen_get_leb_size(ubi_info_t u, size_t* size); + + +/** + * @brief Write a logical EB (fits exactly into 1 physical EB). + * @param u Handle which holds all necessary data. + * @param action Additional operations which shall be applied on this + * logical eraseblock. Mostly injecting artifical errors. + * @return 0 On success. + * else Error. + */ +int ubigen_write_leb(ubi_info_t u, ubigen_action_t action); + +/** + * @brief Write a complete array of logical eraseblocks at once. + * @param u Handle which holds all necessary data. + * @return 0 On success. + * else Error. + */ +int ubigen_write_complete(ubi_info_t u); + +/** + * @brief Write a single block which is extracted from the + * binary input data. + * @param u Handle which holds all necessary data. + * @param blk Logical eraseblock which shall hold a inc. copy entry + * and a bad data crc. + * @return 0 On success. + * else Error. + */ +int ubigen_write_broken_update(ubi_info_t u, uint32_t blk); + +/** + * @brief Use the current ubi_info data and some additional data + * to set an UBI volume table entry from it. + * @param u Handle which holds some of the necessary data. + * @param res_bytes Number of reserved bytes which is stored in the volume + * table entry. + * @param name A string which shall be used as a volume label. + * @param lvol_r A pointer to a volume table entry. + * @return 0 On success. + * else Error. + */ +int ubigen_set_lvol_rec(ubi_info_t u, size_t reserved_bytes, + const char* name, struct ubi_vol_tbl_record *lvol_rec); + +#ifdef __cplusplus +} +#endif + +#endif /* __UBIGEN_H__ */ diff --git a/ubi-utils/src/ubiinfo/ubiflash.h b/ubi-utils/src/ubiinfo/ubiflash.h deleted file mode 100644 index 6883879..0000000 --- a/ubi-utils/src/ubiinfo/ubiflash.h +++ /dev/null @@ -1,185 +0,0 @@ -#ifndef _UBI_FLASH_H -#define _UBI_FLASH_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. - */ - -/* - * FLASH related data structures and constants for UBI. - * UBI scan analysis. - * - * IPL Initial Program Loader - * SPL Secondary Program Loader - */ - -#include <stdint.h> -#include <asm/byteorder.h> -#include <mtd/ubi-header.h> - -#define UBI_BLOCK_IDENT_MAX 16 - -/* Block status information constants */ -enum blockstat { - /* IO Error */ - STAT_IO_FAILED = 1, /* 0xffffffff */ - /* Block is bad */ - STAT_BLOCK_BAD = 2, /* 0xfffffffe */ - /* ECC unrecoverable error */ - STAT_ECC_ERROR = 3, /* 0xfffffffd */ - /* CRC checksum failed */ - STAT_CRC_ERROR = 4, /* 0xfffffffc */ - /* Magic number not available */ - STAT_NO_MAGIC = 5, /* 0xfffffffb */ - /* No image available */ - STAT_NO_IMAGE = 6, - /* Image is invalid */ - STAT_INVALID_IMAGE = 7, - /* Image is defect */ - STAT_DEFECT_IMAGE = 8, -}; - -/* - * Flash types - */ -enum flashtypes { - FLASH_TYPE_NAND = 1, - FLASH_TYPE_NOR, -}; - -/* Nand read buffer size: 2KiB + 64byte spare */ -#define NAND_READ_BUF_SIZE (2048 + 64) - -/* Size of the CRC table */ -#define CRC32_TABLE_SIZE 256 - -/* Image is not available marker for image offs */ -#define UBI_IMAGE_NOT_AVAILABLE 0xFFFFFFFF - -/* Increment this number, whenever you change the structure */ -#define UBI_SCAN_INFO_VERSION 2 - -/* Time measurement as far as the code size allows us to do this */ -#define UBI_TIMESTAMPS 16 - -/** - * struct ubi_scan_info - RAM table filled by IPL scan - * - * @version: Version of the structure - * @bootstatus: Boot status of the current boot - * @flashtype: Flash type (NAND/NOR) - * @flashid: ID of the flash chip - * @flashmfr: Manufacturer ID of the flash chip - * @flashsize: Size of the FLASH - * @blocksize: Eraseblock size - * @blockshift: Shift count to calc block number from offset - * @nrblocks: Number of erase blocks on flash - * @pagesize: Pagesize (NAND) - * @blockinfo: Pointer to an array of block status information - * filled by FLASH scan - * @images: Pointer to FLASH block translation table sorted - * by image type and load order - * @imageblocks: Number of blocks found per image - * @imageoffs: Offset per imagetype to the first - * block in the translation table - * @imagedups duplicate blocks (max. one per volume) - * @imagelen: Length of the loaded image - * @crc32_table: CRC32 table buffer - * @page_buf: Page buffer for NAND FLASH - */ -struct ubi_scan_info { - int version; - unsigned int bootstatus; - unsigned int flashtype; - unsigned int flashid; - unsigned int flashmfr; - unsigned int flashsize; - unsigned int blocksize; - unsigned int blockshift; - unsigned int nrblocks; - unsigned int pagesize; - - struct ubi_vid_hdr *blockinfo; - struct ubi_vid_hdr **images; - unsigned int imageblocks[UBI_BLOCK_IDENT_MAX]; - unsigned int imageoffs[UBI_BLOCK_IDENT_MAX]; - struct ubi_vid_hdr *imagedups[UBI_BLOCK_IDENT_MAX]; - unsigned int imagelen; - uint32_t crc32_table[CRC32_TABLE_SIZE]; - uint8_t page_buf[NAND_READ_BUF_SIZE]; - unsigned int times[UBI_TIMESTAMPS]; -}; - -/* External function definition */ -extern int flash_read(void *buf, unsigned int offs, int len); -extern int flash_read_slice(struct ubi_scan_info *fi, void *buf, - unsigned int offs, int len); -extern void ipl_main(struct ubi_scan_info *fi); - -#ifndef CFG_EXAMPLE_IPL -extern int ipl_scan(struct ubi_scan_info *fi); -extern int ipl_load(struct ubi_scan_info *fi, int nr, uint8_t *loadaddr); - -#define IPL_STATIC - -#else -#define IPL_STATIC static -#endif - -/** - * get_boot_status - get the boot status register - * - * Shift the lower 16 bit into the upper 16 bit and return - * the result. - */ -uint32_t get_boot_status(void); - -/** - * set_boot_status - Set the boot status register - * - * @status: The status value to set - * - */ -void set_boot_status(uint32_t status); - -static inline unsigned int ubi_vid_offset(struct ubi_scan_info *fi) -{ - if (fi->flashtype == FLASH_TYPE_NOR) - return UBI_EC_HDR_SIZE; - else - return fi->pagesize - UBI_VID_HDR_SIZE; -} - -static inline unsigned int ubi_data_offset(struct ubi_scan_info *fi) -{ - if (fi->flashtype == FLASH_TYPE_NOR) - return UBI_EC_HDR_SIZE + UBI_VID_HDR_SIZE; - else - return fi->pagesize; -} - -/** - * IPL checkpoints - */ -#define CHKP_HWINIT 0x3030 -#define CHKP_IPLSCAN_FAILED 0x3034 -#define CHKP_SPL_START 0x3037 -#define CHKP_SPLLOAD_STATUS 0x3130 - -extern void checkpoint(uint32_t cpoint); -extern void switch_watchdog(void); - -#endif diff --git a/ubi-utils/src/ubiinfo/ubiinfo.c b/ubi-utils/src/ubiinfo/ubiinfo.c deleted file mode 100644 index 6f7443b..0000000 --- a/ubi-utils/src/ubiinfo/ubiinfo.c +++ /dev/null @@ -1,406 +0,0 @@ -/* - * 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. - */ - -/* - * Print out information about the UBI table this IPL is using. This - * can be used afterwards to analyze misbehavior of the IPL code. The - * input this program requires is the last 1 MiB DDRAM of our system - * where the scanning table is placed into. - * - * Author: Frank Haverkamp <haver@vnet.ibm.com> - */ - -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <time.h> -#include <argp.h> -#include <getopt.h> -#include <stdint.h> -#include <sys/time.h> -#include <netinet/in.h> - -#define __unused __attribute__((unused)) - -/* This should hopefully be constant and the same in all - * configurations. - */ -#define CFG_IPLSIZE 512 -#define CFG_SPLCODE 512 -#define MEMTOP 0x06600000 /* Sunray 102 MiB */ -#define MEMSIZE 0x00100000 /* 1 MiB */ -#define CODE_SIZE (64 * 1024) - -/* FIXME Except of the memory size this should be defined via - * parameters - * - * CFG_MEMTOP_BAMBOO 0x02000000 - * CFG_MEMTOP_SUNRAY 0x06600000 - */ - -#include "ubiipl.h" -#include "ubiflash.h" - -#define MIN(x,y) ((x)<(y)?(x):(y)) - -#define ERR_RET(rc) { \ - fprintf(stderr, "%s:%d failed rc=%d\n", __func__, \ - __LINE__, (rc)); \ - return (rc); \ - } - -#define VERSION "1.3" - -static error_t parse_opt (int key, char *arg, struct argp_state *state); -const char *argp_program_version = VERSION; -const char *argp_program_bug_address = "<haver@vnet.ibm.com>"; - -static char doc[] = "\nVersion: " VERSION "\n\t" - " at "__DATE__" "__TIME__"\n" - "\n" - "Test program\n"; - -static struct argp_option options[] = { - /* common settings */ - { .name = "verbose", - .key = 'v', - .arg = "<level>", - .flags = 0, - .doc = "Set verbosity level to <level>", - .group = OPTION_ARG_OPTIONAL }, - - { .name = "memtop", - .key = 'm', - .arg = "<memtop>", - .flags = 0, - .doc = "Set top of memory, 102 MiB for Sunray and 16 MiB for Bamboo", - .group = OPTION_ARG_OPTIONAL }, - - { .name = NULL, - .key = 0, - .arg = NULL, - .flags = 0, - .doc = NULL, - .group = 0 }, -}; - -typedef struct test_args { - int verbose; - unsigned long memtop; - char *arg1; - char **options; -} test_args; - -static struct test_args g_args = { - .memtop = MEMTOP, - .verbose = 0, - .arg1 = NULL, - .options = NULL, -}; - -static struct argp argp = { - options: options, - parser: parse_opt, - args_doc: "[last_1MiB_memory.bin]", - doc: doc, - children: NULL, - help_filter: NULL, - argp_domain: NULL, -}; - -static int verbose = 0; - -/** - * @brief Parse the arguments passed into the test case. - * - * @param key The parameter. - * @param arg Argument passed to parameter. - * @param state Location to put information on parameters. - * - * @return error_t - */ -static error_t -parse_opt(int key, char *arg, struct argp_state *state) -{ - /* Get the `input' argument from `argp_parse', which we - know is a pointer to our arguments structure. */ - test_args *args = state->input; - - switch (key) { - /* common settings */ - case 'v': /* --verbose=<level> */ - verbose = args->verbose = strtoul(arg, (char **)NULL, 0); - break; - - case 'm': /* --memtop */ - args->memtop = strtoul(arg, (char **)NULL, 0); - break; - - case ARGP_KEY_NO_ARGS: - /* argp_usage(state); */ - break; - - case ARGP_KEY_ARG: - args->arg1 = arg; - /* Now we consume all the rest of the arguments. - `state->next' is the index in `state->argv' of the - next argument to be parsed, which is the first STRING - we're interested in, so we can just use - `&state->argv[state->next]' as the value for - arguments->strings. - - _In addition_, by setting `state->next' to the end - of the arguments, we can force argp to stop parsing - here and return. */ - - args->options = &state->argv[state->next]; - state->next = state->argc; - break; - - case ARGP_KEY_END: - /* print out message if no arguments are given but PFI - write should be done */ - break; - - default: - return(ARGP_ERR_UNKNOWN); - } - return 0; -} - -static void -hexdump(const char *buf, int len) -{ - char line[16]; - char str[256]; - char dummy[256]; - int j = 0; - - while (len > 0) { - int i; - - strcpy(str, " "); - - for (j = 0; j < MIN(16, len); j++) - line[j] = *buf++; - - for (i = 0; i < j; i++) { - if (!(i & 3)) { - sprintf(dummy, " %.2x", line[i] & 0xff); - strcat(str, dummy); - } else { - sprintf(dummy, "%.2x", line[i] & 0xff); - strcat(str, dummy); - } - } - - /* Print empty space */ - for (; i < 16; i++) - if (!(i & 1)) - strcat(str, " "); - else - strcat(str, " "); - - strcat(str, " "); - for (i = 0; i < j; i++) { - if (isprint(line[i])) { - sprintf(dummy, "%c", line[i]); - strcat(str, dummy); - } else { - strcat(str, "."); - } - } - printf("%s\n", str); - len -= 16; - } -} - -static void -print_status_help(void) -{ - printf("Error Codes from IPL\n"); - printf(" IO Error %d\n", STAT_IO_FAILED); - printf(" Block is bad %d\n", STAT_BLOCK_BAD); - printf(" ECC unrec error %d\n", STAT_ECC_ERROR); - printf(" CRC csum failed %d\n", STAT_CRC_ERROR); - printf(" Magic not avail %d\n", STAT_NO_MAGIC); - printf(" No image avail %d\n", STAT_NO_IMAGE); - printf(" Image is invalid %d\n", STAT_INVALID_IMAGE); - printf(" Image is defect %d\n\n", STAT_DEFECT_IMAGE); - -} - -static void -print_ubi_scan_info(struct ubi_scan_info *fi) -{ - int i; - - printf("ubi_scan_info\n"); - printf(" version %08x\n", ntohl(fi->version)); - printf(" bootstatus %08x\n", ntohl(fi->bootstatus)); - printf(" flashtype %08x\n", ntohl(fi->flashtype)); - printf(" flashid %08x\n", ntohl(fi->flashid)); - printf(" flashmfgr %08x\n", ntohl(fi->flashmfr)); - printf(" flashsize %d bytes (%dM)\n", - ntohl(fi->flashsize), ntohl(fi->flashsize) / (1024 * 1024)); - printf(" blocksize %d bytes\n", ntohl(fi->blocksize)); - printf(" blockshift %d\n", ntohl(fi->blockshift)); - printf(" nrblocks %d\n", ntohl(fi->nrblocks)); - printf(" pagesize %d\n", ntohl(fi->pagesize)); - printf(" imagelen %d\n", ntohl(fi->imagelen)); - printf(" blockinfo %08x\n", ntohl((int)fi->blockinfo)); - - printf(" nr imageblocks imageoffs\n"); - for (i = 0; i < UBI_BLOCK_IDENT_MAX; i++) - printf(" [%2d] %08x %08x\n", i, - ntohl(fi->imageblocks[i]), - ntohl(fi->imageoffs[i])); - - for (i = 0; i < UBI_TIMESTAMPS; i++) { - if (!ntohl(fi->times[i])) - continue; - printf("time[%3d] = %08x %.3f sec\n", i, ntohl(fi->times[i]), - (double)ntohl(fi->times[i]) / 500000000.0); - } - - printf("crc32_table\n"); - hexdump((char *)&fi->crc32_table, sizeof(fi->crc32_table)); - printf("\npage_buf\n"); - hexdump((char *)&fi->page_buf, sizeof(fi->page_buf)); - - printf("\n"); - -} - -static void -print_ubi_block_info(struct ubi_scan_info *fi, - struct ubi_vid_hdr *bi, int nr) -{ - int i; - int unknown = 0; - - printf("\nBINFO\n"); - - for (i = 0; i < nr; i++) { - if ((int)ubi32_to_cpu(bi[i].magic) != UBI_VID_HDR_MAGIC) { - printf("block=%d %08x\n", - i, i * ntohl(fi->blocksize)); -#if 0 - printf("."); - if ((unknown & 0x3f) == 0x3f) - printf("\n"); - unknown++; -#else - hexdump((char *)&bi[i], - sizeof(struct ubi_vid_hdr)); -#endif - } else { - if (unknown) - printf("\n"); - printf("block=%d %08x\n" - " leb_ver=0x%x data_size=%d " - "lnum=%d used_ebs=0x%x\n" - " data_crc=%08x hdr_crc=%08x\n", - i, i * ntohl(fi->blocksize), - ubi32_to_cpu(bi[i].leb_ver), - ubi32_to_cpu(bi[i].data_size), - ubi32_to_cpu(bi[i].lnum), - ubi32_to_cpu(bi[i].used_ebs), - ubi32_to_cpu(bi[i].data_crc), - ubi32_to_cpu(bi[i].hdr_crc)); - hexdump((char *)&bi[i], - sizeof(struct ubi_vid_hdr)); - unknown = 0; - } - } -} - -static int do_read(unsigned int memtop, char *buf, int buf_len __unused) -{ - unsigned long finfo_addr; - unsigned long binfo_addr; - unsigned long images_addr; - unsigned long nrblocks; - unsigned long bi_size; - unsigned long images_size; - struct ubi_scan_info *fi; - struct ubi_vid_hdr *bi; - char *images; - unsigned long memaddr = memtop - MEMSIZE; - - print_status_help(); - - /* Read and print FINFO */ - finfo_addr = MEMSIZE - CFG_IPLSIZE * 1024; - - printf("read info at addr %08lx\n", finfo_addr); - fi = (struct ubi_scan_info *)(buf + finfo_addr); - - binfo_addr = ntohl((unsigned long)fi->blockinfo) - memaddr; - images_addr = ntohl((unsigned long)fi->images) - memaddr; - nrblocks = ntohl(fi->nrblocks); - - printf("BINFO %08lx\n", binfo_addr); - - bi_size = nrblocks * sizeof(struct ubi_vid_hdr); - images_size = nrblocks * sizeof(unsigned int); - - printf("FINFO\n"); - print_ubi_scan_info(fi); - /* hexdump((char *)fi, sizeof(*fi)); */ - - /* Read and print BINFO */ - bi = (struct ubi_vid_hdr *)(buf + binfo_addr); - print_ubi_block_info(fi, bi, nrblocks); - - /* Read and print IMAGES */ - images = buf + images_addr; - printf("\nIMAGES\n"); - hexdump(images, images_size); - - return 0; -} - -int main(int argc, char *argv[]) -{ - char buf[MEMSIZE]; - FILE *fp; - int rc; - - argp_parse(&argp, argc, argv, ARGP_IN_ORDER, 0, &g_args); - - if (!g_args.arg1) { - fprintf(stderr, "Please specify a file " - "name for memory dump!\n"); - exit(EXIT_FAILURE); - } - - memset(buf, 0xAB, sizeof(buf)); - - fp = fopen(g_args.arg1, "r"); - if (!fp) - exit(EXIT_FAILURE); - rc = fread(buf, 1, sizeof(buf), fp); - if (rc != sizeof(buf)) - exit(EXIT_FAILURE); - fclose(fp); - do_read(g_args.memtop, buf, sizeof(buf)); - - exit(EXIT_SUCCESS); -} diff --git a/ubi-utils/src/ubiinfo/ubiipl.h b/ubi-utils/src/ubiinfo/ubiipl.h deleted file mode 100644 index 3a8b900..0000000 --- a/ubi-utils/src/ubiinfo/ubiipl.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef _UBI_IPL_H -#define _UBI_IPL_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. - */ - -/* - * Constants calculated from the CFG_XXX defines - * - * Declaration of the loader function which is invoked by the - * assembler part of the IPL - */ - -/* Size of IPL - is 4K for NAND and can also be 4K for NOR */ -#define IPL_SIZE 4096 - -/* Needed in asm code to upload the data, needed in C-code for CRC32 */ -#define IPL_RAMADDR (CFG_MEMTOP - IPL_SIZE) - -#if !defined(__ASSEMBLY__) - -#include <stdint.h> -#include <mtd/ubi-header.h> - -/* Address of the flash info structure */ -#define FINFO_ADDR (struct ubi_scan_info *) (CFG_MEMTOP - CFG_IPLSIZE * 1024) - -/* Size of the flash info structure */ -#define FINFO_SIZE sizeof(struct ubi_scan_info) - -/* Blockinfo array address */ -#define BINFO_ADDR (struct ubi_vid_hdr *) ((void *)FINFO_ADDR + FINFO_SIZE) - -/* Number of erase blocks */ -#define NR_ERASE_BLOCKS ((CFG_FLASHSIZE * 1024) / CFG_BLOCKSIZE) - -/* Blockinfo size */ -#define BINFO_SIZE (NR_ERASE_BLOCKS * sizeof(struct ubi_vid_hdr)) - -/* Images array address */ -#define IMAGES_ADDR (struct ubi_vid_hdr **) ((void *)BINFO_ADDR + BINFO_SIZE) - -/* Images array size */ -#define IMAGES_SIZE (NR_ERASE_BLOCKS * sizeof(unsigned int)) - -/* Total size of flash info + blockinfo + images */ -#define INFO_SIZE ((FINFO_SIZE + BINFO_SIZE + IMAGES_SIZE) / sizeof(uint32_t)) - -/* Load address of the SPL */ -#define SPL_ADDR (void *) ((void *)FINFO_ADDR - CFG_SPLCODE * 1024) - -#define IPL_SIZE_CRC32 (IPL_SIZE - sizeof(uint32_t)) -#define IPL_RAMADDR_CRC32 ((void *)(IPL_RAMADDR + sizeof(uint32_t))) - -/* - * Linker script magic to ensure that load_spl() is linked to the - * right place - */ -#define __crc32 __attribute__((__section__(".crc32"))) -#define __entry __attribute__((__section__(".entry.text"))) -#define __unused __attribute__((unused)) - -#define MIN(x,y) ((x)<(y)?(x):(y)) - -#define stop_on_error(x) \ - { while (1); } - -void __entry load_spl(void); -void hardware_init(void); - -#endif /* __ASSEMBLY__ */ - -#endif diff --git a/ubi-utils/src/ubimirror/ubimirror.c b/ubi-utils/src/ubimirror.c index e43ba10..e43ba10 100644 --- a/ubi-utils/src/ubimirror/ubimirror.c +++ b/ubi-utils/src/ubimirror.c diff --git a/ubi-utils/src/ubimirror.h b/ubi-utils/src/ubimirror.h new file mode 100644 index 0000000..d7ae2ad --- /dev/null +++ b/ubi-utils/src/ubimirror.h @@ -0,0 +1,66 @@ +#ifndef __UBIMIRROR_H__ +#define __UBIMIRROR_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. + * + * Author: Oliver Lohmann + * + * An utility to mirror UBI volumes. + */ + +#include <stdint.h> + +/** + * @def EUBIMIRROR_SRC_EQ_DST + * @brief Given source volume is also in the set of destination volumes. + */ +#define EUBIMIRROR_SRC_EQ_DST 20 + +/** + * @def EUBIMIRROR_NO_SRC + * @brief The given source volume does not exist. + */ +#define EUBIMIRROR_NO_SRC 21 + +/** + * @def EUBIMIRROR_NO_DST + * @brief One of the given destination volumes does not exist. + */ +#define EUBIMIRROR_NO_DST 22 + +/** + * @brief Mirrors UBI devices from a source device (specified by seqnum) + * to n target devices. + * @param devno Device number used by the UBI operations. + * @param seqnum An index into ids (defines the src_id). + * @param ids An array of ids. + * @param ids_size The number of entries in the ids array. + * @param err_buf A buffer to store verbose error messages. + * @param err_buf_size The size of the error buffer. + * + * @note A seqnum of value < 0 defaults to a seqnum of 0. + * @note A seqnum exceeding the range of ids_size defaults to 0. + * @note An empty ids list results in a empty stmt. + * @pre The UBI volume which shall be used as source volume exists. + * @pre The UBI volumes which are defined as destination volumes exist. + * @post The content of the UBI volume which was defined as source volume + * equals the content of the volumes which were defined as destination. + */ +int ubimirror(uint32_t devno, int seqnum, uint32_t* ids, ssize_t ids_size, + char *err_buf, size_t err_buf_size); + +#endif /* __UBIMIRROR_H__ */ diff --git a/ubi-utils/src/ubimkvol/ubimkvol.c b/ubi-utils/src/ubimkvol.c index f929252..30c569c 100644 --- a/ubi-utils/src/ubimkvol/ubimkvol.c +++ b/ubi-utils/src/ubimkvol.c @@ -33,10 +33,9 @@ #include <string.h> #include <errno.h> +#include "config.h" #include <libubi.h> -#define VERSION "1.1" - static void usage(void); static int param_sanity_check(ubi_lib_t lib); static int parse_options(int argc, char * const argv[]); @@ -214,13 +213,13 @@ static int param_sanity_check(ubi_lib_t lib) if (err) return -1; - if (devn >= ubi.dev_count) { + if (devn >= (int)ubi.dev_count) { fprintf(stderr, "Device %d does not exist\n", devn); goto out; } len = strlen(name); - if (len > ubi.nlen_max) { + if (len > (int)ubi.nlen_max) { fprintf(stderr, "Too long name (%d symbols), max is %d\n", len, ubi.nlen_max); goto out; @@ -236,7 +235,7 @@ out: static void usage(void) { printf("Usage: ubi_mkvol OPTIONS\n" - "Version: " VERSION "\n" + "Version: " PACKAGE_VERSION "\n" "The command line options:\n" "\t-h - this help message\n" "\t-d - UBI device number\n" diff --git a/ubi-utils/src/ubirmvol/ubirmvol.c b/ubi-utils/src/ubirmvol.c index fc5ada5..cb47b6c 100644 --- a/ubi-utils/src/ubirmvol/ubirmvol.c +++ b/ubi-utils/src/ubirmvol.c @@ -28,6 +28,8 @@ #include <stdlib.h> #include <string.h> #include <errno.h> + +#include "config.h" #include <libubi.h> static void usage(void); @@ -150,7 +152,7 @@ static int param_sanity_check(ubi_lib_t lib) if (err) return -1; - if (devn >= ubi.dev_count) { + if (devn >= (int)ubi.dev_count) { fprintf(stderr, "Device %d does not exist\n", devn); goto out; } diff --git a/ubi-utils/src/ubiwritevol/ubiwritevol.c b/ubi-utils/src/ubiupdatevol.c index 8fdbe37..28e1e8f 100644 --- a/ubi-utils/src/ubiwritevol/ubiwritevol.c +++ b/ubi-utils/src/ubiupdatevol.c @@ -68,10 +68,10 @@ static int verbose = 0; static error_t parse_opt (int key, char *arg, struct argp_state *state); -const char *argp_program_bug_address = "<haver@vnet.ibm.com>"; +const char *argp_program_bug_address = PACKAGE_BUGREPORT; -static char doc[] = "\nVersion: " VERSION "\n\t" - HOST_OS" "HOST_CPU" at "__DATE__" "__TIME__"\n" +static char doc[] = "\nVersion: " PACKAGE_VERSION "\n\t" + BUILD_OS" "BUILD_CPU" at "__DATE__" "__TIME__"\n" "\nWrite to UBI Volume.\n"; static struct argp_option options[] = { diff --git a/ubi-utils/src/unubi/unubi.c b/ubi-utils/src/unubi.c index 9cb1354..6d877e7 100644 --- a/ubi-utils/src/unubi/unubi.c +++ b/ubi-utils/src/unubi.c @@ -65,10 +65,11 @@ static struct args myargs = { static error_t parse_opt (int key, char *arg, struct argp_state *state); -const char *argp_program_bug_address = "<haver@vnet.ibm.com>"; +const char *argp_program_bug_address = + "... uuuh, lets wait until it looks nicer"; -static char doc[] = "\nVersion: " VERSION "\n\t" - HOST_OS" "HOST_CPU" at "__DATE__" "__TIME__"\n" +static char doc[] = "\nVersion: " PACKAGE_VERSION "\n\t" + BUILD_OS" "BUILD_CPU" at "__DATE__" "__TIME__"\n" "\nWrite to UBI Volume.\n"; static struct argp_option options[] = { @@ -204,7 +205,7 @@ parse_opt(int key, char *arg, struct argp_state *state) } static inline void -hexdump(FILE *fp, const void *p, size_t size) +hexdump(FILE *fp, const void *p, ssize_t size) { int k; const uint8_t *buf = p; @@ -271,7 +272,7 @@ static int extract_volume(struct args *args, const uint8_t *buf, if (crc != ubi32_to_cpu(vid_hdr->hdr_crc)) continue; - if (volume == ubi32_to_cpu(vid_hdr->vol_id)) { + if (volume == (int)ubi32_to_cpu(vid_hdr->vol_id)) { printf("****** block %4d volume %2d **********\n", i, volume); |