diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2018-01-22 09:49:21 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2018-01-22 09:49:21 +0100 |
commit | 5ebdae4863f64a32826c25c6e0d1dfbc1612d904 (patch) | |
tree | f7c8ae79050fd00a708bfcda11f6681ebb9a32ce /common | |
parent | 034637fbd9dfc5cbcffca1f8f392c6ab0dd6f229 (diff) | |
parent | 2f9b25f41362e99e2b31684b5c9a1a02abc1ae8b (diff) | |
download | barebox-5ebdae4863f64a32826c25c6e0d1dfbc1612d904.tar.gz barebox-5ebdae4863f64a32826c25c6e0d1dfbc1612d904.tar.xz |
Merge branch 'for-next/misc'
Diffstat (limited to 'common')
-rw-r--r-- | common/bootm.c | 9 | ||||
-rw-r--r-- | common/env.c | 54 | ||||
-rw-r--r-- | common/image-fit.c | 77 | ||||
-rw-r--r-- | common/misc.c | 7 | ||||
-rw-r--r-- | common/partitions/dos.c | 25 | ||||
-rw-r--r-- | common/ubiformat.c | 18 |
6 files changed, 138 insertions, 52 deletions
diff --git a/common/bootm.c b/common/bootm.c index c23898bea7..05314a0a10 100644 --- a/common/bootm.c +++ b/common/bootm.c @@ -568,7 +568,7 @@ int bootm_boot(struct bootm_data *bootm_data) if (IS_ENABLED(CONFIG_FITIMAGE) && os_type == filetype_oftree) { struct fit_handle *fit; - fit = fit_open(data->os_file, data->os_part, data->verbose, data->verify); + fit = fit_open(data->os_file, data->verbose, data->verify); if (IS_ERR(fit)) { printf("Loading FIT image %s failed with: %s\n", data->os_file, strerrorp(fit)); @@ -577,6 +577,13 @@ int bootm_boot(struct bootm_data *bootm_data) } data->os_fit = fit; + + ret = fit_open_configuration(data->os_fit, data->os_part); + if (ret) { + printf("Cannot open FIT image configuration '%s'\n", + data->os_part ? data->os_part : "default"); + goto err_out; + } } if (os_type == filetype_uimage) { diff --git a/common/env.c b/common/env.c index df8a4dff60..80d3f7ab50 100644 --- a/common/env.c +++ b/common/env.c @@ -223,34 +223,50 @@ static int setenv_raw(struct list_head *l, const char *name, const char *value) return 0; } -int setenv(const char *_name, const char *value) +static int dev_setenv(const char *name, const char *val) { - char *name = strdup(_name); - char *par; - int ret = 0; - struct list_head *list; + const char *pos, *dot, *varname; + char *devname; + struct device_d *dev; - if (value && !*value) - value = NULL; + pos = name; + + while (1) { + dot = strchr(pos, '.'); + if (!dot) + break; + + devname = xstrndup(name, dot - name); + varname = dot + 1; + dev = get_device_by_name(devname); - if ((par = strchr(name, '.'))) { - struct device_d *dev; + free(devname); - *par++ = 0; - dev = get_device_by_name(name); if (dev) { - ret = dev_set_param(dev, par, value); - if (ret) - eprintf("%s: set parameter %s: %s\n", - dev_name(dev), par, strerror(-ret)); - } else { - ret = -ENODEV; - eprintf("set parameter: no such device %s\n", name); + if (get_param_by_name(dev, varname)) + return dev_set_param(dev, varname, val); } - errno = -ret; + pos = dot + 1; + } + + return -ENODEV; +} + +int setenv(const char *_name, const char *value) +{ + char *name = strdup(_name); + int ret = 0; + struct list_head *list; + + if (value && !*value) + value = NULL; + if (strchr(name, '.')) { + ret = dev_setenv(name, value); + if (ret) + eprintf("Cannot set parameter: %s\n", strerror(-ret)); goto out; } diff --git a/common/image-fit.c b/common/image-fit.c index db5d142147..12379a67ff 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -397,14 +397,37 @@ err_digest_free: return ret; } -static int fit_open_image(struct fit_handle *handle, const char *unit, const void **outdata, - unsigned long *outsize) +int fit_has_image(struct fit_handle *handle, const char *name) +{ + const char *unit; + struct device_node *conf_node = handle->conf_node; + + if (!conf_node) + return -EINVAL; + + if (of_property_read_string(conf_node, name, &unit)) + return 0; + + return 1; +} + +int fit_open_image(struct fit_handle *handle, const char *name, + const void **outdata, unsigned long *outsize) { struct device_node *image = NULL, *hash; - const char *type = NULL, *desc= "(no description)"; + const char *unit, *type = NULL, *desc= "(no description)"; const void *data; int data_len; int ret = 0; + struct device_node *conf_node = handle->conf_node; + + if (!conf_node) + return -EINVAL; + + if (of_property_read_string(conf_node, name, &unit)) { + pr_err("No image named '%s'\n", name); + return -ENOENT; + } image = of_get_child_by_name(handle->root, "images"); if (!image) @@ -523,7 +546,7 @@ default_unit: return -ENOENT; } -static int fit_open_configuration(struct fit_handle *handle, const char *name) +int fit_open_configuration(struct fit_handle *handle, const char *name) { struct device_node *conf_node = NULL; const char *unit, *desc = "(no description)"; @@ -556,22 +579,25 @@ static int fit_open_configuration(struct fit_handle *handle, const char *name) if (ret) return ret; - if (of_property_read_string(conf_node, "kernel", &unit) == 0) { - ret = fit_open_image(handle, unit, &handle->kernel, &handle->kernel_size); + handle->conf_node = conf_node; + + if (fit_has_image(handle, "kernel")) { + ret = fit_open_image(handle, "kernel", &handle->kernel, + &handle->kernel_size); if (ret) return ret; - } else { - return -ENOENT; } - if (of_property_read_string(conf_node, "fdt", &unit) == 0) { - ret = fit_open_image(handle, unit, &handle->oftree, &handle->oftree_size); + if (fit_has_image(handle, "ramdisk")) { + ret = fit_open_image(handle, "ramdisk", &handle->initrd, + &handle->initrd_size); if (ret) return ret; } - if (of_property_read_string(conf_node, "ramdisk", &unit) == 0) { - ret = fit_open_image(handle, unit, &handle->initrd, &handle->initrd_size); + if (fit_has_image(handle, "fdt")) { + ret = fit_open_image(handle, "fdt", &handle->oftree, + &handle->oftree_size); if (ret) return ret; } @@ -579,7 +605,7 @@ static int fit_open_configuration(struct fit_handle *handle, const char *name) return 0; } -struct fit_handle *fit_open(const char *filename, const char *config, bool verbose, +struct fit_handle *fit_open(const char *filename, bool verbose, enum bootm_verify verify) { struct fit_handle *handle = NULL; @@ -609,10 +635,6 @@ struct fit_handle *fit_open(const char *filename, const char *config, bool verbo of_property_read_string(handle->root, "description", &desc); pr_info("'%s': %s\n", filename, desc); - ret = fit_open_configuration(handle, config); - if (ret) - goto err; - return handle; err: if (handle->root) @@ -636,10 +658,23 @@ void fit_close(struct fit_handle *handle) static int do_bootm_sandbox_fit(struct image_data *data) { struct fit_handle *handle; - handle = fit_open(data->os_file, data->os_part, data->verbose); - if (handle) - fit_close(handle); - return 0; + int ret; + void *kernel; + unsigned long kernel_size; + + handle = fit_open(data->os_file, data->verbose); + if (IS_ERR(handle)) + return PTR_ERR(handle); + + ret = fit_open_configuration(handle, data->os_part); + if (ret) + goto out; + + ret = 0; +out: + fit_close(handle); + + return ret; } static struct image_handler sandbox_fit_handler = { diff --git a/common/misc.c b/common/misc.c index c5d3704c82..0888f1f4f6 100644 --- a/common/misc.c +++ b/common/misc.c @@ -187,6 +187,13 @@ const char *barebox_get_hostname(void) } EXPORT_SYMBOL(barebox_get_hostname); +void barebox_set_hostname_no_overwrite(const char *__hostname) +{ + if (!barebox_get_hostname()) + barebox_set_hostname(__hostname); +} +EXPORT_SYMBOL(barebox_set_hostname_no_overwrite); + BAREBOX_MAGICVAR_NAMED(global_hostname, global.hostname, "shortname of the board. Also used as hostname for DHCP requests"); diff --git a/common/partitions/dos.c b/common/partitions/dos.c index 91b5399079..488c2936f7 100644 --- a/common/partitions/dos.c +++ b/common/partitions/dos.c @@ -21,6 +21,22 @@ #include "parser.h" + +enum { +/* These three have identical behaviour; use the second one if DOS FDISK gets + confused about extended/logical partitions starting past cylinder 1023. */ + DOS_EXTENDED_PARTITION = 5, + LINUX_EXTENDED_PARTITION = 0x85, + WIN98_EXTENDED_PARTITION = 0x0f, +}; + +static inline int is_extended_partition(struct partition *p) +{ + return (p->dos_partition_type == DOS_EXTENDED_PARTITION || + p->dos_partition_type == WIN98_EXTENDED_PARTITION || + p->dos_partition_type == LINUX_EXTENDED_PARTITION); +} + /** * Guess the size of the disk, based on the partition table entries * @param dev device to create partitions for @@ -212,13 +228,8 @@ static void dos_partition(void *buf, struct block_device *blk, sprintf(pd->parts[n].partuuid, "%08x-%02d", signature, i + 1); pd->used_entries++; - /* - * Partitions of type 0x05 and 0x0f (and some more) - * contain extended partitions. Only check for type 0x0f - * here as this is the easiest to parse and common - * enough. - */ - if (pentry.dos_partition_type == 0x0f) { + + if (is_extended_partition(&pentry)) { if (!extended_partition) extended_partition = &pd->parts[n]; else diff --git a/common/ubiformat.c b/common/ubiformat.c index 4c5f1f5794..f728119b9a 100644 --- a/common/ubiformat.c +++ b/common/ubiformat.c @@ -190,6 +190,7 @@ static int flash_image(struct ubiformat_args *args, struct mtd_info *mtd, int fd, img_ebs, eb, written_ebs = 0, ret = -1, eb_cnt; off_t st_size; char *buf = NULL; + uint64_t lastprint = 0; eb_cnt = mtd_num_pebs(mtd); @@ -229,8 +230,12 @@ static int flash_image(struct ubiformat_args *args, struct mtd_info *mtd, long long ec; if (!args->quiet && !args->verbose) { - printf("\rubiformat: flashing eraseblock %d -- %2u %% complete ", - eb, (eb + 1) * 100 / eb_cnt); + if (is_timeout(lastprint, 300 * MSECOND) || + eb == eb_cnt - 1) { + printf("\rubiformat: flashing eraseblock %d -- %2u %% complete ", + eb, (eb + 1) * 100 / eb_cnt); + lastprint = get_time_ns(); + } } if (si->ec[eb] == EB_BAD) @@ -325,6 +330,7 @@ static int format(struct ubiformat_args *args, struct mtd_info *mtd, struct ubi_vtbl_record *vtbl; int eb1 = -1, eb2 = -1; long long ec1 = -1, ec2 = -1; + uint64_t lastprint = 0; eb_cnt = mtd_num_pebs(mtd); @@ -340,8 +346,12 @@ static int format(struct ubiformat_args *args, struct mtd_info *mtd, long long ec; if (!args->quiet && !args->verbose) { - printf("\rubiformat: formatting eraseblock %d -- %2u %% complete ", - eb, (eb + 1 - start_eb) * 100 / (eb_cnt - start_eb)); + if (is_timeout(lastprint, 300 * MSECOND) || + eb == eb_cnt - 1) { + printf("\rubiformat: formatting eraseblock %d -- %2u %% complete ", + eb, (eb + 1 - start_eb) * 100 / (eb_cnt - start_eb)); + lastprint = get_time_ns(); + } } if (si->ec[eb] == EB_BAD) |