]> www.infradead.org Git - mtd-utils.git/commitdiff
[MTD] UBI: Fixed 16 KiB blocksize problem.
authorFrank Haverkamp <haver@vnet.ibm.com>
Mon, 10 Jul 2006 13:47:05 +0000 (15:47 +0200)
committerFrank Haverkamp <haver@vnet.ibm.com>
Tue, 31 Oct 2006 14:06:07 +0000 (15:06 +0100)
ubi-utils/src/pfi2bin.c
ubi-utils/src/reader.c
ubi-utils/src/reader.h

index 6536c195f4b71f3f8f7d9a0f9cef78d4553a3901..4c25fafa69e2195583d553b0097c785056e826c8 100644 (file)
@@ -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,
index e4a8cebf4f9418856e484a01a7030a94df30749a..5de06d549e49dbb811add7c36d0aaeab8bb618ff 100644 (file)
@@ -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)
index 93c15e32a764d8d563583e871e703dc5f04905da..d00fa171a23ec963a836176e872bf2a2f230bcfd 100644 (file)
@@ -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;