Skip to content

Commit

Permalink
updated menu code to docking12
Browse files Browse the repository at this point in the history
  • Loading branch information
cnvogelg committed Jan 21, 2012
1 parent 891e7fb commit 26e6616
Show file tree
Hide file tree
Showing 12 changed files with 775 additions and 222 deletions.
2 changes: 1 addition & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typedef struct

typedef struct
{
unsigned char enabled;
unsigned char enabled; // 0: Disabled, 1: Hard file, 2: MMC (entire card), 3-6: Partition 1-4 of MMC card
unsigned char present;
char name[8];
char long_name[16];
Expand Down
149 changes: 90 additions & 59 deletions src/fat.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ unsigned long fat_size; // size of fat

unsigned char sector_buffer[512]; // sector buffer

struct PartitionEntry partitions[4]; // lbastart and sectors will be byteswapped as necessary
int partitioncount;

FATBUFFER fat_buffer; // buffer for caching fat entries
unsigned long buffered_fat_index; // index of buffered FAT sector

Expand All @@ -83,6 +86,27 @@ unsigned char t_sort_table[MAXDIRENTRIES];
extern unsigned long GetTimer(unsigned long);
extern void ErrorMessage(const char *message, unsigned char code);

unsigned long SwapEndianL(unsigned long l)
{
unsigned char *c=(unsigned char *)&l;
return((c[3]<<24)+(c[2]<<16)+(c[1]<<8)+c[0]);
}

void SwapPartitionBytes(int i)
{
// We don't bother to byteswap the CHS geometry fields since we don't use them.
partitions[i].startlba=SwapEndianL(partitions[i].startlba);
partitions[i].sectors=SwapEndianL(partitions[i].sectors);
}

extern char BootPrint(const char *s);
void bprintfl(const char *fmt,unsigned long l)
{
char s[64];
sprintf(s,fmt,l);
BootPrint(s);
}

// FindDrive() checks if a card is present and contains FAT formatted primary partition
unsigned char FindDrive(void)
{
Expand All @@ -91,76 +115,83 @@ unsigned char FindDrive(void)
if (!MMC_Read(0, sector_buffer)) // read MBR
return(0);

// get start of first partition
boot_sector = sector_buffer[457];
boot_sector <<= 8;
boot_sector |= sector_buffer[456];
boot_sector <<= 8;
boot_sector |= sector_buffer[455];
boot_sector <<= 8;
boot_sector |= sector_buffer[454];

// switch (sector_buffer[450])
// {
// case 0x00:
// fattype = 0;
// break;
// case 0x01:
// fattype = 12;
// break;
// case 0x04:
// case 0x06:
// fattype = 16;
// break;
// case 0x0B:
// case 0x0C:
// fattype = 32;
// break;
// default:
// fattype = 255;
// break;
// }
boot_sector=0;
partitioncount=1;

// If we can identify a filesystem on block 0 we don't look for partitions
if (strncmp((const char*)&sector_buffer[0x36], "FAT16 ", 8)==0) // check for FAT16
{ boot_sector = 0;
sector_buffer[450] = 0;
// fattype = 16;
}
partitioncount=0;
if (strncmp((const char*)&sector_buffer[0x52], "FAT32 ", 8)==0) // check for FAT32
{ boot_sector = 0;
sector_buffer[450] = 0;
// fattype = 32;
partitioncount=0;

if(partitioncount)
{
// We have at least one partition, parse the MBR.
struct MasterBootRecord *mbr=(struct MasterBootRecord *)sector_buffer;
memcpy(&partitions[0],&mbr->Partition[0],sizeof(struct PartitionEntry));
memcpy(&partitions[1],&mbr->Partition[1],sizeof(struct PartitionEntry));
memcpy(&partitions[2],&mbr->Partition[2],sizeof(struct PartitionEntry));
memcpy(&partitions[3],&mbr->Partition[3],sizeof(struct PartitionEntry));

switch(mbr->Signature)
{
case 0x55aa: // Little-endian MBR on a big-endian system
BootPrint("Swapping byte order of partition entries");
SwapPartitionBytes(0);
SwapPartitionBytes(1);
SwapPartitionBytes(2);
SwapPartitionBytes(3);
// fall through...
case 0xaa55:
// get start of first partition
boot_sector = partitions[0].startlba;
bprintfl("Start: %ld\n",partitions[0].startlba);
for(partitioncount=4;(partitions[partitioncount-1].sectors==0) && (partitioncount>1); --partitioncount)
;
bprintfl("PartitionCount: %ld\n",partitioncount);
int i;
for(i=0;i<partitioncount;++i)
{
bprintfl("Partition: %ld",i);
bprintfl(" Start: %ld",partitions[i].startlba);
bprintfl(" Size: %ld\n",partitions[i].sectors);
}
WaitTimer(5000);
if (!MMC_Read(boot_sector, sector_buffer)) // read discriptor
return(0);
BootPrint("Read boot sector from first partition\n");
break;
default:
BootPrint("No partition signature found\n");
break;
}
}

if (!MMC_Read(boot_sector, sector_buffer)) // read discriptor
return(0);

if (strncmp((const char*)&sector_buffer[0x36], "FAT16 ", 8)==0) // check for FAT16
{ fattype = 16;
}
fattype = 16;

if (strncmp((const char*)&sector_buffer[0x52], "FAT32 ", 8)==0) // check for FAT32
{ fattype = 32;
}
fattype = 32;

printf("partition type: 0x%02X (", sector_buffer[450]);
switch (fattype)
{
case 0:
printf("NONE");
break;
case 12:
printf("FAT12");
break;
case 16:
printf("FAT16");
break;
case 32:
printf("FAT32");
fat32 = 1;
break;
default:
printf("UNKNOWN");
break;
case 0:
printf("NONE");
break;
case 12:
printf("FAT12");
break;
case 16:
printf("FAT16");
break;
case 32:
printf("FAT32");
fat32 = 1;
break;
default:
printf("UNKNOWN");
break;
}
printf(")\r");

Expand Down
17 changes: 17 additions & 0 deletions src/fat.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ typedef struct
char long_name[261];
} fileTYPE;

struct PartitionEntry
{
unsigned char geometry[8]; // ignored
unsigned long startlba;
unsigned long sectors;
};

struct MasterBootRecord
{
unsigned char bootcode[446]; // ignored
struct PartitionEntry Partition[4]; // We copy these (and byteswap if need be)
unsigned short Signature; // This lets us detect an MBR (and the need for byteswapping).
};

extern struct PartitionEntry partitions[4]; // FirstBlock and LastBlock will be byteswapped as necessary
extern int partitioncount;

typedef struct
{
unsigned char Name[8]; /* filename, blank filled */
Expand Down
24 changes: 12 additions & 12 deletions src/hardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

//#include "stdio.h"
#include "hardware.h"
#include "hardware.h"


//void __init_hardware(void)
Expand Down Expand Up @@ -170,7 +170,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

unsigned long CheckButton(void)
{
// return((~*AT91C_PIOA_PDSR) & BUTTON);
// return((~*AT91C_PIOA_PDSR) & BUTTON);
return(0);
}

Expand All @@ -182,26 +182,26 @@ unsigned long CheckButton(void)
unsigned long GetTimer(unsigned long offset)
{
unsigned long systimer = (*(unsigned short *)0xDEE010);
systimer = systimer<< 20;
systimer += offset << 20;
return (systimer); // valid bits [31:20]
systimer = systimer<< 16;
systimer += offset << 16;
return (systimer); // valid bits [31:16]
}

unsigned long CheckTimer(unsigned long time)
{
unsigned long systimer = (*(unsigned short *)0xDEE010);
systimer = systimer<< 20;
// printf("systimer:%08X ",systimer);
time -= systimer;
if(time & 0x80000000)
unsigned long systimer = (*(unsigned short *)0xDEE010);
systimer = systimer<< 16;
// printf("systimer:%08X ",systimer);
time -= systimer;
if(time & 0x80000000)
return(1);
return(0);
// return(time > systimer);
// return(time > systimer);
}

void WaitTimer(unsigned long time)
{
time = GetTimer(time);
while (!CheckTimer(time));
}

Loading

0 comments on commit 26e6616

Please sign in to comment.