Skip to content

Commit

Permalink
Update bootloader files
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Cutting committed Jan 25, 2023
1 parent 0757da6 commit c8ee0b2
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 129 deletions.
2 changes: 1 addition & 1 deletion src/ISBootloaderAPP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/*
MIT LICENSE
Copyright (c) 2014-2022 Inertial Sense, Inc. - http://inertialsense.com
Copyright (c) 2014-2023 Inertial Sense, Inc. - http://inertialsense.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
Expand Down
2 changes: 1 addition & 1 deletion src/ISBootloaderAPP.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/*
MIT LICENSE
Copyright (c) 2014-2022 Inertial Sense, Inc. - http://inertialsense.com
Copyright (c) 2014-2023 Inertial Sense, Inc. - http://inertialsense.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
Expand Down
59 changes: 43 additions & 16 deletions src/ISBootloaderBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/*
MIT LICENSE
Copyright (c) 2014-2022 Inertial Sense, Inc. - http://inertialsense.com
Copyright (c) 2014-2023 Inertial Sense, Inc. - http://inertialsense.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
Expand Down Expand Up @@ -124,7 +124,8 @@ eImageSignature cISBootloaderBase::get_bin_image_signature(std::string filename,

fseek(blfile, 0x5FFC, SEEK_SET);
unsigned char ver_info[4];
fread(ver_info, 1, 4, blfile);
size_t n = fread(ver_info, 1, 4, blfile);
(void)n;
fclose(blfile);

//Check for marker for valid version info
Expand All @@ -140,7 +141,8 @@ eImageSignature cISBootloaderBase::get_bin_image_signature(std::string filename,

// Look in the old location for this info (v5 and earler)
fseek(blfile, 0x3DFC, SEEK_SET);
fread(ver_info, 1, 4, blfile);
size_t n = fread(ver_info, 1, 4, blfile);
(void)n;
fclose(blfile);

//Check for marker for valid version info
Expand Down Expand Up @@ -234,13 +236,9 @@ is_operation_result cISBootloaderBase::mode_device_app
}
}

char msg[120] = { 0 };
SNPRINTF(msg, sizeof(msg), " | (%s) Incompatible device.", handle->port);
statusfn(NULL, msg, IS_LOG_LEVEL_ERROR);

delete obj;
SLEEP_MS(3000);
return IS_OP_OK;
return IS_OP_CLOSED; // Assume we found something besides app mode
}

is_operation_result cISBootloaderBase::get_device_isb_version(
Expand Down Expand Up @@ -453,15 +451,29 @@ is_operation_result cISBootloaderBase::update_device
(obj)->m_use_progress = true;
addMutex->lock();
contexts.push_back(obj);
*new_context = obj;
addMutex->unlock();
if((obj)->download_image(filenames.bl_IMX_5.path) != IS_OP_OK)

// Retry update up to 3 times, return if cancel flag gets set.
for(size_t i = 0; i < 3; i++)
{
(obj)->m_info_callback((obj), "(DFU) Update failed, retrying...", IS_LOG_LEVEL_ERROR);
(obj)->m_use_progress = false;
is_operation_result result = (obj)->download_image(filenames.bl_IMX_5.path);
if(result == IS_OP_CANCELLED)
{
return IS_OP_CLOSED;
}
else if(result != IS_OP_OK)
{
(obj)->m_info_callback((obj), "(DFU) Update failed, retrying...", IS_LOG_LEVEL_ERROR);
(obj)->m_use_progress = false;
(obj)->reboot();
continue;
}
*new_context = obj;
(obj)->reboot_up(); // Reboot up right away so an App update can happen
return IS_OP_CLOSED;
}
(obj)->reboot_up(); // Reboot up right away so an App update can happen

(obj)->m_info_callback((obj), "(DFU) Update failed, too many retries", IS_LOG_LEVEL_ERROR);
return IS_OP_CLOSED;
}
else
Expand Down Expand Up @@ -607,7 +619,12 @@ is_operation_result cISBootloaderBase::update_device
contexts.push_back(obj);
*new_context = obj;
addMutex->unlock();
if((obj)->download_image(filenames.fw_EVB_2.path) != IS_OP_OK)
is_operation_result result = (obj)->download_image(filenames.fw_EVB_2.path);
if(result == IS_OP_CANCELLED)
{
return IS_OP_CLOSED;
}
else if(result != IS_OP_OK)
{
(obj)->m_info_callback((obj), "(ISB) Update failed, retrying...", IS_LOG_LEVEL_ERROR);
(obj)->m_use_progress = false;
Expand All @@ -631,7 +648,12 @@ is_operation_result cISBootloaderBase::update_device
contexts.push_back(obj);
*new_context = obj;
addMutex->unlock();
if((obj)->download_image(filenames.fw_IMX_5.path) != IS_OP_OK)
is_operation_result result = (obj)->download_image(filenames.fw_IMX_5.path);
if(result == IS_OP_CANCELLED)
{
return IS_OP_CLOSED;
}
else if(result != IS_OP_OK)
{
(obj)->m_info_callback((obj), "(ISB) Update failed, retrying...", IS_LOG_LEVEL_ERROR);
(obj)->m_use_progress = false;
Expand All @@ -655,7 +677,12 @@ is_operation_result cISBootloaderBase::update_device
contexts.push_back(obj);
*new_context = obj;
addMutex->unlock();
if((obj)->download_image(filenames.fw_uINS_3.path) != IS_OP_OK)
is_operation_result result = (obj)->download_image(filenames.fw_uINS_3.path);
if(result == IS_OP_CANCELLED)
{
return IS_OP_CLOSED;
}
else if(result != IS_OP_OK)
{
(obj)->m_info_callback((obj), "(ISB) Update failed, retrying...", IS_LOG_LEVEL_ERROR);
(obj)->m_use_progress = false;
Expand Down
2 changes: 1 addition & 1 deletion src/ISBootloaderBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/*
MIT LICENSE
Copyright (c) 2014-2022 Inertial Sense, Inc. - http://inertialsense.com
Copyright (c) 2014-2023 Inertial Sense, Inc. - http://inertialsense.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
Expand Down
47 changes: 6 additions & 41 deletions src/ISBootloaderDFU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/*
MIT LICENSE
Copyright (c) 2014-2022 Inertial Sense, Inc. - http://inertialsense.com
Copyright (c) 2014-2023 Inertial Sense, Inc. - http://inertialsense.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
Expand Down Expand Up @@ -190,10 +190,6 @@ is_operation_result cISBootloaderDFU::get_serial_number_libusb(libusb_device_han

SLEEP_MS(100);

// Reset the device
// ret_libusb = libusb_reset_device(*handle);
// if (ret_libusb < LIBUSB_SUCCESS) { return IS_OP_ERROR; }

ret_libusb = libusb_claim_interface(*handle, 0);
if (ret_libusb < LIBUSB_SUCCESS) { libusb_release_interface(*handle, 0); return IS_OP_ERROR; }

Expand Down Expand Up @@ -282,13 +278,6 @@ is_operation_result cISBootloaderDFU::download_image(std::string filename)
ihex_image_section_t image[MAX_NUM_IHEX_SECTIONS];
size_t image_sections;

// Reset the device
// ret_libusb = libusb_reset_device(m_dfu.handle_libusb);
// if(ret_libusb < LIBUSB_SUCCESS)
// {
// return IS_OP_ERROR;
// }

SLEEP_MS(100);

ret_libusb = libusb_claim_interface(m_dfu.handle_libusb, 0);
Expand Down Expand Up @@ -496,18 +485,6 @@ is_operation_result cISBootloaderDFU::reboot()
ret_dfu = dfu_wait_for_state(&m_dfu.handle_libusb, DFU_STATE_IDLE);
if (ret_dfu < DFU_ERROR_NONE) { libusb_release_interface(m_dfu.handle_libusb, 0); return IS_OP_ERROR; }

// Set address pointer to flash
ret_dfu = dfu_set_address_pointer(&m_dfu.handle_libusb, 0x08000000);
if (ret_dfu < DFU_ERROR_NONE) { libusb_release_interface(m_dfu.handle_libusb, 0); return IS_OP_ERROR; }

// Request DFU leave
ret_libusb = dfu_DNLOAD(&m_dfu.handle_libusb, 0, NULL, 0);
if (ret_libusb < LIBUSB_SUCCESS) { libusb_release_interface(m_dfu.handle_libusb, 0); return IS_OP_ERROR; }

// Execute DFU leave
ret_dfu = dfu_wait_for_state(&m_dfu.handle_libusb, DFU_STATE_MANIFEST);
if (ret_dfu < DFU_ERROR_NONE) { libusb_release_interface(m_dfu.handle_libusb, 0); return IS_OP_ERROR; }

// Reset USB device
ret_libusb = libusb_reset_device(m_dfu.handle_libusb);
if (ret_libusb < LIBUSB_SUCCESS) { libusb_release_interface(m_dfu.handle_libusb, 0); return IS_OP_ERROR; }
Expand Down Expand Up @@ -577,39 +554,27 @@ cISBootloaderDFU::dfu_error cISBootloaderDFU::dfu_set_address_pointer(libusb_dev

cISBootloaderDFU::dfu_error cISBootloaderDFU::dfu_wait_for_state(libusb_device_handle** dev_handle, dfu_state required_state)
{
int ret_libusb;

dfu_status status;
dfu_status status = DFU_STATUS_ERR_UNKNOWN;
uint32_t waitTime = 0;
dfu_state state;
uint8_t stringIndex;

uint8_t tryCounter = 0;

ret_libusb = dfu_GETSTATUS(dev_handle, &status, &waitTime, &state, &stringIndex);
if (ret_libusb < LIBUSB_SUCCESS)
{
return DFU_ERROR_LIBUSB;
}
dfu_GETSTATUS(dev_handle, &status, &waitTime, &state, &stringIndex);

while (status != DFU_STATUS_OK || state != required_state)
{
if (status != DFU_STATUS_OK)
{
ret_libusb = dfu_CLRSTATUS(dev_handle);
if (ret_libusb < LIBUSB_SUCCESS) return DFU_ERROR_LIBUSB;
dfu_CLRSTATUS(dev_handle);
}

SLEEP_MS(_MAX(waitTime, 10));

ret_libusb = dfu_GETSTATUS(dev_handle, &status, &waitTime, &state, &stringIndex);
if (ret_libusb < LIBUSB_SUCCESS)
{
return DFU_ERROR_LIBUSB;
}
dfu_GETSTATUS(dev_handle, &status, &waitTime, &state, &stringIndex);

tryCounter++;
if (tryCounter > 4) return DFU_ERROR_TIMEOUT;
if (++tryCounter > 5) return DFU_ERROR_TIMEOUT;
}

return DFU_ERROR_NONE;
Expand Down
2 changes: 1 addition & 1 deletion src/ISBootloaderDFU.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/*
MIT LICENSE
Copyright (c) 2014-2022 Inertial Sense, Inc. - http://inertialsense.com
Copyright (c) 2014-2023 Inertial Sense, Inc. - http://inertialsense.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
Expand Down
Loading

0 comments on commit c8ee0b2

Please sign in to comment.