projects
/
pub
/
USBasp.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
4753528
)
Corrections and debug channel in the Incomplete Mass Storage class bootloader.
author
Dean Camera
<dean@fourwalledcubicle.com>
Sat, 9 Mar 2013 07:49:46 +0000
(07:49 +0000)
committer
Dean Camera
<dean@fourwalledcubicle.com>
Sat, 9 Mar 2013 07:49:46 +0000
(07:49 +0000)
Bootloaders/Incomplete/MassStorage/Lib/VirtualFAT.c
patch
|
blob
|
blame
|
history
Bootloaders/Incomplete/MassStorage/Lib/VirtualFAT.h
patch
|
blob
|
blame
|
history
Bootloaders/Incomplete/MassStorage/MassStorage.c
patch
|
blob
|
blame
|
history
Bootloaders/Incomplete/MassStorage/MassStorage.h
patch
|
blob
|
blame
|
history
Bootloaders/Incomplete/MassStorage/makefile
patch
|
blob
|
blame
|
history
diff --git
a/Bootloaders/Incomplete/MassStorage/Lib/VirtualFAT.c
b/Bootloaders/Incomplete/MassStorage/Lib/VirtualFAT.c
index
7b0c5dd
..
2365ba5
100644
(file)
--- a/
Bootloaders/Incomplete/MassStorage/Lib/VirtualFAT.c
+++ b/
Bootloaders/Incomplete/MassStorage/Lib/VirtualFAT.c
@@
-30,22
+30,31
@@
#include "VirtualFAT.h"
#include "VirtualFAT.h"
+#define FAT_TIME(h, m, s) ((h << 11) | (m << 5) | (s >> 1))
+#define FAT_DATE(d, m, y) (((y - 1980) << 9) | (m << 5) | (d << 0))
+
+#define SECTOR_SIZE_BYTES VIRTUAL_MEMORY_BLOCK_SIZE
+#define SECTOR_PER_CLUSTER 4
+#define CLUSTER_SIZE_BYTES (SECTOR_PER_CLUSTER * SECTOR_SIZE_BYTES)
+
+#define FILE_CLUSTERS(size) (size / CLUSTER_SIZE_BYTES)
+
static const FATBootBlock_t BootBlock =
{
.Bootstrap = {0xEB, 0x3C, 0x90},
.Description = "mkdosfs",
static const FATBootBlock_t BootBlock =
{
.Bootstrap = {0xEB, 0x3C, 0x90},
.Description = "mkdosfs",
- .
BlockSize = VIRTUAL_MEMORY_BLOCK_SIZE
,
- .
BlocksPerAllocationUnit = ALLOCATION_UNIT_BLOCKS
,
- .Reserved
Blocks
= 1,
+ .
SectorSize = SECTOR_SIZE_BYTES
,
+ .
SectorsPerCluster = SECTOR_PER_CLUSTER
,
+ .Reserved
Sectors
= 1,
.FATCopies = 2,
.FATCopies = 2,
- .RootDirectoryEntries =
512
,
- .Total
Blocks16
= LUN_MEDIA_BLOCKS,
+ .RootDirectoryEntries =
SECTOR_SIZE_BYTES / sizeof(FATDirectoryEntry_t)
,
+ .Total
Sectors16
= LUN_MEDIA_BLOCKS,
.MediaDescriptor = 0xF8,
.MediaDescriptor = 0xF8,
- .
BlocksPerFAT
= 1,
- .
BlocksPerTrack
= 32,
+ .
SectorsPerFAT
= 1,
+ .
SectorsPerTrack
= 32,
.Heads = 64,
.Heads = 64,
- .Hidden
Blocks
= 0,
- .Total
Blocks32
= 0,
+ .Hidden
Sectors
= 0,
+ .Total
Sectors32
= 0,
.PhysicalDriveNum = 0,
.ExtendedBootRecordSig = 0x29,
.VolumeSerialNumber = 0x12345678,
.PhysicalDriveNum = 0,
.ExtendedBootRecordSig = 0x29,
.VolumeSerialNumber = 0x12345678,
@@
-57,14
+66,14
@@
static const FATBootBlock_t BootBlock =
static FATDirectoryEntry_t FirmwareFileEntry =
{
static FATDirectoryEntry_t FirmwareFileEntry =
{
- .Filename = "F
irmware
",
- .Extension = "
bin
",
+ .Filename = "F
IRMWARE
",
+ .Extension = "
BIN
",
.Attributes = 0,
.Reserved = {0},
.Attributes = 0,
.Reserved = {0},
- .CreationTime =
(1 << 11) | (1 << 5
),
- .CreationDate =
(9 << 9) | (2 << 5) | (14 << 0
),
- .StartingCluster =
4
,
- .FileSize
= (FLASHEND + 1UL)
,
+ .CreationTime =
FAT_TIME(1, 1, 0
),
+ .CreationDate =
FAT_DATE(14, 2, 1989
),
+ .StartingCluster =
2
,
+ .FileSize
Bytes = 2049
,
};
static void WriteBlock(uint16_t BlockNumber)
};
static void WriteBlock(uint16_t BlockNumber)
@@
-78,6
+87,7
@@
static void WriteBlock(uint16_t BlockNumber)
Endpoint_Read_Stream_LE(BlockBuffer, sizeof(BlockBuffer), NULL);
Endpoint_ClearOUT();
Endpoint_Read_Stream_LE(BlockBuffer, sizeof(BlockBuffer), NULL);
Endpoint_ClearOUT();
+ printf("WRITE %d\r\n", BlockNumber);
// TODO: Write to FLASH
}
// TODO: Write to FLASH
}
@@
-86,41
+96,49
@@
static void ReadBlock(uint16_t BlockNumber)
uint8_t BlockBuffer[512];
memset(BlockBuffer, 0x00, sizeof(BlockBuffer));
uint8_t BlockBuffer[512];
memset(BlockBuffer, 0x00, sizeof(BlockBuffer));
+ printf("READ %d", BlockNumber);
+
switch (BlockNumber)
{
case 0:
memcpy(BlockBuffer, &BootBlock, sizeof(FATBootBlock_t));
switch (BlockNumber)
{
case 0:
memcpy(BlockBuffer, &BootBlock, sizeof(FATBootBlock_t));
+ printf(" <B>\r\n");
break;
case 1:
case 2:
break;
case 1:
case 2:
+ printf(" <F>\r\n");
+
/* Cluster 0: Media type/Reserved */
((uint16_t*)&BlockBuffer)[0] = 0xFF00 | BootBlock.MediaDescriptor;
/* Cluster 1: Reserved */
((uint16_t*)&BlockBuffer)[1] = 0xFFFF;
/* Cluster 0: Media type/Reserved */
((uint16_t*)&BlockBuffer)[0] = 0xFF00 | BootBlock.MediaDescriptor;
/* Cluster 1: Reserved */
((uint16_t*)&BlockBuffer)[1] = 0xFFFF;
- /* Cluster 2: Reserved */
- ((uint16_t*)&BlockBuffer)[2] = 0xFFFF;
-
- /* Cluster 3: FIRMWARE.BIN File Entry */
- ((uint16_t*)&BlockBuffer)[3] = 0xFFFF;
-
- /* Cluster 4 onwards: Cluster chain of FIRMWARE.BIN */
- for (uint16_t i = 0; i < ((FLASHEND + 1) / (VIRTUAL_MEMORY_BLOCK_SIZE * ALLOCATION_UNIT_BLOCKS)); i++)
+ /* Cluster 2 onwards: Cluster chain of FIRMWARE.BIN */
+ for (uint16_t i = 0; i < FILE_CLUSTERS(2049); i++)
{
{
- ((uint16_t*)&BlockBuffer)[i +
4] = i + 5
;
+ ((uint16_t*)&BlockBuffer)[i +
2] = i + 3
;
}
/* Mark last cluster as end of file */
}
/* Mark last cluster as end of file */
- ((uint16_t*)&BlockBuffer)[
((FLASHEND + 1) / (VIRTUAL_MEMORY_BLOCK_SIZE * ALLOCATION_UNIT_BLOCKS)) + 4
] = 0xFFFF;
+ ((uint16_t*)&BlockBuffer)[
FILE_CLUSTERS(2049) + 3
] = 0xFFFF;
break;
case 3:
break;
case 3:
+ printf("<R>\r\n");
memcpy(BlockBuffer, &FirmwareFileEntry, sizeof(FATDirectoryEntry_t));
break;
default:
memcpy(BlockBuffer, &FirmwareFileEntry, sizeof(FATDirectoryEntry_t));
break;
default:
+ if ((BlockNumber >= 4) && (BlockNumber < (4 + FILE_CLUSTERS(FIRMWARE_FILE_SIZE))))
+ {
+ printf("<D>\r\n");
+
+ for (uint16_t i = 0; i < 512; i++)
+ BlockBuffer[i] = '0' + BlockNumber; //A' + (i % 26);
+ }
+
break;
}
break;
}
diff --git
a/Bootloaders/Incomplete/MassStorage/Lib/VirtualFAT.h
b/Bootloaders/Incomplete/MassStorage/Lib/VirtualFAT.h
index
2009b68
..
760fb40
100644
(file)
--- a/
Bootloaders/Incomplete/MassStorage/Lib/VirtualFAT.h
+++ b/
Bootloaders/Incomplete/MassStorage/Lib/VirtualFAT.h
@@
-39,26
+39,28
@@
/* Macros: */
#define VIRTUAL_MEMORY_BLOCK_SIZE 512
/* Macros: */
#define VIRTUAL_MEMORY_BLOCK_SIZE 512
- #define ALLOCATION_UNIT_BLOCKS 4
- #define LUN_MEDIA_BLOCKS ((FLASHEND + 1) / VIRTUAL_MEMORY_BLOCK_SIZE) + 16
+
+ #define FIRMWARE_FILE_SIZE (FLASHEND + 1UL)
+
+ #define LUN_MEDIA_BLOCKS ((FIRMWARE_FILE_SIZE / VIRTUAL_MEMORY_BLOCK_SIZE) + 32)
/* Type Definitions: */
typedef struct
{
uint8_t Bootstrap[3];
uint8_t Description[8];
/* Type Definitions: */
typedef struct
{
uint8_t Bootstrap[3];
uint8_t Description[8];
- uint16_t
Block
Size;
- uint8_t
BlocksPerAllocationUnit
;
- uint16_t Reserved
Block
s;
+ uint16_t
Sector
Size;
+ uint8_t
SectorsPerCluster
;
+ uint16_t Reserved
Sector
s;
uint8_t FATCopies;
uint16_t RootDirectoryEntries;
uint8_t FATCopies;
uint16_t RootDirectoryEntries;
- uint16_t Total
Block
s16;
+ uint16_t Total
Sector
s16;
uint8_t MediaDescriptor;
uint8_t MediaDescriptor;
- uint16_t
Block
sPerFAT;
- uint16_t
Block
sPerTrack;
+ uint16_t
Sector
sPerFAT;
+ uint16_t
Sector
sPerTrack;
uint16_t Heads;
uint16_t Heads;
- uint32_t Hidden
Block
s;
- uint32_t Total
Block
s32;
+ uint32_t Hidden
Sector
s;
+ uint32_t Total
Sector
s32;
uint16_t PhysicalDriveNum;
uint8_t ExtendedBootRecordSig;
uint32_t VolumeSerialNumber;
uint16_t PhysicalDriveNum;
uint8_t ExtendedBootRecordSig;
uint32_t VolumeSerialNumber;
@@
-70,14
+72,14
@@
typedef struct
{
typedef struct
{
- uint8_t Filename[8];
- uint8_t Extension[3];
- uint8_t Attributes;
- uint8_t Reserved[10];
+ uint8_t
Filename[8];
+ uint8_t
Extension[3];
+ uint8_t
Attributes;
+ uint8_t
Reserved[10];
uint16_t CreationTime;
uint16_t CreationDate;
uint16_t StartingCluster;
uint16_t CreationTime;
uint16_t CreationDate;
uint16_t StartingCluster;
- uint32_t FileSize;
+ uint32_t FileSize
Bytes
;
} FATDirectoryEntry_t;
/* Function Prototypes: */
} FATDirectoryEntry_t;
/* Function Prototypes: */
diff --git
a/Bootloaders/Incomplete/MassStorage/MassStorage.c
b/Bootloaders/Incomplete/MassStorage/MassStorage.c
index
2d4d973
..
10ea8f8
100644
(file)
--- a/
Bootloaders/Incomplete/MassStorage/MassStorage.c
+++ b/
Bootloaders/Incomplete/MassStorage/MassStorage.c
@@
-95,6
+95,8
@@
void SetupHardware(void)
/* Hardware Initialization */
LEDs_Init();
/* Hardware Initialization */
LEDs_Init();
+ Serial_Init(9600, false);
+ Serial_CreateStream(NULL);
USB_Init();
}
USB_Init();
}
diff --git
a/Bootloaders/Incomplete/MassStorage/MassStorage.h
b/Bootloaders/Incomplete/MassStorage/MassStorage.h
index
a6ad9b2
..
92d69d5
100644
(file)
--- a/
Bootloaders/Incomplete/MassStorage/MassStorage.h
+++ b/
Bootloaders/Incomplete/MassStorage/MassStorage.h
@@
-48,6
+48,7
@@
#include "Lib/SCSI.h"
#include <LUFA/Drivers/Board/LEDs.h>
#include "Lib/SCSI.h"
#include <LUFA/Drivers/Board/LEDs.h>
+ #include <LUFA/Drivers/Peripheral/Serial.h>
#include <LUFA/Drivers/USB/USB.h>
/* Macros: */
#include <LUFA/Drivers/USB/USB.h>
/* Macros: */
diff --git
a/Bootloaders/Incomplete/MassStorage/makefile
b/Bootloaders/Incomplete/MassStorage/makefile
index
fca29ed
..
bb7eed5
100644
(file)
--- a/
Bootloaders/Incomplete/MassStorage/makefile
+++ b/
Bootloaders/Incomplete/MassStorage/makefile
@@
-14,11
+14,11
@@
MCU = at90usb1287
\r
ARCH = AVR8
\r
BOARD = USBKEY
\r
MCU = at90usb1287
\r
ARCH = AVR8
\r
BOARD = USBKEY
\r
-F_CPU =
8
000000
\r
+F_CPU =
16
000000
\r
F_USB = $(F_CPU)
\r
OPTIMIZATION = s
\r
TARGET = MassStorage
\r
F_USB = $(F_CPU)
\r
OPTIMIZATION = s
\r
TARGET = MassStorage
\r
-SRC = $(TARGET).c Descriptors.c Lib/SCSI.c Lib/VirtualFAT.c $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS)
\r
+SRC = $(TARGET).c Descriptors.c Lib/SCSI.c Lib/VirtualFAT.c $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS)
$(LUFA_SRC_SERIAL)
\r
LUFA_PATH = ../../../LUFA
\r
CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -IConfig/ -DBOOT_START_ADDR=$(BOOT_START_OFFSET)
\r
LD_FLAGS = -Wl,--section-start=.text=$(BOOT_START_OFFSET) $(BOOT_API_LD_FLAGS)
\r
LUFA_PATH = ../../../LUFA
\r
CC_FLAGS = -DUSE_LUFA_CONFIG_HEADER -IConfig/ -DBOOT_START_ADDR=$(BOOT_START_OFFSET)
\r
LD_FLAGS = -Wl,--section-start=.text=$(BOOT_START_OFFSET) $(BOOT_API_LD_FLAGS)
\r