diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Makefile | 2 | ||||
-rw-r--r-- | tools/env/fw_env.c | 60 | ||||
-rw-r--r-- | tools/image-host.c | 15 | ||||
-rw-r--r-- | tools/zynqimage.c | 28 | ||||
-rw-r--r-- | tools/zynqmpimage.c | 34 |
5 files changed, 105 insertions, 34 deletions
diff --git a/tools/Makefile b/tools/Makefile index 9edb504fdd..5b81dde4b0 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -112,7 +112,7 @@ fit_check_sign-objs := $(dumpimage-mkimage-objs) fit_check_sign.o # Build a libfdt Python module if swig is available # Use 'sudo apt-get install swig libpython-dev' to enable this hostprogs-$(CONFIG_SPL_OF_PLATDATA) += \ - $(if $(shell which swig),_libfdt.so) + $(if $(shell which swig 2> /dev/null),_libfdt.so) _libfdt.so-sharedobjs += $(LIBFDT_OBJS) libfdt: diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 3dc0d5344c..862a0b1a02 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -1291,18 +1291,6 @@ static int check_device_config(int dev) struct stat st; int fd, rc = 0; - if (DEVOFFSET(dev) % DEVESIZE(dev) != 0) { - fprintf(stderr, "Environment does not start on (erase) block boundary\n"); - errno = EINVAL; - return -1; - } - - if (ENVSIZE(dev) > ENVSECTORS(dev) * DEVESIZE(dev)) { - fprintf(stderr, "Environment does not fit into available sectors\n"); - errno = EINVAL; - return -1; - } - fd = open(DEVNAME(dev), O_RDONLY); if (fd < 0) { fprintf(stderr, @@ -1335,9 +1323,15 @@ static int check_device_config(int dev) goto err; } DEVTYPE(dev) = mtdinfo.type; + if (DEVESIZE(dev) == 0) + /* Assume the erase size is the same as the env-size */ + DEVESIZE(dev) = ENVSIZE(dev); } else { uint64_t size; DEVTYPE(dev) = MTD_ABSENT; + if (DEVESIZE(dev) == 0) + /* Assume the erase size to be 512 bytes */ + DEVESIZE(dev) = 0x200; /* * Check for negative offsets, treat it as backwards offset @@ -1359,6 +1353,22 @@ static int check_device_config(int dev) } } + if (ENVSECTORS(dev) == 0) + /* Assume enough sectors to cover the environment */ + ENVSECTORS(dev) = DIV_ROUND_UP(ENVSIZE(dev), DEVESIZE(dev)); + + if (DEVOFFSET(dev) % DEVESIZE(dev) != 0) { + fprintf(stderr, "Environment does not start on (erase) block boundary\n"); + errno = EINVAL; + return -1; + } + + if (ENVSIZE(dev) > ENVSECTORS(dev) * DEVESIZE(dev)) { + fprintf(stderr, "Environment does not fit into available sectors\n"); + errno = EINVAL; + return -1; + } + err: close(fd); return rc; @@ -1382,10 +1392,10 @@ static int parse_config(struct env_opts *opts) DEVNAME (0) = DEVICE1_NAME; DEVOFFSET (0) = DEVICE1_OFFSET; ENVSIZE (0) = ENV1_SIZE; - /* Default values are: erase-size=env-size */ - DEVESIZE (0) = ENVSIZE (0); - /* #sectors=env-size/erase-size (rounded up) */ - ENVSECTORS (0) = (ENVSIZE(0) + DEVESIZE(0) - 1) / DEVESIZE(0); + + /* Set defaults for DEVESIZE, ENVSECTORS later once we + * know DEVTYPE + */ #ifdef DEVICE1_ESIZE DEVESIZE (0) = DEVICE1_ESIZE; #endif @@ -1397,10 +1407,10 @@ static int parse_config(struct env_opts *opts) DEVNAME (1) = DEVICE2_NAME; DEVOFFSET (1) = DEVICE2_OFFSET; ENVSIZE (1) = ENV2_SIZE; - /* Default values are: erase-size=env-size */ - DEVESIZE (1) = ENVSIZE (1); - /* #sectors=env-size/erase-size (rounded up) */ - ENVSECTORS (1) = (ENVSIZE(1) + DEVESIZE(1) - 1) / DEVESIZE(1); + + /* Set defaults for DEVESIZE, ENVSECTORS later once we + * know DEVTYPE + */ #ifdef DEVICE2_ESIZE DEVESIZE (1) = DEVICE2_ESIZE; #endif @@ -1466,13 +1476,9 @@ static int get_config (char *fname) DEVNAME(i) = devname; - if (rc < 4) - /* Assume the erase size is the same as the env-size */ - DEVESIZE(i) = ENVSIZE(i); - - if (rc < 5) - /* Assume enough env sectors to cover the environment */ - ENVSECTORS (i) = (ENVSIZE(i) + DEVESIZE(i) - 1) / DEVESIZE(i); + /* Set defaults for DEVESIZE, ENVSECTORS later once we + * know DEVTYPE + */ i++; } diff --git a/tools/image-host.c b/tools/image-host.c index 11046952fc..c1a01225e2 100644 --- a/tools/image-host.c +++ b/tools/image-host.c @@ -166,9 +166,11 @@ static int fit_image_setup_sig(struct image_sign_info *info, info->keyname = fdt_getprop(fit, noffset, "key-name-hint", NULL); info->fit = fit; info->node_offset = noffset; - info->algo = image_get_sig_algo(algo_name); + info->name = algo_name; + info->checksum = image_get_checksum_algo(algo_name); + info->crypto = image_get_crypto_algo(algo_name); info->require_keys = require_keys; - if (!info->algo) { + if (!info->checksum || !info->crypto) { printf("Unsupported signature algorithm (%s) for '%s' signature node in '%s' image node\n", algo_name, node_name, image_name); return -1; @@ -213,7 +215,7 @@ static int fit_image_process_sig(const char *keydir, void *keydest, node_name = fit_get_name(fit, noffset, NULL); region.data = data; region.size = size; - ret = info.algo->sign(&info, ®ion, 1, &value, &value_len); + ret = info.crypto->sign(&info, ®ion, 1, &value, &value_len); if (ret) { printf("Failed to sign '%s' signature node in '%s' image node: %d\n", node_name, image_name, ret); @@ -239,7 +241,7 @@ static int fit_image_process_sig(const char *keydir, void *keydest, info.keyname = fdt_getprop(fit, noffset, "key-name-hint", NULL); if (keydest) - ret = info.algo->add_verify_data(&info, keydest); + ret = info.crypto->add_verify_data(&info, keydest); else return -1; @@ -588,7 +590,8 @@ static int fit_config_process_sig(const char *keydir, void *keydest, require_keys ? "conf" : NULL)) return -1; - ret = info.algo->sign(&info, region, region_count, &value, &value_len); + ret = info.crypto->sign(&info, region, region_count, &value, + &value_len); free(region); if (ret) { printf("Failed to sign '%s' signature node in '%s' conf node\n", @@ -617,7 +620,7 @@ static int fit_config_process_sig(const char *keydir, void *keydest, /* Write the public key into the supplied FDT file */ if (keydest) { - ret = info.algo->add_verify_data(&info, keydest); + ret = info.crypto->add_verify_data(&info, keydest); if (ret == -ENOSPC) return -ENOSPC; if (ret) { diff --git a/tools/zynqimage.c b/tools/zynqimage.c index c43bd5d488..43876e7a30 100644 --- a/tools/zynqimage.c +++ b/tools/zynqimage.c @@ -222,6 +222,30 @@ static int zynqimage_check_image_types(uint8_t type) return EXIT_FAILURE; } +static void zynqimage_parse_initparams(struct zynq_header *zynqhdr, + const char *filename) +{ + /* Expect a table of register-value pairs, e.g. "0x12345678 0x4321" */ + FILE *fp = fopen(filename, "r"); + struct zynq_reginit reginit; + unsigned int reg_count = 0; + int r; + + if (!fp) { + fprintf(stderr, "Cannot open initparams file: %s\n", filename); + exit(1); + } + do { + r = fscanf(fp, "%x %x", ®init.address, ®init.data); + if (r == 2) { + zynqhdr->register_init[reg_count] = reginit; + ++reg_count; + } + r = fscanf(fp, "%*[^\n]\n"); /* Skip to next line */ + } while ((r != EOF) && (reg_count < HEADER_REGINITS)); + fclose(fp); +} + static void zynqimage_set_header(void *ptr, struct stat *sbuf, int ifd, struct image_tool_params *params) { @@ -237,6 +261,10 @@ static void zynqimage_set_header(void *ptr, struct stat *sbuf, int ifd, if (params->eflag) zynqhdr->image_load = cpu_to_le32((uint32_t)params->ep); + /* User can pass in text file with init list */ + if (strlen(params->imagename2)) + zynqimage_parse_initparams(zynqhdr, params->imagename2); + zynqhdr->checksum = zynqimage_checksum(zynqhdr); } diff --git a/tools/zynqmpimage.c b/tools/zynqmpimage.c index 3f28eb401d..202faea072 100644 --- a/tools/zynqmpimage.c +++ b/tools/zynqmpimage.c @@ -234,6 +234,36 @@ static int zynqmpimage_check_image_types(uint8_t type) return EXIT_FAILURE; } +static void zynqmpimage_parse_initparams(struct zynqmp_header *zynqhdr, + const char *filename) +{ + FILE *fp; + struct zynqmp_reginit reginit; + unsigned int reg_count = 0; + int r; + struct stat path_stat; + + stat(filename, &path_stat); + if (!S_ISREG(path_stat.st_mode)) + return; + + /* Expect a table of register-value pairs, e.g. "0x12345678 0x4321" */ + fp = fopen(filename, "r"); + if (!fp) { + fprintf(stderr, "Cannot open initparams file: %s\n", filename); + exit(1); + } + do { + r = fscanf(fp, "%x %x", ®init.address, ®init.data); + if (r == 2) { + zynqhdr->register_init[reg_count] = reginit; + ++reg_count; + } + r = fscanf(fp, "%*[^\n]\n"); /* Skip to next line */ + } while ((r != EOF) && (reg_count < HEADER_REGINITS)); + fclose(fp); +} + static void zynqmpimage_set_header(void *ptr, struct stat *sbuf, int ifd, struct image_tool_params *params) { @@ -250,6 +280,10 @@ static void zynqmpimage_set_header(void *ptr, struct stat *sbuf, int ifd, if (params->eflag) zynqhdr->image_load = cpu_to_le32((uint32_t)params->ep); + /* User can pass in text file with init list */ + if (strlen(params->imagename2)) + zynqmpimage_parse_initparams(zynqhdr, params->imagename2); + zynqhdr->checksum = zynqmpimage_checksum(zynqhdr); } |