diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/fastboot.c | 4 | ||||
-rw-r--r-- | common/image-fit.c | 51 | ||||
-rw-r--r-- | common/misc.c | 39 | ||||
-rw-r--r-- | common/oftree.c | 41 | ||||
-rw-r--r-- | common/partitions/efi.c | 4 | ||||
-rw-r--r-- | common/usbgadget.c | 6 |
6 files changed, 106 insertions, 39 deletions
diff --git a/common/fastboot.c b/common/fastboot.c index 04a8573b4a..f8ed40c86e 100644 --- a/common/fastboot.c +++ b/common/fastboot.c @@ -920,9 +920,7 @@ struct file_list *get_fastboot_partitions(void) { if (fastboot_partitions && *fastboot_partitions) return file_list_parse_null(fastboot_partitions); - if (!system_partitions_empty()) - return system_partitions_get(); - return NULL; + return system_partitions_get_null(); } static int fastboot_globalvars_init(void) diff --git a/common/image-fit.c b/common/image-fit.c index 38a372ff52..a410632d70 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -255,10 +255,8 @@ static struct digest *fit_alloc_digest(struct device_node *sig_node, static int fit_check_rsa_signature(struct device_node *sig_node, enum hash_algo algo, void *hash) { - struct rsa_public_key *key; - const char *key_name; - char *key_path; - struct device_node *key_node; + const struct rsa_public_key *key; + const char *key_name = NULL; int sig_len; const char *sig_value; int ret; @@ -269,39 +267,32 @@ static int fit_check_rsa_signature(struct device_node *sig_node, return -EINVAL; } - if (of_property_read_string(sig_node, "key-name-hint", &key_name)) { - pr_err("key name not found in %s\n", sig_node->full_name); - return -EINVAL; - } - - key = rsa_get_key(key_name); - if (IS_ERR(key)) { - key_path = xasprintf("/signature/key-%s", key_name); - key_node = of_find_node_by_path(key_path); - if (!key_node) { - pr_info("failed to find key node %s\n", key_path); - free(key_path); - return -ENOENT; + of_property_read_string(sig_node, "key-name-hint", &key_name); + if (key_name) { + key = rsa_get_key(key_name); + if (key) { + ret = rsa_verify(key, sig_value, sig_len, hash, algo); + if (!ret) + goto ok; } - free(key_path); + } - key = rsa_of_read_key(key_node); + for_each_rsa_key(key) { + if (key_name && !strcmp(key->key_name_hint, key_name)) + continue; - if (IS_ERR(key)) { - pr_info("failed to read key in %s\n", key_node->full_name); - return -ENOENT; - } + ret = rsa_verify(key, sig_value, sig_len, hash, algo); + if (!ret) + goto ok; } - ret = rsa_verify(key, sig_value, sig_len, hash, algo); - if (ret) - pr_err("image signature BAD\n"); - else - pr_info("image signature OK\n"); + pr_err("image signature BAD\n"); - rsa_key_free(key); + return -EBADMSG; +ok: + pr_info("image signature OK\n"); - return ret; + return 0; } /* diff --git a/common/misc.c b/common/misc.c index 226635f0d4..0f6de3e9e5 100644 --- a/common/misc.c +++ b/common/misc.c @@ -149,6 +149,8 @@ EXPORT_SYMBOL(barebox_get_model); BAREBOX_MAGICVAR(global.model, "Product name of this hardware"); static char *hostname; +static char *serial_number; +static char *of_machine_compatible; /* * The hostname is supposed to be the shortname of a board. It should @@ -179,6 +181,43 @@ EXPORT_SYMBOL(barebox_set_hostname_no_overwrite); BAREBOX_MAGICVAR(global.hostname, "shortname of the board. Also used as hostname for DHCP requests"); +void barebox_set_serial_number(const char *__serial_number) +{ + globalvar_add_simple_string("serial_number", &serial_number); + + free(serial_number); + serial_number = xstrdup(__serial_number); +} + +const char *barebox_get_serial_number(void) +{ + return serial_number; +} + +BAREBOX_MAGICVAR(global.serial_number, "Board serial number"); + +void barebox_set_of_machine_compatible(const char *__compatible) +{ + free(of_machine_compatible); + of_machine_compatible = xstrdup(__compatible); +} + +const char *barebox_get_of_machine_compatible(void) +{ + return of_machine_compatible; +} + +static int of_kernel_init(void) +{ + globalvar_add_simple_string("of.kernel.add_machine_compatible", + &of_machine_compatible); + + return 0; +} +device_initcall(of_kernel_init); + +BAREBOX_MAGICVAR(global.of.kernel.add_machine_compatible, "Additional machine/board compatible"); + void __noreturn panic(const char *fmt, ...) { va_list args; diff --git a/common/oftree.c b/common/oftree.c index bce0ff09d6..91b3fcc9fa 100644 --- a/common/oftree.c +++ b/common/oftree.c @@ -206,6 +206,16 @@ static int of_fixup_bootargs(struct device_node *root, void *unused) int err; int instance = reset_source_get_instance(); struct device_d *dev; + const char *serialno; + const char *compat; + + serialno = barebox_get_serial_number(); + if (serialno) + of_property_write_string(root, "serial-number", serialno); + + compat = barebox_get_of_machine_compatible(); + if (compat) + of_prepend_machine_compatible(root, compat); node = of_create_node(root, "/chosen"); if (!node) @@ -478,3 +488,34 @@ int of_autoenable_i2c_by_component(char *path) return ret; } + +int of_prepend_machine_compatible(struct device_node *root, const char *compat) +{ + int cclen = 0, clen = strlen(compat) + 1; + const char *curcompat; + void *buf; + + if (!root) { + root = of_get_root_node(); + if (!root) + return -ENODEV; + } + + if (of_device_is_compatible(root, compat)) + return 0; + + curcompat = of_get_property(root, "compatible", &cclen); + + buf = xzalloc(cclen + clen); + + memcpy(buf, compat, clen); + + if (curcompat) + memcpy(buf + clen, curcompat, cclen); + + of_set_property(root, "compatible", buf, cclen + clen, true); + + free(buf); + + return 0; +} diff --git a/common/partitions/efi.c b/common/partitions/efi.c index 0787b93f12..848bed2261 100644 --- a/common/partitions/efi.c +++ b/common/partitions/efi.c @@ -154,8 +154,8 @@ static int is_gpt_valid(struct block_device *blk, u64 lba, /* Check the GPT header signature */ if (le64_to_cpu((*gpt)->signature) != GPT_HEADER_SIGNATURE) { - dev_dbg(blk->dev, "GUID Partition Table Header signature is wrong:" - "0x%llX != 0x%llX\n", + dev_dbg(blk->dev, "GUID Partition Table Header signature at LBA" + "%llu is wrong: 0x%llX != 0x%llX\n", lba, (unsigned long long)le64_to_cpu((*gpt)->signature), (unsigned long long)GPT_HEADER_SIGNATURE); goto fail; diff --git a/common/usbgadget.c b/common/usbgadget.c index e8c9f7d236..2ec6d9226c 100644 --- a/common/usbgadget.c +++ b/common/usbgadget.c @@ -27,9 +27,7 @@ static inline struct file_list *get_dfu_function(void) { if (dfu_function && *dfu_function) return file_list_parse_null(dfu_function); - if (!system_partitions_empty()) - return system_partitions_get(); - return NULL; + return system_partitions_get_null(); } int usbgadget_register(const struct usbgadget_funcs *funcs) @@ -54,7 +52,7 @@ int usbgadget_register(const struct usbgadget_funcs *funcs) opts->ums_opts.files = file_list_parse_null(funcs->ums_opts); if (IS_ENABLED(CONFIG_USB_GADGET_MASS_STORAGE) && file_list_empty(opts->ums_opts.files)) { file_list_free(opts->ums_opts.files); - opts->ums_opts.files = system_partitions_get(); + opts->ums_opts.files = system_partitions_get_null(); } } |