void test_command_with_args() { uint8_t buf[255]; int pos = 0; int rc; uint8_t dest; uint8_t code; uint16_t mref; rc = encode_cmd(buf, &pos, LS1P_ADDR_ARM, LS1P_REQ_CODE_CMDLOG, 314); assert(rc == LS1P_API_OK); assert(pos == 3); assert(buf[0] == 0x01); rc = encode_uint8(buf, &pos, 123); assert(rc == LS1P_API_OK); assert(pos == 4); rc = encode_uint16(buf, &pos, 4023); assert(rc == LS1P_API_OK); assert(pos == 6); assert(buf[0] == 0x01); assert(buf[1] == 0x01); assert(buf[2] == 0x3A); assert(buf[3] == 0x7B); assert(buf[4] == 0x0F); assert(buf[5] == 0xB7); rc = decode_cmd(buf, &pos, &dest, &code, &mref); assert(rc == LS1P_API_OK); assert(dest == LS1P_ADDR_ARM); assert(code == LS1P_REQ_CODE_CMDLOG); assert(mref == 314); assert(pos == 3); }
extern "C" DECLEXPORT(int) TrustedMain (int argc, char **argv, char **envp) { if (decode_cmd(argc, argv)) { Usage(); return 0; } return VirtualMonitorMain(cmdParam); }
int main(int argc, char *argv[]){ void * data; int retval = -1; int max_fd = -1; int i=1; virtual_cmd_t cmd={0,0}; int rc=1; //get a tab of fd_set same sizo of hardware size fd_set rfds_in; // //call all hardware load function init_hardware(data); // //wake dad all stuff are good while(write(1, &cmd, sizeof(virtual_cmd_t)) != sizeof(virtual_cmd_t)) ; while(read(0, &cmd, sizeof(virtual_cmd_t)) != sizeof(virtual_cmd_t)) ; // while(1) { FD_ZERO(&rfds_in); max_fd = set_watch_fd(&rfds_in) + 1; // retval = select(max_fd, &rfds_in, NULL, NULL, NULL); //because of interrupt system call if(retval<=0) { DEBUG_TRACE("\n--\n"); continue; } //test descriptors which have move else if(retval>0) { //pipe descriptor if(FD_ISSET(0, &rfds_in)) { //read command and exectute it while(read(0, (void *)&cmd, sizeof(virtual_cmd_t)) != sizeof(virtual_cmd_t)) ; //decode cmd decode_cmd(&cmd); } //hardware descriptor for(i=1; i<RFDS_SIZE; i++) { if(hdwr_lst[i]->fd<0) continue; //fprintf(stderr, "fd:%d-hdwr_id:%d\n", hdwr_lst[i]->fd, i); // if(FD_ISSET(hdwr_lst[i]->fd, &rfds_in)) { //fprintf(stderr, "fd:%d-hdwr_id:%d\tNB_SIG(R/W):%d\n", hdwr_lst[i]->fd, i, ++nb_sig); hdwr_lst[i]->read(NULL); } } } } // return 0; }
static int i2c_update_firmware(void) { char *buf; char *p; //record a cmd start char *q; //record a cmd end struct file *filp; struct inode *inode = NULL; mm_segment_t oldfs; int length; int i; int ret; const char filename[]="/system/touch/touchscreen_upgrade.txt"; /* open file */ oldfs = get_fs(); set_fs(KERNEL_DS); filp = filp_open(filename, O_RDONLY, S_IRUSR); if (IS_ERR(filp)) { printk("%s: file %s filp_open error\n", __FUNCTION__,filename); set_fs(oldfs); return -1; } if (!filp->f_op) { printk("%s: File Operation Method Error\n", __FUNCTION__); filp_close(filp, NULL); set_fs(oldfs); return -1; } inode = filp->f_path.dentry->d_inode; if (!inode) { printk("%s: Get inode from filp failed\n", __FUNCTION__); filp_close(filp, NULL); set_fs(oldfs); return -1; } printk("%s file offset opsition: %u\n", __FUNCTION__, (unsigned)filp->f_pos); /* file's size */ length = i_size_read(inode->i_mapping->host); printk("%s: length=%d\n", __FUNCTION__, length); /* allocation buff size */ buf = kmalloc((length+1), GFP_KERNEL); if (!buf) { printk("alloctation memory failed\n"); return -1; } buf[length]= '\0'; /* read data */ if (filp->f_op->read(filp, buf, length, &filp->f_pos)!=length) { printk("%s: file read error\n", __FUNCTION__); filp_close(filp, NULL); set_fs(oldfs); return -1; } p=buf; q=p+1; i=1; do{ while( (*q != 'w') && i < length) { q++; } ret = decode_cmd(p,q-1); //decode i2c commd from update file if (ret == -2) /*flash error */ goto out; else if (ret == 1) { //last cmd success ret = 0; break; } p = q; q = p+1; i++; }while( i < length); // file end flag #if 0 mdelay(1000); ret = i2c_smbus_read_byte_data(g_client,0x01); printk("ret2=%x\n",ret); if (ret == 0xf0) { /*cksum right */ ret = sys_unlink(filename); /*delete firmware name*/ printk("ret3=%d\n",ret); ret = 0; } else ret = -2; #endif out: filp_close(filp, NULL); set_fs(oldfs); kfree(buf); return ret; }