Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
	void *fdt;
	const char *p;
	int len, multilen;
	int n1, n2;

	test_init(argc, argv);
	fdt = load_blob_arg(argc, argv);

	n1 = fdt_path_offset(fdt, "/node1");
	if (n1 < 0)
		FAIL("fdt_path_offset(/node1): %s", fdt_strerror(n1));
	n2 = fdt_path_offset(fdt, "/node2");
	if (n2 < 0)
		FAIL("fdt_path_offset(/node2): %s", fdt_strerror(n2));

	check_ref(fdt, n1, "/node2");
	check_ref(fdt, n2, "/node1");

	/* Check multiple reference */
	multilen = strlen("/node1") + strlen("/node2") + 2;
	p = fdt_getprop(fdt, 0, "multiref", &len);
	if (!p)
		FAIL("fdt_getprop(0, \"multiref\"): %s", fdt_strerror(len));
	if (len != multilen)
		FAIL("multiref has wrong length, %d instead of %d",
		     len, multilen);
	if ((!streq(p, "/node1") || !streq(p + strlen("/node1") + 1, "/node2")))
		FAIL("multiref has wrong value");

	PASS();
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
	void *fdt;
	int offset;
	int subnode1_offset;
	int lenerr;

	test_init(argc, argv);
	fdt = load_blob_arg(argc, argv);

	fdt_get_property(fdt, 0, "nonexistant-property", &lenerr);
	check_error("fdt_get_property(\"nonexistant-property\")", lenerr);

	fdt_getprop(fdt, 0, "nonexistant-property", &lenerr);
	check_error("fdt_getprop(\"nonexistant-property\"", lenerr);

	subnode1_offset = fdt_subnode_offset(fdt, 0, "subnode@1");
	if (subnode1_offset < 0)
		FAIL("Couldn't find subnode1: %s", fdt_strerror(subnode1_offset));

	fdt_getprop(fdt, subnode1_offset, "prop-str", &lenerr);
	check_error("fdt_getprop(\"prop-str\")", lenerr);

	offset = fdt_subnode_offset(fdt, 0, "nonexistant-subnode");
	check_error("fdt_subnode_offset(\"nonexistant-subnode\")", offset);

	offset = fdt_subnode_offset(fdt, 0, "subsubnode");
	check_error("fdt_subnode_offset(\"subsubnode\")", offset);

	offset = fdt_path_offset(fdt, "/nonexistant-subnode");
	check_error("fdt_path_offset(\"/nonexistant-subnode\")", offset);

	PASS();
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
	void *fdt;
	const uint32_t *intp;
	const char *strp;
	int err, lenerr;
	int oldsize, delsize, newsize;

	test_init(argc, argv);
	fdt = load_blob_arg(argc, argv);

	fdt = open_blob_rw(fdt);

	oldsize = fdt_totalsize(fdt);

	intp = check_getprop_cell(fdt, 0, "prop-int", TEST_VALUE_1);
	verbose_printf("int value was 0x%08x\n", *intp);

	err = fdt_delprop(fdt, 0, "prop-int");
	if (err)
		FAIL("Failed to delete \"prop-int\": %s", fdt_strerror(err));

	intp = fdt_getprop(fdt, 0, "prop-int", &lenerr);
	if (intp)
		FAIL("prop-int still present after deletion");
	if (lenerr != -FDT_ERR_NOTFOUND)
		FAIL("Unexpected error on second getprop: %s",
		     fdt_strerror(lenerr));

	strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1,
			     TEST_STRING_1);
	verbose_printf("string value was \"%s\"\n", strp);
	err = fdt_delprop(fdt, 0, "prop-str");
	if (err)
		FAIL("Failed to delete \"prop-str\": %s", fdt_strerror(err));

	strp = fdt_getprop(fdt, 0, "prop-str", &lenerr);
	if (strp)
		FAIL("prop-str still present after deletion");
	if (lenerr != -FDT_ERR_NOTFOUND)
		FAIL("Unexpected error on second getprop: %s",
		     fdt_strerror(lenerr));

	delsize = fdt_totalsize(fdt);

	err = fdt_pack(fdt);
	if (err)
		FAIL("fdt_pack(): %s\n", fdt_strerror(err));

	newsize = fdt_totalsize(fdt);

	verbose_printf("oldsize = %d, delsize = %d, newsize = %d\n",
		       oldsize, delsize, newsize);

	if (newsize >= oldsize)
		FAIL("Tree failed to shrink after deletions");

	PASS();
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
	void *fdt;

	test_init(argc, argv);
	fdt = load_blob_arg(argc, argv);

	check_getprop_cell(fdt, 0, "prop-int", TEST_VALUE_1);
	check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1, TEST_STRING_1);

	PASS();
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{
	void *fdt;
	int n1, n2, n3, n4, n5;
	uint32_t h1, h2, h4, h5;

	test_init(argc, argv);
	fdt = load_blob_arg(argc, argv);

	n1 = fdt_path_offset(fdt, "/node1");
	if (n1 < 0)
		FAIL("fdt_path_offset(/node1): %s", fdt_strerror(n1));
	n2 = fdt_path_offset(fdt, "/node2");
	if (n2 < 0)
		FAIL("fdt_path_offset(/node2): %s", fdt_strerror(n2));
	n3 = fdt_path_offset(fdt, "/node3");
	if (n3 < 0)
		FAIL("fdt_path_offset(/node3): %s", fdt_strerror(n3));
	n4 = fdt_path_offset(fdt, "/node4");
	if (n4 < 0)
		FAIL("fdt_path_offset(/node4): %s", fdt_strerror(n4));
	n5 = fdt_path_offset(fdt, "/node5");
	if (n5 < 0)
		FAIL("fdt_path_offset(/node5): %s", fdt_strerror(n5));

	h1 = fdt_get_phandle(fdt, n1);
	h2 = fdt_get_phandle(fdt, n2);
	h4 = fdt_get_phandle(fdt, n4);
	h5 = fdt_get_phandle(fdt, n5);

	if (h1 != 0x2000)
		FAIL("/node1 has wrong phandle, 0x%x instead of 0x%x",
		     h1, 0x2000);
	if (h2 != 0x1)
		FAIL("/node2 has wrong phandle, 0x%x instead of 0x%x",
		     h2, 0x1);
	if ((h4 == 0x2000) || (h4 == 0x1) || (h4 == 0))
		FAIL("/node4 has bad phandle, 0x%x", h4);

	if ((h5 == 0) || (h5 == -1))
		FAIL("/node5 has bad phandle, 0x%x", h5);
	if ((h5 == h4) || (h5 == h2) || (h5 == h1))
		FAIL("/node5 has duplicate phandle, 0x%x", h5);

	check_ref(fdt, n1, h2);
	check_ref(fdt, n2, h1);
	check_ref(fdt, n3, h4);

	PASS();
}
int main(int argc, char *argv[])
{
	void *fdt;

	test_init(argc, argv);
	fdt = load_blob_arg(argc, argv);

	check_compatible(fdt, "/", "test_tree1");
	check_compatible(fdt, "/subnode@1/subsubnode", "subsubnode1");
	check_compatible(fdt, "/subnode@1/subsubnode", "subsubnode");
	check_compatible(fdt, "/subnode@2/subsubnode", "subsubnode2");
	check_compatible(fdt, "/subnode@2/subsubnode", "subsubnode");

	PASS();
}
Ejemplo n.º 7
0
int main(int argc, char *argv[])
{
	void *fdt;

	test_init(argc, argv);
	fdt = load_blob_arg(argc, argv);

	check_path(fdt, "/");
	check_path(fdt, "/subnode@1");
	check_path(fdt, "/subnode@2");
	check_path(fdt, "/subnode@1/subsubnode");
	check_path(fdt, "/subnode@2/subsubnode@0");

	PASS();
}
Ejemplo n.º 8
0
int main(int argc, char *argv[])
{
    void *fdt;

    test_init(argc, argv);
    fdt = load_blob_arg(argc, argv);

    check_alias(fdt, "/subnode@1", "s1");
    check_alias(fdt, "/subnode@1/subsubnode", "ss1");
    check_alias(fdt, "/subnode@1/subsubnode", "s1/subsubnode");
    check_alias(fdt, "/subnode@1/subsubnode/subsubsubnode", "sss1");
    check_alias(fdt, "/subnode@1/subsubnode/subsubsubnode", "ss1/subsubsubnode");
    check_alias(fdt, "/subnode@1/subsubnode/subsubsubnode", "s1/subsubnode/subsubsubnode");

    PASS();
}
Ejemplo n.º 9
0
int main(int argc, char *argv[])
{
	void *fdt;
	int subnode1_offset, subnode2_offset;
	int subsubnode1_offset, subsubnode2_offset, subsubnode2_offset2;

	test_init(argc, argv);
	fdt = load_blob_arg(argc, argv);

	check_path_offset(fdt, "/", 0);

	subnode1_offset = check_subnode(fdt, 0, "subnode@1");
	subnode2_offset = check_subnode(fdt, 0, "subnode@2");

	check_path_offset(fdt, "/subnode@1", subnode1_offset);
	check_path_offset(fdt, "/subnode@2", subnode2_offset);

	subsubnode1_offset = check_subnode(fdt, subnode1_offset, "subsubnode");
	subsubnode2_offset = check_subnode(fdt, subnode2_offset, "subsubnode@0");
	subsubnode2_offset2 = check_subnode(fdt, subnode2_offset, "subsubnode");

	check_path_offset(fdt, "/subnode@1/subsubnode", subsubnode1_offset);
	check_path_offset(fdt, "/subnode@2/subsubnode@0", subsubnode2_offset);
	check_path_offset(fdt, "/subnode@2/subsubnode", subsubnode2_offset2);

	/* Test paths with extraneous separators */
	check_path_offset(fdt, "//", 0);
	check_path_offset(fdt, "///", 0);
	check_path_offset(fdt, "//subnode@1", subnode1_offset);
	check_path_offset(fdt, "/subnode@1/", subnode1_offset);
	check_path_offset(fdt, "//subnode@1///", subnode1_offset);
	check_path_offset(fdt, "/subnode@2////subsubnode", subsubnode2_offset2);

	/* Test fdt_path_offset_namelen() */
	check_path_offset_namelen(fdt, "/subnode@1", 1, 0);
	check_path_offset_namelen(fdt, "/subnode@1/subsubnode", 10, subnode1_offset);
	check_path_offset_namelen(fdt, "/subnode@1/subsubnode", 11, subnode1_offset);
	check_path_offset_namelen(fdt, "/subnode@2TRAILINGGARBAGE", 10, subnode2_offset);
	check_path_offset_namelen(fdt, "/subnode@2TRAILINGGARBAGE", 11, -FDT_ERR_NOTFOUND);
	check_path_offset_namelen(fdt, "/subnode@2/subsubnode@0/more", 23, subsubnode2_offset2);
	check_path_offset_namelen(fdt, "/subnode@2/subsubnode@0/more", 22, -FDT_ERR_NOTFOUND);
	check_path_offset_namelen(fdt, "/subnode@2/subsubnode@0/more", 24, subsubnode2_offset2);
	check_path_offset_namelen(fdt, "/subnode@2/subsubnode@0/more", 25, -FDT_ERR_NOTFOUND);

	PASS();
}
Ejemplo n.º 10
0
int main(int argc, char *argv[])
{
    void *fdt;
    int err;

    test_init(argc, argv);
    fdt = load_blob_arg(argc, argv);

    check_path(fdt, "/subnode@1");
    check_path(fdt, "/subnode@2");
    check_path(fdt, "/subnode@1/subsubnode");
    check_path(fdt, "/subnode@2/subsubnode@0");
    err = fdt_parent_offset(fdt, 0);
    if (err != -FDT_ERR_NOTFOUND)
        FAIL("fdt_parent_offset(/) returns %d instead of "
             "-FDT_ERR_NOTFOUND", err);

    PASS();
}
Ejemplo n.º 11
0
int main(int argc, char *argv[])
{
	void *fdt;
	int subnode1_offset, subnode2_offset;
	int subsubnode1_offset, subsubnode2_offset, subsubnode2_offset2;
	int ss12_off, ss21_off;

	test_init(argc, argv);
	fdt = load_blob_arg(argc, argv);

	subnode1_offset = check_subnode(fdt, 0, "subnode@1");
	subnode2_offset = check_subnode(fdt, 0, "subnode@2");

	if (subnode1_offset == subnode2_offset)
		FAIL("Different subnodes have same offset");

	check_property_cell(fdt, subnode1_offset, "prop-int", TEST_VALUE_1);
	check_property_cell(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);

	subsubnode1_offset = check_subnode(fdt, subnode1_offset, "subsubnode");
	subsubnode2_offset = check_subnode(fdt, subnode2_offset, "subsubnode@0");
	subsubnode2_offset2 = check_subnode(fdt, subnode2_offset, "subsubnode");

	check_property_cell(fdt, subsubnode1_offset, "prop-int", TEST_VALUE_1);
	check_property_cell(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
	check_property_cell(fdt, subsubnode2_offset2, "prop-int", TEST_VALUE_2);

	if (subsubnode2_offset != subsubnode2_offset2)
		FAIL("Different offsets with and without unit address");

	check_subnode(fdt, subnode1_offset, "ss1");
	ss21_off = fdt_subnode_offset(fdt, subnode2_offset, "ss1");
	if (ss21_off != -FDT_ERR_NOTFOUND)
		FAIL("Incorrectly found ss1 in subnode2");

	ss12_off = fdt_subnode_offset(fdt, subnode1_offset, "ss2");
	if (ss12_off != -FDT_ERR_NOTFOUND)
		FAIL("Incorrectly found ss2 in subnode1");
	check_subnode(fdt, subnode2_offset, "ss2");

	PASS();
}
Ejemplo n.º 12
0
int main(int argc, char *argv[])
{
	void *fdt, *fdt1;
	void *buf;
	int oldsize, bufsize, packsize;
	int err;
	const char *inname;
	char outname[PATH_MAX];

	test_init(argc, argv);
	fdt = load_blob_arg(argc, argv);
	inname = argv[1];

	oldsize = fdt_totalsize(fdt);

	bufsize = oldsize * 2;

	buf = xmalloc(bufsize);
	/* don't leak uninitialized memory into our output */
	memset(buf, 0, bufsize);

	fdt1 = buf;
	err = fdt_open_into(fdt, fdt1, bufsize);
	if (err)
		FAIL("fdt_open_into(): %s", fdt_strerror(err));
	sprintf(outname, "opened.%s", inname);
	save_blob(outname, fdt1);

	err = fdt_pack(fdt1);
	if (err)
		FAIL("fdt_pack(): %s", fdt_strerror(err));
	sprintf(outname, "repacked.%s", inname);
	save_blob(outname, fdt1);

	packsize = fdt_totalsize(fdt1);

	verbose_printf("oldsize = %d, bufsize = %d, packsize = %d\n",
		       oldsize, bufsize, packsize);
	PASS();
}
Ejemplo n.º 13
0
int main(int argc, char *argv[])
{
	void *fdt;
	const struct fdt_node_header *nh;

	test_init(argc, argv);
	fdt = load_blob_arg(argc, argv);

	nh = fdt_offset_ptr(fdt, 0, sizeof(*nh));

	if (! nh)
		FAIL("NULL retrieving root node");

	if (fdt32_to_cpu(nh->tag) != FDT_BEGIN_NODE)
		FAIL("Wrong tag on root node");

	if (strlen(nh->name) != 0)
		FAIL("Wrong name for root node, \"%s\" instead of empty",
		     nh->name);

	PASS();
}
Ejemplo n.º 14
0
int main(int argc, char *argv[])
{
	void *fdt;
	int subnode2_offset, subsubnode2_offset;

	test_init(argc, argv);
	fdt = load_blob_arg(argc, argv);

	subnode2_offset = fdt_path_offset(fdt, "/subnode@2");
	subsubnode2_offset = fdt_path_offset(fdt, "/subnode@2/subsubnode@0");

	if ((subnode2_offset < 0) || (subsubnode2_offset < 0))
		FAIL("Can't find required nodes");

	check_search(fdt, PHANDLE_1, subnode2_offset);
	check_search(fdt, PHANDLE_2, subsubnode2_offset);
	check_search(fdt, ~PHANDLE_1, -FDT_ERR_NOTFOUND);
	check_search(fdt, 0, -FDT_ERR_BADPHANDLE);
	check_search(fdt, -1, -FDT_ERR_BADPHANDLE);

	PASS();
}
Ejemplo n.º 15
0
int main(int argc, char *argv[])
{
	void *fdt, *buf;
	int err;
	uint8_t bytes[] = {0x00, 0x01, 0x02, 0x03, 0x04};

	test_init(argc, argv);
	fdt = load_blob_arg(argc, argv);

	buf = xmalloc(SPACE);
	CHECK(fdt_open_into(fdt, buf, SPACE));
	fdt = buf;

	CHECK(fdt_appendprop(fdt, 0, "prop-bytes", bytes, sizeof(bytes)));
	CHECK(fdt_appendprop_cell(fdt, 0, "prop-int", TEST_VALUE_2));
	CHECK(fdt_appendprop_u64(fdt, 0, "prop-int64", TEST_VALUE64_1));
	CHECK(fdt_appendprop_string(fdt, 0, "prop-str", TEST_STRING_2));

	CHECK(fdt_pack(fdt));

	save_blob("appendprop2.test.dtb", fdt);

	PASS();
}
Ejemplo n.º 16
0
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();
}