static int get_bootloader_message_block(bootloader_message* out, const Volume* v) { wait_for_device(v->blk_device); FILE* f = fopen(v->blk_device, "rb"); if (f == nullptr) { LOGE("failed to open \"%s\": %s\n", v->blk_device, strerror(errno)); return -1; } #ifdef BOARD_RECOVERY_BLDRMSG_OFFSET fseek(f, BOARD_RECOVERY_BLDRMSG_OFFSET, SEEK_SET); #endif bootloader_message temp; int count = fread(&temp, sizeof(temp), 1, f); if (count != 1) { LOGE("failed to read \"%s\": %s\n", v->blk_device, strerror(errno)); return -1; } if (fclose(f) != 0) { LOGE("failed to close \"%s\": %s\n", v->blk_device, strerror(errno)); return -1; } memcpy(out, &temp, sizeof(temp)); return 0; }
static int set_bootloader_message_block(const bootloader_message* in, const Volume* v) { wait_for_device(v->blk_device); int fd = open(v->blk_device, O_WRONLY | O_SYNC); if (fd == -1) { LOGE("failed to open \"%s\": %s\n", v->blk_device, strerror(errno)); return -1; } #ifdef BOARD_RECOVERY_BLDRMSG_OFFSET lseek(fd, BOARD_RECOVERY_BLDRMSG_OFFSET, SEEK_SET); #endif size_t written = 0; const uint8_t* start = reinterpret_cast<const uint8_t*>(in); size_t total = sizeof(*in); while (written < total) { ssize_t wrote = TEMP_FAILURE_RETRY(write(fd, start + written, total - written)); if (wrote == -1) { LOGE("failed to write some bytes: %s\n", strerror(errno)); close(fd); return -1; } written += wrote; } if (fsync(fd) == -1) { LOGE("failed to fsync \"%s\": %s\n", v->blk_device, strerror(errno)); close(fd); return -1; } close(fd); return 0; }
static int set_bootloader_message_block(const bootloader_message* in, const Volume* v) { wait_for_device(v->blk_device); unique_fd fd(open(v->blk_device, O_WRONLY | O_SYNC)); if (fd.get() == -1) { LOGE("failed to open \"%s\": %s\n", v->blk_device, strerror(errno)); return -1; } size_t written = 0; const uint8_t* start = reinterpret_cast<const uint8_t*>(in); size_t total = sizeof(*in); while (written < total) { ssize_t wrote = TEMP_FAILURE_RETRY(write(fd.get(), start + written, total - written)); if (wrote == -1) { LOGE("failed to write %" PRId64 " bytes: %s\n", static_cast<off64_t>(written), strerror(errno)); return -1; } written += wrote; } if (fsync(fd.get()) == -1) { LOGE("failed to fsync \"%s\": %s\n", v->blk_device, strerror(errno)); return -1; } return 0; }
int reset_fota_cookie_mmc(void) { int count = 0; Volume* v = volume_for_path("/FOTA"); if (v == NULL) { LOGE("Cannot load volume /FOTA\n"); return -1; } wait_for_device(v->device); int fd = open(v->device, O_RDWR|O_SYNC); if (fd < 0) { LOGE("Can't open %s\n(%s)\n", v->device, strerror(errno)); return -1; } char data[512]; memset(data, 0x0, sizeof(data)); count = write(fd,(char *)data,512); if (count <= 0) { LOGE("Failed writing %s\n(%s)\n", v->device, strerror(errno)); return -1; } if (close(fd) != 0) { LOGE("Failed closing %s\n(%s)\n", v->device, strerror(errno)); return -1; } return 0; }
static int set_bootloader_message_block(const struct bootloader_message *in, const Volume* v) { wait_for_device(v->blk_device); #if TARGET_BOARD_PLATFORM == rockchip FILE* f = fopen(v->blk_device, "wb+"); #else FILE* f = fopen(v->blk_device, "wb"); #endif if (f == NULL) { LOGE("Can't open %s\n(%s)\n", v->blk_device, strerror(errno)); return -1; } #if TARGET_BOARD_PLATFORM == rockchip int count = rk29_fwrite(in, sizeof(*in), 1, f); #else int count = fwrite(in, sizeof(*in), 1, f); #endif if (count != 1) { LOGE("Failed writing %s\n(%s)\n", v->blk_device, strerror(errno)); return -1; } if (fclose(f) != 0) { LOGE("Failed closing %s\n(%s)\n", v->blk_device, strerror(errno)); return -1; } return 0; }
static int get_bootloader_message_block(struct bootloader_message *out, const Volume* v) { wait_for_device(v->blk_device); FILE* f = fopen(v->blk_device, "rb"); if (f == NULL) { LOGE("Can't open %s\n(%s)\n", v->blk_device, strerror(errno)); return -1; } struct bootloader_message temp; #if TARGET_BOARD_PLATFORM == rockchip int count = rk29_fread(&temp, sizeof(temp), 1, f); #else int count = fread(&temp, sizeof(temp), 1, f); #endif if (count != 1) { LOGE("Failed reading %s\n(%s)\n", v->blk_device, strerror(errno)); return -1; } if (fclose(f) != 0) { LOGE("Failed closing %s\n(%s)\n", v->blk_device, strerror(errno)); return -1; } memcpy(out, &temp, sizeof(temp)); return 0; }
static int set_bootloader_message_block(const struct bootloader_message *in, const Volume* v) { wait_for_device(v->device); FILE* f = fopen(v->device, "wb"); if (f == NULL) { LOGE("Can't open %s\n(%s)\n", v->device, strerror(errno)); return -1; } if (fseek(f, RECOVERY_FLAG_BLOCK * 512, 0)) { LOGE("Failed seek %s\n(%s)\n",v->device, strerror(errno)); return -1; } int count = fwrite(in, sizeof(*in), 1, f); if (count != 1) { LOGE("Failed writing %s\n(%s)\n", v->device, strerror(errno)); return -1; } if (fclose(f) != 0) { LOGE("Failed closing %s\n(%s)\n", v->device, strerror(errno)); return -1; } return 0; }
static int get_bootloader_message_block(struct bootloader_message *out, const Volume* v) { wait_for_device(v->device); FILE* f = fopen(v->device, "rb"); if (f == NULL) { LOGE("Can't open %s\n(%s)\n", v->device, strerror(errno)); return -1; } struct bootloader_message temp; if (fseek(f, RECOVERY_FLAG_BLOCK * 512, 0)) { LOGE("Failed seek %s\n(%s)\n",v->device, strerror(errno)); return -1; } int count = fread(&temp, sizeof(temp), 1, f); if (count != 1) { LOGE("Failed reading %s\n(%s)\n", v->device, strerror(errno)); return -1; } if (fclose(f) != 0) { LOGE("Failed closing %s\n(%s)\n", v->device, strerror(errno)); return -1; } memcpy(out, &temp, sizeof(temp)); return 0; }
int set_bootloader_message_block_name(const struct bootloader_message *in, const char* block_name) { wait_for_device(block_name); FILE* f = fopen(block_name, "wb"); if (f == NULL) { printf("Can't open %s\n(%s)\n", block_name, strerror(errno)); return -1; } int count = fwrite(in, sizeof(*in), 1, f); if (count != 1) { printf("Failed writing %s\n(%s)\n", block_name, strerror(errno)); return -1; } if (fclose(f) != 0) { printf("Failed closing %s\n(%s)\n", block_name, strerror(errno)); return -1; } return 0; }
int ImgCap_V4L2::grabImageToPPM(const char * fileName) { /* 1. wait on device 2. read the device */ fd_set fds; while(true) { struct timeval tv; int r; FD_ZERO(&fds); //cn/im: adds a file descriptor to a file descriptor set FD_SET(r_fd, &fds); tv.tv_sec = 1; tv.tv_usec = 0; //check for readability r = select(r_fd+1, &fds, NULL, NULL, &tv); //these check to see if a camera is connected, if one isn't after one second it throws a connection timeout if (-1 == r) { if (EINTR == errno) continue; if(ImgCap_V4L2::verboseErrorPrinting) std::cerr << "select" <<std::endl; return 1; } if (0 == r) { if(ImgCap_V4L2::verboseErrorPrinting) std::cerr << "Master select timeout" << std::endl; return 2; } break; } wait_for_device(&r_fd, "right"); read_frame(&r_fd, &r_buf); save_frames(fileName); return 0; }
//return a captured image - from wait_and_read_devices void ImgCap_V4L2::grabImageToFile() { /* 1. wait on both devices 2. read the device that was ready first 3. wait on the second device 4. read the second device */ fd_set fds; while(true) { struct timeval tv; int r; FD_ZERO(&fds); //cn/im: adds a file descriptor to a file descriptor set FD_SET(r_fd, &fds); tv.tv_sec = 1; tv.tv_usec = 0; r = select(r_fd+1, &fds, NULL, NULL, &tv); //cn/im: select() is a socket function which monitors a list of file descriptors for readability,so here we have (point to array of file descriptors, number of file descriptors checked, don't check for writeable, no files are checked for exceptions thrown, and a timeout value) //these check to see if a camera is connected, if one isn't after one second it throws a connection timeout if (-1 == r) { if (EINTR == errno) continue; std::cerr << "select" << std::endl; //errno_exit ("select"); } if (0 == r) { std::cerr<< "Master select timeout" << std::endl; exit (EXIT_FAILURE); } break; } wait_for_device(&r_fd, "right"); read_frame(&r_fd, &r_buf); save_frames(); }
int get_bootloader_message_block_name(struct bootloader_message *out) { wait_for_device(device_name); FILE* f = fopen(device_name, "rb"); if (f == NULL) { LOGE("Can't open %s\n(%s)\n", device_name, strerror(errno)); return -1; } struct bootloader_message temp; int count = fread(&temp, sizeof(temp), 1, f); if (count != 1) { LOGE("Failed reading %s\n(%s)\n", device_name, strerror(errno)); return -1; } if (fclose(f) != 0) { LOGE("Failed closing %s\n(%s)\n", device_name, strerror(errno)); return -1; } memcpy(out, &temp, sizeof(temp)); return 0; }
static int get_bootloader_message_block(bootloader_message* out, const Volume* v) { wait_for_device(v->blk_device); FILE* f = fopen(v->blk_device, "rb"); if (f == nullptr) { LOGE("failed to open \"%s\": %s\n", v->blk_device, strerror(errno)); return -1; } bootloader_message temp; int count = fread(&temp, sizeof(temp), 1, f); if (count != 1) { LOGE("failed to read \"%s\": %s\n", v->blk_device, strerror(errno)); return -1; } if (fclose(f) != 0) { LOGE("failed to close \"%s\": %s\n", v->blk_device, strerror(errno)); return -1; } memcpy(out, &temp, sizeof(temp)); return 0; }
static int set_bootloader_message_block(const struct bootloader_message *in, const Volume* v) { wait_for_device(v->blk_device); FILE* f = fopen(v->blk_device, "rb+"); if (f == NULL) { LOGE("Can't open %s\n(%s)\n", v->blk_device, strerror(errno)); return -1; } #ifdef BOARD_RECOVERY_BLDRMSG_OFFSET fseek(f, BOARD_RECOVERY_BLDRMSG_OFFSET, SEEK_SET); #endif int count = fwrite(in, sizeof(*in), 1, f); if (count != 1) { LOGE("Failed writing %s\n(%s)\n", v->blk_device, strerror(errno)); return -1; } if (fclose(f) != 0) { LOGE("Failed closing %s\n(%s)\n", v->blk_device, strerror(errno)); return -1; } return 0; }
static int get_bootloader_message_block(struct bootloader_message *out, const Volume* v) { wait_for_device(v->blk_device); FILE* f = fopen(v->blk_device, "rb"); if (f == NULL) { LOGE("Can't open %s\n(%s)\n", v->blk_device, strerror(errno)); return -1; } #ifdef BOARD_RECOVERY_BLDRMSG_OFFSET fseek(f, BOARD_RECOVERY_BLDRMSG_OFFSET, SEEK_SET); #endif struct bootloader_message temp; int count = fread(&temp, sizeof(temp), 1, f); if (count != 1) { LOGE("Failed reading %s\n(%s)\n", v->blk_device, strerror(errno)); return -1; } if (fclose(f) != 0) { LOGE("Failed closing %s\n(%s)\n", v->blk_device, strerror(errno)); return -1; } memcpy(out, &temp, sizeof(temp)); return 0; }