OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [libdbg64g/] [services/] [exec/] [cmd/] [cmd_loadbin.cpp] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sergeykhbr
/*
2
 *  Copyright 2018 Sergey Khabarov, sergeykhbr@gmail.com
3
 *
4
 *  Licensed under the Apache License, Version 2.0 (the "License");
5
 *  you may not use this file except in compliance with the License.
6
 *  You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *  Unless required by applicable law or agreed to in writing, software
11
 *  distributed under the License is distributed on an "AS IS" BASIS,
12
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *  See the License for the specific language governing permissions and
14
 *  limitations under the License.
15
 */
16
 
17
#include "iservice.h"
18
#include "cmd_loadbin.h"
19
#include <iostream>
20
 
21
namespace debugger {
22
 
23
CmdLoadBin::CmdLoadBin(ITap *tap, ISocInfo *info)
24
    : ICommand ("loadbin", tap, info) {
25
 
26
    briefDescr_.make_string("Load binary file");
27
    detailedDescr_.make_string(
28
        "Description:\n"
29
        "    Load BIN-file to SOC target memory with specified address.\n"
30
        "Example:\n"
31
        "    loadsrec /home/hc08/image.bin 0x04000\n");
32
}
33
 
34
bool CmdLoadBin::isValid(AttributeType *args) {
35
    if ((*args)[0u].is_equal("loadbin")
36
        && args->size() == 3) {
37
        return CMD_VALID;
38
    }
39
    return CMD_INVALID;
40
}
41
 
42
void CmdLoadBin::exec(AttributeType *args, AttributeType *res) {
43
    res->make_nil();
44
    if (!isValid(args)) {
45
        generateError(res, "Wrong argument list");
46
        return;
47
    }
48
 
49
    const char *filename = (*args)[1].to_string();
50
    FILE *fp = fopen(filename, "rb");
51
    if (!fp) {
52
        generateError(res, "File not found");
53
        return;
54
    }
55
    fseek(fp, 0, SEEK_END);
56
    int sz = ftell(fp);
57
    rewind(fp);
58
    uint8_t *image = new uint8_t[sz];
59
    fread(image, 1, sz, fp);
60
    fclose(fp);
61
 
62
    uint64_t addr = (*args)[2].to_uint64();
63
    tap_->write(addr, sz, image);
64
    delete [] image;
65
}
66
 
67
}  // namespace debugger

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.