示例#1
0
DSTATUS disk_initialize (
	BYTE pdrv				/* Physical drive nmuber (0..) */
)
{
	DSTATUS stat;
	int result = 0;
        
        stat = STA_NOINIT;
        drvstatus = STA_NOINIT;
        
        result = sd_card_init(&sddevice);
        
        if (result != -1) {

                stat = 0;
                drvstatus = 0;
        }

        return stat;

}
示例#2
0
int bdevs_init()
{
        return sd_card_init(&block_dev_table[0]);
}
示例#3
0
void kernel_main(uint32_t boot_dev, uint32_t arm_m_type, uint32_t atags)
{
	atag_cmd_line = (void *)0;
	_atags = atags;
	_arm_m_type = arm_m_type;
	UNUSED(boot_dev);

	// First use the serial console
	stdout_putc = uart_putc;
	stderr_putc = uart_putc;
	stream_putc = def_stream_putc;	

	// Dump ATAGS
	parse_atags(atags, atag_cb);

	int result = fb_init();
	if(result == 0)
		puts("Successfully set up frame buffer");
	else
	{
		puts("Error setting up framebuffer:");
		puthex(result);
	}

	// Switch to the framebuffer for output
	stdout_putc = split_putc;

	printf("Welcome to Rpi bootloader\n");
	printf("ARM system type is %x\n", arm_m_type);
	if(atag_cmd_line != (void *)0)
		printf("Command line: %s\n", atag_cmd_line);

	struct usb_hcd *usb_hcd;
	dwc_usb_init(&usb_hcd, DWC_USB_BASE);
	
	struct block_device *sd_dev;

	if(sd_card_init(&sd_dev) == 0)
		read_mbr(sd_dev, (void*)0, (void*)0);

	// List devices
	printf("MAIN: device list: ");
	char **devs = vfs_get_device_list();
	while(*devs)
		printf("%s ", *devs++);
	printf("\n");

	// Look for a boot configuration file, starting with the default device,
	// then iterating through all devices
	
	FILE *f = (void*)0;
	
	// Default device
	char **fname = boot_cfg_names;
	char *found_cfg;
	while(*fname)
	{
		f = fopen(*fname, "r");
		if(f)
		{
			found_cfg = *fname;
			break;
		}

		fname++;
	}

	if(!f)
	{
		// Try other devices
		char **dev = vfs_get_device_list();
		while(*dev)
		{
			int dev_len = strlen(*dev);
			
			fname = boot_cfg_names;
			while(*fname)
			{
				int fname_len = strlen(*fname);
				char *new_str = (char *)malloc(dev_len + fname_len + 3);
				new_str[0] = 0;
				strcat(new_str, "(");
				strcat(new_str, *dev);
				strcat(new_str, ")");
				strcat(new_str, *fname);

				f = fopen(new_str, "r");

				if(f)
				{
					found_cfg = new_str;					
					break;
				}

				free(new_str);
				fname++;
			}

			if(f)
				break;

			dev++;
		}
	}

	if(!f)
	{
		printf("MAIN: No bootloader configuration file found\n");
	}
	else
	{	
		printf("MAIN: Found bootloader configuration: %s\n", found_cfg);
		char *buf = (char *)malloc(f->len + 1);
		buf[f->len] = 0;		// null terminate
		fread(buf, 1, f->len, f);
		fclose(f);
		cfg_parse(buf);
	}
}
示例#4
0
文件: main.c 项目: Marvenlee/cheviot
void Main (void)
{
	void (*kernel_entry_point)(struct BootInfo *bi);
	void (*procman_entry_point)(void);
	size_t nbytes_read;
	size_t filesz;
	void *mod;
	void *addr;
	vm_addr heap_base, heap_ceiling;
	vm_addr user_stack_base, user_stack_ceiling;

    // Initialize bootloader
	
	dbg_init();
	BlinkLEDs(10);
	sd_card_init(&bdev);
	fat_init();
	init_mem();

	// Load kernel at 1MB mark
	
	if (elf_load ("BOOT/KERNEL", (void *)&kernel_entry_point) != 0)
		KPanic ("Cannot load kernel");
	
	kernel_phdr_cnt = phdr_cnt;
	bmemcpy (kernel_phdr_table, phdr_table, sizeof (Elf32_PHdr) *  MAX_PHDR);
	
	user_base = 0x00800000;
	heap_base    = segment_table[segment_cnt-1].base;
	heap_ceiling = segment_table[segment_cnt-1].ceiling;
		
	if (heap_ceiling > user_base)
		heap_ceiling = user_base;
	
	addr = SegmentCreate (heap_base, heap_ceiling - heap_base, SEG_TYPE_ALLOC, MAP_FIXED | PROT_READWRITE);

	if (addr == NULL)
		KPanic ("Could not allocate HEAP!");

	KLog ("heap_base = %#010x, heap_ceiling = %#010x", heap_base, heap_ceiling);

    
    // Load root process (the Executive at 8MB mark
		
	if (elf_load ("BOOT/FILESYS", (void *)&procman_entry_point) != 0)
		KPanic ("Cannot load filesystem manager");

	procman_phdr_cnt = phdr_cnt;
	bmemcpy (procman_phdr_table, phdr_table, sizeof (Elf32_PHdr) * MAX_PHDR);


    // Allocate memory for module table, read startup.txt
    // and load modules above 8MB
    
	module_table = SegmentCreate (user_base, sizeof (struct Module) * NMODULE, SEG_TYPE_ALLOC, PROT_READWRITE);
	KLog ("module_table = %#010x", module_table);

	if ((vm_addr)module_table < user_base)
		KPanic ("Bad module_table");
	
	if (fat_open ("BOOT/STARTUP.TXT") != 0)
		KPanic ("Cannot open STARTUP.TXT");
	
	module_cnt = 0;
	
	while (module_cnt < NMODULE)
	{
		if ((nbytes_read = fat_getline(module_table[module_cnt].name, 64)) == 0)
			break;
		
		if (module_table[module_cnt].name[0] == '\0' ||
			module_table[module_cnt].name[0] == '\n' ||
			module_table[module_cnt].name[0] == '\r' ||
			module_table[module_cnt].name[0] == ' ')
		{
			KLOG ("Skipping blank lines");
			continue;
		}
		
		if (fat_open (module_table[module_cnt].name) != 0)
			KPanic ("Cannot open module");
		
		filesz = fat_get_filesize();
		
		mod = SegmentCreate (user_base, filesz, SEG_TYPE_ALLOC, PROT_READWRITE);
		
		if (fat_read (mod, filesz) == filesz)
		{
			module_table[module_cnt].addr = mod;
			module_table[module_cnt].size = filesz;
			module_cnt++;
		}
	}
	
	
	// Allocate a stack for the Executive
	
	user_stack_base = SegmentCreate (user_base, 65536, SEG_TYPE_ALLOC, PROT_READWRITE);	
	user_stack_ceiling = user_stack_base + 65536;

    
    // Pass the bootinfo, segment_table and module_table to kernel.
    
	bootinfo.procman_entry_point = procman_entry_point;
	bootinfo.user_stack_base = user_stack_base;
	bootinfo.user_stack_ceiling = user_stack_ceiling;
	bootinfo.user_base = user_base;
	bootinfo.heap_base = heap_base;
	bootinfo.heap_ceiling = heap_ceiling;
	bootinfo.screen_width = screen_width;
	bootinfo.screen_height = screen_height;
	bootinfo.screen_buf = screen_buf;
	bootinfo.screen_pitch = screen_pitch;
	bootinfo.module_table = module_table;
	bootinfo.module_cnt = module_cnt;
	bootinfo.segment_table = segment_table;
	bootinfo.segment_cnt = segment_cnt;
		
	KLOG ("Calling KERNEL entry point %#010x", (uint32) kernel_entry_point);
	
	kernel_entry_point(&bootinfo);
	while (1);
}