#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
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";
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)
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,
#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); \
}
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;
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)
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)