mkimage: Automatically expand FDT in more cases
The original code did not cover every case and there was a missing negative sign in one case. Expand the coverage and fix the bug. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
04819a4ff1
commit
597a8b2c68
|
@ -405,11 +405,15 @@ int rsa_add_verify_data(struct image_sign_info *info, void *keydest)
|
||||||
if (parent == -FDT_ERR_NOTFOUND) {
|
if (parent == -FDT_ERR_NOTFOUND) {
|
||||||
parent = fdt_add_subnode(keydest, 0, FIT_SIG_NODENAME);
|
parent = fdt_add_subnode(keydest, 0, FIT_SIG_NODENAME);
|
||||||
if (parent < 0) {
|
if (parent < 0) {
|
||||||
|
ret = parent;
|
||||||
|
if (ret != -FDT_ERR_NOSPACE) {
|
||||||
fprintf(stderr, "Couldn't create signature node: %s\n",
|
fprintf(stderr, "Couldn't create signature node: %s\n",
|
||||||
fdt_strerror(parent));
|
fdt_strerror(parent));
|
||||||
return -EINVAL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (ret)
|
||||||
|
goto done;
|
||||||
|
|
||||||
/* Either create or overwrite the named key node */
|
/* Either create or overwrite the named key node */
|
||||||
snprintf(name, sizeof(name), "key-%s", info->keyname);
|
snprintf(name, sizeof(name), "key-%s", info->keyname);
|
||||||
|
@ -417,18 +421,22 @@ int rsa_add_verify_data(struct image_sign_info *info, void *keydest)
|
||||||
if (node == -FDT_ERR_NOTFOUND) {
|
if (node == -FDT_ERR_NOTFOUND) {
|
||||||
node = fdt_add_subnode(keydest, parent, name);
|
node = fdt_add_subnode(keydest, parent, name);
|
||||||
if (node < 0) {
|
if (node < 0) {
|
||||||
|
ret = node;
|
||||||
|
if (ret != -FDT_ERR_NOSPACE) {
|
||||||
fprintf(stderr, "Could not create key subnode: %s\n",
|
fprintf(stderr, "Could not create key subnode: %s\n",
|
||||||
fdt_strerror(node));
|
fdt_strerror(node));
|
||||||
return -EINVAL;
|
}
|
||||||
}
|
}
|
||||||
} else if (node < 0) {
|
} else if (node < 0) {
|
||||||
fprintf(stderr, "Cannot select keys parent: %s\n",
|
fprintf(stderr, "Cannot select keys parent: %s\n",
|
||||||
fdt_strerror(node));
|
fdt_strerror(node));
|
||||||
return -ENOSPC;
|
ret = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
ret = fdt_setprop_string(keydest, node, "key-name-hint",
|
ret = fdt_setprop_string(keydest, node, "key-name-hint",
|
||||||
info->keyname);
|
info->keyname);
|
||||||
|
}
|
||||||
if (!ret)
|
if (!ret)
|
||||||
ret = fdt_setprop_u32(keydest, node, "rsa,num-bits", bits);
|
ret = fdt_setprop_u32(keydest, node, "rsa,num-bits", bits);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
|
@ -449,10 +457,11 @@ int rsa_add_verify_data(struct image_sign_info *info, void *keydest)
|
||||||
ret = fdt_setprop_string(keydest, node, "required",
|
ret = fdt_setprop_string(keydest, node, "required",
|
||||||
info->require_keys);
|
info->require_keys);
|
||||||
}
|
}
|
||||||
|
done:
|
||||||
BN_free(modulus);
|
BN_free(modulus);
|
||||||
BN_free(r_squared);
|
BN_free(r_squared);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret == FDT_ERR_NOSPACE ? -ENOSPC : -EIO;
|
return ret == -FDT_ERR_NOSPACE ? -ENOSPC : -EIO;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -609,11 +609,13 @@ static int fit_config_process_sig(const char *keydir, void *keydest,
|
||||||
/* Write the public key into the supplied FDT file */
|
/* Write the public key into the supplied FDT file */
|
||||||
if (keydest) {
|
if (keydest) {
|
||||||
ret = info.algo->add_verify_data(&info, keydest);
|
ret = info.algo->add_verify_data(&info, keydest);
|
||||||
|
if (ret == -ENOSPC)
|
||||||
|
return -ENOSPC;
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printf("Failed to add verification data for '%s' signature node in '%s' image node\n",
|
printf("Failed to add verification data for '%s' signature node in '%s' image node\n",
|
||||||
node_name, conf_name);
|
node_name, conf_name);
|
||||||
return ret == FDT_ERR_NOSPACE ? -ENOSPC : -EIO;
|
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue