fw-update-unsigned.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2019 Intel Corporation. All Rights Reserved.
3 
4 #include "fw-update-unsigned.h"
5 #include <algorithm>
6 
7 namespace librealsense
8 {
9  std::vector<flash_payload_header> parse_payloads(const std::vector<uint8_t>& flash_buffer, size_t number_of_payloads)
10  {
11  std::vector<flash_payload_header> rv;
12  size_t offset = 0;
13  for (int i = 0; i < number_of_payloads; i++)
14  {
15  flash_payload_header fph = {};
16  memcpy(&fph, flash_buffer.data() + i * sizeof(fph), sizeof(fph));
17  offset += fph.data_offset + fph.data_size;
18  rv.push_back(fph);
19  }
20  return rv;
21  }
22 
23  std::vector<flash_table> parse_tables(const std::vector<uint8_t>& flash_buffer, flash_table toc, flash_structure structure)
24  {
25  std::vector<flash_table> rv;
26  auto num_of_tables = toc.header.size / sizeof(uint64_t);
27 
28  std::vector<uint32_t> offsets(num_of_tables);
29  for (int i = 0; i < num_of_tables; i++)
30  {
31  memcpy(&offsets[i], toc.data.data() + (i * sizeof(uint64_t)) + 4, sizeof(uint32_t));
32  }
33 
34  for (auto&& o : offsets)
35  {
37  memcpy(&h, flash_buffer.data() + o, sizeof(h));
38 
39  std::vector<uint8_t> d;
40  if (h.type == 0 || h.size == 0 || h.size > 0x1000)
41  continue;
42 
43  d.resize(h.size);
44  memcpy(d.data(), flash_buffer.data() + o + sizeof(h), d.size());
45 
46  auto types = structure.read_only_sections_types;
47  auto it = std::find_if(types.begin(), types.end(), [h](uint16_t t) { return t == h.type; });
48  bool read_only = it != types.end();
49  flash_table ft = { h, d, o, read_only };
50 
51  rv.push_back(ft);
52  }
53  rv.push_back(toc);
54  return rv;
55  }
56 
57  std::vector<uint8_t> merge_images(flash_info from, flash_info to, const std::vector<uint8_t> image)
58  {
59  std::vector<uint8_t> rv(image);
60 
61  for (auto&& table : from.read_write_section.tables)
62  {
63  if (!table.read_only)
64  continue;
65  memcpy(rv.data() + table.offset, &table.header, sizeof(table.header));
66  memcpy(rv.data() + table.offset + sizeof(table.header), table.data.data(), table.header.size);
67  }
68 
69  for (auto&& table : from.read_only_section.tables)
70  {
71  if (!table.read_only)
72  continue;
73  memcpy(rv.data() + table.offset, &table.header, sizeof(table.header));
74  memcpy(rv.data() + table.offset + sizeof(table.header), table.data.data(), table.header.size);
75  }
76 
77  return rv;
78  }
79 
80  flash_table parse_table_of_contents(const std::vector<uint8_t>& flash_buffer, uint32_t toc_offset)
81  {
82  flash_table rv = {};
83 
84  memcpy(&rv.header, flash_buffer.data() + toc_offset, sizeof(rv.header));
85  rv.data.resize(rv.header.size);
86  memcpy(rv.data.data(), flash_buffer.data() + toc_offset + sizeof(rv.header), rv.data.size());
87 
88  rv.read_only = false;
89  rv.offset = toc_offset;
90 
91  return rv;
92  }
93 
94  flash_section parse_flash_section(const std::vector<uint8_t>& flash_buffer, flash_table toc, flash_structure s)
95  {
96  flash_section rv = {};
97 
98  rv.table_of_content = toc;
99  rv.payloads = parse_payloads(flash_buffer, s.payload_count);
100  rv.tables = parse_tables(flash_buffer, toc, s);
101  rv.version = toc.header.version;
102  rv.app_size = rv.payloads.back().data_offset + rv.payloads.back().data_size;
103 
104  return rv;
105  }
106 }
flash_section parse_flash_section(const std::vector< uint8_t > &flash_buffer, flash_table toc, flash_structure s)
std::vector< flash_payload_header > payloads
std::vector< uint16_t > read_only_sections_types
GLdouble s
unsigned short uint16_t
Definition: stdint.h:79
d
Definition: rmse.py:171
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:1960
GLenum GLenum GLsizei void * image
GLdouble t
std::vector< flash_table > parse_tables(const std::vector< uint8_t > &flash_buffer, flash_table toc, flash_structure structure)
GLsizei GLenum GLenum * types
std::vector< flash_payload_header > parse_payloads(const std::vector< uint8_t > &flash_buffer, size_t number_of_payloads)
unsigned int uint32_t
Definition: stdint.h:80
std::vector< uint8_t > data
unsigned __int64 uint64_t
Definition: stdint.h:90
std::vector< uint8_t > merge_images(flash_info from, flash_info to, const std::vector< uint8_t > image)
flash_table parse_table_of_contents(const std::vector< uint8_t > &flash_buffer, uint32_t toc_offset)
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glext.h:2580
GLenum GLenum GLsizei void * table
static auto it
std::vector< flash_table > tables
int i
GLintptr offset


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:15