static int do_format(void) { struct ptable *ptbl = &the_ptable; unsigned next; int n; block_dev_desc_t *dev_desc; unsigned long blocks_to_write, result; dev_desc = get_dev_by_name(FASTBOOT_BLKDEV); if (!dev_desc) { printf("error getting device %s\n", FASTBOOT_BLKDEV); return -1; } if (!dev_desc->lba) { printf("device %s has no space\n", FASTBOOT_BLKDEV); return -1; } printf("blocks %lu\n", dev_desc->lba); start_ptbl(ptbl, dev_desc->lba); for (n = 0, next = 0; fbt_partitions[n].name; n++) { u64 sz = fbt_partitions[n].size_kb * 2; if (fbt_partitions[n].name[0] == '-') { next += sz; continue; } if (sz == 0) sz = dev_desc->lba - next; if (add_ptn(ptbl, next, next + sz - 1, fbt_partitions[n].name)) return -1; next += sz; } end_ptbl(ptbl); blocks_to_write = DIV_ROUND_UP(sizeof(struct ptable), dev_desc->blksz); #if defined(CONFIG_MACH_MESON8_ODROIDC) /* Since the bootloader is located on MBR, the board partition must be * stored in other sector. In ODROIDC, it is just after bootloader. * <start sector> = <bootloader size (kB) / 512 */ result = dev_desc->block_write(dev_desc->dev, CONFIG_CUSTOM_MBR_LBA, blocks_to_write, ptbl); #else result = dev_desc->block_write(dev_desc->dev, 0, blocks_to_write, ptbl); #endif if (result != blocks_to_write) { printf("\nFormat failed, block_write()" " returned %lu instead of %lu\n", result, blocks_to_write); return -1; } printf("\nnew partition table of %lu %lu-byte blocks\n", blocks_to_write, dev_desc->blksz); fbt_reset_ptn(); return 0; }
void * socket_uart_send_manager(void * arg) { int listen_fd = open_server_socket(UNIX_SOCKET_UART_SEND); int com_fd; socklen_t len; struct sockaddr_un clt_addr; pthread_t real_send; pthread_create(&real_send, NULL, uart_send_worker, NULL); while(1) { len = sizeof(clt_addr); com_fd = accept(listen_fd,(struct sockaddr*)&clt_addr,&len); if(com_fd < 0) { perror("cannot accept client connect request"); close(listen_fd); unlink(UNIX_SOCKET_UART_SEND); exit(-1); } int n = 0; uint8_t recv_buf[MAX_BUFSIZ]; if( (n = read(com_fd,recv_buf,sizeof(recv_buf))) < 0) { LOG_ERROR("[%s] Read Error\n",__func__); exit(-1); } LOG_DEBUG("I read a request message, the request is: %s",recv_buf); if(is_invalid_message((char *)recv_buf, n)) { LOG_ERROR("InvalidMessage"); process_message_invalid_message(com_fd); close(com_fd); } else { message_t * message = deserialized_message(recv_buf,n); uart_dev_t * dev = get_dev_by_name(message->name); if(dev == NULL) { LOG_ERROR("InvalidName"); process_message_invalid_name(com_fd, message->name); close(com_fd); } else { LOG_DEBUG("ValidMessage"); message->dev = dev; queue_enqueue(context->send_queue, message); process_message_succeed(com_fd); close(com_fd); } } } return NULL; }
/*Mount a FS*/ void mount(int i) { char *args = ( char *)i; struct device *device ; int nr = 0; char output[MAX_PATH+1],*ptr,*str; char pathname[MAX_PATH+1]; int dev_number=-1; /*max 3 args*/ char *argv[3] = { NULL,FAT12_NAME,NULL }; if(! args ) { out_usage: printf("usage: mount mountpoint FS DEVICE\n"); goto out; } /*get the args: mountpoint,FS,devicename*/ strncpy(output,args,sizeof(output)-1); ptr = output; while(ptr && *ptr) { /*skip leading spaces*/ while(*ptr && isspace(*ptr) ) ++ptr; if( ! *ptr ) break; if( nr >= 3 ) { goto out_usage; } str = strchr(ptr,' '); if(str) { *str++ = 0; } /*store the arg*/ argv[nr++] = ptr; ptr = str; } if(!argv[0] ) { printf("No mount point specified...\n"); goto out_usage; } if(! argv[2] ) { dev_number = MKDEV(FDC_BLKDEV_MAJOR_NR,0); } else { device = get_dev_by_name(argv[2]); if(!device) { printf("Device %s not found...\n",argv[2]); goto out; } dev_number = device->dev; } trim_file_separator(argv[0],pathname,sizeof(pathname)-1); /*Special check for MOUNTS of / via shell.Not allowed*/ if(!strcmp(pathname,FILE_SEPARATOR_STR) ) { printf("cannot mount already mounted \"%s\", again as it cannot be unmounted...\n",FILE_SEPARATOR_STR); goto out; } vfs_mount(pathname,argv[1],dev_number); out:; }
int data_transfer_name(const char *dev_name,int block,int size,unsigned char *data,int cmd) { struct device *device; int err = -1; device = get_dev_by_name(dev_name); if(! device ) { printf("device %s not found in Function %s,Line %d\n",dev_name,__FUNCTION__,__LINE__); goto out; } err = do_data_transfer(device,block,size,data,cmd); out: return err; }
void * socket_uart_recv_manager(void * arg) { int listen_fd = open_server_socket(UNIX_SOCKET_UART_RECV); pthread_t real_recv; int result = pthread_create(&real_recv, NULL, uart_recv_worker, NULL); assert(result == 0); socklen_t len = -1; struct sockaddr_un clt_addr; int com_fd = -1; while(1) { len = sizeof(clt_addr); com_fd = accept(listen_fd,(struct sockaddr*)&clt_addr,&len); if(com_fd < 0) { perror("cannot accept client connect request"); close(listen_fd); unlink(UNIX_SOCKET_UART_SEND); exit(-1); } int n = 0; uint8_t recv_buf[MAX_BUFSIZ]; if( (n = read(com_fd,recv_buf,sizeof(recv_buf))) < 0) { LOG_ERROR("[%s] Read Error\n",__func__); } if(is_invalid_message((char *)recv_buf, n)) { process_message_invalid_message(com_fd); close(com_fd); } else { message_t * message = deserialized_message(recv_buf,n); #if 0 LOG_DEBUG("XXXXXXXXXXXXXXXXXXXXXXXXXXXX"); view_message(message); LOG_DEBUG("____________________________"); #endif uart_dev_t * dev = get_dev_by_name(message->name); if(dev == NULL) { process_message_invalid_name(com_fd, message->name); close(com_fd); } else { struct timeval now; gettimeofday(&now,NULL); message_t * fit = NULL; socket_recv_handler * process_socket_recv = get_socket_recv_handler_by_protocol(dev->protocol); process_socket_recv->func(dev, message, &fit); if((fit == NULL)) { process_message_not_fit(com_fd); } else if((now.tv_sec - fit->stamp.tv_sec) > 10) { free_message(fit); process_message_not_fit(com_fd); } else { process_message_fitted(com_fd, fit); } free_message(message); close(com_fd); } } } return NULL; }
static switch_status_t portaudio_stream_file_open(switch_file_handle_t *handle, const char *path) { portaudio_stream_context_t *context; portaudio_stream_source_t *source; switch_memory_pool_t *pool; switch_status_t status = SWITCH_STATUS_FALSE; switch_thread_t *thread; switch_threadattr_t *thd_attr = NULL; uint32_t rate = PREFERRED_RATE; char *npath; int devNumber; int tmp; handle->pre_buffer_datalen = 0; if (switch_test_flag(handle, SWITCH_FILE_FLAG_WRITE)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This format does not support writing! (yet)\n"); return status; } npath = switch_core_strdup(module_pool, path); tmp = handle->samplerate; if (tmp == 8000 || tmp == 16000 || tmp == 32000 || tmp == 48000) { rate = tmp; } if (*path == '#') { devNumber = get_dev_by_number(npath + 1, 1); } else { devNumber = get_dev_by_name(npath, 1); } npath = switch_mprintf("device-%d at %d", devNumber, rate); switch_mutex_lock(globals.mutex); source = switch_core_hash_find(globals.source_hash, npath); /* dev isnt there, try to start thread */ if (!source) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, " source isnt Created, create and start thread!\n"); if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, " :S no pool\n"); } else { source = switch_core_alloc(pool, sizeof(*source)); if (source != NULL) { source->pool = pool; source->sourcedev = devNumber; source->sourcename = switch_core_strdup(source->pool, npath); source->rate = rate; source->interval = 20; source->channels = 1; source->timer_name = "soft"; source->prebuf = DEFAULT_PREBUFFER_SIZE; source->stopped = 0; source->ready = 0; source->samples = switch_samples_per_packet(source->rate, source->interval); switch_mutex_init(&source->mutex, SWITCH_MUTEX_NESTED, source->pool); switch_threadattr_create(&thd_attr, source->pool); switch_threadattr_detach_set(thd_attr, 1); switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); switch_thread_create(&thread, thd_attr, read_stream_thread, source, source->pool); } } } switch_mutex_unlock(globals.mutex); switch_yield(1000000); /* dev already engaged */ if (source) { /*wait for source to be ready */ while (source->ready == 0) { switch_yield(100000); } if (switch_thread_rwlock_tryrdlock(source->rwlock) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, " error rwlock !\n"); source = NULL; } } if (source) { status = SWITCH_STATUS_SUCCESS; if ((context = switch_core_alloc(handle->memory_pool, sizeof(*context))) == 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, " error allocating context!\n"); status = SWITCH_STATUS_MEMERR; } else { /* everything goes fine at this point */ handle->samples = 0; handle->samplerate = source->rate; handle->channels = 1; handle->format = 0; handle->sections = 0; handle->seekable = 0; handle->speed = 0; handle->private_info = context; handle->interval = source->interval; switch_mutex_init(&context->audio_mutex, SWITCH_MUTEX_NESTED, handle->memory_pool); if (switch_buffer_create_dynamic(&context->audio_buffer, 512, 1024, 0) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n"); status = SWITCH_STATUS_MEMERR; } else { /* context created... then continue */ context->source = source; context->file = handle->file; context->func = handle->func; context->line = handle->line; context->handle = handle; switch_mutex_lock(source->mutex); context->next = source->context_list; source->context_list = context; source->total++; switch_mutex_unlock(source->mutex); } } } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown source %s\n", path); status = SWITCH_STATUS_FALSE; } return status; }