From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
To: barebox@lists.infradead.org
Cc: Lior Amsalem <alior@marvell.com>,
Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
Subject: [PATCH 04/12] scripts/kwbimage: simplify the v1 image creation
Date: Wed, 15 May 2013 00:32:17 +0200 [thread overview]
Message-ID: <1368570745-23348-5-git-send-email-thomas.petazzoni@free-electrons.com> (raw)
In-Reply-To: <1368570745-23348-1-git-send-email-thomas.petazzoni@free-electrons.com>
We now assume that at most one binary header can be added, so we no
longer need to loop for all configuration options to find the binary
blobs. We simply find the binary blob configuration option in
'binarye' and use that when we need to generate the corresponding
header.
Also, just like we did for the v0 image creation, use
image_find_option() to find the value of the different options needed
to create the main header.
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
scripts/kwbimage.c | 151 ++++++++++++++++++++++++----------------------------
1 file changed, 70 insertions(+), 81 deletions(-)
diff --git a/scripts/kwbimage.c b/scripts/kwbimage.c
index d4f65a8..631f131 100644
--- a/scripts/kwbimage.c
+++ b/scripts/kwbimage.c
@@ -802,12 +802,12 @@ static void *image_create_v0(struct image_cfg_element *image_cfg,
static void *image_create_v1(struct image_cfg_element *image_cfg,
int cfgn, const char *output, size_t *imagesz)
{
- struct image_cfg_element *e, *payloade;
+ struct image_cfg_element *e, *payloade, *binarye;
struct main_hdr_v1 *main_hdr;
size_t headersz, payloadsz, totalsz;
void *image, *cur;
int hasext = 0;
- int cfgi, ret;
+ int ret;
/* Calculate the size of the header and the size of the
* payload */
@@ -824,24 +824,24 @@ static void *image_create_v1(struct image_cfg_element *image_cfg,
return NULL;
}
- e = image_find_option(image_cfg, cfgn, IMAGE_CFG_BINARY);
- if (e) {
+ binarye = image_find_option(image_cfg, cfgn, IMAGE_CFG_BINARY);
+ if (binarye) {
struct stat s;
- ret = stat(e->binary.file, &s);
+ ret = stat(binarye->binary.file, &s);
if (ret < 0) {
char *cwd = get_current_dir_name();
fprintf(stderr,
"Didn't find the file '%s' in '%s' which is mandatory to generate the image\n"
"This file generally contains the DDR3 training code, and should be extracted from an existing bootable\n"
"image for your board. See 'kwbimage -x' to extract it from an existing image.\n",
- e->binary.file, cwd);
+ binarye->binary.file, cwd);
free(cwd);
return NULL;
}
headersz += s.st_size +
- e->binary.nargs * sizeof(unsigned int);
+ binarye->binary.nargs * sizeof(unsigned int);
hasext = 1;
}
@@ -878,96 +878,85 @@ static void *image_create_v1(struct image_cfg_element *image_cfg,
cur = main_hdr = image;
cur += sizeof(struct main_hdr_v1);
+ /* Fill the main header */
main_hdr->blocksize = payloadsz + sizeof(uint32_t);
main_hdr->headersz_lsb = headersz & 0xFFFF;
main_hdr->headersz_msb = (headersz & 0xFFFF0000) >> 16;
main_hdr->srcaddr = headersz;
main_hdr->ext = hasext;
+ main_hdr->version = 1;
+ e = image_find_option(image_cfg, cfgn, IMAGE_CFG_BOOT_FROM);
+ if (e)
+ main_hdr->blockid = e->bootfrom;
+ e = image_find_option(image_cfg, cfgn, IMAGE_CFG_DEST_ADDR);
+ if (e)
+ main_hdr->destaddr = e->dstaddr;
+ e = image_find_option(image_cfg, cfgn, IMAGE_CFG_EXEC_ADDR);
+ if (e)
+ main_hdr->execaddr = e->execaddr;
+ e = image_find_option(image_cfg, cfgn, IMAGE_CFG_NAND_BLKSZ);
+ if (e)
+ main_hdr->nandblocksize = e->nandblksz / (64 * 1024);
+ e = image_find_option(image_cfg, cfgn, IMAGE_CFG_NAND_BADBLK_LOCATION);
+ if (e)
+ main_hdr->nandbadblklocation = e->nandbadblklocation;
- /* First, take care of filling the main header */
- for (cfgi = 0; cfgi < cfgn; cfgi++) {
- struct image_cfg_element *el = &image_cfg[cfgi];
- if (el->type == IMAGE_CFG_VERSION)
- main_hdr->version = 1;
- else if (el->type == IMAGE_CFG_BOOT_FROM)
- main_hdr->blockid = el->bootfrom;
- else if (el->type == IMAGE_CFG_DEST_ADDR)
- main_hdr->destaddr = el->dstaddr;
- else if (el->type == IMAGE_CFG_EXEC_ADDR)
- main_hdr->execaddr = el->execaddr;
- else if (el->type == IMAGE_CFG_NAND_BLKSZ)
- main_hdr->nandblocksize = el->nandblksz / (64 * 1024);
- else if (el->type == IMAGE_CFG_NAND_BADBLK_LOCATION)
- main_hdr->nandbadblklocation = el->nandbadblklocation;
- else
- break;
- }
-
- /* Then, fill the extension headers */
- for (; cfgi < cfgn; cfgi++) {
- struct image_cfg_element *el = &image_cfg[cfgi];
-
- if (el->type == IMAGE_CFG_BINARY) {
- struct opt_hdr_v1 *hdr = cur;
- unsigned int *args;
- size_t binhdrsz;
- struct stat s;
- int argi;
- FILE *bin;
-
- hdr->headertype = OPT_HDR_V1_BINARY_TYPE;
-
- bin = fopen(el->binary.file, "r");
- if (!bin) {
- fprintf(stderr, "Cannot open binary file %s\n",
- el->binary.file);
- return NULL;
- }
-
- fstat(fileno(bin), &s);
+ if (binarye) {
+ struct opt_hdr_v1 *hdr = cur;
+ unsigned int *args;
+ size_t binhdrsz;
+ struct stat s;
+ int argi;
+ FILE *bin;
- binhdrsz = sizeof(struct opt_hdr_v1) +
- (el->binary.nargs + 1) * sizeof(unsigned int) +
- s.st_size;
- hdr->headersz_lsb = binhdrsz & 0xFFFF;
- hdr->headersz_msb = (binhdrsz & 0xFFFF0000) >> 16;
+ hdr->headertype = OPT_HDR_V1_BINARY_TYPE;
- cur += sizeof(struct opt_hdr_v1);
+ bin = fopen(binarye->binary.file, "r");
+ if (!bin) {
+ fprintf(stderr, "Cannot open binary file %s\n",
+ binarye->binary.file);
+ return NULL;
+ }
- args = cur;
- *args = el->binary.nargs;
- args++;
- for (argi = 0; argi < el->binary.nargs; argi++)
- args[argi] = el->binary.args[argi];
+ fstat(fileno(bin), &s);
- cur += (el->binary.nargs + 1) * sizeof(unsigned int);
+ binhdrsz = sizeof(struct opt_hdr_v1) +
+ (binarye->binary.nargs + 1) * sizeof(unsigned int) +
+ s.st_size;
+ hdr->headersz_lsb = binhdrsz & 0xFFFF;
+ hdr->headersz_msb = (binhdrsz & 0xFFFF0000) >> 16;
- ret = fread(cur, s.st_size, 1, bin);
- if (ret != 1) {
- fprintf(stderr,
- "Could not read binary image %s\n",
- el->binary.file);
- return NULL;
- }
+ cur += sizeof(struct opt_hdr_v1);
- fclose(bin);
+ args = cur;
+ *args = binarye->binary.nargs;
+ args++;
+ for (argi = 0; argi < binarye->binary.nargs; argi++)
+ args[argi] = binarye->binary.args[argi];
- cur += s.st_size;
+ cur += (binarye->binary.nargs + 1) * sizeof(unsigned int);
- /* See if we have a next header or not, and if
- * so, add the marker indicating that we are
- * not the last header */
- if ((cfgi < (cfgn - 1)) &&
- (image_cfg[cfgi + 1].type != IMAGE_CFG_PAYLOAD))
- *((unsigned char *) cur) = 1;
- cur += sizeof(uint32_t);
- } else if (el->type == IMAGE_CFG_PAYLOAD)
- break;
- else {
- fprintf(stderr, "Invalid element type %d (cfgi=%d)\n",
- el->type, cfgi);
+ ret = fread(cur, s.st_size, 1, bin);
+ if (ret != 1) {
+ fprintf(stderr,
+ "Could not read binary image %s\n",
+ binarye->binary.file);
return NULL;
}
+
+ fclose(bin);
+
+ cur += s.st_size;
+
+ /*
+ * For now, we don't support more than one binary
+ * header, and no other header types are
+ * supported. So, the binary header is necessarily the
+ * last one
+ */
+ *((unsigned char *) cur) = 0;
+
+ cur += sizeof(uint32_t);
}
/* Calculate and set the header checksum */
--
1.7.9.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2013-05-14 22:32 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-14 22:32 [PATCH 00/12] Support for Marvell Kirkwood and Dove SoCs Thomas Petazzoni
2013-05-14 22:32 ` [PATCH 01/12] scripts/kwbimage: add a new function image_count_options() Thomas Petazzoni
2013-05-14 22:32 ` [PATCH 02/12] scripts/kwbimage: add a few sanity checks Thomas Petazzoni
2013-05-14 22:32 ` [PATCH 03/12] scripts/kwbimage: make the v0 image creation more flexible Thomas Petazzoni
2013-05-14 22:32 ` Thomas Petazzoni [this message]
2013-05-14 22:32 ` [PATCH 05/12] scripts/kwbimage: make image_boot_mode_id() return -1 on failure Thomas Petazzoni
2013-05-14 22:32 ` [PATCH 06/12] scripts/kwbimage: add support for NAND ECC and page size header fields Thomas Petazzoni
2013-05-14 22:32 ` [PATCH 07/12] arm: mach-mvebu: rename Armada 370/XP core code Thomas Petazzoni
2013-05-14 22:32 ` [PATCH 08/12] arm: mvebu: initial support for Marvell Dove SoCs Thomas Petazzoni
2013-05-14 22:32 ` [PATCH 09/12] arm: mvebu: add Feroceon CPU type Thomas Petazzoni
2013-05-14 22:32 ` [PATCH 10/12] arm: mvebu: initial support for Marvell Kirkwood SoCs Thomas Petazzoni
2013-05-14 22:32 ` [PATCH 11/12] arm: mvebu: add basic support for SolidRun CuBox Thomas Petazzoni
2013-05-14 22:32 ` [PATCH 12/12] arm: mvebu: add basic support for Globalscale Guruplug board Thomas Petazzoni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1368570745-23348-5-git-send-email-thomas.petazzoni@free-electrons.com \
--to=thomas.petazzoni@free-electrons.com \
--cc=alior@marvell.com \
--cc=barebox@lists.infradead.org \
--cc=ezequiel.garcia@free-electrons.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox