Vadim Iosevich | d50ea46 | 2017-03-30 16:19:08 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of The Linux Foundation nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #ifndef _FLASH_SECTIONS_H_ |
| 31 | #define _FLASH_SECTIONS_H_ |
| 32 | |
| 33 | #include "wiburn.h" |
| 34 | #include "ini_parser_types.h" |
| 35 | #include "flash.h" |
| 36 | #include "CCRC32.h" |
| 37 | |
| 38 | enum tag_ids { |
| 39 | image_format_version_tag_id = 0x1, |
| 40 | fw_version_tag_id = 0x2, |
| 41 | fw_timestamp_tag_id = 0x3, |
| 42 | usb_format_version_tag_id = 0x1, |
| 43 | usb_version_tag_id = 0x2, |
| 44 | usb_timestamp_tag_id = 0x3, |
| 45 | configuration_id_tag_id = 0x4, |
| 46 | device_id_tag_id = 0x5, |
| 47 | hw_id_tag_id = 0x6, |
| 48 | end_tag_id = 0xff |
| 49 | }; |
| 50 | |
| 51 | #pragma pack(push, 1) |
| 52 | template <class PRODUCT> |
| 53 | struct pointers_t |
| 54 | { |
| 55 | typename PRODUCT::REG signature; |
| 56 | ADDRESS32 hw_pointer; |
| 57 | ADDRESS32 fw1_pointer; |
| 58 | typename PRODUCT::REG fw1_length; |
| 59 | ADDRESS32 fw1_data_pointer; |
| 60 | typename PRODUCT::REG fw1_data_length; |
| 61 | ADDRESS32 fw2_pointer; |
| 62 | typename PRODUCT::REG fw2_length; |
| 63 | ADDRESS32 fw2_data_pointer; |
| 64 | typename PRODUCT::REG fw2_data_length; |
| 65 | ADDRESS32 production_pointer; |
| 66 | ADDRESS32 ids_pointer; |
| 67 | typename PRODUCT::REG pointer_section_version; |
| 68 | ADDRESS32 fw1_static_conf_pointer; |
| 69 | ADDRESS32 fw2_static_conf_pointer; |
| 70 | ADDRESS32 config_section_pointer; |
| 71 | ADDRESS32 image_info_pointer; |
| 72 | ADDRESS32 radio_tx_cnf_pointer; |
| 73 | ADDRESS32 radio_rx_cnf_pointer; |
| 74 | ADDRESS32 radio_tx_cnf2_pointer; |
| 75 | ADDRESS32 radio_rx_cnf2_pointer; |
| 76 | ADDRESS32 raw_data_pointer; |
| 77 | typename PRODUCT::REG raw_data_length; |
| 78 | |
| 79 | // Unused |
| 80 | ADDRESS32 usb_pointer; |
| 81 | ADDRESS32 usb_info_pointer; |
| 82 | ADDRESS32 user_pointer; |
| 83 | }; |
| 84 | #pragma pack(pop) |
| 85 | |
| 86 | #pragma pack(push, 1) |
| 87 | template <class PRODUCT> |
| 88 | struct address_value_t |
| 89 | { |
| 90 | typename PRODUCT::ADDRESS address; |
| 91 | typename PRODUCT::REG value; |
| 92 | }; |
| 93 | #pragma pack(pop) |
| 94 | |
| 95 | #pragma pack(push, 1) |
| 96 | template <class PRODUCT> |
| 97 | struct address_value_mask_t |
| 98 | { |
| 99 | typename PRODUCT::ADDRESS address; |
| 100 | typename PRODUCT::REG value; |
| 101 | typename PRODUCT::REG mask; |
| 102 | }; |
| 103 | #pragma pack(pop) |
| 104 | |
| 105 | |
| 106 | #pragma pack(push, 1) |
| 107 | struct tag_header_t |
| 108 | { |
| 109 | BYTE reserved; |
| 110 | BYTE tag_id; |
| 111 | u_int16_t tag_size; |
| 112 | void disp(const char *name); |
| 113 | }; |
| 114 | #pragma pack(pop) |
| 115 | |
| 116 | #pragma pack(push, 1) |
| 117 | struct format_version_tag_t |
| 118 | { |
| 119 | BYTE format_version; |
| 120 | BYTE reserved [3]; |
| 121 | void disp(const char *name); |
| 122 | }; |
| 123 | #pragma pack(pop) |
| 124 | |
| 125 | #pragma pack(push, 1) |
| 126 | struct version_tag_t |
| 127 | { |
| 128 | u_int32_t minor : 8; |
| 129 | u_int32_t major : 8; |
| 130 | u_int32_t build : 13; |
| 131 | u_int32_t sub_minor : 3; |
| 132 | void disp(const char *name); |
| 133 | }; |
| 134 | #pragma pack(pop) |
| 135 | |
| 136 | #pragma pack(push, 1) |
| 137 | struct timestamp_tag_t |
| 138 | { |
| 139 | BYTE min; |
| 140 | BYTE hour; |
| 141 | BYTE reserved1; |
| 142 | BYTE sec; |
| 143 | BYTE month; |
| 144 | BYTE day; |
| 145 | u_int16_t year; |
| 146 | void disp(const char *name); |
| 147 | }; |
| 148 | #pragma pack(pop) |
| 149 | |
| 150 | #pragma pack(push, 1) |
| 151 | struct configuration_id_tag_t |
| 152 | { |
| 153 | BYTE id [16]; |
| 154 | void disp(const char *name); |
| 155 | }; |
| 156 | #pragma pack(pop) |
| 157 | |
| 158 | #pragma pack(push, 1) |
| 159 | struct device_id_tag_t |
| 160 | { |
| 161 | u_int16_t device_id; |
| 162 | BYTE revision_id; |
| 163 | BYTE misc; |
| 164 | void disp(const char *name); |
| 165 | }; |
| 166 | #pragma pack(pop) |
| 167 | |
| 168 | #pragma pack(push, 1) |
| 169 | struct hw_id_tag_t |
| 170 | { |
| 171 | BYTE digital_soc_id; |
| 172 | BYTE board_id; |
| 173 | BYTE antenna_id; |
| 174 | BYTE rf_id; |
| 175 | u_int16_t serial_id; |
| 176 | u_int16_t reserved; |
| 177 | void disp(const char *name); |
| 178 | }; |
| 179 | #pragma pack(pop) |
| 180 | |
| 181 | #pragma pack(push, 1) |
| 182 | struct end_tag_t |
| 183 | { |
| 184 | u_int16_t reserved1; |
| 185 | u_int16_t reserved2; |
| 186 | void disp(const char *name); |
| 187 | }; |
| 188 | #pragma pack(pop) |
| 189 | |
| 190 | class tag_base_t |
| 191 | { |
| 192 | public: |
| 193 | virtual char *get_tag() = 0; |
| 194 | tag_base_t (BYTE id, const char* name); |
| 195 | virtual ~tag_base_t() {}; |
| 196 | virtual void disp() = 0; |
| 197 | public: |
| 198 | tag_header_t m_header; |
| 199 | const char *m_name; |
| 200 | }; |
| 201 | |
| 202 | template <class Tag> |
| 203 | class tag_t: public tag_base_t |
| 204 | { |
| 205 | public: |
| 206 | char *get_tag(); |
| 207 | tag_t (BYTE id, const char* name = 0); |
| 208 | virtual ~tag_t() {}; |
| 209 | void disp(); |
| 210 | public: |
| 211 | Tag m_tag; |
| 212 | }; |
| 213 | |
| 214 | |
| 215 | #pragma pack(push, 1) |
| 216 | struct section_header_t |
| 217 | { |
| 218 | BYTE reserved; |
| 219 | BYTE section_id; |
| 220 | u_int16_t section_size; |
| 221 | }; |
| 222 | #pragma pack(pop) |
| 223 | |
| 224 | class flash_section |
| 225 | { |
| 226 | public: |
| 227 | flash_section (const char *name); |
| 228 | virtual void write_to_buffer(BYTE *buffer ) = 0; |
| 229 | int size () const; |
| 230 | int get_max_size () const; |
| 231 | void set_max_size ( u_int32_t max_size ); |
| 232 | void set_offset (u_int32_t offset); |
| 233 | u_int32_t get_offset () const; |
| 234 | virtual ~flash_section() {}; |
| 235 | protected: |
| 236 | u_int32_t m_size; |
| 237 | u_int32_t m_max_size; |
| 238 | u_int32_t m_offset; |
| 239 | const char *m_name; |
| 240 | u_int32_t m_crc; |
| 241 | CCRC32 m_CalcCRC; |
| 242 | }; |
| 243 | |
| 244 | class usb_section_t : public flash_section |
| 245 | { |
| 246 | public: |
| 247 | //usb_section_t (const char *name, u_int16_t *ptr_low, u_int16_t* ptr_high); |
| 248 | usb_section_t (const char *name, ADDRESS32 *ptr); |
| 249 | void write_to_buffer(BYTE *buffer ) ; |
| 250 | void handle_ini_section (const ini_section_t &ini_section); |
| 251 | void set_offset (int offset); |
| 252 | ~usb_section_t(); |
| 253 | public: |
| 254 | IMAGE *m_buffer; |
| 255 | // u_int16_t *m_ptr_low; |
| 256 | // u_int16_t *m_ptr_high; |
| 257 | ADDRESS32 *m_ptr; |
| 258 | }; |
| 259 | |
| 260 | class id_section : public flash_section |
| 261 | { |
| 262 | public: |
| 263 | //id_section (const char *name, BYTE id, u_int16_t *ptr_low, u_int16_t* ptr_high); |
| 264 | id_section (const char *name, BYTE id, ADDRESS32 *ptr); |
| 265 | void set_offset (int offset); |
| 266 | |
| 267 | public: |
| 268 | section_header_t header; |
| 269 | // u_int16_t *m_ptr_low; |
| 270 | // u_int16_t *m_ptr_high; |
| 271 | ADDRESS32 *m_ptr; |
| 272 | }; |
| 273 | |
| 274 | class variable_section_t : public id_section |
| 275 | { |
| 276 | public: |
| 277 | // variable_section_t (const char *name, BYTE id, u_int16_t *ptr_low, u_int16_t *ptr_high); |
| 278 | variable_section_t (const char *name, BYTE id, ADDRESS32 *ptr); |
| 279 | ~variable_section_t (); |
| 280 | protected: |
| 281 | int m_buffer_size; |
| 282 | }; |
| 283 | |
| 284 | template <class PRODUCT> |
| 285 | class hw_section_t : public variable_section_t |
| 286 | { |
| 287 | public: |
| 288 | // hw_section_t (const char *name, BYTE id, u_int16_t *ptr_low, u_int16_t *ptr_high); |
| 289 | hw_section_t (const char *name, BYTE id, ADDRESS32 *ptr); |
| 290 | public: |
| 291 | void handle_ini_section (u_int8_t translation_map_bits, const ini_section_t &ini_section); |
| 292 | void init (flash_base *flash); |
| 293 | bool operator == (const hw_section_t &r_side) const; |
| 294 | void write_to_buffer(BYTE *buffer ) ; |
| 295 | ~hw_section_t (); |
| 296 | address_value_t <PRODUCT> *m_buffer; |
| 297 | u_int16_t *m_length; |
| 298 | u_int32_t m_termination [2]; |
| 299 | |
| 300 | }; |
| 301 | |
| 302 | template <class PRODUCT> |
| 303 | class fw_section_t : public variable_section_t |
| 304 | { |
| 305 | public: |
| 306 | //fw_section_t (const char *name, BYTE id, u_int16_t *ptr_low, u_int16_t *ptr_high); |
| 307 | fw_section_t (const char *name, BYTE id, ADDRESS32 *ptr); |
| 308 | public: |
| 309 | void handle_ini_section (u_int8_t translation_map_bits, const ini_section_t &ini_section); |
| 310 | void write_to_buffer(BYTE *buffer ) ; |
| 311 | ~fw_section_t (); |
| 312 | address_value_mask_t <PRODUCT> *m_buffer; |
| 313 | }; |
| 314 | |
| 315 | template <class PRODUCT> |
| 316 | class image_section_t : public variable_section_t |
| 317 | { |
| 318 | public: |
| 319 | //image_section_t (const char *name, BYTE id, u_int16_t *ptr_low, u_int16_t *ptr_high, u_int16_t *length); |
| 320 | image_section_t (const char *name, BYTE id, ADDRESS32 *ptr, typename PRODUCT::REG *length); |
| 321 | void handle_ini_section (const ini_section_t &ini_section); |
| 322 | void write_to_buffer(BYTE *buffer ) ; |
| 323 | void set_offset (int offset); |
| 324 | ~image_section_t (); |
| 325 | public: |
| 326 | IMAGE *m_buffer; |
| 327 | //u_int16_t *m_length; |
| 328 | typename PRODUCT::REG *m_length; |
| 329 | }; |
| 330 | |
| 331 | template <class PRODUCT> |
| 332 | class pointer_section_t : public flash_section |
| 333 | { |
| 334 | public: |
| 335 | pointer_section_t (const char *name); |
| 336 | void init (flash_base *fl); |
| 337 | void write_to_buffer(BYTE *buffer ) ; |
| 338 | bool operator == (const pointer_section_t <PRODUCT> &r_side) const; |
| 339 | public: |
| 340 | pointers_t <PRODUCT> m_pointers; |
| 341 | }; |
| 342 | |
| 343 | template <class PRODUCT> |
| 344 | class info_section_t : public variable_section_t |
| 345 | { |
| 346 | public: |
| 347 | typedef vector <tag_base_t*> tag_vector_t; |
| 348 | public: |
| 349 | // info_section_t (const char *name, BYTE id, u_int16_t *ptr_low, u_int16_t *ptr_high); |
| 350 | info_section_t (const char *name, BYTE id, ADDRESS32 *ptr); |
| 351 | virtual void handle_ini_section (const ini_section_t &ini_section, |
| 352 | const string &name) = 0; |
| 353 | virtual void init (flash_base *flash) = 0; |
| 354 | void write_to_buffer(BYTE *buffer ) ; |
| 355 | ~info_section_t (); |
| 356 | void disp() const; |
| 357 | |
| 358 | public: |
| 359 | tag_vector_t m_tags; |
| 360 | u_int16_t *m_length; |
| 361 | }; |
| 362 | |
| 363 | template <class PRODUCT> |
| 364 | class image_info_section_t : public info_section_t<PRODUCT> |
| 365 | { |
| 366 | public: |
| 367 | //image_info_section_t (const char *name, BYTE id, u_int16_t *ptr_low, u_int16_t *ptr_high); |
| 368 | image_info_section_t (const char *name, BYTE id, ADDRESS32 *ptr); |
| 369 | void handle_ini_section (const ini_section_t &ini_section, |
| 370 | const string &name); |
| 371 | void init (flash_base *fl); |
| 372 | ~image_info_section_t (); |
| 373 | }; |
| 374 | |
| 375 | template <class PRODUCT> |
| 376 | class usb_info_section_t : public info_section_t<PRODUCT> |
| 377 | { |
| 378 | public: |
| 379 | // usb_info_section_t (const char *name, BYTE id, u_int16_t *ptr_low, u_int16_t *ptr_high); |
| 380 | usb_info_section_t (const char *name, BYTE id, ADDRESS32 *ptr); |
| 381 | void handle_ini_section (const ini_section_t &ini_section, |
| 382 | const string &name); |
| 383 | void init (flash_base *fl); |
| 384 | ~usb_info_section_t (); |
| 385 | }; |
| 386 | |
| 387 | template <class PRODUCT> |
| 388 | class system_config_section_t : public flash_section |
| 389 | { |
| 390 | public: |
| 391 | system_config_section_t (const char *name, ADDRESS32 *ptr); |
| 392 | void set_offset (int offset); |
| 393 | void write_to_buffer(BYTE *buffer ) ; |
| 394 | |
| 395 | public: |
| 396 | ADDRESS32 *m_ptr; |
| 397 | }; |
| 398 | |
| 399 | |
| 400 | #pragma pack(push, 1) |
| 401 | struct ids_section |
| 402 | { |
| 403 | BYTE reserved1; |
| 404 | BYTE version; |
| 405 | BYTE mac_address [6]; |
| 406 | BYTE ssid [32]; |
| 407 | u_int16_t local; |
| 408 | u_int16_t reserved2; |
| 409 | u_int16_t ppm; |
| 410 | u_int16_t reserved3; |
| 411 | u_int32_t board_type; |
| 412 | u_int16_t lo_power_xif_gc; |
| 413 | u_int16_t lo_power_stg2_bias; |
| 414 | u_int16_t vga_bias; |
| 415 | u_int16_t vga_stg1_fine_bias; |
| 416 | u_int16_t ats_ver; |
| 417 | u_int16_t mlt_ver; |
| 418 | u_int16_t bl_ver; |
| 419 | u_int16_t lo_power_gc_ctrl; |
| 420 | u_int16_t production1; |
| 421 | u_int16_t production2; |
| 422 | u_int16_t production3; |
| 423 | u_int16_t production4; |
| 424 | u_int16_t production5; |
| 425 | u_int16_t production6; |
| 426 | u_int16_t production7; |
| 427 | u_int16_t production8; |
| 428 | u_int16_t production9; |
| 429 | u_int16_t production10; |
| 430 | u_int16_t production11; |
| 431 | u_int16_t production12; |
| 432 | u_int16_t production13; |
| 433 | u_int16_t production14; |
| 434 | u_int16_t production15; |
| 435 | u_int16_t production16; |
| 436 | }; |
| 437 | #pragma pack(pop) |
| 438 | |
| 439 | template <typename T, class PRODUCT> |
| 440 | struct const_section_t: public id_section |
| 441 | { |
| 442 | public: |
| 443 | // const_section_t (const char *name, BYTE id, u_int16_t *ptr_low, u_int16_t* ptr_high); |
| 444 | const_section_t (const char *name, BYTE id, ADDRESS32 *ptr); |
| 445 | virtual void handle_ini_section (const ini_section_t &ini_section) = 0; |
| 446 | void write_to_buffer(BYTE *buffer ) ; |
| 447 | virtual void init (flash_base *fl); |
| 448 | virtual void initReduced (flash_base *fl, int reductionSize); |
| 449 | public: |
| 450 | T m_section; |
| 451 | }; |
| 452 | |
| 453 | |
| 454 | template <class PRODUCT> |
| 455 | struct ids_section_t: public const_section_t <ids_section, PRODUCT> |
| 456 | { |
| 457 | public: |
| 458 | // ids_section_t (const char *name, BYTE id, u_int16_t *ptr_low, u_int16_t* ptr_high); |
| 459 | ids_section_t (const char *name, BYTE id, ADDRESS32 *ptr); |
| 460 | void handle_ini_section (const ini_section_t &ini_section); |
| 461 | void disp() const; |
| 462 | void disp_to_file(const char* ids_ini_file) const; |
| 463 | }; |
| 464 | #endif //#ifndef _FLASH_SECTIONS_H_ |