Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions libuuu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set(SOURCES
zip.cpp
fat.cpp
rominfo.cpp
conf.cpp
)

set(generated_files_dir "${CMAKE_BINARY_DIR}/libuuu/gen")
Expand Down
89 changes: 83 additions & 6 deletions libuuu/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@
#include "buffer.h"
#include "sdp.h"
#include "fastboot.h"
#include "conf.h"
#include <sys/stat.h>
#include <thread>

#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <sstream>

static CmdMap g_cmd_map;
static CmdObjCreateMap g_cmd_create_map;
Expand Down Expand Up @@ -235,12 +237,19 @@ int get_string_in_square_brackets(string &cmd, string &context)

uint32_t str_to_uint(string &str)
{
if (str.size() > 2)
uint32_t val = 0;
std::stringstream ss;
if (str.size() > 2 &&
str.substr(0, 2).compare("0x") == 0)
{
if (str.substr(0, 2).compare("0x") == 0)
return strtoul(str.substr(2).c_str(), NULL, 16);
ss << std::hex << str.substr(2);
}
return strtoul(str.c_str(), NULL, 10);
else
{
ss << std::dec << str;
}
ss >> val;
return val;
}

template <class T> shared_ptr<CmdBase> new_cmd_obj(char *p)
Expand Down Expand Up @@ -289,6 +298,7 @@ CmdObjCreateMap::CmdObjCreateMap()

(*this)["_ALL:DONE"] = new_cmd_obj<CmdDone>;
(*this)["_ALL:DELAY"] = new_cmd_obj<CmdDelay>;
(*this)["_ALL:CONFIG"] = new_cmd_obj<CmdConfig>;
(*this)["_ALL:SH"] = new_cmd_obj<CmdShell>;
(*this)["_ALL:SHELL"] = new_cmd_obj<CmdShell>;
(*this)["_ALL:<"] = new_cmd_obj<CmdShell>;
Expand Down Expand Up @@ -415,6 +425,73 @@ int CmdDelay::run(CmdCtx *)
return 0;
}

int CmdConfig::parser(char * /*p*/)
{
try
{
size_t pos = 0;
string param = get_next_param(m_cmd, pos);

if (param.find(':') != string::npos)
param = get_next_param(m_cmd, pos);

if (str_to_upper(param) != "CONFIG")
{
string err = "CmdConfig::parser Uknown Commnd:";
err += param;
set_last_err_string(err);
return -1;
}

string args = get_next_param(m_cmd, pos);
if (str_to_upper(args) == "USB::HID::MAX_PACKET_SIZE")
{
string size = get_next_param(m_cmd, pos);
Conf::GetConf().m_USB.m_HIDMaxTransfer = str_to_uint(size);
cout << "changed USB::HID::MAX_PACKET_SIZE to " << Conf::GetConf().m_USB.m_HIDMaxTransfer << endl;
}
else if (str_to_upper(args) == "USB::HID::TIMEOUT" )
{
string ms = get_next_param(m_cmd, pos);
Conf::GetConf().m_USB.m_HIDTimeout = str_to_uint(ms);
cout << "changed USB::HID::TIMEOUT to " << Conf::GetConf().m_USB.m_HIDTimeout << endl;
}
else if (str_to_upper(args) == "USB::BULK::MAX_PACKET_SIZE" )
{
string size = get_next_param(m_cmd, pos);
Conf::GetConf().m_USB.m_BulkMaxTransfer = str_to_uint(size);
cout << "changed USB::BULK::MAX_PACKET_SIZE to " << Conf::GetConf().m_USB.m_BulkMaxTransfer << endl;
}
else if (str_to_upper(args) == "USB::BULK::TIMEOUT")
{
string ms = get_next_param(m_cmd, pos);
Conf::GetConf().m_USB.m_BulkTimeout = str_to_uint(ms);
cout << "changed CONF::USB::BULK::TIMEOUT to " << Conf::GetConf().m_USB.m_BulkTimeout << endl;
}
else
{
string err = "CmdConfig::parser invalid parameter:";
err += m_cmd;
set_last_err_string(err);
return -1;

}
}
catch (string const& except)
{
string err(" error at line : ");
err += except;
throw err;
}
return 0;
}

int CmdConfig::run(CmdCtx *)
{
return 0;
}


