Exemplo n.º 1
0
int bladerf_load_fpga(struct bladerf *dev, const char *fpga_file)
{
    uint8_t *buf = NULL;
    size_t  buf_size;
    int status;

    /* TODO sanity check FPGA:
     *  - Check for x40 vs x115 and verify FPGA image size
     *  - Known header/footer on images?
     *  - Checksum/hash?
     */
    status = file_read_buffer(fpga_file, &buf, &buf_size);
    if (status != 0) {
        goto error;
    }

    if (!valid_fpga_size(buf_size)) {
        status = BLADERF_ERR_INVAL;
        goto error;
    }

    status = dev->fn->load_fpga(dev, buf, buf_size);
    if (status == 0) {
        status = bladerf_init_device(dev);
    }

error:
    free(buf);
    return status;
}
Exemplo n.º 2
0
int fpga_load_from_file(struct bladerf *dev, const char *fpga_file)
{
    uint8_t *buf = NULL;
    size_t  buf_size;
    int status;

    status = file_read_buffer(fpga_file, &buf, &buf_size);
    if (status != 0) {
        goto error;
    }

    if (!valid_fpga_size(dev->fpga_size, buf_size)) {
        status = BLADERF_ERR_INVAL;
        goto error;
    }

    status = dev->fn->load_fpga(dev, buf, buf_size);
    if (status != 0) {
        goto error;
    }

    status = fpga_check_version(dev);
    if (status != 0) {
        goto error;
    }

    status = init_device(dev);
    if (status != 0) {
        goto error;
    }

error:
    free(buf);
    return status;
}
Exemplo n.º 3
0
int fpga_write_to_flash(struct bladerf *dev, const char *fpga_file)
{
    int status;
    size_t buf_size;
    uint8_t *buf = NULL;

    status = file_read_buffer(fpga_file, &buf, &buf_size);
    if (status == 0) {
        if (!valid_fpga_size(dev->fpga_size, buf_size)) {
            status = BLADERF_ERR_INVAL;
        } else {
            status = flash_write_fpga_bitstream(dev, &buf, buf_size);
        }
    }

    free(buf);
    return status;
}
Exemplo n.º 4
0
int bladerf_flash_fpga(struct bladerf *dev, const char *fpga_file)
{
    int status;
    uint8_t *buf;
    size_t buf_size;
    const char env_override[] = "BLADERF_SKIP_FPGA_SIZE_CHECK";

    status = file_read_buffer(fpga_file, &buf, &buf_size);
    if (status == 0) {
        if (!getenv(env_override) && !valid_fpga_size(buf_size)) {
            log_info("Detected potentially invalid firmware file.\n");
            log_info("Define BLADERF_SKIP_FPGA_SIZE_CHECK in your evironment "
                       "to skip this check.\n");
            status = BLADERF_ERR_INVAL;
        } else {
            status = flash_write_fpga_bitstream(dev, &buf, buf_size);
            free(buf);
        }
    }

    return status;
}