Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
Updater.h
1 /*
2  * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  * of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 #if !defined(_Updater_h_)
31 #define _Updater_h_
32 
33 #include "Bootloader.h"
34 #include "SourceFile.h"
35 
38 
39 using namespace blfwk;
40 
41 namespace blfwk
42 {
44 
46 {
47  uint32_t value;
48  std::string description;
49 
51  : value(0)
52  , description("")
53  {
54  }
55 
56  updater_enum_t(uint32_t value, const char *description)
57  : value(value)
58  , description(description)
59  {
60  }
61 
62  updater_enum_t(const updater_enum_t &old_enum)
63  {
64  value = old_enum.value;
65  description = old_enum.description.c_str();
66  }
67 };
68 const updater_enum_t kUpdaterState_NotReady(0, "Not ready");
69 const updater_enum_t kUpdaterState_Ready(1, "Ready");
70 const updater_enum_t kUpdaterState_Working(2, "Working");
71 const updater_enum_t kUpdaterState_Idle(3, "Idle");
72 const updater_enum_t kUpdaterState_Complete(4, "Complete");
74 
76 
77 const updater_enum_t kUpdaterTask_Erasing(0, "Erasing");
78 const updater_enum_t kUpdaterTask_Flashing(1, "Writing");
79 const updater_enum_t kUpdaterTask_Reseting(2, "Reseting");
80 const updater_enum_t kUpdaterTask_Executing(3, "Jumping");
81 
83 {
84  updater_enum_t task_desc;
85  uint32_t current;
86  uint32_t total;
87 
88  updater_task_t(const updater_enum_t &task_desc, uint32_t total)
89  : task_desc(task_desc)
90  , current(0)
91  , total(total)
92  {
93  }
94 
96  : task_desc()
97  , current(0)
98  , total(0)
99  {
100  }
101 };
102 
103 typedef std::vector<updater_task_t> updater_task_vector_t;
104 
106 
107 const updater_enum_t kUpdaterOperation_Update(0, "Update");
108 
110 
112 {
113  updater_enum_t operation_desc;
114  updater_task_vector_t tasks;
115  uint32_t current_task;
116  bool user_stopped;
117 
118  uint32_t current()
119  {
120  uint32_t current = 0;
121 
122  for (uint32_t i = 0; i < current_task; ++i)
123  {
124  current += tasks[i].total;
125  }
126 
127  current += tasks[current_task].current;
128 
129  return current;
130  }
131 
132  uint32_t total()
133  {
134  uint32_t total = 0;
135  for (uint32_t i = 0; i < tasks.size(); ++i)
136  {
137  total += tasks[i].total;
138  }
139  return total;
140  }
141 
142  updater_operation_t(updater_enum_t operation_desc)
143  : operation_desc(operation_desc)
144  , tasks()
145  , current_task(0)
146  , user_stopped(false)
147  {
148  }
149 
150  updater_operation_t(uint32_t value, const char *description)
151  : operation_desc(value, description)
152  , tasks()
153  , current_task(0)
154  , user_stopped(false)
155  {
156  }
157 };
159 
167 class Updater : public Bootloader
168 {
169 public:
172 
174  virtual ~Updater();
175 
177 
178  typedef void (*progress_callback_t)(updater_operation_t *op);
180 
183 
187  void setCallback(progress_callback_t callback) { m_progressCallback = callback; }
192  void registerCallback(void (*callback)(int, int, int), bool *abort)
193  {
194  m_progress.registerCallback(callback, abort);
195  }
196 
203  status_t flashFirmware(const char *filename, uint32_t base_address);
204 
211  void eraseAllUnsecure();
212 
221  void unlock(string backdoor_key);
222 
231  bool isCommandSupported(const cmd_t &command);
233  //
234 
243  uint32_vector_t getProperty(property_t tag);
244 
248  uint32_t getSectorSize() { return m_sector_size; };
252  uint32_t getFlshSize() { return m_flashSize; };
261  void eraseFlashRegion(uint32_t start, uint32_t length);
262 
267  void eraseFlashAll(uint32_t memoryId);
268 
279  void programOnce(uint32_t index, uint32_t byteCount, string data);
281  //
282 
283 protected:
285 
286 
293  void writeMemory(DataSource::Segment *segment);
294 
302  void writeMemory(uint32_t address, const uchar_vector_t &data);
303 
305  status_t flashFromSourceFile();
306 
308  status_t flashFromSBFile(const char *filename);
309 
310 protected:
311  uint32_t m_base_address;
312  uint32_t m_sector_size;
313  uint32_t m_flashStart;
314  uint32_t m_flashSize;
316  progress_callback_t m_progressCallback;
318 };
319 
320 }; // namespace blfwk
321 
323 
324 #endif // _Updater_h_
SourceFile * m_sourceFile
SourceFile object.
Definition: Updater.h:315
Represents the host bootloader.
Definition: src/blfwk/Bootloader.h:52
Progress m_progress
Progress control.
Definition: Updater.h:317
Definition: BlfwkErrors.h:16
Update class contains the functionality necessary to update the firmware on a device running Bootload...
Definition: Updater.h:167
uint32_t getFlshSize()
get Device&#39;s flash size.
Definition: Updater.h:252
uint32_t m_sector_size
Sector size of the flash on the device.
Definition: Updater.h:312
uint32_t m_base_address
Base address of the image.
Definition: Updater.h:311
updater_operation_t m_operation
Struct used to monitor the Operation progress.
Definition: Updater.h:182
uint32_t m_flashSize
The flash size (in bytes) of the device.
Definition: Updater.h:314
Definition: Command.h:53
Definition: Updater.h:111
Definition: Updater.h:82
Definition: Updater.h:45
Abstract base class for a source file containing executable code.
Definition: src/blfwk/SourceFile.h:56
uint32_t getSectorSize()
get Device&#39;s flash sector size.
Definition: Updater.h:248
Discrete, contiguous part of the source&#39;s data.
Definition: src/blfwk/DataSource.h:65
Contains the callback function for progress and abort phase.
Definition: Command.h:225
void setCallback(progress_callback_t callback)
Set the user-defined function to call on progress events.
Definition: Updater.h:187
Definition: Command.h:117
uint32_t m_flashStart
Start address of the flash on the device.
Definition: Updater.h:313
void registerCallback(void(*callback)(int, int, int), bool *abort)
Set callback for progress and abort control.
Definition: Updater.h:192
progress_callback_t m_progressCallback
Callback used to report update progress.
Definition: Updater.h:316
Definition: Peripheral.h:60