FireBirdLib - Topfield TMS PVR TAP Programming Library
LoadFirmwareDat.c
Go to the documentation of this file.
1#include <stdlib.h>
2#include <stdio.h>
3#include <fcntl.h>
4#include <sys/stat.h>
5#include "FBLib_main.h"
6
7bool LoadFirmwareDat(tFWDATHeader **FWDatHeader, tToppyInfo **ToppyInfo, tFWInfo **FWInfo)
8{
10
11 static byte *FWDATBin = NULL;
12 char AbsPath[FBLIB_DIR_SIZE];
13 FILE *fp;
14 dword blk;
15 tFWDATHeader *FWDAT;
16 struct stat statbuf;
17
18 if(!FWDATBin)
19 {
20 TAP_SPrint(AbsPath, "%s/ProgramFiles/Settings/%s", TAPFSROOT, FIRMWAREDAT);
21 if(lstat(AbsPath, &statbuf))
22 {
23 TAP_SPrint(AbsPath, "%s/ProgramFiles/%s", TAPFSROOT, FIRMWAREDAT);
24 if(lstat(AbsPath, &statbuf))
25 {
26 TRACEEXIT();
27 return FALSE;
28 }
29 }
30
31 if((fp = fopen(AbsPath, "r")) == NULL)
32 {
33 TRACEEXIT();
34 return FALSE;
35 }
36
37 if((FWDATBin = TAP_MemAlloc(statbuf.st_size)) == NULL)
38 {
39 fclose(fp);
40
41 TRACEEXIT();
42 return FALSE;
43 }
44
45 blk = fread(FWDATBin, statbuf.st_size, 1, fp);
46 fclose(fp);
47 }
48 else blk = 1; // already loaded
49
50 FWDAT = (tFWDATHeader *) FWDATBin;
51
52 //Check Magic and other things
53 if(blk == 0 ||
54 FWDAT->Magic != 0x12345678 ||
55 FWDAT->ToppyInfoLayoutVersion != 0 ||
56 FWDAT->FWInfoLayoutVersion != 0)
57 {
58 TAP_MemFree(FWDATBin);
59 FWDATBin = NULL;
60
61 TRACEEXIT();
62 return FALSE;
63 }
64
65 if(FWDatHeader) *FWDatHeader = FWDAT;
66 if(ToppyInfo) *ToppyInfo = (tToppyInfo *) (FWDAT + 1);
67 if(FWInfo) *FWInfo = (tFWInfo *) ((tToppyInfo *) (FWDAT + 1) + FWDAT->NrOfToppyInfoEntries);
68
69 TRACEEXIT();
70 return TRUE;
71}
struct __STDIO_FILE_STRUCT FILE
Definition: FBLib_hdd.h:137
#define FIRMWAREDAT
Definition: FBLib_main.h:6
bool LoadFirmwareDat(tFWDATHeader **FWDatHeader, tToppyInfo **ToppyInfo, tFWInfo **FWInfo)
#define FBLIB_DIR_SIZE
Definition: libFireBird.h:1871
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define TRACEENTER()
Definition: libFireBird.h:1243
#define TAPFSROOT
Definition: libFireBird.h:1870
dword NrOfToppyInfoEntries
Definition: libFireBird.h:111
word FWInfoLayoutVersion
Definition: libFireBird.h:110
word ToppyInfoLayoutVersion
Definition: libFireBird.h:109