Beispiel #1
0
const struct fdt_property *fdt_get_property_namelen(const void *fdt,
						    int nodeoffset,
						    const char *name,
						    int namelen, int *lenp)
{
	uint32_t tag;
	const struct fdt_property *prop;
	int offset, nextoffset;
	int err;

	if (((err = fdt_check_header(fdt)) != 0)
	    || ((err = _fdt_check_node_offset(fdt, nodeoffset)) < 0))
			goto fail;

	nextoffset = err;
	do {
		offset = nextoffset;

		tag = fdt_next_tag(fdt, offset, &nextoffset);
		switch (tag) {
		case FDT_END:
			if (nextoffset < 0)
				err = nextoffset;
			else
				/* FDT_END tag with unclosed nodes */
				err = -FDT_ERR_BADSTRUCTURE;
			goto fail;

		case FDT_PROP:
			prop = _fdt_offset_ptr(fdt, offset);
			if (_fdt_string_eq(fdt, fdt32_to_cpu(prop->nameoff),
					   name, namelen)) {
				/* Found it! */
				if (lenp)
					*lenp = fdt32_to_cpu(prop->len);

				return prop;
			}
			break;
		}
	} while ((tag != FDT_BEGIN_NODE) && (tag != FDT_END_NODE));

	err = -FDT_ERR_NOTFOUND;
 fail:
	if (lenp)
		*lenp = err;
	return NULL;
}
Beispiel #2
0
/*
 * chosen {
 * bootargs="console=ttyS0,115200 ubi.mtd=4 root=ubi0:rootfs rootfstype=ubifs";
 * };

 * offset: node "/chosen"의 offset
 * name: property "bootargs"
 * namelen: property "bootargs" 길이
 * lenp: property 내용의 길이
*/
const struct fdt_property *fdt_get_property_namelen(const void *fdt,
						    int offset,
						    const char *name,
						    int namelen, int *lenp)
{
	/*
	 * node안의 property들을 순회하면서 찾고자 하는 name의 property 리턴
	 * 참고로 아래 for문에서 offset을 계속 받아오면서 값을 체크하고 있음
	 * 즉, 순회하면서 찾는 property가 없거나 탐색시 에러가 나면 탐색 중단
	*/
	for (offset = fdt_first_property_offset(fdt, offset);
	     (offset >= 0);
	     (offset = fdt_next_property_offset(fdt, offset))) {
		const struct fdt_property *prop;

		/*
		 * offset만큼 위치한 property에 접근해서
		 * lenp에 property의 value의 길이를 저장
		 * 하지만 에러가 나는 경우엔 for문을 빠져나감
		*/
		if (!(prop = fdt_get_property_by_offset(fdt, offset, lenp))) {
			offset = -FDT_ERR_INTERNAL;
			break;
		}
		/*
		 * 찾고자 하는 property가 맞는지 확인하고
		 * 맞다면 가져온 property 구조체를 리턴
		*/
		if (_fdt_string_eq(fdt, fdt32_to_cpu(prop->nameoff),
				   name, namelen))
			return prop;
	}

	/*
	 * 찾는 property가 없는경우 or property 접근하다 에러가 난 경우
	 * lenp에 에러값 저장
	*/
	if (lenp)
		*lenp = offset;

	return NULL;
}
Beispiel #3
0
const struct fdt_property *fdt_get_property_namelen(const void *fdt,
						    int offset,
						    const char *name,
						    int namelen, int *lenp)
{
	for (offset = fdt_first_property_offset(fdt, offset);
	     (offset >= 0); (offset = fdt_next_property_offset(fdt, offset))) {
		const struct fdt_property *prop;

		if (!(prop = fdt_get_property_by_offset(fdt, offset, lenp))) {
			offset = -FDT_ERR_INTERNAL;
			break;
		}
		if (_fdt_string_eq(fdt, fdt32_to_cpu(prop->nameoff),
				   name, namelen))
			return prop;
	}

	if (lenp)
		*lenp = offset;
	return NULL;
}
Beispiel #4
0
const struct fdt_property *fdt_get_property_namelen(const void *fdt,
						    int nodeoffset,
						    const char *name,
						    int namelen, int *lenp)
{
	uint32_t tag;
	const struct fdt_property *prop;
	int namestroff;
	int offset, nextoffset;
	int err;

	if (((err = fdt_check_header(fdt)) != 0)
	    || ((err = _fdt_check_node_offset(fdt, nodeoffset)) < 0))
			goto fail;

	nextoffset = err;
	do {
		offset = nextoffset;

		tag = fdt_next_tag(fdt, offset, &nextoffset);
		switch (tag) {
		case FDT_END:
			err = -FDT_ERR_TRUNCATED;
			goto fail;

		case FDT_BEGIN_NODE:
		case FDT_END_NODE:
		case FDT_NOP:
			break;

		case FDT_PROP:
			err = -FDT_ERR_BADSTRUCTURE;
			prop = fdt_offset_ptr(fdt, offset, sizeof(*prop));
			if (! prop)
				goto fail;
			namestroff = fdt32_to_cpu(prop->nameoff);
			if (_fdt_string_eq(fdt, namestroff, name, namelen)) {
				/* Found it! */
				int len = fdt32_to_cpu(prop->len);
				prop = fdt_offset_ptr(fdt, offset,
						      sizeof(*prop)+len);
				if (! prop)
					goto fail;

				if (lenp)
					*lenp = len;

				return prop;
			}
			break;

		default:
			err = -FDT_ERR_BADSTRUCTURE;
			goto fail;
		}
	} while ((tag != FDT_BEGIN_NODE) && (tag != FDT_END_NODE));

	err = -FDT_ERR_NOTFOUND;
 fail:
	if (lenp)
		*lenp = err;
	return NULL;
}