-
Notifications
You must be signed in to change notification settings - Fork 302
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
Raspberry usb fix #92
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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) | ||
|
@@ -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>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure all protocol need config command. There are already have CFG: protocol to set PID VID to protocol map? which will run once at beginning. CFG: HID -maxtimeout 1000 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is CFG protocol? this isn't documented... I don't understand your remark.... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in help
|
||
(*this)["_ALL:SH"] = new_cmd_obj<CmdShell>; | ||
(*this)["_ALL:SHELL"] = new_cmd_obj<CmdShell>; | ||
(*this)["_ALL:<"] = new_cmd_obj<CmdShell>; | ||
|
@@ -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; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid print at libuuu, which will block UI deplay. |
||
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; | ||
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dose CmdBase::insert_param_info match your parser requirement? That simplify parser work. |
||
} | ||
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) | ||
|
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; | ||
} | ||
|
||
|
||
|
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(); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
{ | ||
|
@@ -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; | ||
|
@@ -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); | ||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. m_Maxsize_pre_cmd need be update at beginning, such as construct function or at parser function. so needn't change below code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the code is needed here because we have to know about the packet size to split the content, using construct fonction or at parser level will imply lot of modifications since there is no way to go from parser to low level constructor, doing so will require modify lot of API... I didn't wanted to go that way because it overcomplicate the process, while a configuration class singleton store the configuration in a dedicated place and is easely integrated |
||
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)) | ||
|
@@ -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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's problem do you try to fix? the function should be the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't know why but the old code fail to convert on x86_64 latest ubuntu.... and well c++ conversion function are more robust than the strtoul legacy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It pass ubuntu 18.08 at auto build system.