static void associate_stdin_handler(struct serial_binding *b) { SERIAL_DEBUG("associate_stdin called on basic interface\n"); terminal = b; set_new_input_consumer(basic_serial_input); // try to send something, if we have it ready if (inbuf[ninbuf].buf != NULL) { tx_handler(b); } }
static errval_t connect_cb(void *st, struct serial_binding *b) { SERIAL_DEBUG("Client connected to basic interface.\n"); b->rx_vtbl = serial_rx_vtbl; terminal = b; set_new_input_consumer(basic_serial_input); // try to send something, if we have it ready if (inbuf[ninbuf].buf != NULL) { tx_handler(b); } return SYS_ERR_OK; }
static void basic_serial_input(char *data, size_t length) { if (inbuf[ninbuf].buf == NULL) { // allocate a buffer inbuf[ninbuf].buf = malloc(length); assert(inbuf[ninbuf].buf != NULL); memcpy(inbuf[ninbuf].buf, data, length); inbuf[ninbuf].len = length; } else { // append new data to existing buffer inbuf[ninbuf].buf = realloc(inbuf[ninbuf].buf, inbuf[ninbuf].len + length); assert(inbuf[ninbuf].buf != NULL); memcpy(inbuf[ninbuf].buf + inbuf[ninbuf].len, data, length); inbuf[ninbuf].len += length; } // try to send something, if we're not already doing so if (terminal != NULL && inbuf[!ninbuf].buf == NULL) { tx_handler(terminal); } }
int do_fastboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { int ret = 1; char fbparts[4096], *env; int check_timeout = 0; uint64_t timeout_endtime = 0; uint64_t timeout_ticks = 0; long timeout_seconds = -1; int continue_from_disconnect = 0; /* * Place the runtime partitions at the end of the * static paritions. First save the start off so * it can be saved from run to run. */ if (static_pcount >= 0) { /* Reset */ pcount = static_pcount; } else { /* Save */ static_pcount = pcount; } env = getenv("fbparts"); if (env) { unsigned int len; len = strlen(env); if (len && len < 4096) { char *s, *e; memcpy(&fbparts[0], env, len + 1); printf("Fastboot: Adding partitions from environment\n"); s = &fbparts[0]; e = s + len; while (s < e) { if (add_partition_from_environment(s, &s)) { printf("Error:Fastboot: Abort adding partitions\n"); /* reset back to static */ pcount = static_pcount; break; } /* Skip a bunch of delimiters */ while (s < e) { if ((' ' == *s) || ('\t' == *s) || ('\n' == *s) || ('\r' == *s) || (',' == *s)) { s++; } else { break; } } } } } /* Time out */ if (2 == argc) { long try_seconds; char *try_seconds_end; /* Check for timeout */ try_seconds = simple_strtol(argv[1], &try_seconds_end, 10); if ((try_seconds_end != argv[1]) && (try_seconds >= 0)) { check_timeout = 1; timeout_seconds = try_seconds; printf("Fastboot inactivity timeout %ld seconds\n", timeout_seconds); } } if (1 == check_timeout) { timeout_ticks = (uint64_t) (timeout_seconds * get_tbclk()); } do { continue_from_disconnect = 0; /* Initialize the board specific support */ if (0 == fastboot_init(&interface)) { int poll_status; /* If we got this far, we are a success */ ret = 0; printf("fastboot initialized\n"); timeout_endtime = get_ticks(); timeout_endtime += timeout_ticks; while (1) { uint64_t current_time = 0; poll_status = fastboot_poll(); if (1 == check_timeout) current_time = get_ticks(); if (FASTBOOT_ERROR == poll_status) { /* Error */ break; } else if (FASTBOOT_DISCONNECT == poll_status) { /* beak, cleanup and re-init */ printf("Fastboot disconnect detected\n"); continue_from_disconnect = 1; break; } else if ((1 == check_timeout) && (FASTBOOT_INACTIVE == poll_status)) { /* No activity */ if (current_time >= timeout_endtime) { printf("Fastboot inactivity detected\n"); break; } } else { /* Something happened */ if (1 == check_timeout) { /* Update the timeout endtime */ timeout_endtime = current_time; timeout_endtime += timeout_ticks; } } /* Check if the user wanted to terminate with ^C */ if ((FASTBOOT_INACTIVE == poll_status) && (ctrlc())) { printf("Fastboot ended by user\n"); break; } /* * Check if the fastboot client wanted to * continue booting */ if (continue_booting) { printf("Fastboot ended by client\n"); break; } /* Check if there is something to upload */ tx_handler(); } } /* Reset the board specific support */ fastboot_shutdown(); /* restart the loop if a disconnect was detected */ } while (continue_from_disconnect); return ret; }