void images_list() { Image* curImage = imageList; while(curImage != NULL) { print_fourcc(curImage->type); bufferPrintf("(%d/%d): offset: 0x%x, length: 0x%x, padded: 0x%x\r\n", curImage->index, curImage->hashMatch, curImage->offset, curImage->length, curImage->padded); curImage = curImage->next; } }
void images_uninstall(uint32_t _fourcc, uint32_t _unreplace) { ImageDataList* list = NULL; ImageDataList* cur = NULL; ImageDataList* oldImage = NULL; mtd_t *dev = images_device(); if(!dev) return; mtd_prepare(dev); Image* curImage = imageList; while(curImage != NULL) { if(curImage->type != _fourcc) { if(cur == NULL) { list = cur = malloc(sizeof(ImageDataList)); } else { cur->next = malloc(sizeof(ImageDataList)); cur = cur->next; } bufferPrintf("Reading: "); print_fourcc(curImage->type); bufferPrintf(" (%d bytes)\r\n", curImage->padded); cur->type = curImage->type; cur->next = NULL; cur->data = malloc(curImage->padded); mtd_read(dev, cur->data, curImage->offset, curImage->padded); if(_fourcc != _unreplace && cur->type == _unreplace) { oldImage = cur; } } else { bufferPrintf("Skipping: "); print_fourcc(curImage->type); bufferPrintf(" (%d bytes)\r\n", curImage->padded); } curImage = curImage->next; } mtd_finish(dev); if(_fourcc != _unreplace && oldImage == NULL) { bufferPrintf("No openiBoot installation was found.\n"); while(list != NULL) { cur = list; list = list->next; free(cur->data); free(cur); } return; } oldImage->type = _fourcc; images_change_type(oldImage->data, _fourcc); images_rewind(); while(list != NULL) { cur = list; list = list->next; AppleImg3RootHeader* header = (AppleImg3RootHeader*) cur->data; bufferPrintf("Flashing: "); print_fourcc(cur->type); bufferPrintf(" (%x, %d bytes)\r\n", cur->data, header->base.size); images_append(cur->data, header->base.size); free(cur->data); free(cur); } bufferPrintf("Images uninstalled.\r\n"); images_release(); images_setup(); bufferPrintf("Uninstall complete.\r\n"); }
void images_install(void* newData, size_t newDataLen, uint32_t newFourcc, uint32_t replaceFourcc) { ImageDataList* list = NULL; ImageDataList* cur = NULL; ImageDataList* toReplace = NULL; ImageDataList* verify = NULL; int isReplace = (replaceFourcc != newFourcc) ? TRUE : FALSE; int isUpgrade = FALSE; mtd_t *dev = images_device(); if(!dev) return; mtd_prepare(dev); Image* curImage = imageList; while(curImage != NULL) { if(cur == NULL) { list = cur = verify = malloc(sizeof(ImageDataList)); } else { cur->next = malloc(sizeof(ImageDataList)); cur = cur->next; } bufferPrintf("Reading: "); print_fourcc(curImage->type); bufferPrintf(" (%d bytes)\r\n", curImage->padded); cur->type = curImage->type; cur->next = NULL; cur->data = malloc(curImage->padded); mtd_read(dev, cur->data, curImage->offset, curImage->padded); if(isReplace && cur->type == replaceFourcc) { isUpgrade = TRUE; } else if(cur->type == newFourcc) { toReplace = cur; } curImage = curImage->next; } mtd_finish(dev); if(!isUpgrade) { bufferPrintf("Performing installation... (%d bytes)\r\n", newDataLen); ImageDataList* ibox = malloc(sizeof(ImageDataList)); ibox->type = replaceFourcc; ibox->data = toReplace->data; ibox->next = toReplace->next; toReplace->next = ibox; toReplace->data = images_inject_img3(toReplace->data, newData, newDataLen); images_change_type(ibox->data, ibox->type); } else { bufferPrintf("Performing upgrade... (%d bytes)\r\n", newDataLen); void* newIBoot = images_inject_img3(toReplace->data, newData, newDataLen); free(toReplace->data); toReplace->data = newIBoot; } //check for size and availability size_t newPaddedDataLen=0; size_t totalBytes=0; //if somebody can find how to get padded length for new ibot maybe this loop not needed while(verify != NULL) { cur = verify; verify = verify->next; AppleImg3RootHeader* header = (AppleImg3RootHeader*) cur->data; totalBytes += header->base.size; if(cur->type == newFourcc) { newPaddedDataLen = header->base.size; } } bufferPrintf("Total size to be written %d\r\n",totalBytes); if((ImagesStart + totalBytes) >= 0xfc000) { bufferPrintf("**ABORTED** Writing total image size: 0x%x, new ibot size: 0x%x at 0x%x would overflow NOR!\r\n", totalBytes, newPaddedDataLen,ImagesStart); images_rewind(); images_release(); images_setup(); return; } bufferPrintf("Flashing...\r\n"); images_rewind(); while(list != NULL) { cur = list; list = list->next; AppleImg3RootHeader* header = (AppleImg3RootHeader*) cur->data; bufferPrintf("Flashing: "); print_fourcc(cur->type); bufferPrintf(" (%x, %d bytes)\r\n", cur->data, header->base.size); images_append(cur->data, header->base.size); free(cur->data); free(cur); } bufferPrintf("Flashing Complete, Free space after flashing %d\r\n",0xfc000-MaxOffset); images_release(); images_setup(); //bufferPrintf("Configuring openiBoot settings...\r\n"); /*#ifndef CONFIG_S5L8720 //TODO: add this back in once FTL is up and running Volume* volume; io_func* io; io = bdev_open(0); volume = openVolume(io); char buffer [sizeof(XSTRINGIFY(OPENIBOOT_VERSION))]; strcpy(buffer, XSTRINGIFY(OPENIBOOT_VERSION)); add_hfs(volume, (uint8_t*)buffer, sizeof(buffer), "/openiboot"); closeVolume(volume); CLOSE(io); ftl_sync(); #endif*/ // TODO: This is broken now, move into menu.c for next release -- Ricky26 /* if(!nvram_getvar("opib-temp-os")) { nvram_setvar("opib-temp-os", "0"); } if(!nvram_getvar("opib-default-os")) { nvram_setvar("opib-default-os", "1"); } if(!nvram_getvar("opib-menu-timeout")) { nvram_setvar("opib-menu-timeout", "10000"); } nvram_save();*/ // TODO: The defaults should NOT be written to NVRAM. -- Ricky26 //bufferPrintf("openiBoot installation complete.\r\n"); }
int main(int argc, char *argv[]) { int cameraFd; cameraFd = open("/dev/video0", O_RDWR|O_NONBLOCK); if (cameraFd < 0) { std::cout << "open /dev/video0 failed!" << std::endl; exit(EXIT_FAILURE); } int dumpFd; dumpFd = open("record.yuv", O_RDWR|O_TRUNC|O_CREAT, 0666); if (dumpFd < 0) { die(); } struct v4l2_capability capability; int ret = ioctl(cameraFd, VIDIOC_QUERYCAP, &capability); if (ret < 0) { die(); } if (!(capability.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { std::cout << "not an video capture device!" << std::endl; exit(EXIT_FAILURE); } if (!(capability.capabilities & V4L2_CAP_STREAMING)) { std::cout << "does not support streaming i/o" << std::endl; exit(EXIT_FAILURE); } std::stringstream ss; ss << "Driver name: " << capability.driver; std::cout << ss.str() << std::endl; int index = 0; ret = ioctl(cameraFd, VIDIOC_G_INPUT, &index); if (ret < 0) { die(); } std::cout << "device index: " << index << std::endl; struct v4l2_input input; memset(&input, 0, sizeof(input)); input.index = index; ret = ioctl(cameraFd, VIDIOC_ENUMINPUT, &input); if (ret < 0) die(); std::cout << "dump v4l2_input:" << std::endl; std::cout << " index:" << input.index << std::endl; std::cout << " name:" << input.name << std::endl; std::cout << " type:" << input.type << std::endl; std::cout << " std:" << input.std << std::endl; std::cout << " status:" << input.status << std::endl; std::cout << " capabilities:" << input.capabilities << std::endl; struct v4l2_format fmt; memset(&fmt, 0, sizeof(fmt)); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; fmt.fmt.pix.width = 640; fmt.fmt.pix.height = 480; fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420; fmt.fmt.pix.field = V4L2_FIELD_NONE; if (ioctl(cameraFd, VIDIOC_S_FMT, &fmt) < 0) { die(); } memset(&fmt, 0, sizeof(fmt)); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (ioctl(cameraFd, VIDIOC_G_FMT, &fmt) < 0) { die(); } std::cout << "\nv4l2_format:" << std::endl; std::cout << " width:" << fmt.fmt.pix.width << std::endl; std::cout << " height:" << fmt.fmt.pix.height << std::endl; std::cout << " pixel_format:" << print_fourcc(fmt.fmt.pix.pixelformat) << std::endl; std::cout << " field:" << fmt.fmt.pix.field << std::endl; struct v4l2_requestbuffers req; memset(&req, 0, sizeof(req)); req.count = 4; req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; req.memory = V4L2_MEMORY_MMAP; if (ioctl(cameraFd, VIDIOC_REQBUFS, &req) < 0) { if (EINVAL == errno) { std::cout << "does not surrpot memory mapping!\n" << std::endl; return -1; } else { die(); } } VideoBuffer* buffers = (VideoBuffer*)calloc(req.count, sizeof(*buffers)); struct v4l2_buffer buf; struct v4l2_buffer bufs[4]; for (int numBufs = 0; numBufs < req.count; ++numBufs) { memset(&buf, 0, sizeof(buf)); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; buf.index = numBufs; if (ioctl(cameraFd, VIDIOC_QUERYBUF, &buf) == -1) return -1; bufs[numBufs] = buf; buffers[numBufs].length = buf.length; buffers[numBufs].start = mmap(NULL, buf.length, PROT_READ|PROT_WRITE, MAP_SHARED, cameraFd, buf.m.offset); if (buffers[numBufs].start == MAP_FAILED) { return -1; } } for (int i = 0; i < 4; ++i) { memset(&buf, 0, sizeof(buf)); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; buf.index = i; buf.m.offset = bufs[i].m.offset; if (ioctl(cameraFd, VIDIOC_QBUF, &buf) < 0) { die(); } } int type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (ioctl(cameraFd, VIDIOC_STREAMON, &type) < 0) { die(); } std::cout << "begin... " << std::endl; struct SwsContext *swsContext = sws_getContext(640, 480, AV_PIX_FMT_YUYV422, 640, 480, AV_PIX_FMT_YUV420P,SWS_BILINEAR, NULL, NULL, NULL); AVFrame* pSrcFrame, *pDstFrame; pSrcFrame = av_frame_alloc(); pSrcFrame->width = 640; pSrcFrame->height = 480; pSrcFrame->format = AV_PIX_FMT_YUYV422; av_frame_get_buffer(pSrcFrame, 0); std::cout << "linesize:" << pSrcFrame->linesize[0] << std::endl; pDstFrame = av_frame_alloc(); pDstFrame->width = 640; pDstFrame->height = 480; pDstFrame->format = AV_PIX_FMT_YUV420P; av_frame_get_buffer(pDstFrame, 0); //pDstFrame->linesize[1] = 160; //pDstFrame->linesize[2] = 160; std::cout << "linesize:" << pDstFrame->linesize[0] << std::endl; std::cout << "linesize:" << pDstFrame->linesize[1] << std::endl; std::cout << "linesize:" << pDstFrame->linesize[2] << std::endl; fd_set fds; FD_ZERO(&fds); FD_SET(cameraFd, &fds); int maxFds = cameraFd+1; struct timeval tv; int frame_cnt = 100; while (frame_cnt) { tv.tv_sec = 1; tv.tv_usec = 0; ret = select(maxFds, &fds, nullptr, nullptr, &tv); if (ret < 0) { die(); } else if (ret == 0) { } else { if (FD_ISSET(cameraFd, &fds)) { struct v4l2_buffer capture_buf; memset(&capture_buf, 0, sizeof(capture_buf)); capture_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; capture_buf.memory = V4L2_MEMORY_MMAP; if (ioctl(cameraFd, VIDIOC_DQBUF, &capture_buf) < 0) { std::cout << "error VIDIOC_DQBUF" << std::endl; return -1; } assert(capture_buf.index<4); pSrcFrame->data[0] = (uint8_t*)buffers[capture_buf.index].start; ret = sws_scale(swsContext, pSrcFrame->data, pSrcFrame->linesize, 0, 0, pDstFrame->data, pDstFrame->linesize); //std::cout << "sws_scale ret " << ret << std::endl; //std::cout << pDstFrame->linesize[0] << std::endl; //std::cout << pDstFrame->linesize[1] << std::endl; //std::cout << pDstFrame->linesize[2] << std::endl; write(dumpFd, buffers[capture_buf.index].start, capture_buf.bytesused); //write(dumpFd, pDstFrame->data[0], pDstFrame->linesize[0]*480); //write(dumpFd, pDstFrame->data[1], pDstFrame->linesize[1]*480); //write(dumpFd, pDstFrame->data[2], pDstFrame->linesize[2]*480); --frame_cnt; if (ioctl(cameraFd, VIDIOC_QBUF, &capture_buf) < 0) { die(); } } } } type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (ioctl(cameraFd, VIDIOC_STREAMOFF, &type) < 0) { die(); } close(dumpFd); return 0; }
void images_uninstall() { ImageDataList* list = NULL; ImageDataList* cur = NULL; ImageDataList* iboot = NULL; Image* curImage = imageList; bufferPrintf("Reading images...\r\n"); while(curImage != NULL) { if(curImage->type != fourcc("ibot")) { if(cur == NULL) { list = cur = malloc(sizeof(ImageDataList)); } else { cur->next = malloc(sizeof(ImageDataList)); cur = cur->next; } bufferPrintf("Reading: "); print_fourcc(curImage->type); bufferPrintf(" (%d bytes)\r\n", curImage->padded); cur->type = curImage->type; cur->next = NULL; cur->data = malloc(curImage->padded); nor_read(cur->data, curImage->offset, curImage->padded); if(cur->type == fourcc("ibox")) { iboot = cur; } } else { bufferPrintf("Skipping: "); print_fourcc(curImage->type); bufferPrintf(" (%d bytes)\r\n", curImage->padded); } curImage = curImage->next; } if(iboot == NULL) { bufferPrintf("openiboot does not seem to be installed\n"); while(list != NULL) { cur = list; list = list->next; free(cur->data); free(cur); } return; } iboot->type = fourcc("ibot"); images_change_type(iboot->data, fourcc("ibot")); bufferPrintf("Flashing...\r\n"); images_rewind(); while(list != NULL) { cur = list; list = list->next; AppleImg3RootHeader* header = (AppleImg3RootHeader*) cur->data; bufferPrintf("Flashing: "); print_fourcc(cur->type); bufferPrintf(" (%x, %d bytes)\r\n", cur->data, header->base.size); images_append(cur->data, header->base.size); free(cur->data); free(cur); } bufferPrintf("Done with uninstallation!\r\n"); images_release(); images_setup(); bufferPrintf("Refreshed image list\r\n"); }
void images_install(void* newData, size_t newDataLen) { ImageDataList* list = NULL; ImageDataList* cur = NULL; ImageDataList* iboot = NULL; int isUpgrade = FALSE; Image* curImage = imageList; bufferPrintf("Reading images...\r\n"); while(curImage != NULL) { if(cur == NULL) { list = cur = malloc(sizeof(ImageDataList)); } else { cur->next = malloc(sizeof(ImageDataList)); cur = cur->next; } bufferPrintf("Reading: "); print_fourcc(curImage->type); bufferPrintf(" (%d bytes)\r\n", curImage->padded); cur->type = curImage->type; cur->next = NULL; cur->data = malloc(curImage->padded); nor_read(cur->data, curImage->offset, curImage->padded); if(cur->type == fourcc("ibox")) { isUpgrade = TRUE; } else if(cur->type == fourcc("ibot")) { iboot = cur; } curImage = curImage->next; } if(!isUpgrade) { bufferPrintf("Performing installation... (%d bytes)\r\n", newDataLen); ImageDataList* ibox = malloc(sizeof(ImageDataList)); ibox->type = fourcc("ibox"); ibox->data = iboot->data; ibox->next = iboot->next; iboot->next = ibox; iboot->data = images_inject_img3(iboot->data, newData, newDataLen); images_change_type(ibox->data, ibox->type); } else { bufferPrintf("Performing upgrade... (%d bytes)\r\n", newDataLen); void* newIBoot = images_inject_img3(iboot->data, newData, newDataLen); free(iboot->data); iboot->data = newIBoot; } bufferPrintf("Flashing...\r\n"); images_rewind(); while(list != NULL) { cur = list; list = list->next; AppleImg3RootHeader* header = (AppleImg3RootHeader*) cur->data; bufferPrintf("Flashing: "); print_fourcc(cur->type); bufferPrintf(" (%x, %d bytes)\r\n", cur->data, header->base.size); images_append(cur->data, header->base.size); free(cur->data); free(cur); } bufferPrintf("Done with installation!\r\n"); images_release(); images_setup(); bufferPrintf("Refreshed image list\r\n"); }
void images_install(void* newData, size_t newDataLen, uint32_t newFourcc, uint32_t replaceFourcc) { ImageDataList* list = NULL; ImageDataList* cur = NULL; ImageDataList* toReplace = NULL; ImageDataList* verify = NULL; int isReplace = (replaceFourcc != newFourcc) ? TRUE : FALSE; int isUpgrade = FALSE; Image* curImage = imageList; while(curImage != NULL) { if(cur == NULL) { list = cur = verify = malloc(sizeof(ImageDataList)); } else { cur->next = malloc(sizeof(ImageDataList)); cur = cur->next; } bufferPrintf("Reading: "); print_fourcc(curImage->type); bufferPrintf(" (%d bytes)\r\n", curImage->padded); cur->type = curImage->type; cur->next = NULL; cur->data = malloc(curImage->padded); nor_read(cur->data, curImage->offset, curImage->padded); if(isReplace && cur->type == replaceFourcc) { isUpgrade = TRUE; } else if(cur->type == newFourcc) { toReplace = cur; } curImage = curImage->next; } if(!isUpgrade) { bufferPrintf("Performing installation... (%d bytes)\r\n", newDataLen); ImageDataList* ibox = malloc(sizeof(ImageDataList)); ibox->type = replaceFourcc; ibox->data = toReplace->data; ibox->next = toReplace->next; toReplace->next = ibox; toReplace->data = images_inject_img3(toReplace->data, newData, newDataLen); images_change_type(ibox->data, ibox->type); } else { bufferPrintf("Performing upgrade... (%d bytes)\r\n", newDataLen); void* newIBoot = images_inject_img3(toReplace->data, newData, newDataLen); free(toReplace->data); toReplace->data = newIBoot; } //check for size and availability size_t newPaddedDataLen=0; size_t totalBytes=0; //if somebody can find how to get padded length for new ibot maybe this loop not needed while(verify != NULL) { cur = verify; verify = verify->next; AppleImg3RootHeader* header = (AppleImg3RootHeader*) cur->data; totalBytes += header->base.size; if(cur->type == newFourcc) { newPaddedDataLen = header->base.size; } } bufferPrintf("Total size to be written %d\r\n",totalBytes); if((ImagesStart + totalBytes) >= 0xfc000) { bufferPrintf("**ABORTED** Writing total image size: 0x%x, new ibot size: 0x%x at 0x%x would overflow NOR!\r\n", totalBytes, newPaddedDataLen,ImagesStart); images_rewind(); images_release(); images_setup(); return; } bufferPrintf("Flashing...\r\n"); images_rewind(); while(list != NULL) { cur = list; list = list->next; AppleImg3RootHeader* header = (AppleImg3RootHeader*) cur->data; bufferPrintf("Flashing: "); print_fourcc(cur->type); bufferPrintf(" (%x, %d bytes)\r\n", cur->data, header->base.size); images_append(cur->data, header->base.size); free(cur->data); free(cur); } bufferPrintf("Flashing Complete, Free space after flashing %d\r\n",0xfc000-MaxOffset); images_release(); images_setup(); bufferPrintf("Configuring openiBoot settings...\r\n"); nvram_setvar("opib-version", "0.1.2"); if(!nvram_getvar("opib-temp-os")) { nvram_setvar("opib-temp-os", "0"); } if(!nvram_getvar("opib-default-os")) { nvram_setvar("opib-default-os", "0"); } if(!nvram_getvar("opib-menu-timeout")) { nvram_setvar("opib-menu-timeout", "10000"); } nvram_save(); bufferPrintf("openiBoot installation complete.\r\n"); }