Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for partial read command in memconfig_utils. #627

Merged
merged 1 commit into from
Jun 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions applications/memconfig_utils/targets/linux.x86/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "utils/GcTcpHub.hxx"
#include "utils/Crc.hxx"
#include "utils/FileUtils.hxx"
#include "utils/format_utils.hxx"
#include "executor/Executor.hxx"
#include "executor/Service.hxx"

Expand Down Expand Up @@ -87,15 +88,19 @@ static const char *filename = nullptr;
static uint64_t destination_nodeid = 0;
static uint64_t destination_alias = 0;
static int memory_space_id = openlcb::MemoryConfigDefs::SPACE_CONFIG;
static uint32_t offset = 0;
static constexpr uint32_t NLEN = (uint32_t)-1;
static uint32_t len = NLEN;
static bool partial_read = false;
static bool do_read = false;
static bool do_write = false;

void usage(const char *e)
{
fprintf(stderr,
"Usage: %s ([-i destination_host] [-p port] | [-d device_path]) [-s "
"memory_space_id] [-c csum_algo] (-r|-w) (-n nodeid | -a "
"alias) -f filename\n",
"memory_space_id] [-o offset] [-l len] [-c csum_algo] (-r|-w) "
"(-n nodeid | -a alias) -f filename\n",
e);
fprintf(stderr, "Connects to an openlcb bus and performs the "
"bootloader protocol on openlcb node with id nodeid with "
Expand All @@ -120,7 +125,7 @@ void usage(const char *e)
void parse_args(int argc, char *argv[])
{
int opt;
while ((opt = getopt(argc, argv, "hp:i:d:n:a:s:f:rw")) >= 0)
while ((opt = getopt(argc, argv, "hp:i:d:n:a:s:f:rwo:l:")) >= 0)
{
switch (opt)
{
Expand Down Expand Up @@ -148,6 +153,12 @@ void parse_args(int argc, char *argv[])
case 's':
memory_space_id = strtol(optarg, nullptr, 16);
break;
case 'o':
offset = strtol(optarg, nullptr, 10);
break;
case 'l':
len = strtol(optarg, nullptr, 10);
break;
case 'r':
do_read = true;
break;
Expand All @@ -159,7 +170,9 @@ void parse_args(int argc, char *argv[])
usage(argv[0]);
}
}
if (!filename || (!destination_nodeid && !destination_alias))
partial_read = do_read && ((offset != 0) || (len != NLEN));
if ((!filename && !partial_read) ||
(!destination_nodeid && !destination_alias))
{
usage(argv[0]);
}
Expand Down Expand Up @@ -213,7 +226,13 @@ int appl_main(int argc, char *argv[])
printf("Result: %04x\n", b->data()->resultCode);
}

if (do_read)
if (do_read && partial_read)
{
auto b = invoke_flow(&g_memcfg_cli, openlcb::MemoryConfigClientRequest::READ_PART, dst, memory_space_id, offset, len);
printf("Result: %04x\n", b->data()->resultCode);
printf("Data: %s\n", string_to_hex(b->data()->payload).c_str());
}
else if (do_read)
{
auto cb = [](openlcb::MemoryConfigClientRequest *rq) {
static size_t last_len = rq->payload.size();
Expand Down