-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflash_tool.c
More file actions
174 lines (137 loc) · 5.08 KB
/
flash_tool.c
File metadata and controls
174 lines (137 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include "flash_tool.h"
void flash_tool_rescue_mode() {
static unsigned int const addresses[] = {0x1100+512*0,0x1100+512*1,0x1100+512*2,0x1100+512*3,0x1100+512*4,0x1100+512*5,0x1100+512*6,0x1100+512*7};
unsigned char i;
print("\33[H\33[2JFLASH BIOS\r\nREAD SDCARD Sector 1-8");
for (i=0; i<8; i++) {
chipset_load_sector_into_memory((void *) addresses[i],i+1);
}
print("\r\nWRITE EEPROM");
chipset_flash_bios((void *) 0x1100);
}
/*
void flash_tool_fat16() {
// MBR
MasterBootRecord* const mbr = malloc(MBR_SIZE);
PartitionDescriptor* partition;
unsigned char i, choice;
// BPB
BiosParameterBlock* const bpb = malloc(FAT16_BPB_SIZE);
unsigned long FirstDataSector, AbsoluteFirstRootDirSecNum;
// Root Directory
DirectoryEntry* const rootDirectory = malloc(BYTE_PER_SECTOR);
unsigned char const RootDirSectors = ((ROOT_ENTRY_COUNT*32) + (BYTE_PER_SECTOR - 1))/BYTE_PER_SECTOR;
unsigned char sector;
DirectoryEntry *entry;
// Fat
unsigned int* fat = malloc(BYTE_PER_SECTOR);
static unsigned int lastFatSectorLoaded = 0; // long
unsigned int AbsoluteFirstSectorOfCluster, FatOffset, AbsoluteThisFatSecNum; // long
unsigned int ThisFatEntryOffset, cluster;
// Bios file
static DirectoryEntry* bios_file_entry = NULL;
static unsigned int bios_root_directory_sector = 0;
unsigned char* const bios_file = malloc(BIOS_SIZE);
unsigned char* bios_data = bios_file;
unsigned int j;
print("\33[H\33[2JBIOS - FLASH TOOL v1.0\r\n\r\nPrerequisites :\r\n- FAT16 Primary partition\r\n- Must reside in first physical 32 MB\r\n- 512 bytes/sector\r\n- 1 sector/cluster\r\n- 512 entries in root directory");
// Load MBR
chipset_load_sector_into_memory(mbr, MBR_SECTOR);
if (mbr->signature != MBR_SIGNATURE) {
print("\r\nMBR MISSING");
return;
}
print("\r\n");
// List partition
for (i=0; i<4; i++) {
print("\r\nPartition ");
print_unsigned_char(i);
switch (mbr->partitionTable[i].systemID) {
case (PARTITION_TYPE_EMPTY):
print(": EMPTY");
break;
case (PARTITION_TYPE_FAT16):
print(": FAT16");
break;
default:
print(": 0x");
print_hex(mbr->partitionTable[i].systemID);
}
}
print("\r\n");
// Select a partition
do {
print("\r\nSelect a partition: ");
choice = getc();
putc(choice);
i = choice - '0';
if (i>3) continue;
if (mbr->partitionTable[i].systemID != PARTITION_TYPE_FAT16) {
print("\r\nONLY FAT16 !!");
}
} while (mbr->partitionTable[i].systemID != PARTITION_TYPE_FAT16);
partition = &mbr->partitionTable[i];
// Load BPB
chipset_load_sector_into_memory(bpb, partition->firstPartitionSector);
AbsoluteFirstRootDirSecNum = bpb->BPB_RsvSecCnt + bpb->BPB_NumFATs * bpb->BPB_FATs16 + partition->firstPartitionSector;
FirstDataSector = bpb->BPB_RsvSecCnt + (bpb->BPB_NumFATs * bpb->BPB_FATs16) + RootDirSectors;
if ((bpb->BPB_BytsPerSec != BYTE_PER_SECTOR) ||
(bpb->BPB_SecPerClus != 1) ||
(bpb->BPB_RootEntCnt != ROOT_ENTRY_COUNT) ||
(partition->firstPartitionSector + partition->numberOfSector > 65535)) {
print("\r\nPrerequisites mismatch !");
return;
}
print("\r\n");
// List Root Directory and Search BIOS.BIN
for (sector = 0; sector < RootDirSectors; sector++) {
// Load a root directory sector;
chipset_load_sector_into_memory(rootDirectory, AbsoluteFirstRootDirSecNum + sector);
entry = rootDirectory;
for (i=0; i<16; i++, entry++) {
if (entry->DIR_Name[0] == 0x00) {sector = RootDirSectors; break;} // end of directory
if (entry->DIR_Name[0] == 0xE5) continue; // deleted file
if (entry->DIR_Attr == ATTR_DIRECTORY) continue; // sub directory
print("\r\n");
fat16_print_file_name(entry->DIR_Name);
if (fat16_compare_file_name(entry->DIR_Name) == TRUE) {
bios_file_entry = entry;
bios_root_directory_sector = sector;
}
}
}
// If BIOS not found
if (bios_file_entry == NULL) {
print("\r\nBIOS.BIN not found in root directory !");
return;
}
chipset_load_sector_into_memory(rootDirectory, AbsoluteFirstRootDirSecNum + bios_root_directory_sector);
// BIOS found
print("\r\n\r\n");
fat16_print_file_name(bios_file_entry->DIR_Name);
print(" found !");
// Load BIOS.BIN
print("\r\nREAD FILE");
// init memory
for(j=0;j<BIOS_SIZE;j++) {
bios_file[j] = 0x00;
}
cluster = bios_file_entry->DIR_FstClusLO;
do {
// Load sector of data (1 cluster = 1 sector)
AbsoluteFirstSectorOfCluster = ((cluster-2) * bpb->BPB_SecPerClus) + FirstDataSector + partition->firstPartitionSector;
chipset_load_sector_into_memory(bios_data, AbsoluteFirstSectorOfCluster);
bios_data += 512;
// Load FAT
FatOffset = cluster * 2; // FAT Entry index
AbsoluteThisFatSecNum = bpb->BPB_RsvSecCnt + (FatOffset / bpb->BPB_BytsPerSec) + partition->firstPartitionSector; // FAT Entry Sector
ThisFatEntryOffset = (cluster % bpb->BPB_BytsPerSec); //(FATOffset % bpb->BPB_BytsPerSec);
if (lastFatSectorLoaded != AbsoluteThisFatSecNum) {
chipset_load_sector_into_memory(fat, AbsoluteThisFatSecNum);
lastFatSectorLoaded = AbsoluteThisFatSecNum;
}
cluster = fat[ThisFatEntryOffset];
} while (cluster < 0xFFF8);
print("\r\nWRITE EEPROM");
chipset_flash_bios(bios_file);
}*/