예제 #1
0
파일: main.c 프로젝트: LuckJC/pro-mk
int main(int argc,char *argv[])
{
    //struct image *norImages = NULL;
    //unsigned int num_nor_images = 0;
    struct image download_agent = { NULL, 0, 0, "", 0 };
    struct image download_agent_TCM = { NULL, 0, 0, "", 0 };
    struct image download_EPP = { NULL, 0, 0, "", 0 };
    struct image nor_flash_table = { NULL, 0, 0, "", 0 };
    struct image nand_flash_table = { NULL, 0, 0, "", 0 };
    struct image *linux_images = NULL;
    //unsigned int num_images = 0;
    unsigned int num_linux_images = 0;
    unsigned int bmt_address = 0;
    //int i = 0;

    struct image boot_loader = { NULL, 0, 0, "", 0 };
    struct image ext_boot_loader = { NULL, 0, 0, "", 0 };
    //struct image dsp_boot_loader = { NULL, 0, 0, "", 0 };
    struct image rom_image = { NULL, 0, 0, "", 0 };
    //struct image secondary_rom_image = { NULL, 0, 0, "", 0 };
    //struct image dsp_rom_image = { NULL, 0, 0, "", 0 };
    //struct image demand_paging_image = { NULL, 0, 0, "", 0 };

    //jone.wang@

    //freopen(TEMPORARY_LOG_FILE, "a", stdout); setbuf(stdout, NULL);
    //freopen(TEMPORARY_LOG_FILE, "a", stderr); setbuf(stderr, NULL);
    //fflush(stdout);
    //fflush(stderr);
    //setbuf(stdout, NULL);
    //setbuf(stderr, NULL);
    //fprintf(stdout, "Brom Ite main =================\n");
    //added by xiaohui 4-19

    if (argc < 2) {
        fprintf(stderr, "Usage: %s filepath [write_block_size] [trace_log]\n", basename(argv[0]));
        return -1;
    }

    char path[BUFSIZ] = "";
    strcpy(path, argv[1]);

    /* "/system/etc/firmware/modem" normally */
    if (access(path, R_OK) != 0) {
        fprintf(stderr, "path '%s` is invalid. %d, %s\n", path, errno, strerror(errno));
        return -1;
    }

    path[strlen(path)] = '/';
    LOG("path: %s\n", path);

    if (generate_all_image_path(path) != 0)
        return -1;

    //strcpy(dev_path,argv[2]);
    //pipe_fd = atoi(argv[3]);
    //pipe_buf = (char *)malloc(PIPE_BUF_SIZE);
    //if(!pipe_buf)
        //return 0;
    //printf("dev_path=%s\n",dev_path);
    //printf("pipe fd=%d\n",pipe_fd);

    log_feedback("begin to feedback!!!\n");
    //printf("%s\n",pipe_buf);
    //return 0;
    //added by xiaohui 4-19    

    if (argc > 2) {
        int psiz = atoi(argv[2]);
        if (psiz > 0) {
            PSIZ = psiz;
        }
    }
    LOG("PSIZ = %d\n", PSIZ);

    int trace_log = 0;
    if (argc > 3) {
        if (argv[3][0] == '0')
            trace_log = 0;
        else
            trace_log = 1;
    }
    if (trace_log)
        LOG("enable log tracing\n");
    enable_log = trace_log;

    int rc = -1;

    do {
        // Acquire pointers to DA, flash tables, and images
        if ((rc = acquire_download_agent(&download_agent,DOWNLOAD_AGENT_FILE_PATH,DOWNLOAD_AGENT_LOAD_ADDR)) != 0)
            break;
        //acquire_download_agent(&download_agent_TCM,DOWNLOAD_AGENT_TCM_FILE_PATH, DOWNLOAD_AGENT_TCM_LOAD_ADDR);
        if ((rc = acquire_download_agent(&download_EPP,DOWNLOAD_EPP_FILE_PATH, DOWNLOAD_EPP_LOAD_ADDR)) != 0)
            break;
        if ((rc = acquire_flash_table(&nor_flash_table, NOR_FLASH_TABLE_FILE_PATH)) != 0)
            break;
        if ((rc = acquire_flash_table(&nand_flash_table, NAND_FLASH_TABLE_FILE_PATH)) != 0)
            break;

        //Acquire Boot loader
        if ((rc = acquire_image(&boot_loader, BOOT_LOADER_FILE_PATH,0)) != 0)
            break;
        if ((rc = acquire_image(&ext_boot_loader, EXT_BOOT_LOADER_FILE_PATH,0)) != 0)
            break;
        //acquire_image(&dsp_boot_loader, DSP_BOOT_LOADER_FILE_PATH,0);
        //Acquire ROM images
        if ((rc = acquire_image(&rom_image, ROM_FILE_PATH,0)) != 0)
            break;
        //acquire_image(&secondary_rom_image, SECONDARY_ROM_FILE_PATH,0);
        //acquire_image(&dsp_rom_image, DSP_ROM_FILE_PATH,0);
        //acquire_image(&demand_paging_image, DEMAND_PAGING_ROM0_FILE_PATH,0);

        //Acquire linux partition images
        if ((rc = acquire_linux_images(&linux_images, &num_linux_images, &bmt_address)) != 0)
            break;
    } while (0);

    if (rc != 0)
        return rc;

    rc = download_images(&download_agent,
                         &download_agent_TCM,
                         &nor_flash_table,
                         &nand_flash_table,
                         &download_EPP,
                         &boot_loader,
                         &ext_boot_loader,
                         NULL, //&dsp_boot_loader,
                         &rom_image,
                         NULL, //&secondary_rom_image,
                         NULL, //&dsp_rom_image,
                         NULL, //&demand_paging_image,
                         linux_images,
                         (const struct ExternalMemorySetting *)&externalMemorySetting,
                         sizeof(LINUX_PARTITION_IMAGE_FILE_NAME) / sizeof(LINUX_PARTITION_IMAGE_FILE_NAME[0]), //num_linux_images,modified by xiaohui 4-22
                         bmt_address,
                         1, /*0:UART, 1:USB*/
                         1 /*0:NOR, 1:NAND*/);
    if (rc != S_DONE) {
        printf("download failed, rc %d\n", rc);
    } else {
        //jone.wang
        printf("download done\n");
    }

    release_images(&linux_images, num_linux_images);

    release_image(&boot_loader);
    release_image(&ext_boot_loader);
    release_image(&rom_image);
    //release_image(&secondary_rom_image);
    //release_image(&demand_paging_image);

    release_flash_table(&nand_flash_table);
    release_flash_table(&nor_flash_table);
    release_download_agent(&download_agent);
    release_download_agent(&download_agent_TCM);
    release_download_agent(&download_EPP);

    //added by xiaohui 4-19
    //close(pipe_fd);
    //free(pipe_buf);

    printf("brom_lite end, rc %d\n", rc);
    return rc;
}
예제 #2
0
void ImageLoader::load_images(bool forceDownload)
{
    if (forceDownload || must_download())
        download_images();
}