yprog.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * $Id: yprog.h 25587 2016-10-18 14:38:13Z seb $
4  *
5  * Declaration of firmware upgrade functions
6  *
7  * - - - - - - - - - License information: - - - - - - - - -
8  *
9  * Copyright (C) 2011 and beyond by Yoctopuce Sarl, Switzerland.
10  *
11  * Yoctopuce Sarl (hereafter Licensor) grants to you a perpetual
12  * non-exclusive license to use, modify, copy and integrate this
13  * file into your software for the sole purpose of interfacing
14  * with Yoctopuce products.
15  *
16  * You may reproduce and distribute copies of this file in
17  * source or object form, as long as the sole purpose of this
18  * code is to interface with Yoctopuce products. You must retain
19  * this notice in the distributed source file.
20  *
21  * You should refer to Yoctopuce General Terms and Conditions
22  * for additional information regarding your rights and
23  * obligations.
24  *
25  * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
26  * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
27  * WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS
28  * FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO
29  * EVENT SHALL LICENSOR BE LIABLE FOR ANY INCIDENTAL, SPECIAL,
30  * INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA,
31  * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR
32  * SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT
33  * LIMITED TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR
34  * CONTRIBUTION, OR OTHER SIMILAR COSTS, WHETHER ASSERTED ON THE
35  * BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE), BREACH OF
36  * WARRANTY, OR OTHERWISE.
37  *
38  *********************************************************************/
39 
40 #ifndef YPROG_H
41 #define YPROG_H
42 #include "ydef.h"
43 
44 #ifdef MICROCHIP_API
45 typedef int ProgIface;
46 #else
47 #include "yproto.h"
49 #endif
50 
51 #if !defined(MICROCHIP_API) || (defined(YHUB) && defined(FLASH_FIRMW_FIRSTPAGE))
52 #define PROG_SUBDEV
53 #endif
54 
55 #define MAX_ROM_ZONES_PER_FILES 16
56 #define MAX_FLASH_ZONES_PER_FILES 4
57 
58 #define BYN_SIGN ((u32) ('B'| ((u16)'Y'<<8) | ((u32)'N'<<16) ))
59 #define BYN_REV_V4 4
60 #define BYN_REV_V5 5
61 #define BYN_REV_V6 6
62 
63 #ifndef C30
64 #pragma pack(push,1)
65 #endif
66 
67 
68 #define USE_V6_BYN_FILE
69 
70 
71 typedef struct{
72  union {
73  u32 sign;
74  struct {
75  char a;
76  char b;
77  char c;
78  char d;
79  } signchars;
80  };
81  u16 rev;
82  char serial[YOCTO_SERIAL_LEN];
83  char pictype[20];
84  char product[YOCTO_PRODUCTNAME_LEN];
85  char firmware[YOCTO_FIRMWARE_LEN];
87 
88 typedef struct{
89  u32 nbzones;
90  u32 datasize;
92 
93 typedef struct{
94  char prog_version[YOCTO_FIRMWARE_LEN];
95  u16 pad;
96  u32 nbzones;
97  u32 datasize;
99 
100 typedef struct{
101  u8 md5chk[16];
102  char prog_version[YOCTO_FIRMWARE_LEN]; // 22 bytes
107 }byn_head_v6;
108 
109 typedef struct{
111  union {
115  };
117 
118 
119 
120 #define BYN_HEAD_SIZE_V4 (sizeof(byn_head_sign)+sizeof(byn_head_v4))
121 #define BYN_HEAD_SIZE_V5 (sizeof(byn_head_sign)+sizeof(byn_head_v5))
122 #define BYN_HEAD_SIZE_V6 (sizeof(byn_head_sign)+sizeof(byn_head_v6))
123 #define BYN_MD5_OFS_V6 (sizeof(byn_head_sign)+16)
124 
125 typedef struct{
127  u32 len;
128 }byn_zone;
129 
130 #ifdef CPU_BIG_ENDIAN
131 void decode_byn_head_multi(byn_head_multi *byn_head);
132 void decode_byn_zone(byn_zone *zone);
133 #define DECODE_U16(NUM) ((((NUM) & 0xff00) >> 8) | (((NUM)&0xff) << 8))
134 #define DECODE_U32(NUM) ((((NUM) >> 24) & 0xff) | (((NUM) << 8) & 0xff0000) | (((NUM) >> 8) & 0xff00) | (((NUM) << 24) & 0xff000000 ))
135 #else
136 #define decode_byn_head_multi(dummy) {}
137 #define decode_byn_zone(dummy) {}
138 #define DECODE_U16(NUM) (NUM)
139 #define DECODE_U32(NUM) (NUM)
140 #endif
141 
142 typedef struct{
143  u32 addr;
144  u32 nbinstr;
145  u32 nbblock;
146  u8 *ptr;
147  u32 len;
148 }romzone;
149 
150 typedef struct{
151  u32 page;
152  u8 *ptr;
153  u32 len;
154 }flashzone;
155 
156 typedef struct {
157  u32 nbrom;
158  u32 nbflash;
161 }newmemzones;
162 
163 typedef struct{
174 #ifndef MICROCHIP_API
180 #endif
181 }BootloaderSt;
182 
183 // from yfirmupd.c
184 extern BootloaderSt firm_dev;
185 extern USB_Packet firm_pkt;
186 
187 #ifndef C30
188 #pragma pack(pop)
189 #endif
190 YRETCODE yapiGetBootloadersDevs(char *serials, unsigned int maxNbSerial, unsigned int *totalBootladers, char *errmsg);
191 
192 // Return 1 if the communication channel to the device is busy
193 // Return 0 if there is no ongoing transaction with the device
195 
196 // Return 0 if there command was successfully queued for sending
197 // Return -1 if the output channel is busy and the command could not be sent
198 int ypSendBootloaderCmd(BootloaderSt *dev, const USB_Packet *pkt,char *errmsg);
199 // Return 0 if a reply packet was available and returned
200 // Return -1 if there was no reply available
201 int ypGetBootloaderReply(BootloaderSt *dev, USB_Packet *pkt,char *errmsg);
202 // Power cycle the device
204 int IsValidBynHead(const byn_head_multi *head, u32 size, u16 flags, char *errmsg);
205 
206 #ifndef MICROCHIP_API
207 const char* prog_GetCPUName(BootloaderSt *dev);
208 int ValidateBynCompat(const byn_head_multi *head, u32 size, const char *serial, u16 flags, BootloaderSt *dev, char *errmsg);
209 int IsValidBynFile(const byn_head_multi *head, u32 size, const char *serial, u16 flags, char *errmsg);
210 int BlockingRead(BootloaderSt *dev, USB_Packet *pkt, int maxwait, char *errmsg);
211 int SendDataPacket(BootloaderSt *dev, int program, u32 address, u8 *data, int nbinstr, char *errmsg);
212 #endif
213 
214 //#define DEBUG_FIRMWARE
215 typedef enum
216 {
217  YPROG_DONE = 0u, // Finished with procedure
218  YPROG_WAITING // Waiting for asynchronous process to complete, call again later
219 } YPROG_RESULT;
220 
221 
222 #define MAX_FIRMWARE_LEN 0x100000ul
223 #define INVALID_FIRMWARE 0xfffffffful
224 #define FLASH_NB_REBOOT_RETRY 1
225 
226 typedef enum{
228 #ifndef MICROCHIP_API
230 #endif
239 #ifndef MICROCHIP_API
241 #endif
246 
247 typedef enum {
253 
254 
255 #define BLOCK_FLASH_TIMEOUT 4000u
256 #define PROG_GET_INFO_TIMEOUT 10000u
257 #define ZONE_VERIF_TIMEOUT 4000u
258 #define FLASH_SUBDEV_TIMEOUT 59000u
259 #define YPROG_BOOTLOADER_TIMEOUT 20000u
260 #define YPROG_FORCE_FW_UPDATE 1u
261 
262 #ifdef MICROCHIP_API
263 #define FLASH_ERRMSG_LEN 56
264 #else
265 #define FLASH_ERRMSG_LEN YOCTO_ERRMSG_LEN
266 #endif
267 
268 
269 #define PROG_IN_ERROR 0x8000
270 typedef struct {
271 #ifndef MICROCHIP_API
272  u8 *firmware;
274 #endif
275  u32 len;
276  union {
278  u8 bynBuff[sizeof(byn_head_multi)];
279  };
280  u16 flags;
281  u16 currzone;
282  s16 progress;
285  union {
287  u8 bzBuff[sizeof(byn_zone)];
288  };
290  u32 zOfs;
291  u32 zNbInstr;
292  u32 stepB;
296  char errmsg[FLASH_ERRMSG_LEN];
298 
299 extern FIRMWARE_CONTEXT fctx;
300 
301 
302 // memo: u=universal y=yapi h=hub
303 
304 #ifdef YAPI_IN_YDEVICE
305 #define uGetFirmware(ofs, dst, size) hProgGetFirmware(ofs, dst, size)
306 void hProgInit(void);
307 void hProgFree(void);
308 #else
309 #define uGetFirmware(ofs, dst, size) yGetFirmware(ofs, dst, size)
310 void yProgInit(void);
311 void yProgFree(void);
312 YRETCODE yapiCheckFirmware_internal(const char *serial, const char *rev, u32 flags, const char *path, char *buffer, int buffersize, int *fullsize, char *errmsg);
313 YRETCODE yapiUpdateFirmware_internal(const char *serial, const char *firmwarePath, const char *settings, int force, int startUpdate, char *msg);
314 #endif
315 
316 
317 
318 #define uGetFirmwareBynHead(head_ptr) {uGetFirmware(0, (u8*)(head_ptr), sizeof(byn_head_multi));decode_byn_head_multi(head_ptr);}
319 #define uGetFirmwareBynZone(offset,zone_ptr) {uGetFirmware(offset,(u8*)(zone_ptr),sizeof(byn_zone)); decode_byn_zone(zone_ptr);}
320 
322 int yNetHubGetBootloaders(const char *hubserial, char *buffer, char *errmsg);
323 #endif
u32 nbrom
Definition: yprog.h:157
u16 pad
Definition: yprog.h:95
FLASH_ZONE_STATE zst
Definition: yprog.h:284
const char * prog_GetCPUName(BootloaderSt *dev)
Definition: yprog.c:120
u16 rev
Definition: yprog.h:81
void * yCRITICAL_SECTION
Definition: ydef.h:366
byn_head_multi bynHead
Definition: yprog.h:277
char d
Definition: yprog.h:78
u16 first_yfs3_page
Definition: yprog.h:179
u32 ROM_total_size
Definition: yprog.h:105
yInterfaceSt ProgIface
Definition: yprog.h:48
int SendDataPacket(BootloaderSt *dev, int program, u32 address, u8 *data, int nbinstr, char *errmsg)
Definition: yprog.c:436
u32 len
Definition: yprog.h:153
#define YOCTO_PRODUCTNAME_LEN
Definition: ydef.h:422
u32 addr
Definition: yprog.h:143
char c
Definition: yprog.h:77
#define FLASH_ERRMSG_LEN
Definition: yprog.h:265
#define MAX_ROM_ZONES_PER_FILES
Definition: yprog.h:55
void yProgFree(void)
Definition: yprog.c:88
u32 page
Definition: yprog.h:151
char a
Definition: yprog.h:75
int BlockingRead(BootloaderSt *dev, USB_Packet *pkt, int maxwait, char *errmsg)
Definition: yprog.c:423
#define YOCTO_FIRMWARE_LEN
Definition: ydef.h:423
u32 last_addr
Definition: yprog.h:167
u32 nbblock
Definition: yprog.h:145
u8 FLA_nb_zone
Definition: yprog.h:104
FLASH_DEVICE_STATE stepA
Definition: yprog.h:283
#define decode_byn_zone(dummy)
Definition: yprog.h:137
byn_head_v5 v5
Definition: yprog.h:113
int ypGetBootloaderReply(BootloaderSt *dev, USB_Packet *pkt, char *errmsg)
Definition: yprog.c:403
u32 addr_page
Definition: yprog.h:126
#define YOCTO_SERIAL_LEN
Definition: ydef.h:420
void yProgInit(void)
Definition: yprog.c:76
u32 nbzones
Definition: yprog.h:96
Definition: yprog.h:142
int ypSendBootloaderCmd(BootloaderSt *dev, const USB_Packet *pkt, char *errmsg)
Definition: yprog.c:396
u32 pr_blk_size
Definition: yprog.h:165
byn_head_v6 v6
Definition: yprog.h:112
yCRITICAL_SECTION cs
Definition: yprog.h:273
byn_head_sign h
Definition: yprog.h:110
char b
Definition: yprog.h:76
u32 yTime
Definition: ydef.h:210
u16 devid_rev
Definition: yprog.h:171
YRETCODE
Definition: ydef.h:376
FLASH_DEVICE_STATE
Definition: yprog.h:226
u8 * ptr
Definition: yprog.h:146
u16 ext_page_size
Definition: yprog.h:176
u16 ext_total_pages
Definition: yprog.h:177
BootloaderSt firm_dev
Definition: yprog.c:67
u32 sign
Definition: yprog.h:73
int ypBootloaderShutdown(BootloaderSt *dev)
YRETCODE yapiUpdateFirmware_internal(const char *serial, const char *firmwarePath, const char *settings, int force, int startUpdate, char *msg)
Definition: yprog.c:2362
u16 first_code_page
Definition: yprog.h:178
int IsValidBynFile(const byn_head_multi *head, u32 size, const char *serial, u16 flags, char *errmsg)
Definition: yprog.c:328
u8 ROM_nb_zone
Definition: yprog.h:103
int ValidateBynCompat(const byn_head_multi *head, u32 size, const char *serial, u16 flags, BootloaderSt *dev, char *errmsg)
Definition: yprog.c:314
u32 nbzones
Definition: yprog.h:89
u32 nbinstr
Definition: yprog.h:144
byn_zone bz
Definition: yprog.h:286
u32 FLA_total_size
Definition: yprog.h:106
u32 settings_addr
Definition: yprog.h:168
byn_head_v4 v4
Definition: yprog.h:114
u8 * firmware
Definition: yprog.h:272
int IsValidBynHead(const byn_head_multi *head, u32 size, u16 flags, char *errmsg)
Definition: yprog.c:243
u32 datasize
Definition: yprog.h:90
int yNetHubGetBootloaders(const char *hubserial, char *buffer, char *errmsg)
Definition: yprog.c:1420
YRETCODE yapiCheckFirmware_internal(const char *serial, const char *rev, u32 flags, const char *path, char *buffer, int buffersize, int *fullsize, char *errmsg)
Definition: yprog.c:2333
u32 len
Definition: yprog.h:147
#define MAX_FLASH_ZONES_PER_FILES
Definition: yprog.h:56
FIRMWARE_CONTEXT fctx
Definition: yprog.c:64
YPROG_RESULT
Definition: yprog.h:215
u32 endofconfig
Definition: yprog.h:173
yTime timeout
Definition: yprog.h:289
USB_Packet firm_pkt
Definition: yprog.c:68
u16 ext_jedec_id
Definition: yprog.h:175
int ypIsSendBootloaderBusy(BootloaderSt *dev)
Definition: yprog.c:388
FLASH_ZONE_STATE
Definition: yprog.h:247
u8 devid_model
Definition: yprog.h:170
u32 nbflash
Definition: yprog.h:158
u32 er_blk_size
Definition: yprog.h:166
u8 devid_family
Definition: yprog.h:169
YRETCODE yapiGetBootloadersDevs(char *serials, unsigned int maxNbSerial, unsigned int *totalBootladers, char *errmsg)
Definition: yapi.c:3541
u32 datasize
Definition: yprog.h:97
ProgIface iface
Definition: yprog.h:164
u8 * ptr
Definition: yprog.h:152
YPROG_RESULT uFlashDevice(void)
Definition: yprog.c:1047
u16 flashErase
Definition: yprog.h:293
#define decode_byn_head_multi(dummy)
Definition: yprog.h:136
u32 len
Definition: yprog.h:127
u32 startconfig
Definition: yprog.h:172


yoctopuce_altimeter
Author(s): Anja Sheppard
autogenerated on Mon Jun 10 2019 15:49:11