int main(int argc, char **argv) { uint8_t slot_id; char tstr[64] = {0}; if (argc < 3) { goto err_exit; } if (!strcmp(argv[1], "slot1")) { slot_id = 1; } else if (!strcmp(argv[1] , "slot2")) { slot_id = 2; } else if (!strcmp(argv[1] , "slot3")) { slot_id = 3; } else if (!strcmp(argv[1] , "slot4")) { slot_id = 4; } else if (!strcmp(argv[1] , "sled")) { slot_id = 0; } else { goto err_exit; } if (!strcmp(argv[2], "--usb")) { printf("fpc-util: switching USB channel to slot%d\n", slot_id); return pal_switch_usb_mux(slot_id); } else if (!strcmp(argv[2], "--identify")) { if (argc != 4) { goto err_exit; } printf("fpc-util: identification for %s is %s\n", argv[1], argv[3]); if (slot_id == 0) { sprintf(tstr, "identify_sled"); } else { sprintf(tstr, "identify_slot%d", slot_id); } if (strcmp(argv[3] , "on") && strcmp(argv[3] , "off")) { goto err_exit; } return pal_set_key_value(tstr, argv[3]); } else { goto err_exit; } return 0; err_exit: print_usage_help(); return -1; }
int fw_update_slot(char **argv, uint8_t slot_id) { uint8_t status; int ret; char cmd[80]; ret = pal_is_fru_prsnt(slot_id, &status); if (ret < 0) { printf("pal_is_fru_prsnt failed for fru: %d\n", slot_id); goto err_exit; } if (status == 0) { printf("slot%d is empty!\n", slot_id); goto err_exit; } if (!strcmp(argv[3], "--cpld")) { return bic_update_fw(slot_id, UPDATE_CPLD, argv[4]); } if (!strcmp(argv[3], "--bios")) { sprintf(cmd, "power-util slot%u off", slot_id); system(cmd); ret = bic_update_fw(slot_id, UPDATE_BIOS, argv[4]); sprintf(cmd, "power-util slot%u on", slot_id); system(cmd); return ret; } if (!strcmp(argv[3], "--bic")) { return bic_update_fw(slot_id, UPDATE_BIC, argv[4]); } if (!strcmp(argv[3], "--bicbl")) { return bic_update_fw(slot_id, UPDATE_BIC_BOOTLOADER, argv[4]); } err_exit: print_usage_help(); return -1; }
int main(int argc, char **argv) { uint8_t slot_id; int ret = 0; char cmd[80]; // Check for border conditions if ((argc != 3) && (argc != 5)) { goto err_exit; } // Derive slot_id from first parameter if (!strcmp(argv[1], "slot1")) { slot_id = 1; } else if (!strcmp(argv[1] , "slot2")) { slot_id =2; } else if (!strcmp(argv[1] , "slot3")) { slot_id =3; } else if (!strcmp(argv[1] , "slot4")) { slot_id =4; } else if (!strcmp(argv[1] , "all")) { slot_id =5; } else { goto err_exit; } // check operation to perform if (!strcmp(argv[2], "--version")) { if (slot_id < 5) { print_fw_ver(slot_id); return 0; } for (slot_id = 1; slot_id < 5; slot_id++) { printf("Get version info for slot%d\n", slot_id); print_fw_ver(slot_id);; printf("\n"); } return 0; } if (!strcmp(argv[2], "--update")) { if (argc != 5) { goto err_exit; } if (slot_id < 5) { return fw_update_slot(argv, slot_id); } printf("Updating all slots....\n"); for (slot_id = 1; slot_id < 5; slot_id++) { if (fw_update_slot(argv, slot_id)) { printf("fw_util: updating %s on slot %d failed!\n", argv[3], slot_id); ret++; } } if (ret) { printf("fw_util: updating all slots failed!\n"); return -1; } printf("fw_util: updated all slots successfully!\n"); return 0; } err_exit: print_usage_help(); return -1; }
int main(int argc, char* argv[]) { size_t i = 0; uint8_t verbose = 0; FILE* sup_file = stdin; char* sup_filename = NULL; FILE* srt_file = NULL; char* srt_filename = NULL; uint32_t srt_start_time = 0, srt_end_time = 0; char* srt_timecode = NULL; size_t pgm_file_num = 0; char* pgm_base_filename = "movie_subtitle"; char* pgm_filename = NULL; unsigned char* canvas = NULL; size_t canvas_len = 0, canvas_width = 0, canvas_height = 0; size_t subimgs_cnt = 0; struct subimage** subimgs; struct subimage* subimg = NULL; size_t packet_num = 0; struct sup_packet* packet = NULL; struct sup_segment_pcs* pcs = NULL; struct sup_segment_pds* pds = NULL; struct sup_segment_wds* wds = NULL; struct sup_segment_ods* ods = NULL; for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "-?")) { print_usage_help(argv[0]); return EXIT_SUCCESS; } else if (!strcmp(argv[i], "-v")) { verbose = 1; } else if (!strcmp(argv[i], "-i")) { i++; if (i == argc || strlen(argv[i]) == 0) { ERROR("Please specify an input file.\n"); return EXIT_FAILURE; } else { sup_filename = argv[i]; } } else if (!strcmp(argv[i], "-o")) { i++; if (i == argc || strlen(argv[i]) == 0) { ERROR("Please specify the base name for PGM images.\n"); return EXIT_FAILURE; } else { pgm_base_filename = argv[i]; } } } if (sup_filename != NULL) { if ((sup_file = fopen(sup_filename, "rb")) == NULL) { ERROR("Failed opening SUP file %s.\n", sup_filename); return EXIT_FAILURE; } } pgm_filename = calloc(strlen(pgm_base_filename) + 10, sizeof(char)); if (pgm_filename == NULL) { perror("main(): calloc(PGM_FILENAME)"); fclose(sup_file); return EXIT_FAILURE; } srt_filename = calloc(strlen(pgm_base_filename) + 6, sizeof(char)); if (srt_filename == NULL) { perror("main(): calloc(SRT_FILENAME)"); fclose(sup_file); return EXIT_FAILURE; } else { sprintf(srt_filename, "%s.srtx", pgm_base_filename); } if ((srt_file = fopen(srt_filename, "w")) == NULL) { ERROR("Failed opening SRT file %s.\n", srt_filename); free(srt_filename); fclose(sup_file); return EXIT_FAILURE; } srt_timecode = calloc(SRT_TIMECODE_LEN + 1, sizeof(char)); if (srt_timecode == NULL) { perror("main(): calloc(SRT_TIMESTAMP)"); free(srt_filename); fclose(srt_file); fclose(sup_file); return EXIT_FAILURE; } subimgs = NULL; packet = calloc(1, sizeof(struct sup_packet)); pcs = calloc(1, sizeof(struct sup_segment_pcs)); pds = calloc(1, sizeof(struct sup_segment_pds)); wds = calloc(1, sizeof(struct sup_segment_wds)); ods = calloc(1, sizeof(struct sup_segment_ods)); if (sup_init_packet(packet) || sup_init_segment_pcs(pcs) || sup_init_segment_pds(pds) || sup_init_segment_wds(wds) || sup_init_segment_ods(ods)) { ERROR("SUP placeholders' initialization failed.\n"); free(ods); if (wds != NULL) { free(wds->windows); free(wds); } if (pds != NULL) { free(pds->colors); free(pds); } if (pcs != NULL) { free(pcs->objects); free(pcs); } if (packet != NULL) { free(packet->segment); free(packet); } free(srt_timecode); free(srt_filename); fclose(srt_file); fclose(sup_file); return EXIT_FAILURE; } for (; !feof(sup_file); packet_num++) { if (sup_read_packet(sup_file, packet)) { continue; } if (packet->segment_type == SUP_SEGMENT_PCS) { /* Set up composition. */ if (sup_parse_segment_pcs(packet, pcs)) { ERROR("Bad PCS %lu.\n", packet_num); continue; } else if (verbose) { dump_segment_pcs(pcs); } if (pcs->comp_state == SUP_PCS_STATE_EPOCH_START) { /** * Start a new composition: clear the image buffer, * reset the timecodes. */ if (canvas_width != pcs->video_width || canvas_height != pcs->video_height) { if (canvas != NULL) { free(canvas); } canvas_width = pcs->video_width; canvas_height = pcs->video_height; canvas_len = canvas_width * canvas_height; if ((canvas = malloc(canvas_len)) == NULL) { perror("main(): malloc(CANVAS)"); break; } } srt_start_time = pcs->pts_msec; srt_end_time = 0; } else if (pcs->pts_msec >= srt_start_time + SUP2PGM_MERGE_THRESHOLD) { /* Save the previously rendered composition. */ srt_end_time = pcs->pts_msec; if (!save_sup_image(srt_file, pgm_file_num, srt_start_time, srt_end_time, srt_timecode, pgm_base_filename, pgm_filename, canvas, canvas_width, canvas_height)) { pgm_file_num++; } srt_start_time = pcs->pts_msec; srt_end_time = 0; } pgm_clear(canvas, canvas_width, canvas_height); } else if (packet->segment_type == SUP_SEGMENT_PDS) { /* Extract palette. */ if (sup_parse_segment_pds(packet, pds)) { ERROR("Bad PDS %lu.\n", packet_num); continue; } else if (verbose) { dump_segment_pds(pds); } } else if (packet->segment_type == SUP_SEGMENT_WDS) { /* Extract windows info. */ if (sup_parse_segment_wds(packet, wds)) { ERROR("Bad WDS %lu.\n", packet_num); continue; } else if (verbose) { dump_segment_wds(wds); } } else if (packet->segment_type == SUP_SEGMENT_ODS) { /* Decode and render caption image. */ if (sup_parse_segment_ods(packet, ods)) { ERROR("Bad ODS %lu.\n", packet_num); continue; } else if (verbose) { dump_segment_ods(ods); } if (subimgs_cnt < ods->obj_id + 1) { subimgs = realloc(subimgs, (ods->obj_id + 1) * sizeof(struct subimage*)); if (subimgs == NULL) { perror("main(): realloc(SUBIMGS)"); break; } else { for (i = subimgs_cnt; i <= ods->obj_id; i++) { subimgs[i] = malloc(sizeof(struct subimage)); if (subimgs[i] == NULL) { perror("main(): malloc(SUBIMG)"); } else { subimgs[i]->max_len = 0; subimgs[i]->len = 0; subimgs[i]->img = NULL; } } subimgs_cnt = ods->obj_id + 1; } } subimg = subimgs[ods->obj_id]; if (subimg == NULL) { break; } if (subimg->img == NULL) { subimg->max_len = SUP_PACKET_MAX_SEGMENT_LEN; if ((subimg->img = malloc(subimg->max_len)) == NULL) { perror("main(): malloc(SUBIMG)"); break; } } if (ods->obj_flag & SUP_ODS_FIRST) { subimg->len = 0; } if (subimg->len + ods->raw_data_len > subimg->max_len) { subimg->max_len = subimg->len + ods->raw_data_len; if ((subimg->img = realloc(subimg->img, subimg->max_len)) == NULL) { perror("main(): realloc(SUBIMG)"); break; } } memcpy(subimg->img + subimg->len, ods->raw_data, ods->raw_data_len); subimg->len += ods->raw_data_len; } else if (packet->segment_type == SUP_SEGMENT_END) { /* Render composition. */ if (verbose) { dump_segment_end(packet); } if (pcs->num_of_objects > 0) { for (i = 0; i < pcs->num_of_objects; i++) { if (pcs->objects[i].obj_id < subimgs_cnt) { subimg = subimgs[pcs->objects[i].obj_id]; render_sup_image(canvas, canvas_len, subimg->img, subimg->len, pcs->objects[i].obj_id, pcs, wds, pds, ods); } } } /* Reset composition placeholders. */ sup_init_segment_pcs(pcs); sup_init_segment_pds(pds); sup_init_segment_wds(wds); sup_init_segment_ods(ods); } else { ERROR("Unknown segment type 0x%02x for packet %lu.\n", packet->segment_type, packet_num); } } DEBUG("%lu packets parsed, %lu images saved.\n", packet_num, pgm_file_num); free(ods); free(wds->windows); free(wds); free(pds->colors); free(pds); free(pcs->objects); free(pcs); free(packet->segment); free(packet); for (i = 0; i < subimgs_cnt; i++) { free(subimgs[i]->img); free(subimgs[i]); } free(subimgs); free(canvas); free(pgm_filename); free(srt_timecode); free(srt_filename); fclose(srt_file); fclose(sup_file); return EXIT_SUCCESS; }