コード例 #1
0
ファイル: fdt_ro.c プロジェクト: Noltari/u-boot
int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen)
{
	const char *end = path + namelen;
	const char *p = path;
	int offset = 0;

	FDT_CHECK_HEADER(fdt);

	/* see if we have an alias */
	if (*path != '/') {
		const char *q = fdt_path_next_separator(path, namelen);

		if (!q)
			q = end;

		p = fdt_get_alias_namelen(fdt, p, q - p);
		if (!p)
			return -FDT_ERR_BADPATH;
		offset = fdt_path_offset(fdt, p);

		p = q;
	}

	while (*p && (p < end)) {
		const char *q;

		while (*p == '/')
			p++;

		if (*p == '\0' || *p == ':')
			return offset;

		q = fdt_path_next_separator(p, end - p);
		if (!q)
			q = end;

		offset = fdt_subnode_offset_namelen(fdt, offset, p, q-p);
		if (offset < 0)
			return offset;

		p = q;
	}

	return offset;
}
コード例 #2
0
ファイル: fdt_ro.c プロジェクト: hsienchieh/uefilab
int fdt_path_offset(const void *fdt, const char *path)
{
	const char *end = path + strlen(path);
	const char *p = path;
	int offset = 0;

	FDT_CHECK_HEADER(fdt);

	/* see if we have an alias */
	if (*path != '/') {
		const char *q = strchr(path, '/');

		if (!q)
			q = end;

		p = fdt_get_alias_namelen(fdt, p, q - p);
		if (!p)
			return -FDT_ERR_BADPATH;
		offset = fdt_path_offset(fdt, p);

		p = q;
	}

	while (*p) {
		const char *q;

		while (*p == '/')
			p++;
		if (! *p)
			return offset;
		q = strchr(p, '/');
		if (! q)
			q = end;

		offset = fdt_subnode_offset_namelen(fdt, offset, p, q-p);
		if (offset < 0)
			return offset;

		p = q;
	}

	return offset;
}
コード例 #3
0
ファイル: serial-uclass.c プロジェクト: OpenNoah/u-boot
static int serial_check_stdout(const void *blob, struct udevice **devp)
{
	int node;

	/* Check for a chosen console */
	node = fdtdec_get_chosen_node(blob, "stdout-path");
	if (node < 0) {
		const char *str, *p, *name;

		/*
		 * Deal with things like
		 *	stdout-path = "serial0:115200n8";
		 *
		 * We need to look up the alias and then follow it to the
		 * correct node.
		 */
		str = fdtdec_get_chosen_prop(blob, "stdout-path");
		if (str) {
			p = strchr(str, ':');
			name = fdt_get_alias_namelen(blob, str,
					p ? p - str : strlen(str));
			if (name)
				node = fdt_path_offset(blob, name);
		}
	}
	if (node < 0)
		node = fdt_path_offset(blob, "console");
	if (!uclass_get_device_by_of_offset(UCLASS_SERIAL, node, devp))
		return 0;

	/*
	 * If the console is not marked to be bound before relocation, bind it
	 * anyway.
	 */
	if (node > 0 && !lists_bind_fdt(gd->dm_root, offset_to_ofnode(node),
					devp)) {
		if (!device_probe(*devp))
			return 0;
	}

	return -ENODEV;
}
コード例 #4
0
ファイル: fdt_ro.c プロジェクト: hsienchieh/uefilab
const char *fdt_get_alias(const void *fdt, const char *name)
{
	return fdt_get_alias_namelen(fdt, name, strlen(name));
}
コード例 #5
0
ファイル: serial-uclass.c プロジェクト: bradbishop/u-boot
static void serial_find_console_or_panic(void)
{
	const void *blob = gd->fdt_blob;
	struct udevice *dev;
	int node;

	if (CONFIG_IS_ENABLED(OF_CONTROL) && blob) {
		/* Check for a chosen console */
		node = fdtdec_get_chosen_node(blob, "stdout-path");
		if (node < 0) {
			const char *str, *p, *name;

			/*
			 * Deal with things like
			 *	stdout-path = "serial0:115200n8";
			 *
			 * We need to look up the alias and then follow it to
			 * the correct node.
			 */
			str = fdtdec_get_chosen_prop(blob, "stdout-path");
			if (str) {
				p = strchr(str, ':');
				name = fdt_get_alias_namelen(blob, str,
						p ? p - str : strlen(str));
				if (name)
					node = fdt_path_offset(blob, name);
			}
		}
		if (node < 0)
			node = fdt_path_offset(blob, "console");
		if (!uclass_get_device_by_of_offset(UCLASS_SERIAL, node,
						    &dev)) {
			gd->cur_serial_dev = dev;
			return;
		}

		/*
		* If the console is not marked to be bound before relocation,
		* bind it anyway.
		*/
		if (node > 0 &&
		    !lists_bind_fdt(gd->dm_root, blob, node, &dev)) {
			if (!device_probe(dev)) {
				gd->cur_serial_dev = dev;
				return;
			}
		}
	}
	if (!SPL_BUILD || !CONFIG_IS_ENABLED(OF_CONTROL) || !blob) {
		/*
		* Try to use CONFIG_CONS_INDEX if available (it is numbered
		* from 1!).
		*
		* Failing that, get the device with sequence number 0, or in
		* extremis just the first serial device we can find. But we
		* insist on having a console (even if it is silent).
		*/
#ifdef CONFIG_CONS_INDEX
#define INDEX (CONFIG_CONS_INDEX - 1)
#else
#define INDEX 0
#endif
		if (!uclass_get_device_by_seq(UCLASS_SERIAL, INDEX, &dev) ||
		    !uclass_get_device(UCLASS_SERIAL, INDEX, &dev) ||
		    (!uclass_first_device(UCLASS_SERIAL, &dev) && dev)) {
			gd->cur_serial_dev = dev;
			return;
		}
#undef INDEX
	}

#ifdef CONFIG_REQUIRE_SERIAL_CONSOLE
	panic_str("No serial driver found");
#endif
}
コード例 #6
0
ファイル: fdt_ro.c プロジェクト: fehead/linux_m
/*
 * chosen {
 * bootargs = "console=ttyS0,115200 ubi.mtd=4 root=ubi0:rootfs rootfstype=ubifs";
 * };

 * 호출: int offset = fdt_path_offset(fdt, "/chosen");
*/
int fdt_path_offset(const void *fdt, const char *path)
{
	/*
	 * p : "chosen"의 시작 주소
	 * end : "chosen"의 끝 주소
	*/
	const char *end = path + strlen(path);
	const char *p = path;
	int offset = 0;

	FDT_CHECK_HEADER(fdt);

	/* see if we have an alias */
	if (*path != '/') {
		// path가 '/'로 시작하지 않으면 path내에서 '/' 위치 찾음
		const char *q = strchr(path, '/');

		// path내에 '/'가 없으면 끝 주소로 지정
		if (!q)
			q = end;

		/*
		 * '/'로 시작하지 않았다면 alias라고 가정하고 원래 node명 탐색
		 * p: alias명
		 * q-p: alias 길이
		*/ 
		p = fdt_get_alias_namelen(fdt, p, q - p);
		// alias도 아닌경우 에러 리턴
		if (!p)
			return -FDT_ERR_BADPATH;
		offset = fdt_path_offset(fdt, p);

		p = q;
	}

	/*
	 * "chosen"의 alias가 없으면 여기서 탐색
	 * 여기서는 node의 이름이 "chosen"인지 아닌지 탐색
	*/
	while (*p) {
		const char *q;

		// path내에서 '/'가 아닌곳까지 이동
		while (*p == '/')
			p++;
		// path 끝까지 이동한 경우
		if (! *p)
			return offset;
		// p를 기준으로 다음 '/' 위치까지 찾아서
		q = strchr(p, '/');
		// 다음 '/'가 없다면 path의 끝으로 지정
		if (! q)
			q = end;
	
		// path에서 '/'로 split 해보면서
		// 하위 node들중 해당 이름의 node가 있는지 탐색
		offset = fdt_subnode_offset_namelen(fdt, offset, p, q-p);
		if (offset < 0)
			return offset;

		p = q;
	}

	return offset;
}