Пример #1
0
void init_hw(){
	boot_event(BOOT_EVENT_INIT_CLOCK, 0);
	mcu_core_initclock(1);

#if defined DEBUG_BOOTLOADER
	if( mcu_debug_init() < 0 ){
		sos_led_root_error(0);
	}

	dsetmode(0);
	dsetwritefunc(debug_write_func);

	dstr("STACK:"); dhex((u32)stack_ptr); dstr("\n");
	dstr("APP:"); dhex((u32)app_reset); dstr("\n");
#endif
	cortexm_delay_ms(50);
	cortexm_enable_interrupts(); //Enable the interrupts
	boot_event(BOOT_EVENT_INIT, 0);
}
Пример #2
0
void link_cmd_ioctl(link_data_t * args){
	int err;
	int size;
	size = _IOCTL_SIZE(args->op.ioctl.request);
	bootloader_attr_t attr;
	bootloader_writepage_t wattr;

	dstr("IOCTL REQ: "); dhex(args->op.ioctl.request); dstr("\n");

	switch(args->op.ioctl.request){
	case I_BOOTLOADER_ERASE:
		//the erase takes awhile -- so send the reply a little early
		link_protocol_slavewrite(phy_handle, &args->reply, sizeof(args->reply), NULL, NULL);
		args->op.cmd = 0;

		erase_flash();
		is_erased = true;
		return;
	case I_BOOTLOADER_GETATTR:
		//write data to io_buf
		attr.version = BCDVERSION;
		_hwpl_core_getserialno(attr.serialno);

		err = link_protocol_slavewrite(phy_handle, &attr, size, NULL, NULL);
		if ( err == -1 ){
			args->op.cmd = 0;
			args->reply.err = -1;
		}

		attr.startaddr = PROGRAM_START_ADDR;
		break;
	case I_BOOTLOADER_RESET:
		if( args->op.ioctl.arg == 0 ){
			link_cmd_reset(args);
		} else {
			link_cmd_reset_bootloader(args);
		}
		break;
	case I_BOOTLOADER_WRITEPAGE:

#ifdef __SECURE
		//decrypt incoming data

#endif

		err = link_protocol_slaveread(phy_handle, &wattr, size, NULL, NULL);
		if( err < 0 ){
			dstr("failed to read data\n");
			break;
		}

		args->reply.err = flash_writepage(FLASH_PORT, (flash_writepage_t*)&wattr);
		if( args->reply.err < 0 ){
			dstr("Failed to write flash\n");
		}

		break;
	default:
		args->reply.err_number = EINVAL;
		args->reply.err = -1;
		break;
	}

	if ( args->reply.err < 0 ){
		args->reply.err_number = errno;
	}

}