⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bootx_init.c

📁 linux内核源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  Early boot support code for BootX bootloader * *  Copyright (C) 2005 Ben. Herrenschmidt (benh@kernel.crashing.org) * *  This program is free software; you can redistribute it and/or *  modify it under the terms of the GNU General Public License *  as published by the Free Software Foundation; either version *  2 of the License, or (at your option) any later version. */#include <linux/kernel.h>#include <linux/string.h>#include <linux/init.h>#include <linux/utsrelease.h>#include <asm/sections.h>#include <asm/prom.h>#include <asm/page.h>#include <asm/bootx.h>#include <asm/btext.h>#include <asm/io.h>#undef DEBUG#define SET_BOOT_BAT#ifdef DEBUG#define DBG(fmt...) do { bootx_printf(fmt); } while(0)#else#define DBG(fmt...) do { } while(0)#endifextern void __start(unsigned long r3, unsigned long r4, unsigned long r5);static unsigned long __initdata bootx_dt_strbase;static unsigned long __initdata bootx_dt_strend;static unsigned long __initdata bootx_node_chosen;static boot_infos_t * __initdata bootx_info;static char __initdata bootx_disp_path[256];/* Is boot-info compatible ? */#define BOOT_INFO_IS_COMPATIBLE(bi) \	((bi)->compatible_version <= BOOT_INFO_VERSION)#define BOOT_INFO_IS_V2_COMPATIBLE(bi)	((bi)->version >= 2)#define BOOT_INFO_IS_V4_COMPATIBLE(bi)	((bi)->version >= 4)#ifdef CONFIG_BOOTX_TEXTstatic void __init bootx_printf(const char *format, ...){	const char *p, *q, *s;	va_list args;	unsigned long v;	va_start(args, format);	for (p = format; *p != 0; p = q) {		for (q = p; *q != 0 && *q != '\n' && *q != '%'; ++q)			;		if (q > p)			btext_drawtext(p, q - p);		if (*q == 0)			break;		if (*q == '\n') {			++q;			btext_flushline();			btext_drawstring("\r\n");			btext_flushline();			continue;		}		++q;		if (*q == 0)			break;		switch (*q) {		case 's':			++q;			s = va_arg(args, const char *);			if (s == NULL)				s = "<NULL>";			btext_drawstring(s);			break;		case 'x':			++q;			v = va_arg(args, unsigned long);			btext_drawhex(v);			break;		}	}}#else /* CONFIG_BOOTX_TEXT */static void __init bootx_printf(const char *format, ...) {}#endif /* CONFIG_BOOTX_TEXT */static void * __init bootx_early_getprop(unsigned long base,					 unsigned long node,					 char *prop){	struct bootx_dt_node *np = (struct bootx_dt_node *)(base + node);	u32 *ppp = &np->properties;	while(*ppp) {		struct bootx_dt_prop *pp =			(struct bootx_dt_prop *)(base + *ppp);		if (strcmp((char *)((unsigned long)pp->name + base),			   prop) == 0) {			return (void *)((unsigned long)pp->value + base);		}		ppp = &pp->next;	}	return NULL;}#define dt_push_token(token, mem) \	do { \		*(mem) = _ALIGN_UP(*(mem),4); \		*((u32 *)*(mem)) = token; \		*(mem) += 4; \	} while(0)static unsigned long __init bootx_dt_find_string(char *str){	char *s, *os;	s = os = (char *)bootx_dt_strbase;	s += 4;	while (s <  (char *)bootx_dt_strend) {		if (strcmp(s, str) == 0)			return s - os;		s += strlen(s) + 1;	}	return 0;}static void __init bootx_dt_add_prop(char *name, void *data, int size,				  unsigned long *mem_end){	unsigned long soff = bootx_dt_find_string(name);	if (data == NULL)		size = 0;	if (soff == 0) {		bootx_printf("WARNING: Can't find string index for <%s>\n",			     name);		return;	}	if (size > 0x20000) {		bootx_printf("WARNING: ignoring large property ");		bootx_printf("%s length 0x%x\n", name, size);		return;	}	dt_push_token(OF_DT_PROP, mem_end);	dt_push_token(size, mem_end);	dt_push_token(soff, mem_end);	/* push property content */	if (size && data) {		memcpy((void *)*mem_end, data, size);		*mem_end = _ALIGN_UP(*mem_end + size, 4);	}}static void __init bootx_add_chosen_props(unsigned long base,					  unsigned long *mem_end){	u32 val;	bootx_dt_add_prop("linux,bootx", NULL, 0, mem_end);	if (bootx_info->kernelParamsOffset) {		char *args = (char *)((unsigned long)bootx_info) +			bootx_info->kernelParamsOffset;		bootx_dt_add_prop("bootargs", args, strlen(args) + 1, mem_end);	}	if (bootx_info->ramDisk) {		val = ((unsigned long)bootx_info) + bootx_info->ramDisk;		bootx_dt_add_prop("linux,initrd-start", &val, 4, mem_end);		val += bootx_info->ramDiskSize;		bootx_dt_add_prop("linux,initrd-end", &val, 4, mem_end);	}	if (strlen(bootx_disp_path))		bootx_dt_add_prop("linux,stdout-path", bootx_disp_path,				  strlen(bootx_disp_path) + 1, mem_end);}static void __init bootx_add_display_props(unsigned long base,					   unsigned long *mem_end,					   int has_real_node){	boot_infos_t *bi = bootx_info;	u32 tmp;	if (has_real_node) {		bootx_dt_add_prop("linux,boot-display", NULL, 0, mem_end);		bootx_dt_add_prop("linux,opened", NULL, 0, mem_end);	} else		bootx_dt_add_prop("linux,bootx-noscreen", NULL, 0, mem_end);	tmp = bi->dispDeviceDepth;	bootx_dt_add_prop("linux,bootx-depth", &tmp, 4, mem_end);	tmp = bi->dispDeviceRect[2] - bi->dispDeviceRect[0];	bootx_dt_add_prop("linux,bootx-width", &tmp, 4, mem_end);	tmp = bi->dispDeviceRect[3] - bi->dispDeviceRect[1];	bootx_dt_add_prop("linux,bootx-height", &tmp, 4, mem_end);	tmp = bi->dispDeviceRowBytes;	bootx_dt_add_prop("linux,bootx-linebytes", &tmp, 4, mem_end);	tmp = (u32)bi->dispDeviceBase;	if (tmp == 0)		tmp = (u32)bi->logicalDisplayBase;	tmp += bi->dispDeviceRect[1] * bi->dispDeviceRowBytes;	tmp += bi->dispDeviceRect[0] * ((bi->dispDeviceDepth + 7) / 8);	bootx_dt_add_prop("linux,bootx-addr", &tmp, 4, mem_end);}static void __init bootx_dt_add_string(char *s, unsigned long *mem_end){	unsigned int l = strlen(s) + 1;	memcpy((void *)*mem_end, s, l);	bootx_dt_strend = *mem_end = *mem_end + l;}static void __init bootx_scan_dt_build_strings(unsigned long base,					       unsigned long node,					       unsigned long *mem_end){	struct bootx_dt_node *np = (struct bootx_dt_node *)(base + node);	u32 *cpp, *ppp = &np->properties;	unsigned long soff;	char *namep;	/* Keep refs to known nodes */	namep = np->full_name ? (char *)(base + np->full_name) : NULL;       	if (namep == NULL) {		bootx_printf("Node without a full name !\n");		namep = "";	}	DBG("* strings: %s\n", namep);	if (!strcmp(namep, "/chosen")) {		DBG(" detected /chosen ! adding properties names !\n");		bootx_dt_add_string("linux,bootx", mem_end);		bootx_dt_add_string("linux,stdout-path", mem_end);		bootx_dt_add_string("linux,initrd-start", mem_end);		bootx_dt_add_string("linux,initrd-end", mem_end);		bootx_dt_add_string("bootargs", mem_end);		bootx_node_chosen = node;	}	if (node == bootx_info->dispDeviceRegEntryOffset) {		DBG(" detected display ! adding properties names !\n");		bootx_dt_add_string("linux,boot-display", mem_end);		bootx_dt_add_string("linux,opened", mem_end);		strncpy(bootx_disp_path, namep, 255);	}	/* get and store all property names */	while (*ppp) {		struct bootx_dt_prop *pp =			(struct bootx_dt_prop *)(base + *ppp);		namep = pp->name ? (char *)(base + pp->name) : NULL; 		if (namep == NULL || strcmp(namep, "name") == 0) 			goto next;		/* get/create string entry */		soff = bootx_dt_find_string(namep);		if (soff == 0)			bootx_dt_add_string(namep, mem_end);	next:		ppp = &pp->next;	}	/* do all our children */	cpp = &np->child;	while(*cpp) {		np = (struct bootx_dt_node *)(base + *cpp);		bootx_scan_dt_build_strings(base, *cpp, mem_end);		cpp = &np->sibling;	}}static void __init bootx_scan_dt_build_struct(unsigned long base,					      unsigned long node,					      unsigned long *mem_end){	struct bootx_dt_node *np = (struct bootx_dt_node *)(base + node);	u32 *cpp, *ppp = &np->properties;	char *namep, *p, *ep, *lp;	int l;	dt_push_token(OF_DT_BEGIN_NODE, mem_end);	/* get the node's full name */	namep = np->full_name ? (char *)(base + np->full_name) : NULL;	if (namep == NULL)		namep = "";	l = strlen(namep);	DBG("* struct: %s\n", namep);	/* Fixup an Apple bug where they have bogus \0 chars in the	 * middle of the path in some properties, and extract	 * the unit name (everything after the last '/').	 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -