Exemplo n.º 1
0
extern int _read(int file, char* ptr, int len)
{
    if(file < 3) {
        int i;
        for(i = 0; i < len; i++) {
            *ptr = retarget_getc();
            ptr++;
        }
        return len;
    } else {
        int read_bytes = len;
        int bytes;
        bytes = vm_fs_read(file, ptr, len, &read_bytes);
        LOG("_read(%d, %s, %d, %d) - %d\n", file, ptr, len, read_bytes, bytes);
        return bytes;
    }
}
/* The callback to be invoked by the system engine. */
void handle_sysevt(VMINT message, VMINT param) {
    switch (message) {
    case VM_EVENT_CREATE:
        break;
    case VM_EVENT_PAINT: {
        VMWCHAR path[100];
        VMINT fs = 0;
        VMCHAR flag = 0;
        VMCHAR write = 'a';
        VMINT write_size = 0;
        VMINT ret = 0;
        /* This file is a flag to not update the firmware after the firmware was updated and the board reboots.
           It's to prevent calling the update API in an endless loop. */
        vm_chset_ascii_to_ucs2(path, 100, "c:\\firmware.txt");
        fs = vm_fs_open(path,VM_FS_MODE_READ,FALSE);
        if(fs<0) {
            fs = vm_fs_open(path,VM_FS_MODE_CREATE_ALWAYS_WRITE,FALSE);
        }
        if(fs>=0) {
            vm_fs_read(fs,(void *)&flag,sizeof(VMCHAR),&write_size);
            if(flag==0) {
                vm_fs_seek(fs,0,VM_FS_BASE_BEGINNING);
                vm_fs_write(fs,(void *)&write,sizeof(VMCHAR),&write_size);
            }
            vm_fs_close(fs);
            if(flag=='a') {
                vm_log_info("firmware:have firmware update");
                ret = firmware_read_update_status();
                vm_log_info("firmware:update result = %d ",ret);
                vm_fs_delete(path);
            }
            if(flag==0) {
                vm_log_info("firmware update begin");
                vm_firmware_trigger_update();
                vm_log_info("firmware update end");
                vm_pwr_reboot();
            }
        }
    }
    break;
    default:
        break;
    }
}
Exemplo n.º 3
0
VMBOOL read_conf_string(VMSTR variable_name, VMSTR output_buffer, VMUINT output_buffer_size) {
	VMINT res;
	VMUINT conf_size;
	VMUINT bytes_read;
	VMSTR conf_data;
	VMSTR key;
	VMSTR value;
	VMBOOL result_string_valid = FALSE;

	if (conf_handle_valid)
	{
		res = vm_fs_get_size(conf_handle, &conf_size);
		if (VM_IS_SUCCEEDED(res))
		{
			conf_data = vm_calloc(conf_size + strlen(conf_defaults) + 1);
			if (conf_data != NULL)
			{
				vm_fs_seek(conf_handle, 0, VM_FS_BASE_BEGINNING);
				res = vm_fs_read(conf_handle, conf_data, conf_size, &bytes_read);
				if (VM_IS_SUCCEEDED(res))
				{
					strcat(conf_data, conf_defaults);
					key = strtok(conf_data, "=");
					while (key != NULL) 
					{
						value = strtok(NULL, "\n");
						if (value != NULL && strcmp(variable_name, key) == 0 && strlen(value) < output_buffer_size)
						{
							strcpy(output_buffer, value);
							result_string_valid = TRUE;
							break;
						}
						key = strtok(NULL, "=");
					} 
				}
				vm_free(conf_data);
			}
		}
	}
	return result_string_valid;
}
VMINT firmware_read_update_status() {
    VMINT fd = -1;
    VMINT32 ret = 1;
    vm_firmware_update_status_t update_info;
    VMWCHAR path[100];
    VMUINT read = 0;
    vm_chset_ascii_to_ucs2(path, 100, "c:\\update_status");
    fd = vm_fs_open(path, VM_FS_MODE_READ,TRUE);
    if (fd >= 0) {
        vm_fs_read(fd, (void *)&update_info, sizeof(update_info), &read);
        if (read == sizeof(update_info)) {
            ret = update_info.error_code;	/* refer to VM_FIRMWARE_UPDATE_RESULT in vmfirmware.h*/
        }
        else {
            ret = 2;	/*incorrect file size */
        }
        vm_fs_close(fd);
    }
    else {
        ret = 1;	/* file could not be found */
    }
    return ret;
}