void test_ramdisk(void)
{
	uint8_t user_input = '2';
	struct record_t test;
	struct record_t local_copy;
	struct record_t test_t;

	srand(cph_get_millis());

	test.wan_msg.tagMac = 1;
	test.wan_msg.tagBattery = 2;
	test.wan_msg.tagRssi = 3;
	struct record_t test_2;
	local_copy = test;

	ramdisk_init();

	while(true) {

		test_2.wan_msg.tagMac = rand();
		test_2.wan_msg.tagRssi = rand() % 65535;
		test_2.wan_msg.tagBattery = rand() % 65535;
		test_2.next = NULL;

		if(user_input == '2')
			ramdisk_write(test_2);

		else if(user_input =='1')
			ramdisk_write(test);

		else if(user_input == 'f')
			local_copy = *ramdisk_next(ramdisk_find(test.wan_msg.tagMac));

		else if(user_input == 'p')
			print_records();

		else if(user_input == 'e')
			ramdisk_erase(local_copy);

		else if(user_input == 'r')
			local_copy = test;

		else
			user_input = 'q';

//		scanf(" %c", &user_input);

		if(user_input == 'q')
			break;

	}

}
Example #2
0
int main(int argc, char* argv[]){
	int i=0;
	uint8_t* rd;
    uint8_t buf[30]="adfasdfasgfaaaaaaaaaaa";
    
	char name[14];
	char search_name[14];
	rd=ramdisk_init();
	int root_block_id=search_file(rd, "/");
    int search_file_inodeNO;
    int remove_flag;
    int a;
	printf("root block id is %d\n", root_block_id);
	
	struct inode* root_inode;
	if(!(root_inode=(struct inode*)malloc(sizeof(struct inode)))){
		printf("No mem space!\n");
		exit(-1);
	}
    //create_dir(rd,0,"ts_dir");
	//create a file under root named Jiayi.txt
    create_file(rd, 0, "ts_file.txt");
    for (i = 0; i<1024 ; i++)
    {
        a = write_ramdisk(rd,1,i*20,buf,20);
	    printf("a = %d; i = %d\n", a, i);
//        sprintf(name, "ts_%d.txt", i);
//        create_file(rd, 1, name);
    }

 /*   for (i = 1; i<=FILE_NUM ; i++)
    {
        sprintf(search_name, "/ts_%d.txt", i);
	    search_file_inodeNO = search_file(rd,search_name);
        printf("File InodeNO is:%d\n", search_file_inodeNO);
    }*/
    //remove_flag=remove_file(rd,0,2,"ts_2.txt");
    //(remove_flag==(-1))?(printf("Remove fail!\n")):(printf("Remove success!\n"));
    //search_file_inodeNO=search_file(rd,"/ts_2.txt");
    //printf("File InodeNO is:%d\n", search_file_inodeNO);
    remove_flag=remove_file(rd,0,1,"ts_file.txt");
    (remove_flag==(-1))?(printf("Remove fail!\n")):(printf("Remove success!\n"));
    search_file_inodeNO=search_file(rd,"/ts_file.txt");
    printf("File InodeNO is:%d\n", search_file_inodeNO);
    
	return 0;
}
Example #3
0
int main(int argc, char **argv){
	printf("blocksize:  %u\n", BLOCK_SIZE);
	printf("refs/block: %u\n", (unsigned int) (BLOCK_SIZE / sizeof(block_no)));

	/* First create the lowest level "store".
	 */
	block_if disk = ramdisk_init(blocks, DISK_SIZE);

	/* Add a disk to keep track of statistics.
	 */
	block_if sdisk = statdisk_init(disk);

	/* Add a layer of caching.
	 */
	block_if cdisk = cachedisk_init(sdisk, cache, CACHE_SIZE);

	/* Add a layer of checking to make sure the cache layer works.
	 */
	block_if xdisk = checkdisk_init(cdisk, "cache");

	// TODO:  INSERT YOUR TESTS HERE
	block_t block;
	strcpy((char *) &block, "Hello World");
	(*xdisk->write)(xdisk, 3, &block);
	(*xdisk->read)(xdisk, 3, &block);
	printf("%s\n", (char *) &block);

	strcpy((char *) &block, "Hello World");
	(*cdisk->write)(cdisk, 3, &block);
	(*cdisk->read)(cdisk, 3, &block);

	/* Print stats.
	 */
	statdisk_dump_stats(sdisk);
	cachedisk_dump_stats(cdisk);

	/* Clean up.
	 */
	(*xdisk->destroy)(xdisk);
	(*cdisk->destroy)(cdisk);	

	(*sdisk->destroy)(sdisk);
	(*disk->destroy)(disk);

	return 0;
}
Example #4
0
int main(void)
{
	rcc_clock_setup_hse_3v3(&rcc_hse_8mhz_3v3[RCC_CLOCK_3V3_120MHZ]);

	rcc_periph_clock_enable(RCC_GPIOB);
	rcc_periph_clock_enable(RCC_OTGHS);

	gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE,
			GPIO13 | GPIO14 | GPIO15);
	gpio_set_af(GPIOB, GPIO_AF12, GPIO13 | GPIO14 | GPIO15);

	msc_dev = usbd_init(&otghs_usb_driver, &dev_descr, &config_descr,
			    usb_strings, 3,
			    usbd_control_buffer, sizeof(usbd_control_buffer));

	ramdisk_init();
	usb_msc_init(msc_dev, 0x82, 64, 0x01, 64, "VendorID", "ProductID",
		"0.00", ramdisk_blocks(), ramdisk_read, ramdisk_write);

	for (;;) {
		usbd_poll(msc_dev);
	}
}
Example #5
0
int main(int argc, char* argv[]) {
  (void)argc;
  (void)argv;
  struct coresrv_init *data = (struct coresrv_init *)_libc_init_get()->data;
  syscall_log("coresrv", "main", "initializing..");

  struct timeval time;
  gettimeofday(&time, 0);
  char msg[128];
  sprintf(msg, "Current UNIX time is %llu", (unsigned long long)time.tv_sec);
  syscall_log("coresrc", "main", msg);

  broker_init();

  vfs_init();
  vfs_t vfs;
  VFS_BIND(&vfs);
  syscall_log("coresrv", "main", "created VFS");

  // devfs needs to be bound first so that we can allocate device numbers.
  devfs_init();
  devfs_op_t devfs_op;
  DEVFS_BIND(&devfs_op);

  initfs_init();
  initfs_op_t initfs_op;
  INITFS_BIND(&initfs_op);
  vfs_fs_t initfs;
  dev_t init_dev = devfs_op.alloc_dev();
  if (initfs_op.create(data->initrd_base, data->initrd_size, init_dev, &initfs)) exit(-1);
  if (vfs.mount("/", &initfs)) exit(-1);
  syscall_log("coresrv", "main", "mounted initfs at /");

  vfs_fs_t devfs;
  if (devfs_op.create(&devfs)) exit(-1);
  if (vfs.mount("/dev", &devfs)) exit(-1);
  syscall_log("coresrv", "main", "mounted devfs at /dev");

  pci_init();
  pci_op_t pci_op;
  PCI_BIND(&pci_op);
  vfs_node_t pci;
  if (pci_op.create(&pci)) exit(-1);
  if (devfs_op.add_dev(&devfs, "pci", &pci, &pci.stat.st_rdev)) exit(-1);
  syscall_log("coresrv", "main", "added /dev/pci");

  console_init();
  console_op_t console_op;
  CONSOLE_BIND(&console_op);
  vfs_node_t console;
  if (console_op.create(&console)) exit(-1);
  if (devfs_op.add_dev(&devfs, "console", &console, &console.stat.st_rdev)) exit(-1);
  syscall_log("coresrv", "main", "added /dev/console");

  ramdisk_init();
  ramdisk_op_t ramdisk_op;
  RAMDISK_BIND(&ramdisk_op);
  vfs_node_t ramdisk;
  if (ramdisk_op.create(0x200000, &ramdisk)) exit(-1);
  if (devfs_op.add_dev(&devfs, "ramdisk$", &ramdisk, &ramdisk.stat.st_rdev)) exit(-1);
  syscall_log("coresrv", "main", "added /dev/ramdisk");

  tmpfs_init();
  tmpfs_op_t tmpfs_op;
  TMPFS_BIND(&tmpfs_op);
  vfs_fs_t tmpfs;
  dev_t tmp_dev = devfs_op.alloc_dev();
  if (tmpfs_op.create(0x200000, tmp_dev, &tmpfs)) exit(-1);
  if (vfs.mount("/tmp", &tmpfs)) exit(-1);
  syscall_log("coresrv", "main", "mounted tmpfs at /tmp");
  
  fat16_init();
  fat16_op_t fat16_op;
  FAT16_BIND(&fat16_op);
  vfs_fs_t fatfs;
  if (fat16_op.create(&ramdisk, &fatfs)) exit(-1);
  if (vfs.mount("/home", &fatfs)) exit(-1);
  syscall_log("coresrv", "main", "mounted fat16 at /home");

  /*
  pid_t init = fork();
  if (!init) {
    execl(argv[1], argv[1], (void*)0);
  } else while (wait(0) == -1);
  */

  ps2_init();

  // TODO: funny way to just sleep
  syscall_log("corsrv", "main", "sleeping for good.");
  syscall_set_signal_mask(~0ull);
  syscall_wait_signal(1<<SIGINT);
}
Example #6
0
/*
 * Bootstrap-CPU start; we came from head.S
 */
