diff options
author | Frank Haverkamp <haver@vnet.ibm.com> | 2006-07-10 15:47:05 +0200 |
---|---|---|
committer | Frank Haverkamp <haver@vnet.ibm.com> | 2006-10-31 15:06:07 +0100 |
commit | 02e51e7e0b4c50d900d3a246b2bce73df3a191ee (patch) | |
tree | 42b80dc4a076300cc17f7e9d2f5739470abefab3 /ubi-utils/src | |
parent | c474d44341b1ab9b1b39cf2bbf8686a610b54614 (diff) |
[MTD] UBI: Fixed 16 KiB blocksize problem.
Diffstat (limited to 'ubi-utils/src')
-rw-r--r-- | ubi-utils/src/pfi2bin.c | 20 | ||||
-rw-r--r-- | ubi-utils/src/reader.c | 35 | ||||
-rw-r--r-- | ubi-utils/src/reader.h | 1 |
3 files changed, 41 insertions, 15 deletions
diff --git a/ubi-utils/src/pfi2bin.c b/ubi-utils/src/pfi2bin.c index 6536c19..4c25faf 100644 --- a/ubi-utils/src/pfi2bin.c +++ b/ubi-utils/src/pfi2bin.c @@ -42,6 +42,8 @@ #include "peb.h" #include "crc32.h" +#define PROGRAM_VERSION "1.2" + #define MAX_FNAME 255 #define DEFAULT_ERASE_COUNT 0 /* Hmmm.... Perhaps */ #define ERR_BUF_SIZE 1024 @@ -71,9 +73,9 @@ static const char copyright [] __attribute__((unused)) = static error_t parse_opt (int key, char *arg, struct argp_state *state); -const char *argp_program_version = PACKAGE_VERSION; +const char *argp_program_version = PROGRAM_VERSION; const char *argp_program_bug_address = PACKAGE_BUGREPORT; -static char doc[] = "\nVersion: " PACKAGE_VERSION "\n\tBuilt on " +static char doc[] = "\nVersion: " PROGRAM_VERSION "\n\tBuilt on " BUILD_CPU" "BUILD_OS" at "__DATE__" "__TIME__"\n" "\n" "pfi2bin - a tool to convert PFI files into binary images.\n"; @@ -355,6 +357,8 @@ write_ubi_volume_table(pdd_data_t pdd, list_t raw_pebs, size_t leb_size, leb_total, j = 0; uint8_t *ptr = NULL; FILE* fp_leb = NULL; + int vt_slots; + size_t vol_tab_size_limit; rc = peb_new(0, 0, &cmp_peb); if (rc != 0) @@ -379,11 +383,21 @@ write_ubi_volume_table(pdd_data_t pdd, list_t raw_pebs, goto err; ubigen_destroy(&u); + /* + * The number of supported volumes is restricted by the eraseblock size + * and by the UBI_MAX_VOLUMES constant. + */ + vt_slots = leb_size / UBI_VTBL_RECORD_SIZE; + if (vt_slots > UBI_MAX_VOLUMES) + vt_slots = UBI_MAX_VOLUMES; + vol_tab_size_limit = vt_slots * UBI_VTBL_RECORD_SIZE; + ptr = (uint8_t*) malloc(leb_size * sizeof(uint8_t)); if (ptr == NULL) goto err; + memset(ptr, 0xff, leb_size); - memcpy(ptr, vol_tab, vol_tab_size); + memcpy(ptr, vol_tab, vol_tab_size_limit); fp_leb = my_fmemopen(ptr, leb_size, "r"); rc = ubigen_create(&u, UBI_LAYOUT_VOL_ID, UBI_VID_DYNAMIC, diff --git a/ubi-utils/src/reader.c b/ubi-utils/src/reader.c index e4a8ceb..5de06d5 100644 --- a/ubi-utils/src/reader.c +++ b/ubi-utils/src/reader.c @@ -34,8 +34,9 @@ #include "reader.h" /* @FIXME hard coded offsets right now - get them from Artem? */ -#define NAND_DEFAULT_VID_HDR_OFF 1984 -#define NOR_DEFAULT_VID_HDR_OFF 64 +#define NAND2048_DEFAULT_VID_HDR_OFF 1984 +#define NAND512_DEFAULT_VID_HDR_OFF 448 +#define NOR_DEFAULT_VID_HDR_OFF 64 #define EBUF_PFI(fmt...) \ do { int i = snprintf(err_buf, err_buf_size, "%s\n", label); \ @@ -74,8 +75,27 @@ read_pdd_data(FILE* fp_pdd, pdd_data_t* pdd_data, } if (strcmp(value, "NAND") == 0) { + + rc = bootenv_get_num(pdd, "flash_page_size", + &(res->flash_page_size)); + if (rc != 0) { + EBUF("Cannot read 'flash_page_size' from pdd."); + goto err; + } res->flash_type = NAND_FLASH; - res->vid_hdr_offset = NAND_DEFAULT_VID_HDR_OFF; + + switch (res->flash_page_size) { + case 512: + res->vid_hdr_offset = NAND512_DEFAULT_VID_HDR_OFF; + break; + case 2048: + res->vid_hdr_offset = NAND2048_DEFAULT_VID_HDR_OFF; + break; + default: + EBUF("Unsupported 'flash_page_size' %d.", + res->flash_page_size); + goto err; + } } else if (strcmp(value, "NOR") == 0){ res->flash_type = NOR_FLASH; @@ -113,11 +133,6 @@ 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 __unused, pfi_raw_t* pfi_raw, const char* label, char* err_buf, size_t err_buf_size) @@ -175,10 +190,6 @@ read_pfi_raw(pfi_header pfi_hd, FILE* fp_pfi __unused, 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 __unused, pfi_ubi_t* pfi_ubi, const char *label, char* err_buf, size_t err_buf_size) diff --git a/ubi-utils/src/reader.h b/ubi-utils/src/reader.h index 93c15e3..d00fa17 100644 --- a/ubi-utils/src/reader.h +++ b/ubi-utils/src/reader.h @@ -40,6 +40,7 @@ typedef struct pfi_ubi *pfi_ubi_t; struct pdd_data { uint32_t flash_size; + uint32_t flash_page_size; uint32_t eb_size; uint32_t vid_hdr_offset; flash_type_t flash_type; |