diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/buildman/README | 23 | ||||
-rw-r--r-- | tools/env/fw_env.c | 1 | ||||
-rw-r--r-- | tools/kwbimage.c | 60 | ||||
-rw-r--r-- | tools/kwbimage.h | 3 | ||||
-rw-r--r-- | tools/mkimage.c | 30 | ||||
-rw-r--r-- | tools/rkcommon.c | 96 | ||||
-rw-r--r-- | tools/rkcommon.h | 36 | ||||
-rw-r--r-- | tools/rkimage.c | 4 | ||||
-rw-r--r-- | tools/rksd.c | 26 | ||||
-rw-r--r-- | tools/rkspi.c | 23 | ||||
-rw-r--r-- | tools/zynqimage.c | 3 |
11 files changed, 212 insertions, 93 deletions
diff --git a/tools/buildman/README b/tools/buildman/README index 10c7135b5f2..66502af62ea 100644 --- a/tools/buildman/README +++ b/tools/buildman/README @@ -156,7 +156,6 @@ aarch64: /opt/linaro/gcc-linaro-aarch64-none-elf-4.8-2013.10_linux [toolchain-alias] x86: i386 blackfin: bfin -sh: sh4 nds32: nds32le openrisc: or32 @@ -341,6 +340,28 @@ Testing - found '/home/sjg/.buildman-toolchains/gcc-4.5.1-nolibc/or32-linux/bin/or32-linux-gcc' Tool chain test: OK +Or download them all from kernel.org and move them to /toolchains directory, + +$ for i in aarch64 arm avr32 i386 m68k microblaze mips or32 powerpc sparc + do + ./tools/buildman/buildman --fetch-arch $i + done +$ sudo mkdir -p /toolchains +$ sudo mv ~/.buildman-toolchains/*/* /toolchains/ + +For those not available from kernel.org, download from the following links. + +arc: https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/releases/ + arc_gnu_2015.06_prebuilt_uclibc_le_archs_linux_install.tar.gz +blackfin: http://sourceforge.net/projects/adi-toolchain/files/ + blackfin-toolchain-elf-gcc-4.5-2014R1_45-RC2.x86_64.tar.bz2 +nds32: http://osdk.andestech.com/packages/ + nds32le-linux-glibc-v1.tgz +nios2: http://sourcery.mentor.com/public/gnu_toolchain/nios2-linux-gnu/ + sourceryg++-2015.11-27-nios2-linux-gnu-i686-pc-linux-gnu.tar.bz2 +sh: http://sourcery.mentor.com/public/gnu_toolchain/sh-linux-gnu/ + renesas-4.4-200-sh-linux-gnu-i686-pc-linux-gnu.tar.bz2 + Buildman should now be set up to use your new toolchain. At the time of writing, U-Boot has these architectures: diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index ba11f7727b8..39f733376ed 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -10,6 +10,7 @@ #define _GNU_SOURCE +#include <compiler.h> #include <errno.h> #include <env_flags.h> #include <fcntl.h> diff --git a/tools/kwbimage.c b/tools/kwbimage.c index 5f6d91c4865..369aba7bcab 100644 --- a/tools/kwbimage.c +++ b/tools/kwbimage.c @@ -232,11 +232,12 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params, main_hdr = image; /* Fill in the main header */ - main_hdr->blocksize = payloadsz + sizeof(uint32_t) - headersz; - main_hdr->srcaddr = headersz; + main_hdr->blocksize = + cpu_to_le32(payloadsz + sizeof(uint32_t) - headersz); + main_hdr->srcaddr = cpu_to_le32(headersz); main_hdr->ext = has_ext; - main_hdr->destaddr = params->addr; - main_hdr->execaddr = params->ep; + main_hdr->destaddr = cpu_to_le32(params->addr); + main_hdr->execaddr = cpu_to_le32(params->ep); e = image_find_option(IMAGE_CFG_BOOT_FROM); if (e) @@ -246,7 +247,7 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params, main_hdr->nandeccmode = e->nandeccmode; e = image_find_option(IMAGE_CFG_NAND_PAGESZ); if (e) - main_hdr->nandpagesize = e->nandpagesz; + main_hdr->nandpagesize = cpu_to_le16(e->nandpagesz); main_hdr->checksum = image_checksum8(image, sizeof(struct main_hdr_v0)); @@ -255,15 +256,17 @@ static void *image_create_v0(size_t *imagesz, struct image_tool_params *params, int cfgi, datai; ext_hdr = image + sizeof(struct main_hdr_v0); - ext_hdr->offset = 0x40; + ext_hdr->offset = cpu_to_le32(0x40); for (cfgi = 0, datai = 0; cfgi < cfgn; cfgi++) { e = &image_cfg[cfgi]; if (e->type != IMAGE_CFG_DATA) continue; - ext_hdr->rcfg[datai].raddr = e->regdata.raddr; - ext_hdr->rcfg[datai].rdata = e->regdata.rdata; + ext_hdr->rcfg[datai].raddr = + cpu_to_le32(e->regdata.raddr); + ext_hdr->rcfg[datai].rdata = + cpu_to_le32(e->regdata.rdata); datai++; } @@ -321,8 +324,9 @@ static size_t image_headersz_v1(struct image_tool_params *params, return 0; } - headersz += s.st_size + - binarye->binary.nargs * sizeof(unsigned int); + headersz += sizeof(struct opt_hdr_v1) + + s.st_size + + (binarye->binary.nargs + 2) * sizeof(uint32_t); if (hasext) *hasext = 1; } @@ -376,12 +380,13 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, cur += sizeof(struct main_hdr_v1); /* Fill the main header */ - main_hdr->blocksize = payloadsz - headersz + sizeof(uint32_t); - main_hdr->headersz_lsb = headersz & 0xFFFF; + main_hdr->blocksize = + cpu_to_le32(payloadsz - headersz + sizeof(uint32_t)); + main_hdr->headersz_lsb = cpu_to_le16(headersz & 0xFFFF); main_hdr->headersz_msb = (headersz & 0xFFFF0000) >> 16; - main_hdr->destaddr = params->addr; - main_hdr->execaddr = params->ep; - main_hdr->srcaddr = headersz; + main_hdr->destaddr = cpu_to_le32(params->addr); + main_hdr->execaddr = cpu_to_le32(params->ep); + main_hdr->srcaddr = cpu_to_le32(headersz); main_hdr->ext = hasext; main_hdr->version = 1; e = image_find_option(IMAGE_CFG_BOOT_FROM); @@ -397,7 +402,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, binarye = image_find_option(IMAGE_CFG_BINARY); if (binarye) { struct opt_hdr_v1 *hdr = cur; - unsigned int *args; + uint32_t *args; size_t binhdrsz; struct stat s; int argi; @@ -415,7 +420,7 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, fstat(fileno(bin), &s); binhdrsz = sizeof(struct opt_hdr_v1) + - (binarye->binary.nargs + 1) * sizeof(unsigned int) + + (binarye->binary.nargs + 2) * sizeof(uint32_t) + s.st_size; /* @@ -424,18 +429,18 @@ static void *image_create_v1(size_t *imagesz, struct image_tool_params *params, * next-header byte and 3-byte alignment at the end. */ binhdrsz = ALIGN_SUP(binhdrsz, 4) + 4; - hdr->headersz_lsb = binhdrsz & 0xFFFF; + hdr->headersz_lsb = cpu_to_le16(binhdrsz & 0xFFFF); hdr->headersz_msb = (binhdrsz & 0xFFFF0000) >> 16; cur += sizeof(struct opt_hdr_v1); args = cur; - *args = binarye->binary.nargs; + *args = cpu_to_le32(binarye->binary.nargs); args++; for (argi = 0; argi < binarye->binary.nargs; argi++) - args[argi] = binarye->binary.args[argi]; + args[argi] = cpu_to_le32(binarye->binary.args[argi]); - cur += (binarye->binary.nargs + 1) * sizeof(unsigned int); + cur += (binarye->binary.nargs + 1) * sizeof(uint32_t); ret = fread(cur, s.st_size, 1, bin); if (ret != 1) { @@ -720,7 +725,8 @@ static void kwbimage_set_header(void *ptr, struct stat *sbuf, int ifd, free(image_cfg); /* Build and add image checksum header */ - checksum = image_checksum32((uint32_t *)ptr, sbuf->st_size); + checksum = + cpu_to_le32(image_checksum32((uint32_t *)ptr, sbuf->st_size)); size = write(ifd, &checksum, sizeof(uint32_t)); if (size != sizeof(uint32_t)) { fprintf(stderr, "Error:%s - Checksum write %d bytes %s\n", @@ -810,7 +816,15 @@ static int kwbimage_generate(struct image_tool_params *params, tparams->header_size = alloc_len; tparams->hdr = hdr; - return 0; + /* + * The resulting image needs to be 4-byte aligned. At least + * the Marvell hdrparser tool complains if its unaligned. + * By returning 1 here in this function, called via + * tparams->vrec_header() in mkimage.c, mkimage will + * automatically pad the the resulting image to a 4-byte + * size if necessary. + */ + return 1; } /* diff --git a/tools/kwbimage.h b/tools/kwbimage.h index 9d2585c0e72..e6e3d1d4f9a 100644 --- a/tools/kwbimage.h +++ b/tools/kwbimage.h @@ -9,6 +9,7 @@ #ifndef _KWBIMAGE_H_ #define _KWBIMAGE_H_ +#include <compiler.h> #include <stdint.h> #define KWBIMAGE_MAX_CONFIG ((0x1dc - 0x20)/sizeof(struct reg_config)) @@ -115,7 +116,7 @@ struct opt_hdr_v1 { #define OPT_HDR_V1_REGISTER_TYPE 0x3 #define KWBHEADER_V1_SIZE(hdr) \ - (((hdr)->headersz_msb << 16) | (hdr)->headersz_lsb) + (((hdr)->headersz_msb << 16) | le16_to_cpu((hdr)->headersz_lsb)) enum kwbimage_cmd { CMD_INVALID, diff --git a/tools/mkimage.c b/tools/mkimage.c index 8af9d50e2cd..8f8b6df37cd 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -311,21 +311,25 @@ NXTARG: ; exit (retval); } - dfd = open(params.datafile, O_RDONLY | O_BINARY); - if (dfd < 0) { - fprintf(stderr, "%s: Can't open %s: %s\n", - params.cmdname, params.datafile, strerror(errno)); - exit(EXIT_FAILURE); - } + if ((params.type != IH_TYPE_MULTI) && (params.type != IH_TYPE_SCRIPT)) { + dfd = open(params.datafile, O_RDONLY | O_BINARY); + if (dfd < 0) { + fprintf(stderr, "%s: Can't open %s: %s\n", + params.cmdname, params.datafile, + strerror(errno)); + exit(EXIT_FAILURE); + } - if (fstat(dfd, &sbuf) < 0) { - fprintf(stderr, "%s: Can't stat %s: %s\n", - params.cmdname, params.datafile, strerror(errno)); - exit(EXIT_FAILURE); - } + if (fstat(dfd, &sbuf) < 0) { + fprintf(stderr, "%s: Can't stat %s: %s\n", + params.cmdname, params.datafile, + strerror(errno)); + exit(EXIT_FAILURE); + } - params.file_size = sbuf.st_size + tparams->header_size; - close(dfd); + params.file_size = sbuf.st_size + tparams->header_size; + close(dfd); + } /* * In case there an header with a variable diff --git a/tools/rkcommon.c b/tools/rkcommon.c index 43896226c0d..72621fd095c 100644 --- a/tools/rkcommon.c +++ b/tools/rkcommon.c @@ -25,7 +25,7 @@ enum { * * @signature: Signature (must be RKSD_SIGNATURE) * @disable_rc4: 0 to use rc4 for boot image, 1 to use plain binary - * @code1_offset: Offset in blocks of the SPL code from this header + * @init_offset: Offset in blocks of the SPL code from this header * block. E.g. 4 means 2KB after the start of this header. * Other fields are not used by U-Boot */ @@ -33,38 +33,102 @@ struct header0_info { uint32_t signature; uint8_t reserved[4]; uint32_t disable_rc4; - uint16_t code1_offset; - uint16_t code2_offset; - uint8_t reserved1[490]; - uint16_t usflashdatasize; - uint16_t ucflashbootsize; + uint16_t init_offset; + uint8_t reserved1[492]; + uint16_t init_size; + uint16_t init_boot_size; uint8_t reserved2[2]; }; +/** + * struct spl_info - spl info for each chip + * + * @imagename: Image name(passed by "mkimage -n") + * @spl_hdr: Boot ROM requires a 4-bytes spl header + * @spl_size: Spl size(include extra 4-bytes spl header) + */ +struct spl_info { + const char *imagename; + const char *spl_hdr; + const uint32_t spl_size; +}; + +static struct spl_info spl_infos[] = { + { "rk3036", "RK30", 0x1000 }, + { "rk3288", "RK32", 0x8000 }, +}; + static unsigned char rc4_key[16] = { 124, 78, 3, 4, 85, 5, 9, 7, 45, 44, 123, 56, 23, 13, 23, 17 }; -int rkcommon_set_header(void *buf, uint file_size) +static struct spl_info *rkcommon_get_spl_info(char *imagename) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(spl_infos); i++) + if (!strncmp(imagename, spl_infos[i].imagename, 6)) + return spl_infos + i; + + return NULL; +} + +int rkcommon_check_params(struct image_tool_params *params) +{ + int i; + + if (rkcommon_get_spl_info(params->imagename) != NULL) + return 0; + + fprintf(stderr, "ERROR: imagename (%s) is not supported!\n", + strlen(params->imagename) > 0 ? params->imagename : "NULL"); + + fprintf(stderr, "Available imagename:"); + for (i = 0; i < ARRAY_SIZE(spl_infos); i++) + fprintf(stderr, "\t%s", spl_infos[i].imagename); + fprintf(stderr, "\n"); + + return -1; +} + +const char *rkcommon_get_spl_hdr(struct image_tool_params *params) +{ + struct spl_info *info = rkcommon_get_spl_info(params->imagename); + + /* + * info would not be NULL, because of we checked params before. + */ + return info->spl_hdr; +} + +int rkcommon_get_spl_size(struct image_tool_params *params) +{ + struct spl_info *info = rkcommon_get_spl_info(params->imagename); + + /* + * info would not be NULL, because of we checked params before. + */ + return info->spl_size; +} + +int rkcommon_set_header(void *buf, uint file_size, + struct image_tool_params *params) { struct header0_info *hdr; - if (file_size > RK_MAX_CODE1_SIZE) + if (file_size > rkcommon_get_spl_size(params)) return -ENOSPC; - memset(buf, '\0', RK_CODE1_OFFSET * RK_BLK_SIZE); + memset(buf, '\0', RK_INIT_OFFSET * RK_BLK_SIZE); hdr = (struct header0_info *)buf; hdr->signature = RK_SIGNATURE; hdr->disable_rc4 = 1; - hdr->code1_offset = RK_CODE1_OFFSET; - hdr->code2_offset = 8; - - hdr->usflashdatasize = (file_size + RK_BLK_SIZE - 1) / RK_BLK_SIZE; - hdr->usflashdatasize = (hdr->usflashdatasize + 3) & ~3; - hdr->ucflashbootsize = hdr->usflashdatasize; + hdr->init_offset = RK_INIT_OFFSET; - debug("size=%x, %x\n", params->file_size, hdr->usflashdatasize); + hdr->init_size = (file_size + RK_BLK_SIZE - 1) / RK_BLK_SIZE; + hdr->init_size = (hdr->init_size + 3) & ~3; + hdr->init_boot_size = hdr->init_size + RK_MAX_BOOT_SIZE / RK_BLK_SIZE; rc4_encode(buf, RK_BLK_SIZE, rc4_key); diff --git a/tools/rkcommon.h b/tools/rkcommon.h index 57fd726004c..c69540f5f38 100644 --- a/tools/rkcommon.h +++ b/tools/rkcommon.h @@ -10,11 +10,40 @@ enum { RK_BLK_SIZE = 512, - RK_CODE1_OFFSET = 4, - RK_MAX_CODE1_SIZE = 32 << 10, + RK_INIT_OFFSET = 4, + RK_MAX_BOOT_SIZE = 512 << 10, + RK_SPL_HDR_START = RK_INIT_OFFSET * RK_BLK_SIZE, + RK_SPL_HDR_SIZE = 4, + RK_SPL_START = RK_SPL_HDR_START + RK_SPL_HDR_SIZE, + RK_IMAGE_HEADER_LEN = RK_SPL_START, }; /** + * rkcommon_check_params() - check params + * + * @return 0 if OK, -1 if ERROR. + */ +int rkcommon_check_params(struct image_tool_params *params); + +/** + * rkcommon_get_spl_hdr() - get 4-bytes spl hdr for a Rockchip boot image + * + * Rockchip's bootrom requires the spl loader to start with a 4-bytes + * header. The content of this header depends on the chip type. + */ +const char *rkcommon_get_spl_hdr(struct image_tool_params *params); + +/** + * rkcommon_get_spl_size() - get spl size for a Rockchip boot image + * + * Different chip may have different sram size. And if we want to jump + * back to the bootrom after spl, we may need to reserve some sram space + * for the bootrom. + * The spl loader size should be sram size minus reserved size(if needed) + */ +int rkcommon_get_spl_size(struct image_tool_params *params); + +/** * rkcommon_set_header() - set up the header for a Rockchip boot image * * This sets up a 2KB header which can be interpreted by the Rockchip boot ROM. @@ -23,6 +52,7 @@ enum { * @file_size: Size of the file we want the boot ROM to load, in bytes * @return 0 if OK, -ENOSPC if too large */ -int rkcommon_set_header(void *buf, uint file_size); +int rkcommon_set_header(void *buf, uint file_size, + struct image_tool_params *params); #endif diff --git a/tools/rkimage.c b/tools/rkimage.c index 7b292f4235d..f9fdcfa712f 100644 --- a/tools/rkimage.c +++ b/tools/rkimage.c @@ -9,6 +9,7 @@ #include "imagetool.h" #include <image.h> +#include "rkcommon.h" static uint32_t header; @@ -30,7 +31,8 @@ static void rkimage_print_header(const void *buf) static void rkimage_set_header(void *buf, struct stat *sbuf, int ifd, struct image_tool_params *params) { - memcpy(buf, "RK32", 4); + memcpy(buf + RK_SPL_HDR_START, rkcommon_get_spl_hdr(params), + RK_SPL_HDR_SIZE); } static int rkimage_extract_subimage(void *buf, struct image_tool_params *params) diff --git a/tools/rksd.c b/tools/rksd.c index a8dbe987509..a2baa74d312 100644 --- a/tools/rksd.c +++ b/tools/rksd.c @@ -13,18 +13,7 @@ #include "mkimage.h" #include "rkcommon.h" -enum { - RKSD_SPL_HDR_START = RK_CODE1_OFFSET * RK_BLK_SIZE, - RKSD_SPL_START = RKSD_SPL_HDR_START + 4, - RKSD_HEADER_LEN = RKSD_SPL_START, -}; - -static char dummy_hdr[RKSD_HEADER_LEN]; - -static int rksd_check_params(struct image_tool_params *params) -{ - return 0; -} +static char dummy_hdr[RK_IMAGE_HEADER_LEN]; static int rksd_verify_header(unsigned char *buf, int size, struct image_tool_params *params) @@ -42,15 +31,16 @@ static void rksd_set_header(void *buf, struct stat *sbuf, int ifd, unsigned int size; int ret; - size = params->file_size - RKSD_SPL_HDR_START; - ret = rkcommon_set_header(buf, size); + size = params->file_size - RK_SPL_HDR_START; + ret = rkcommon_set_header(buf, size, params); if (ret) { /* TODO(sjg@chromium.org): This method should return an error */ printf("Warning: SPL image is too large (size %#x) and will not boot\n", size); } - memcpy(buf + RKSD_SPL_HDR_START, "RK32", 4); + memcpy(buf + RK_SPL_HDR_START, rkcommon_get_spl_hdr(params), + RK_SPL_HDR_SIZE); } static int rksd_extract_subimage(void *buf, struct image_tool_params *params) @@ -72,7 +62,7 @@ static int rksd_vrec_header(struct image_tool_params *params, { int pad_size; - pad_size = RKSD_SPL_HDR_START + RK_MAX_CODE1_SIZE; + pad_size = RK_SPL_HDR_START + rkcommon_get_spl_size(params); debug("pad_size %x\n", pad_size); return pad_size - params->file_size; @@ -84,9 +74,9 @@ static int rksd_vrec_header(struct image_tool_params *params, U_BOOT_IMAGE_TYPE( rksd, "Rockchip SD Boot Image support", - RKSD_HEADER_LEN, + RK_IMAGE_HEADER_LEN, dummy_hdr, - rksd_check_params, + rkcommon_check_params, rksd_verify_header, rksd_print_header, rksd_set_header, diff --git a/tools/rkspi.c b/tools/rkspi.c index a3c4c739164..800e235168f 100644 --- a/tools/rkspi.c +++ b/tools/rkspi.c @@ -14,18 +14,10 @@ #include "rkcommon.h" enum { - RKSPI_SPL_HDR_START = RK_CODE1_OFFSET * RK_BLK_SIZE, - RKSPI_SPL_START = RKSPI_SPL_HDR_START + 4, - RKSPI_HEADER_LEN = RKSPI_SPL_START, RKSPI_SECT_LEN = RK_BLK_SIZE * 4, }; -static char dummy_hdr[RKSPI_HEADER_LEN]; - -static int rkspi_check_params(struct image_tool_params *params) -{ - return 0; -} +static char dummy_hdr[RK_IMAGE_HEADER_LEN]; static int rkspi_verify_header(unsigned char *buf, int size, struct image_tool_params *params) @@ -45,7 +37,7 @@ static void rkspi_set_header(void *buf, struct stat *sbuf, int ifd, int ret; size = params->orig_file_size; - ret = rkcommon_set_header(buf, size); + ret = rkcommon_set_header(buf, size, params); debug("size %x\n", size); if (ret) { /* TODO(sjg@chromium.org): This method should return an error */ @@ -53,7 +45,8 @@ static void rkspi_set_header(void *buf, struct stat *sbuf, int ifd, size); } - memcpy(buf + RKSPI_SPL_HDR_START, "RK32", 4); + memcpy(buf + RK_SPL_HDR_START, rkcommon_get_spl_hdr(params), + RK_SPL_HDR_SIZE); /* * Spread the image out so we only use the first 2KB of each 4KB @@ -89,12 +82,12 @@ static int rkspi_vrec_header(struct image_tool_params *params, { int pad_size; - pad_size = (RK_MAX_CODE1_SIZE + 0x7ff) / 0x800 * 0x800; + pad_size = (rkcommon_get_spl_size(params) + 0x7ff) / 0x800 * 0x800; params->orig_file_size = pad_size; /* We will double the image size due to the SPI format */ pad_size *= 2; - pad_size += RKSPI_SPL_HDR_START; + pad_size += RK_SPL_HDR_START; debug("pad_size %x\n", pad_size); return pad_size - params->file_size; @@ -106,9 +99,9 @@ static int rkspi_vrec_header(struct image_tool_params *params, U_BOOT_IMAGE_TYPE( rkspi, "Rockchip SPI Boot Image support", - RKSPI_HEADER_LEN, + RK_IMAGE_HEADER_LEN, dummy_hdr, - rkspi_check_params, + rkcommon_check_params, rkspi_verify_header, rkspi_print_header, rkspi_set_header, diff --git a/tools/zynqimage.c b/tools/zynqimage.c index 25f558d24c7..c43bd5d4882 100644 --- a/tools/zynqimage.c +++ b/tools/zynqimage.c @@ -212,8 +212,7 @@ static int zynqimage_check_params(struct image_tool_params *params) return -1; } - return !((params->lflag || params->dflag) || - (params->dflag && params->eflag)); + return !(params->lflag || params->dflag); } static int zynqimage_check_image_types(uint8_t type) |