示例#1
0
文件: erase.c 项目: wxh0000mm/bladeRF
int cmd_erase(struct cli_state *state, int argc, char **argv)
{
    int status;
    int addr, len;
    int eb_offset, n_ebs;
    bool ok;

    if (argc != 3) {
        return CLI_RET_NARGS;
    }

    eb_offset = str2uint(argv[1], 0, INT_MAX, &ok);
    if(!ok) {
        cli_err(state, argv[0],
                "Invalid value for \"eb_offset\" (%s)\n", argv[1]);
        return CLI_RET_INVPARAM;
    }

    n_ebs = str2uint(argv[2], 0, INT_MAX, &ok);
    if(!ok) {
        cli_err(state, argv[0], "Invalid value for \"n_ebs\" (%s)\n", argv[2]);
        return CLI_RET_INVPARAM;
    }

    addr = eb_offset;
    len  = n_ebs;

    status = bladerf_erase_flash(state->dev, addr, len);

    if (status >= 0) {
        printf("\n  Erased %d blocks at 0x%02x\n\n", len, addr);
        return CLI_RET_OK;
    } else {
        state->last_lib_error = status;
        return CLI_RET_LIBBLADERF;
    }
}
示例#2
0
文件: erase.c 项目: guyt101z/bladeRF
int cmd_erase(struct cli_state *state, int argc, char **argv)
{
    int status;
    int page_offset, n_bytes;
    bool ok;

    if (!cli_device_is_opened(state)) {
        return CMD_RET_NODEV;
    }

    if (argc != 3) {
        return CMD_RET_NARGS;
    }

    page_offset = str2uint(argv[1], 0, INT_MAX, &ok);
    if(!ok) {
        cli_err(state, argv[0], "Invalid value for \"page_offset\" (%s)", argv[1]);
        return CMD_RET_INVPARAM;
    }

    n_bytes = str2uint(argv[2], 0, INT_MAX, &ok);
    if(!ok) {
        cli_err(state, argv[0], "Invalid value for \"n_bytes\" (%s)", argv[2]);
        return CMD_RET_INVPARAM;
    }

    status = bladerf_erase_flash(state->dev, page_offset, n_bytes);

    if (status >= 0) {
        printf("Erased %d pages at %d\n", status, page_offset);
        return CMD_RET_OK;
    } else {
        state->last_lib_error = status;
        return CMD_RET_LIBBLADERF;
    }
}
示例#3
0
int cmd_flash_init_cal(struct cli_state *state, int argc, char **argv)
{
    int rv;
    bool ok;
    uint16_t dac;
    bladerf_fpga_size fpga_size;
    struct bladerf_image *image = NULL;
    uint32_t page, count;

    if(argc != 3 && argc != 4) {
        return CLI_RET_NARGS;
    }

    rv = str2fpga(argv[1], &fpga_size);
    if (rv != 0) {
        cli_err(state, argv[0], "Invalid FPGA provided.\n");
        return rv;
    }

    dac = str2uint(argv[2], 0, 0xffff, &ok);
    if(!ok) {
        cli_err(state, argv[0], "Invalid VCTCXO trim value provided.\n");
        return CLI_RET_INVPARAM;
    }

    image = bladerf_alloc_cal_image(fpga_size, dac);
    if (!image) {
        return CLI_RET_MEM;
    }

    if (argc == 3) {
        rv = flash_check_state(state, argv[0]);
        if (rv != 0) {
            goto cmd_flash_init_cal_out;
        }

        rv = bladerf_erase_flash(state->dev, BLADERF_FLASH_EB_CAL,
                                 BLADERF_FLASH_EB_LEN_CAL);
        if (rv != 0) {
            goto cmd_flash_init_cal_out;
        }

        page = BLADERF_FLASH_TO_PAGES(image->address);
        count = BLADERF_FLASH_TO_PAGES(image->length);

        rv = bladerf_write_flash(state->dev, image->data, page, count);
        if(rv < 0) {
            cli_err(state, argv[0],
            "Failed to write calibration data.\n"
            "\n"
            "    This may have resulted in a corrupted flash. If the device fails to\n"
            "    boot at the next power cycle, re-flash the firmware.\n"
            "\n"
            "    See the following page for more information:\n"
            "      https://github.com/Nuand/bladeRF/wiki/Upgrading-bladeRF-firmware\n"
            );

            state->last_lib_error = rv;
            rv = CLI_RET_LIBBLADERF;
        } else {
            rv = 0;
        }
    } else {
        char *filename;
        assert(argc == 4);

        filename = input_expand_path(argv[3]);
        rv = bladerf_image_write(image, filename);
        free(filename);
    }

cmd_flash_init_cal_out:
    bladerf_free_image(image);
    return rv;
}