From patchwork Sun Jun 3 09:27:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [U-Boot, resend] Added UBL_MAGIC_PLL number for ublimage + added automatic page size calculation Date: Sat, 02 Jun 2012 23:27:32 -0000 From: Stijn Souffriau X-Patchwork-Id: 162486 Message-Id: <1338715653-6802-2-git-send-email-stijn.souffriau@essensium.com> To: u-boot@lists.denx.de Cc: trini@ti.com, s-paulraj@ti.com --- tools/mkimage.h | 6 ++++++ tools/ublimage.c | 31 +++++++++++++++++++++++++++++-- tools/ublimage.h | 2 ++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/tools/mkimage.h b/tools/mkimage.h index 5fe1a48..cd835f0 100644 --- a/tools/mkimage.h +++ b/tools/mkimage.h @@ -140,6 +140,12 @@ struct image_type_params { void mkimage_register (struct image_type_params *tparams); /* + * This struct contains the global parameters and is initialized + * by the main core before any image type specific functions are called. + */ +extern struct mkimage_params params; + +/* * There is a c file associated with supported image type low level code * for ex. default_image.c, fit_image.c * init is the only function referred by mkimage core. diff --git a/tools/ublimage.c b/tools/ublimage.c index d6b4017..b5fa5c2 100644 --- a/tools/ublimage.c +++ b/tools/ublimage.c @@ -36,6 +36,10 @@ #include #include "ublimage.h" +#include +#include +#include + /* * Supported commands for configuration file */ @@ -58,8 +62,9 @@ static table_entry_t ublimage_cmds[] = { * this is needed to set the correct flash offset */ static table_entry_t ublimage_bootops[] = { - {UBL_MAGIC_SAFE, "safe", "Safe boot mode", }, - {-1, "", "Invalid", }, + {UBL_MAGIC_SAFE,"safe", "Safe boot mode", }, + {UBL_MAGIC_PLL, "pll", "With PLL enabled to have higher ARM/DMA clocks", }, + {-1, "", "Invalid", }, }; static struct ubl_header ublimage_header; @@ -89,6 +94,22 @@ static void print_hdr(struct ubl_header *ubl_hdr) printf("start page : %08x\n", ubl_hdr->page); } +/* + * This function calculates the size of the datafile in NAND pages + */ +static uint32_t get_data_pages_size(void) +{ + uint32_t size = 0; + struct stat buf; + int rv = stat(params.datafile, &buf); + if (rv == 0) { + size = (buf.st_size/UBL_BLOCK_SIZE) + (buf.st_size % UBL_BLOCK_SIZE == 0 ? 0 : 1); + } else { + fprintf(stderr, "Error: could not stat datafile %s\n", params.datafile); + } + return size; +} + static void parse_cfg_cmd(struct ubl_header *ublhdr, int32_t cmd, char *token, char *name, int lineno, int fld, int dcd_len) { @@ -171,6 +192,12 @@ static uint32_t parse_cfg_file(struct ubl_header *ublhdr, char *name) *ptr = 0xff; ptr++; } + + /* By default, the size of the data in NAND pages + * will be automatically calculated but it can be overwritten + * in the configuration file. + */ + ublhdr->pages = get_data_pages_size(); /* * Very simple parsing, line starting with # are comments diff --git a/tools/ublimage.h b/tools/ublimage.h index e440625..cbff8b7 100644 --- a/tools/ublimage.h +++ b/tools/ublimage.h @@ -61,6 +61,8 @@ enum ublimage_fld_types { #define UBL_MAGIC_DMA_IC (0x44) /* DMA + ICache + Fast EMIF boot mode */ #define UBL_MAGIC_DMA_IC_FAST (0x55) +/* With PLL enabled to have higher ARM/DMA clocks */ +#define UBL_MAGIC_PLL (0x66) /* Define max UBL image size */ #define UBL_IMAGE_SIZE (0x00003800u)