int jz47xx_board_init_f(ulong api_addr, struct slpt_task *task)
{
	bd_t *bd;
	ulong addr, addr_malloc;

	/* compiler optimization barrier needed for GCC >= 3.4 */
	__asm__ __volatile__("" : : : "memory");

#ifndef CONFIG_SLPT
	/* unmap kuseg area */
	clear_c0_status(ST0_ERL);
	/* init BTB */
	__write_32bit_c0_register($16,7,0x10);
#endif

	/* Reserve memory for U-Boot code, data & bss
	 * round up to next 16 kB limit
	 */

	addr = bss_end();
	addr |= 16 * 1024 - 1;
	addr++;

	/* initialize the slpt task, and kernel api_addr
	 */
	uboot_slpt_task = task;
	slpt_kernel_get_api_val = (void *)api_addr;

	/*
	 * (permanently) allocate a Board Info struct
	 * and a permanent copy of the "global" data
	 */
	gd = (gd_t *)addr;
	memset((void *)gd, 0, sizeof(gd_t));
	if (initcall_run_list(init_sequence_f))
		hang();

	debug("Reserving %ldk for U-Boot: [%08x, %08lx)\n",
			(bss_end() - CONFIG_SYS_MONITOR_BASE) >> 10,
			CONFIG_SYS_MONITOR_BASE, bss_end());
	debug("Reserving %zu Bytes for Global Data: [%08lx, %08lx)\n",
			sizeof(gd_t), addr, addr + sizeof(gd_t));
	addr += sizeof(gd_t);

	bd = (bd_t *)addr;
	memset((void *)bd, 0, sizeof(bd_t));
	gd->bd = bd;
	debug("Reserving %zu Bytes for Board Info: [%08lx, %08lx)\n",
			sizeof(bd_t), addr, addr + sizeof(bd_t));
	addr += sizeof(bd_t);

	 /* Reserve memory for malloc() arena.
	 */
	debug("Reserving %dk for malloc(): [%08lx, %08lx)\n",
			misc_param.malloc_len >> 10, addr,
			addr + misc_param.malloc_len);
	addr_malloc = addr;
	addr += misc_param.malloc_len;

	/* Reserve memory for boot params.
	 */
	bd->bi_boot_params = addr;
	debug("Reserving %dk for boot params(): [%08lx, %08lx)\n",
			CONFIG_SYS_BOOTPARAMS_LEN >> 10,
			addr, addr + CONFIG_SYS_BOOTPARAMS_LEN);
	/* addr += CONFIG_SYS_BOOTPARAMS_LEN; */

	/*
	 * Finally, we set up a new (bigger) stack.
	 *
	 * Leave some safety gap for SP, force alignment on 16 byte boundary
	 * Clear initial stack frame
	 */
#if 0
	addr_sp -= 16;
	addr_sp &= ~0xF;
	s = (ulong *)addr_sp;
	*s-- = 0;
	*s-- = 0;
	addr_sp = (ulong)s;
#endif
	debug("Stack Pointer at: %08x\n",
			CONFIG_SYS_SDRAM_BASE + CONFIG_SYS_INIT_SP_OFFSET);

	/*
	 * Save local variables to board info struct
	 */
	bd->bi_memstart	= CONFIG_SYS_SDRAM_BASE;	/* start of DRAM */
	bd->bi_memsize	= gd->ram_size;		/* size of DRAM in bytes */
	bd->bi_baudrate	= gd->baudrate;		/* Console Baudrate */

	gd->flags |= GD_FLG_RELOC;	/* tell others: relocation done */

	serial_initialize();

	debug("Now running bottom half, api_addr: %lx\n", api_addr);

	gd->reloc_off = 0;

	monitor_flash_len = image_copy_end() - CONFIG_SYS_MONITOR_BASE;
	/* debug("image_copy_end: %08lx, monitor_flash_len: %08lx\n",
			image_copy_end(), monitor_flash_len); */

	mem_malloc_init(addr_malloc, misc_param.malloc_len);

//	run_initcall_level(init_sequence_r_stage0, (gd_t *)gd);
//	run_initcall_level(init_sequence_r_stage1, (gd_t *)gd);
	run_initcall_level(init_sequence_r_stage2, (gd_t *)gd);
	run_initcall_level(init_sequence_r_stage3, (gd_t *)gd);

	/* Initialize from environment */
	load_addr = getenv_ulong("loadaddr", 16, load_addr);
	debug("load_addr: %08lx\n", load_addr);

#ifndef CONFIG_JZ47XX_SLPT
	gd->have_console = 1;
	/* main_loop() can return to retry autoboot, if so just run it again. */
	for (;;)
		main_loop();
#else
	slpt_initcall_onetime();
#endif

#ifdef CONFIG_SLPT_DEBUG
	gd->have_console = 1;
#endif
	return 0;
	/* NOTREACHED - no way out of command loop except booting */
}
Exemple #2
0
void board_init_f(ulong bootflag)
{
	gd_t gd_data, *id;
	bd_t *bd;
	init_fnc_t **init_fnc_ptr;
	ulong addr, addr_sp, len;
	ulong *s;

	/* Pointer is writable since we allocated a register for it.
	 */
	gd = &gd_data;
	/* compiler optimization barrier needed for GCC >= 3.4 */
	__asm__ __volatile__("" : : : "memory");

	memset((void *)gd, 0, sizeof(gd_t));

	for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
		if ((*init_fnc_ptr)() != 0)
			hang();
	}

	/*
	 * Now that we have DRAM mapped and working, we can
	 * relocate the code and continue running from DRAM.
	 */
	addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;

	/* We can reserve some RAM "on top" here.
	 */

	/* round down to next 4 kB limit.
	 */
	addr &= ~(4096 - 1);
	debug("Top of RAM usable for U-Boot at: %08lx\n", addr);

	/* Reserve memory for U-Boot code, data & bss
	 * round down to next 16 kB limit
	 */
	len = bss_end() - CONFIG_SYS_MONITOR_BASE;
	addr -= len;
	addr &= ~(16 * 1024 - 1);

	debug("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);

	 /* Reserve memory for malloc() arena.
	 */
	addr_sp = addr - TOTAL_MALLOC_LEN;
	debug("Reserving %dk for malloc() at: %08lx\n",
			TOTAL_MALLOC_LEN >> 10, addr_sp);

	/*
	 * (permanently) allocate a Board Info struct
	 * and a permanent copy of the "global" data
	 */
	addr_sp -= sizeof(bd_t);
	bd = (bd_t *)addr_sp;
	gd->bd = bd;
	debug("Reserving %zu Bytes for Board Info at: %08lx\n",
			sizeof(bd_t), addr_sp);

	addr_sp -= sizeof(gd_t);
	id = (gd_t *)addr_sp;
	debug("Reserving %zu Bytes for Global Data at: %08lx\n",
			sizeof(gd_t), addr_sp);

	/* Reserve memory for boot params.
	 */
	addr_sp -= CONFIG_SYS_BOOTPARAMS_LEN;
	bd->bi_boot_params = addr_sp;
	debug("Reserving %dk for boot params() at: %08lx\n",
			CONFIG_SYS_BOOTPARAMS_LEN >> 10, addr_sp);

	/*
	 * Finally, we set up a new (bigger) stack.
	 *
	 * Leave some safety gap for SP, force alignment on 16 byte boundary
	 * Clear initial stack frame
	 */
	addr_sp -= 16;
	addr_sp &= ~0xF;
	s = (ulong *)addr_sp;
	*s-- = 0;
	*s-- = 0;
	addr_sp = (ulong)s;
	debug("Stack Pointer at: %08lx\n", addr_sp);

	/*
	 * Save local variables to board info struct
	 */
	bd->bi_memstart	= CONFIG_SYS_SDRAM_BASE;	/* start of DRAM */
	bd->bi_memsize	= gd->ram_size;		/* size of DRAM in bytes */

	memcpy(id, (void *)gd, sizeof(gd_t));

	relocate_code(addr_sp, id, addr);

	/* NOTREACHED - relocate_code() does not return */
}