blob: a013e16ee48abe26bf494f00d63489097fbe6b41 [file] [log] [blame]
Vadim Iosevichd50ea462017-03-30 16:19:08 +03001/*
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_IMAGE_H_
31#define _FLASH_IMAGE_H_
32
33#include "wiburn.h"
34#include "flash_sections.h"
35#include "ini_parser.h"
36#include "product.h"
37
38u_int16_t crc_16 (const u_int32_t *buffer, int size);
39
40template <class PRODUCT>
41class flash_image
42{
43public:
44 flash_image ();
45 ~flash_image ();
46 void init (ini_parser_base *parser, bool full_image, bool isReducedSip); // init from ini file
47 void init (const char *filename); // init from image file
48 void init_pointer_section (flash_base *fl); // init from flash
49 void init_hw_conf_section (flash_base *fl); // init from flash
50 // void init_radio_tx_conf_section (flash_base *fl); // init from flash
51 // void init_radio_rx_conf_section (flash_base *fl); // init from flash
52 // void init_radio_tx_conf2_section (flash_base *fl); // init from flash
53 // void init_radio_rx_conf2_section (flash_base *fl); // init from flash
54 void init_image_info_section (flash_base *fl); // init from flash
55 void init_ids_section (flash_base *fl, bool isReduced); // init from flash
56 void init_usb_info_section (flash_base *fl); // init from flash
57 void save (const char *filename);
58 const BYTE* get_image (void) const;
59 u_int32_t get_image_size (void) const;
60 const pointer_section_t <PRODUCT> & get_pointer_section(void) const;
61 const hw_section_t <PRODUCT> & get_hw_conf_section(void) const;
62 // const hw_section_t <marlon> & get_radio_tx_conf_section(void) const;
63 // const hw_section_t <marlon> & get_radio_rx_conf_section(void) const;
64 // const hw_section_t <marlon> & get_radio_tx_conf2_section(void) const;
65 // const hw_section_t <marlon> & get_radio_rx_conf2_section(void) const;
66 const image_info_section_t<PRODUCT>& get_image_info_section(void) const;
67 const usb_info_section_t<PRODUCT>& get_usb_info_section(void) const;
68 const ids_section_t<PRODUCT>& get_ids_section(void) const;
69 // const image_section_t<PRODUCT>& get_fw1_code_section () const;
70 // const image_section_t<PRODUCT>& get_fw2_code_section () const;
71private:
72 pointer_section_t <PRODUCT> pointer_section;
73 hw_section_t <PRODUCT> hw_conf_section;
74
75 image_section_t<PRODUCT> fw1_code_section;
76 image_section_t<PRODUCT> fw1_data_section;
77 fw_section_t <PRODUCT> fw1_static_conf_section;
78
79 image_section_t<PRODUCT> fw2_code_section;
80 image_section_t<PRODUCT> fw2_data_section;
81 fw_section_t <PRODUCT> fw2_static_conf_section;
82
83 system_config_section_t <PRODUCT> system_config_section;
84
85 hw_section_t <PRODUCT> production_section;
86 fw_section_t <PRODUCT> user_conf_section;
87
88 image_info_section_t<PRODUCT> image_info_section;
89 ids_section_t<PRODUCT> ids_section;
90
91 usb_section_t usb_section;
92 usb_info_section_t<PRODUCT> usb_info_section;
93
94 hw_section_t <marlon> radio_tx_conf_section;
95 hw_section_t <marlon> radio_rx_conf_section;
96 hw_section_t <marlon> radio_tx_conf2_section;
97 hw_section_t <marlon> radio_rx_conf2_section;
98
99 image_section_t<PRODUCT> raw_data_section;
100
101 IProduct* proxy_product;
102
103private:
104#ifdef FLASH_256KB
105 BYTE m_image [(1<<21)/8]; //2Mbits - 256KB
106#else
Vadim Iosevichfd2a0e02017-09-19 11:59:56 +0300107 BYTE* m_image;
108 int m_imageSize;
Vadim Iosevichd50ea462017-03-30 16:19:08 +0300109#endif
110};
111
112#endif //#ifndef _FLASH_IMAGE_H_