int CmdShell::parser(char * p)
{
if (p)
Expand Down
12 changes: 11 additions & 1 deletion libuuu/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <vector>
#include <map>
#include <memory>
#include <iostream>

#include "liberror.h"
#include "libcomm.h"
Expand Down Expand Up @@ -107,7 +108,6 @@ class CmdBase
string param;
if (get_string_in_square_brackets(prot, param))
return -1;

if (!param.empty())
{
size_t param_pos = 0;
Expand Down Expand Up @@ -161,6 +161,16 @@ class CmdDelay :public CmdBase
int run(CmdCtx *p);
};

class CmdConfig :public CmdBase
{
public:
virtual int parser(char *p = NULL);
CmdConfig(char *p) :CmdBase(p) { };
int run(CmdCtx *p);
};



class CmdShell : public CmdBase
{
public:
Expand Down
51 changes: 51 additions & 0 deletions libuuu/conf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2018 NXP.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* Neither the name of the NXP Semiconductor nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/


#include "conf.h"


Conf::Conf()
{
m_USB.m_BulkMaxTransfer = 0x10000;
m_USB.m_BulkTimeout = 2000;
m_USB.m_HIDMaxTransfer= 0x10000;
m_USB.m_HIDTimeout = 2000;
}

Conf& Conf::GetConf()
{
static Conf instance;
return instance;
}



52 changes: 52 additions & 0 deletions libuuu/conf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2018 NXP.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* Neither the name of the NXP Semiconductor nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/

#include <cstdint>
#include <cstddef>


class Conf
{
public:
struct UsbConf
{
size_t m_BulkMaxTransfer;
uint64_t m_BulkTimeout;
size_t m_HIDMaxTransfer;
uint64_t m_HIDTimeout;
};
public:
static Conf& GetConf();
UsbConf m_USB;

private:
Conf();
};
15 changes: 10 additions & 5 deletions libuuu/fastboot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <fstream>
#include <sys/stat.h>
#include "sparse.h"
#include "conf.h"

int FastBoot::Transport(string cmd, void *p, size_t size, vector<uint8_t> *input)
{
Expand Down Expand Up @@ -170,7 +171,6 @@ int FBCmd::run(CmdCtx *ctx)
if (dev.open(ctx->m_dev))
return -1;

dev.m_timeout = m_timeout;

FastBoot fb(&dev);
string cmd;
Expand Down Expand Up @@ -212,6 +212,10 @@ int FBCopy::parser(char *p)

size_t pos = 0;
string s;

if (parser_protocal(p, pos))
return -1;

s = get_next_param(m_cmd, pos);
if (s.find(":") != s.npos)
s = get_next_param(m_cmd, pos);
Expand Down Expand Up @@ -310,11 +314,13 @@ int FBCopy::run(CmdCtx *ctx)
nt.total = buff->size();
call_notify(nt);

for (i = 0; i < buff->size(); i += this->m_Maxsize_pre_cmd)
for (i = 0;
i < buff->size();
i += Conf::GetConf().m_USB.m_BulkMaxTransfer)
{
size_t sz = buff->size() - i;
if (sz > m_Maxsize_pre_cmd)
sz = m_Maxsize_pre_cmd;
if (sz > Conf::GetConf().m_USB.m_BulkMaxTransfer)
sz = Conf::GetConf().m_USB.m_BulkMaxTransfer;

cmd.format("donwload:%08X", sz);
if (fb.Transport(cmd, buff->data() + i, sz))
Expand Down Expand Up @@ -515,7 +521,6 @@ int FBFlashCmd::run(CmdCtx *ctx)
return -1;

FastBoot fb(&dev);
dev.m_timeout = m_timeout;

shared_ptr<FileBuffer> pdata = get_file_buffer(m_filename);
if (pdata == NULL)
Expand Down
5 changes: 2 additions & 3 deletions libuuu/fastboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,13 @@ class FBDownload : public CmdBase
int run(CmdCtx *ctx);
};

class FBCopy : public CmdBase
class FBCopy : public FBCmd
{
public:
string m_local_file;
string m_target_file;
bool m_bDownload;
size_t m_Maxsize_pre_cmd;
int parser(char *p=NULL);
FBCopy(char *p) :CmdBase(p) { m_Maxsize_pre_cmd = 0x10000; };
FBCopy(char *p) :FBCmd(p) { };
int run(CmdCtx *ctx);
};
3 changes: 1 addition & 2 deletions libuuu/sdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ int SDPJumpCmd::run(CmdCtx *ctx)
int SDPBootlogCmd::run(CmdCtx *ctx)
{
HIDTrans dev;
dev.m_read_timeout = 2000;

if (dev.open(ctx->m_dev))
return -1;
Expand Down Expand Up @@ -383,4 +382,4 @@ int SDPBootlogCmd::run(CmdCtx *ctx)
}
}
return 0;
}
}
Loading