void __no_return kernel_start(void)
{
	/* Before anything else, zero the bss section. As said by C99:
	 * “All objects with static storage duration shall be inited
	 * before program startup”, and that the implicit init is done
	 * with zero. Kernel assembly code also assumes a zeroed BSS
	 * space */
	clear_bss();

	/*
	 * Very-early setup: Do not call any code that will use
	 * printk(), `current', per-CPU vars, or a spin lock.
	 */

	setup_idt();

	schedulify_this_code_path(BOOTSTRAP);

	/*
	 * Memory Management init
	 */

	print_info();

	/* First, don't override the ramdisk area (if any) */
	ramdisk_init();

	/* Then discover our physical memory map .. */
	e820_init();

	/* and tokenize the available memory into allocatable pages */
	pagealloc_init();

	/* With the page allocator in place, git rid of our temporary
	 * early-boot page tables and setup dynamic permanent ones */
	vm_init();

	/* MM basics done, enable dynamic heap memory to kernel code
	 * early on .. */
	kmalloc_init();

	/*
	 * Secondary-CPUs startup
	 */

	/* Discover our secondary-CPUs and system IRQs layout before
	 * initializing the local APICs */
	mptables_init();

	/* Remap and mask the PIC; it's just a disturbance */
	serial_init();
	pic_init();

	/* Initialize the APICs (and map their MMIO regs) before enabling
	 * IRQs, and before firing other cores using Inter-CPU Interrupts */
	apic_init();
	ioapic_init();

	/* SMP infrastructure ready, fire the CPUs! */
	smpboot_init();

	keyboard_init();

	/* Startup finished, roll-in the scheduler! */
	sched_init();
	local_irq_enable();

	/*
	 * Second part of kernel initialization (Scheduler is now on!)
	 */

	ext2_init();

	// Signal the secondary cores to run their own test-cases code.
	// They've been waiting for us (thread 0) till all of kernel
	// subsystems has been properly initialized.  Wait No More!
	smpboot_trigger_secondary_cores_testcases();

	run_test_cases();
	halt();
}
Example #7
0
int main(int argc, char **argv){
	char *trace = argc == 1 ? "trace.txt" : argv[1];
	int cache_size = argc > 2 ? atoi(argv[2]) : 16;
	int ramdisk = 1;

	printf("blocksize:  %u\n", BLOCK_SIZE);
	printf("refs/block: %u\n", (unsigned int) (BLOCK_SIZE / sizeof(block_no)));

	/* First create the lowest level "store".
	 */
	block_if disk;
	if (ramdisk) {
		disk = ramdisk_init(blocks, DISK_SIZE);
	}
	else {
		disk = disk_init("disk.dev", DISK_SIZE);
	}

	/* Start a timer to try to detect infinite loops or just insanely slow code.
	 */
	signal(SIGALRM, sigalrm);
	alarm(5);

	/* Virtualize the store, creating a collection of 64 virtual stores.
	 */
	if (treedisk_create(disk, MAX_INODES) < 0) {
		panic("trace: can't create treedisk file system");
	}

	/* Add a disk to keep track of statistics.
	 */
	block_if sdisk = statdisk_init(disk);

	/* Add a layer of caching.
	 */
	block_t *cache = malloc(cache_size * BLOCK_SIZE);
	block_if cdisk = cachedisk_init(sdisk, cache, cache_size);

	/* Add a layer of checking to make sure the cache layer works.
	 */
	block_if xdisk = checkdisk_init(cdisk, "cache");

	/* Run a trace.
	 */
	block_if tdisk = tracedisk_init(xdisk, trace, MAX_INODES);

	/* Clean up.
	 */
	(*tdisk->destroy)(tdisk);
	(*xdisk->destroy)(xdisk);
	(*cdisk->destroy)(cdisk);

	/* No longer running treedisk or cachedisk code.
	 */
	alarm(0);

	/* Print stats.
	 */
	statdisk_dump_stats(sdisk);

	(*sdisk->destroy)(sdisk);

	/* Check that disk just one more time for good measure.
	 */
	treedisk_check(disk);

	(*disk->destroy)(disk);

	free(cache);

	return 0;
}
Example #8
0
int ramdisk_main(void){
    ramdisk_init();
    workloop();
    return 0;
}
Example #9
0
void moboot_init(const struct app_descriptor *app)
{
	int rv, keys_pressed;
	unsigned act;
	menu_entry_t *real_entries[32];

	char *ptr;
	int rc;
	char path[256];
	char *newpath;
	char *newtitle;
	char *newname;

	unsigned xoff, yoff;

	unsigned ramdisk_mounted, ramdisk_start, ramdisk_size;

	unsigned i, j;

	unsigned default_menu_entry = 0;
	unsigned next_menu_entry = 0;

	char default_image[256];
	char next_image[256];

	unsigned default_timeout;
	unsigned counted_images;
	unsigned use_next;
	ssize_t splash_sz;
	void *splash_ptr = NULL;
	ssize_t background_sz;
	void *background_ptr;
	ssize_t tile_sz;
	void *tile_ptr;
	char splash_path[256];

	unsigned boot_flags;

	ssize_t rdmsgsz;
	char *rdmsg;

	keys_pressed = 0;

	display_surface = NULL;

	entries = real_entries;

	gfx_trans = 0;

	gfxconsole_clear();
	gfxconsole_setpos(0,0);

	ramdisk_mounted = 0;
	atags_get_ramdisk(&ramdisk_start, &ramdisk_size);
	if (ramdisk_size && ramdisk_start) {
		ramdisk_init((void*)ramdisk_start, ramdisk_size);
		if (fs_mount("/ramdisk", "/dev/ramdisk")) {
			printf("Ramdisk start=%08x size=%08x\n", ramdisk_start, ramdisk_size);
			printf("Unable to mount /ramdisk\n");
			printf("Press SELECT to continue\n");
			gpiokeys_wait_select();
		} else {
			ramdisk_mounted = 1;
		}
	}


    if (fs_mount("/boot", "/dev/mmcblk0p13")) {
		printf("\nUnable to mount /boot, exiting.\n");
		while (1) {
			thread_sleep(20);
		}
	}

	default_timeout = 5;
	if ((rv = fs_load_file("/boot/moboot.timeout", &default_image, 256)) > 0) {
		default_image[rv] = 0;
		if (default_image[rv - 1] == '\n') default_image[rv - 1] = 0;
		default_timeout = atoui(default_image);
	}
	default_image[0] = 0;
	rv = fs_load_file("/boot/moboot.default", &default_image, 256);
	if (rv > 0) {
		default_image[rv] = 0;
		if (default_image[rv - 1] == '\n') default_image[rv - 1] = 0;
	}
	use_next = 0;
	next_image[0] = 0;
	rv = fs_load_file("/boot/moboot.next", &next_image, 256);
	if (rv > 0) {
		next_image[rv] = 0;
		if (next_image[rv - 1] == '\n') next_image[rv - 1] = 0;
	}

	tile_sz = fs_load_file_mem("/boot/moboot.background.tga", &tile_ptr);

	background_surface = NULL;
	tile_surface = NULL;

	if (tile_sz > 0) {
		tile_surface = tga_decode(tile_ptr, tile_sz,
									GFX_FORMAT_RGB_x888);
		struct display_info disp_info;
		if (!display_surface) {
			display_get_info(&disp_info);
			display_surface = gfx_create_surface_from_display(&disp_info);
		}
		background_surface = gfx_create_surface(NULL,
								display_surface->width,
								display_surface->height,
								display_surface->stride,
								display_surface->format);
		for (i = 0; i < display_surface->width; i += tile_surface->width) {
			for (j = 0; j < display_surface->height;
							j += tile_surface->height) {
				gfx_surface_blend(background_surface,
									tile_surface,
									i, j);
			}
		}
	}


	num_menu_entries = 0;

	i = 0;
	counted_images = 0;
	while ((rc = fs_dirent("/boot", i, &ptr)) > 0) {
		sprintf(path, "/boot/%s", ptr);
		if (strncmp("uImage.", ptr, 7) == 0) {
			if (strncmp("uImage.moboot", ptr, 13) != 0) {
				newtitle = malloc(strlen(ptr) - 7 + 5 + 1);
				sprintf(newtitle, "boot %s", ptr + 7);
				newpath = malloc(strlen(ptr) + 6 + 1);
				sprintf(newpath, "/boot/%s", ptr);
				newname = malloc(strlen(ptr) - 7 + 1);
				sprintf(newname, "%s", ptr + 7);
				if (strcmp(default_image, ptr + 7) == 0) {
					default_menu_entry = num_menu_entries;
				}
				if (strcmp(next_image, ptr + 7) == 0) {
					next_menu_entry = num_menu_entries;
					use_next = 1;
				}
				set_menu_entry(newtitle, BOOT_FS, newpath, newname);
				counted_images++;
			}
		}
		free(ptr);
		i++;
	}
	if (rc < 0) {
		dprintf(SPEW, "/boot dirList ERROR rc = %d\n", rc);
	}
	i = 0;
	while ((rc = fs_dirent("/ramdisk/boot", i, &ptr)) > 0) {
		sprintf(path, "/ramdisk/boot/%s", ptr);
		if (strncmp("uImage.", ptr, 7) == 0) {
			if (strncmp("uImage.moboot", ptr, 13) != 0) {
				newtitle = malloc(strlen(ptr) - 7 + 5 + 1);
				sprintf(newtitle, "boot %s", ptr + 7);
				newpath = malloc(strlen(ptr) + 14 + 1);
				sprintf(newpath, "/ramdisk/boot/%s", ptr);
				newname = malloc(strlen(ptr) - 7 + 1);
				sprintf(newname, "%s", ptr + 7);
				if (strcmp(default_image, ptr + 7) == 0) {
					default_menu_entry = num_menu_entries;
				}
				if (strcmp(next_image, ptr + 7) == 0) {
					next_menu_entry = num_menu_entries;
					use_next = 1;
				}
				set_menu_entry(newtitle, BOOT_FS, newpath, newname);
				counted_images++;
			}
		}
		free(ptr);
		i++;
	}
	if (rc < 0) {
		dprintf(SPEW, "/ramdisk/boot dirList ERROR rc = %d\n", rc);
	}
	
	if (counted_images == 0) {
		set_menu_entry("boot", BOOT_FS, "/boot/uImage-2.6.35-palm-tenderloin", "default");
	}


	if (gpiokeys_poll(KEY_ALL)) {
		keys_pressed = 1;
		printf("\nPlease release key(s)...");
		while (1) {
			thread_sleep(20);
			if (!gpiokeys_poll(KEY_ALL)) {
				break;
			}
		}
	}

	gfx_trans = 0;
	if (tile_surface) {
		gfx_trans = 1;
	}


	set_menu_entry("boot webOS Recovery", BOOT_RECOVER, "", "recover");
	set_menu_entry("reboot", BOOT_REBOOT, "", "reboot");
	// set_menu_entry("DFU", BOOT_DFU, "", "");
	set_menu_entry("shutdown", BOOT_SHUTDOWN, "", "shutdown");

	xoff = (gfxconsole_getwidth() - 16 ) / 2;
	if (num_menu_entries < 10) {
		yoff = (gfxconsole_getheight() - 12) / 2;
	} else {
		yoff = (gfxconsole_getheight() - (num_menu_entries + 4)) / 2;
	}

#if 0
	tgasz = fs_load_file_mem("/boot/moboot.tga", &tgaptr);

	tga_surface = NULL;

	if (tgasz > 0) {
		tga_surface = tga_decode(tgaptr, tgasz, GFX_FORMAT_RGB_x888);
		struct display_info disp_info;
		if (!display_surface) {
			display_get_info(&disp_info);
			display_surface = gfx_create_surface_from_display(&disp_info);
		}
	}
#endif

	while (1) {
		gfxconsole_clear();

		show_background();

		if (background_surface) {
			gfxconsole_setbackground(background_surface);
		}

		gfxconsole_settrans(gfx_trans);

		gfxconsole_setpos(xoff,yoff);
		if (gfx_trans) {
			gfxconsole_set_colors(0xffffffff, 0x00000000);
			printf("moboot %s", MOBOOT_VERSION);
			gfxconsole_setpos(xoff,yoff);
			gfxconsole_set_colors(0x00000000, 0x00000000);
		} else {
			gfxconsole_set_colors(0x00000000, 0xffffffff);
			printf("moboot %s", MOBOOT_VERSION);
			gfxconsole_set_colors(0x00000000, 0x000000ff);
		}

		if (!use_next || keys_pressed) {
			act = moboot_menu(xoff, yoff + 2, entries, default_menu_entry, num_menu_entries, keys_pressed ? 0 : default_timeout);
		} else {
			act = next_menu_entry;
			use_next = 0;
		}

		keys_pressed = 1;

		gfxconsole_setpos(xoff, yoff + 2 + num_menu_entries + 2);

		boot_flags = BOOTLINUX_NOFLAGS;

		switch (entries[act]->type) {
			case BOOT_RECOVER:
				reboot_device(RESTART_REASON_RECOVER);
				break;
			case BOOT_REBOOT:
				reboot_device(RESTART_REASON_REBOOT);
				break;
			case BOOT_DFU:
				reboot_device(RESTART_REASON_DFU);
				break;
			case BOOT_SHUTDOWN:
				reboot_device(RESTART_REASON_SHUTDOWN);
				break;
			case BOOT_FS:
				gfxconsole_clear();
				gfxconsole_settrans(gfx_trans);
				show_background();
				gfxconsole_setpos(0,0);

				if (gfx_trans) {
					gfxconsole_set_colors(0x00000000, 0x00000000);
				} else {
					gfxconsole_set_colors(0x00000000, 0x000000ff);
				}

				printf("Selected: '%s'\n\n", entries[act]->title);
				printf("Loading '%s'... ", entries[act]->arg);
				if ((rv = fs_load_file(entries[act]->arg,
							(void *)SCRATCH_ADDR, 
							SCRATCH_SIZE * 1024 * 1024)) < 0) {
					printf("FAILED\n");
				} else {
					printf("OK\n");

					/* check for verbose boot */
					sprintf(splash_path, "/boot/moboot.verbose.%s", 
								entries[act]->name);

					splash_sz = fs_load_file_mem(splash_path, &splash_ptr);

					if (splash_sz > 0) {
						if (strncmp(splash_ptr, "yes", 3) == 0) {
							boot_flags |= BOOTLINUX_VERBOSE;
						}
					}

					/* check for sercon boot */
					sprintf(splash_path, "/boot/moboot.sercon.%s", 
								entries[act]->name);

					splash_sz = fs_load_file_mem(splash_path, &splash_ptr);

					if (splash_sz > 0) {
						if (strncmp(splash_ptr, "yes", 3) == 0) {
							boot_flags |= BOOTLINUX_SERCON;
						}
					}

					if (splash_ptr) free(splash_ptr);

					/* check for splash image */
					sprintf(splash_path, "/boot/moboot.splash.%s.tga", 
								entries[act]->name);

					splash_sz = fs_load_file_mem(splash_path, &splash_ptr);

					splash_surface = NULL;

					if (splash_sz > 0) {
						splash_surface = tga_decode(splash_ptr, splash_sz,
													GFX_FORMAT_RGB_x888);
						struct display_info disp_info;
						if (!display_surface) {
							display_get_info(&disp_info);
							display_surface = gfx_create_surface_from_display(
													&disp_info);
						}
					}

					/* do it to it! */
					bootlinux_uimage_mem((void *)SCRATCH_ADDR, rv, boot_splash,
							boot_flags);
				}

				gfxconsole_set_colors(0x00000000, 0x00ff0000);
				printf("\n\nBOOT FAILED!\n\nPress SELECT to continue\n");
				gfxconsole_set_colors(0x00000000, 0x000000ff);
				gpiokeys_wait_select();
				break;
		}
	}
}
Example #10
0
void kernel_main(uint32_t r0, uint32_t r1, uint32_t *atags,
		uint32_t memory_kernel) {

	unsigned int memory_total;
	int init_process,idle_process;
	struct atag_info_t atag_info;
	uint32_t framebuffer_width=800,framebuffer_height=600;
	uint32_t temperature;

	(void) r0;	/* Ignore boot method */

	/* Initialize Software Structures */
	processes_init();

	/* Detect Hardware */
	atags_detect(atags,&atag_info);
	hardware_type=atag_info.hardware_type;

	/* Initialize Hardware */

	/* Serial console is most important so do that first */
	uart_init();

	/* Enable HW random number generator */
	bcm2835_rng_init();

	/* Enable Interrupts */
	enable_interrupts();

	/************************/
	/* Boot message!	*/
	/************************/

	printk("\nBooting VMWos...\n");

	/**************************/
	/* Device Drivers	  */
	/**************************/

	/* Set up ACT LED */
	led_init();

	/* Set up timer */
	timer_init();

	/* Set up keyboard */
	ps2_keyboard_init();

	/* Enable the Framebuffer */
	if (atag_info.framebuffer_x!=0) {
		framebuffer_width=atag_info.framebuffer_x;
	}
	if (atag_info.framebuffer_y!=0) {
		framebuffer_height=atag_info.framebuffer_y;
	}

	framebuffer_init(framebuffer_width,framebuffer_height,24);
	framebuffer_console_init();

	/* Delay to allow time for serial port to settle */
	/* So we can actually see the output on the terminal */
	delay(0x3f0000);

	printk("\nWaiting for serial port to be ready (press any key)\n");
	uart_getc();

	uart_enable_interrupts();


	/* Clear screen */
	printk("\n\033[2J\n\n");

	/* Print boot message */
	printk("\033[0;41m   \033[42m \033[44m   \033[42m \033[44m   \033[0m VMW OS\n");
	printk(" \033[0;41m \033[42m   \033[44m \033[42m   \033[44m \033[0m  Version 0.%d\n\n",VERSION);

	/* Print hardware version */
	printk("Hardware version: %x ",r1);
	if (r1==0xc42) printk("(Raspberry Pi)");
	else printk("(Unknown Hardware)");
	printk("\n");

	printk("Detected Model ");
	switch(hardware_type) {
		case RPI_MODEL_A:	printk("A"); break;
		case RPI_MODEL_APLUS:	printk("A+"); break;
		case RPI_MODEL_B:	printk("B"); break;
		case RPI_MODEL_BPLUS:	printk("B+"); break;
		case RPI_MODEL_B2:	printk("B2"); break;
		case RPI_COMPUTE_NODE:	printk("Compute Node"); break;
		default:		printk("Unknown %x",hardware_type); break;
	}
	printk("\n");

	/* Check temperature */
	temperature=thermal_read();
	printk("CPU Temperature: %dC, %dF\n",
		temperature/1000,
		((temperature*9)/5000)+32);

	/* Print ATAGS */
	atags_dump(atags);

	printk("\n");

	/* Get amount of RAM from ATAGs */
	memory_total=atag_info.ramsize;

	/* Init memory subsystem */
	memory_init(memory_total,memory_kernel);

	/* Start HW Perf Counters */
	arm1176_init_pmu();

#if 0
	asm("nop");
	asm("nop");
	asm("nop");
	asm("nop");

	asm("nop");
	asm("nop");
	asm("nop");
	asm("nop");

	asm("nop");
	asm("nop");
	asm("nop");
	asm("nop");

	asm("nop");

//	printk("Heisenbug!\n");
#endif

	/* Setup Memory Hierarchy */
#if 1
	memset_benchmark(memory_total);
#else
	/* Enable L1 i-cache */
	printk("Enabling L1 icache\n");
	enable_l1_dcache();

	/* Enable branch predictor */
	printk("Enabling branch predictor\n");

	/* Enable L1 d-cache */
	printk("Enabling MMU with 1:1 Virt/Phys page mapping\n");
	enable_mmu(0,memory_total);
	printk("Enabling L1 dcache\n");
	enable_l1_dcache();
#endif

	/* Init the file descriptor table */
	fd_table_init();

	/* Initialize the ramdisk */
	ramdisk_init(initrd_image,sizeof(initrd_image));

	/* Mount the ramdisk */
	mount("/dev/ramdisk","/","romfs",0,NULL);

	/* Load the idle thread */
	idle_process=load_process("idle",PROCESS_FROM_RAM,
				(char *)&idle_task,8,4096);

	init_process=load_process("shell",PROCESS_FROM_DISK,
				NULL,0,8192);

	load_process("printa",PROCESS_FROM_DISK,
				NULL,0,8192);

	load_process("printb",PROCESS_FROM_DISK,
				NULL,0,8192);


	/* Enter our "init" process*/
	printk("\nEntering userspace by starting process %d!\n",
		init_process);

	process[idle_process].ready=1;
	process[init_process].ready=1;

	userspace_started=1;

	/* run init and restore stack as we won't return */
	run_process(init_process,0x8000);

	/* we should never get here */

	while(1) {

		/* Loop Forever */
		/* Should probably execute a wfi instruction */
	}

}