BIGNUM *x, *y;
signature_node = fdt_subnode_offset(fdt, 0, FIT_SIG_NODENAME);
- if (signature_node < 0) {
- fprintf(stderr, "Could not find 'signature node: %s\n",
+ if (signature_node == -FDT_ERR_NOTFOUND) {
+ signature_node = fdt_add_subnode(fdt, 0, FIT_SIG_NODENAME);
+ if (signature_node < 0) {
+ if (signature_node != -FDT_ERR_NOSPACE) {
+ fprintf(stderr, "Couldn't create signature node: %s\n",
+ fdt_strerror(signature_node));
+ }
+ return signature_node;
+ }
+ } else if (signature_node < 0) {
+ fprintf(stderr, "Cannot select keys signature_node: %s\n",
fdt_strerror(signature_node));
return signature_node;
}
- key_node = fdt_add_subnode(fdt, signature_node, key_node_name);
- if (key_node < 0) {
- fprintf(stderr, "Could not create '%s' node: %s\n",
- key_node_name, fdt_strerror(key_node));
+ /* Either create or overwrite the named key node */
+ key_node = fdt_subnode_offset(fdt, signature_node, key_node_name);
+ if (key_node == -FDT_ERR_NOTFOUND) {
+ key_node = fdt_add_subnode(fdt, signature_node, key_node_name);
+ if (key_node < 0) {
+ if (key_node != -FDT_ERR_NOSPACE) {
+ fprintf(stderr, "Could not create key subnode: %s\n",
+ fdt_strerror(key_node));
+ }
+ return key_node;
+ }
+ } else if (key_node < 0) {
+ fprintf(stderr, "Cannot select keys key_node: %s\n",
+ fdt_strerror(key_node));
return key_node;
}
fdt_key_name = info->keyname ? info->keyname : "default-key";
ret = prepare_ctx(&ctx, info);
- if (ret >= 0)
+ if (ret >= 0) {
ret = do_add(&ctx, fdt, fdt_key_name);
+ if (ret < 0)
+ ret = ret == -FDT_ERR_NOSPACE ? -ENOSPC : -EIO;
+ }
free_ctx(&ctx);
return ret;