static inline int fdt_setprop_uxx(void *fdt, int nodeoffset, const char *name, uint64_t val, int is_u64) { if (is_u64) return fdt_setprop_u64(fdt, nodeoffset, name, val); else return fdt_setprop_u32(fdt, nodeoffset, name, (uint32_t)val); }
int dev_tree_setprop_u64(void *fdt, char *node, const char *property, uint64_t value) { int ret = 0; int offset; offset = fdt_path_offset(fdt, node); if (offset < 0) { dprintf(CRITICAL, "Could not found %s node.\n" , node); return offset; } ret = fdt_setprop_u64(fdt, offset, property, value); if (ret < 0) { dprintf(CRITICAL, "Could not set %lld value to %s property in %s node.\n", value, property, node); return ret; } return ret; }
int main(int argc, char *argv[]) { void *fdt; void *buf; const uint32_t *intp; const char *strp; int err; test_init(argc, argv); fdt = load_blob_arg(argc, argv); buf = xmalloc(SPACE); err = fdt_open_into(fdt, buf, SPACE); if (err) FAIL("fdt_open_into(): %s", fdt_strerror(err)); fdt = buf; intp = check_getprop_cell(fdt, 0, "prop-int", TEST_VALUE_1); verbose_printf("Old int value was 0x%08x\n", *intp); err = fdt_setprop_string(fdt, 0, "prop-int", NEW_STRING); if (err) FAIL("Failed to set \"prop-int\" to \"%s\": %s", NEW_STRING, fdt_strerror(err)); strp = check_getprop_string(fdt, 0, "prop-int", NEW_STRING); verbose_printf("New value is \"%s\"\n", strp); strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1, TEST_STRING_1); verbose_printf("Old string value was \"%s\"\n", strp); err = fdt_setprop(fdt, 0, "prop-str", NULL, 0); if (err) FAIL("Failed to empty \"prop-str\": %s", fdt_strerror(err)); check_getprop(fdt, 0, "prop-str", 0, NULL); err = fdt_setprop_u32(fdt, 0, "prop-u32", TEST_VALUE_2); if (err) FAIL("Failed to set \"prop-u32\" to 0x%08x: %s", TEST_VALUE_2, fdt_strerror(err)); check_getprop_cell(fdt, 0, "prop-u32", TEST_VALUE_2); err = fdt_setprop_cell(fdt, 0, "prop-cell", TEST_VALUE_2); if (err) FAIL("Failed to set \"prop-cell\" to 0x%08x: %s", TEST_VALUE_2, fdt_strerror(err)); check_getprop_cell(fdt, 0, "prop-cell", TEST_VALUE_2); err = fdt_setprop_u64(fdt, 0, "prop-u64", TEST_VALUE64_1); if (err) FAIL("Failed to set \"prop-u64\" to 0x%016llx: %s", TEST_VALUE64_1, fdt_strerror(err)); check_getprop_64(fdt, 0, "prop-u64", TEST_VALUE64_1); PASS(); }
int rsa_add_verify_data(struct image_sign_info *info, void *keydest) { BIGNUM *modulus, *r_squared; uint64_t exponent; uint32_t n0_inv; int parent, node; char name[100]; int ret; int bits; RSA *rsa; debug("%s: Getting verification data\n", __func__); ret = rsa_get_pub_key(info->keydir, info->keyname, &rsa); if (ret) return ret; ret = rsa_get_params(rsa, &exponent, &n0_inv, &modulus, &r_squared); if (ret) return ret; bits = BN_num_bits(modulus); parent = fdt_subnode_offset(keydest, 0, FIT_SIG_NODENAME); if (parent == -FDT_ERR_NOTFOUND) { parent = fdt_add_subnode(keydest, 0, FIT_SIG_NODENAME); if (parent < 0) { ret = parent; if (ret != -FDT_ERR_NOSPACE) { fprintf(stderr, "Couldn't create signature node: %s\n", fdt_strerror(parent)); } } } if (ret) goto done; /* Either create or overwrite the named key node */ snprintf(name, sizeof(name), "key-%s", info->keyname); node = fdt_subnode_offset(keydest, parent, name); if (node == -FDT_ERR_NOTFOUND) { node = fdt_add_subnode(keydest, parent, name); if (node < 0) { ret = node; if (ret != -FDT_ERR_NOSPACE) { fprintf(stderr, "Could not create key subnode: %s\n", fdt_strerror(node)); } } } else if (node < 0) { fprintf(stderr, "Cannot select keys parent: %s\n", fdt_strerror(node)); ret = node; } if (!ret) { ret = fdt_setprop_string(keydest, node, "key-name-hint", info->keyname); } if (!ret) ret = fdt_setprop_u32(keydest, node, "rsa,num-bits", bits); if (!ret) ret = fdt_setprop_u32(keydest, node, "rsa,n0-inverse", n0_inv); if (!ret) { ret = fdt_setprop_u64(keydest, node, "rsa,exponent", exponent); } if (!ret) { ret = fdt_add_bignum(keydest, node, "rsa,modulus", modulus, bits); } if (!ret) { ret = fdt_add_bignum(keydest, node, "rsa,r-squared", r_squared, bits); } if (!ret) { ret = fdt_setprop_string(keydest, node, FIT_ALGO_PROP, info->name); } if (!ret && info->require_keys) { ret = fdt_setprop_string(keydest, node, "required", info->require_keys); } done: BN_free(modulus); BN_free(r_squared); if (ret) return ret == -FDT_ERR_NOSPACE ? -ENOSPC : -EIO; return 0; }