Add APIs to the incomplete Mass Storage bootloader.
authorDean Camera <dean@fourwalledcubicle.com>
Fri, 8 Mar 2013 15:52:05 +0000 (15:52 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Fri, 8 Mar 2013 15:52:05 +0000 (15:52 +0000)
Bootloaders/Incomplete/MassStorage/BootloaderAPI.c [new file with mode: 0644]
Bootloaders/Incomplete/MassStorage/BootloaderAPI.h [new file with mode: 0644]
Bootloaders/Incomplete/MassStorage/BootloaderAPITable.S [new file with mode: 0644]
Bootloaders/Incomplete/MassStorage/makefile

diff --git a/Bootloaders/Incomplete/MassStorage/BootloaderAPI.c b/Bootloaders/Incomplete/MassStorage/BootloaderAPI.c
new file mode 100644 (file)
index 0000000..997cca9
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+             LUFA Library
+     Copyright (C) Dean Camera, 2013.
+
+  dean [at] fourwalledcubicle [dot] com
+           www.lufa-lib.org
+*/
+
+/*
+  Copyright 2013  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+  Permission to use, copy, modify, distribute, and sell this
+  software and its documentation for any purpose is hereby granted
+  without fee, provided that the above copyright notice appear in
+  all copies and that both that the copyright notice and this
+  permission notice and warranty disclaimer appear in supporting
+  documentation, and that the name of the author not be used in
+  advertising or publicity pertaining to distribution of the
+  software without specific, written prior permission.
+
+  The author disclaims all warranties with regard to this
+  software, including all implied warranties of merchantability
+  and fitness.  In no event shall the author be liable for any
+  special, indirect or consequential damages or any damages
+  whatsoever resulting from loss of use, data or profits, whether
+  in an action of contract, negligence or other tortious action,
+  arising out of or in connection with the use or performance of
+  this software.
+*/
+
+/** \file
+ *
+ *  Bootloader user application API functions.
+ */
+
+#include "BootloaderAPI.h"
+
+void BootloaderAPI_ErasePage(const uint32_t Address)
+{
+       boot_page_erase_safe(Address);
+       boot_spm_busy_wait();
+       boot_rww_enable();
+}
+
+void BootloaderAPI_WritePage(const uint32_t Address)
+{
+       boot_page_write_safe(Address);
+       boot_spm_busy_wait();
+       boot_rww_enable();
+}
+
+void BootloaderAPI_FillWord(const uint32_t Address, const uint16_t Word)
+{
+       boot_page_fill_safe(Address, Word);
+}
+
+uint8_t BootloaderAPI_ReadSignature(const uint16_t Address)
+{
+       return boot_signature_byte_get(Address);
+}
+
+uint8_t BootloaderAPI_ReadFuse(const uint16_t Address)
+{
+       return boot_lock_fuse_bits_get(Address);
+}
+
+uint8_t BootloaderAPI_ReadLock(void)
+{
+       return boot_lock_fuse_bits_get(GET_LOCK_BITS);
+}
+
+void BootloaderAPI_WriteLock(const uint8_t LockBits)
+{
+       boot_lock_bits_set_safe(LockBits);
+}
+
diff --git a/Bootloaders/Incomplete/MassStorage/BootloaderAPI.h b/Bootloaders/Incomplete/MassStorage/BootloaderAPI.h
new file mode 100644 (file)
index 0000000..c57da8b
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+             LUFA Library
+     Copyright (C) Dean Camera, 2013.
+
+  dean [at] fourwalledcubicle [dot] com
+           www.lufa-lib.org
+*/
+
+/*
+  Copyright 2013  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+
+  Permission to use, copy, modify, distribute, and sell this
+  software and its documentation for any purpose is hereby granted
+  without fee, provided that the above copyright notice appear in
+  all copies and that both that the copyright notice and this
+  permission notice and warranty disclaimer appear in supporting
+  documentation, and that the name of the author not be used in
+  advertising or publicity pertaining to distribution of the
+  software without specific, written prior permission.
+
+  The author disclaims all warranties with regard to this
+  software, including all implied warranties of merchantability
+  and fitness.  In no event shall the author be liable for any
+  special, indirect or consequential damages or any damages
+  whatsoever resulting from loss of use, data or profits, whether
+  in an action of contract, negligence or other tortious action,
+  arising out of or in connection with the use or performance of
+  this software.
+*/
+
+/** \file
+ *
+ *  Header file for BootloaderAPI.c.
+ */
+
+#ifndef _BOOTLOADER_API_H_
+#define _BOOTLOADER_API_H_
+
+       /* Includes: */
+               #include <avr/io.h>
+               #include <avr/boot.h>
+               #include <stdbool.h>
+
+               #include <LUFA/Common/Common.h>
+
+               #include "Config/AppConfig.h"
+
+       /* Function Prototypes: */
+               void    BootloaderAPI_ErasePage(const uint32_t Address);
+               void    BootloaderAPI_WritePage(const uint32_t Address);
+               void    BootloaderAPI_FillWord(const uint32_t Address, const uint16_t Word);
+               uint8_t BootloaderAPI_ReadSignature(const uint16_t Address);
+               uint8_t BootloaderAPI_ReadFuse(const uint16_t Address);
+               uint8_t BootloaderAPI_ReadLock(void);
+               void    BootloaderAPI_WriteLock(const uint8_t LockBits);
+
+#endif
+
diff --git a/Bootloaders/Incomplete/MassStorage/BootloaderAPITable.S b/Bootloaders/Incomplete/MassStorage/BootloaderAPITable.S
new file mode 100644 (file)
index 0000000..2aded74
--- /dev/null
@@ -0,0 +1,91 @@
+/*\r
+             LUFA Library\r
+     Copyright (C) Dean Camera, 2011.\r
+\r
+  dean [at] fourwalledcubicle [dot] com\r
+           www.lufa-lib.org\r
+*/\r
+\r
+/*\r
+  Copyright 2013  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+\r
+  Permission to use, copy, modify, distribute, and sell this\r
+  software and its documentation for any purpose is hereby granted\r
+  without fee, provided that the above copyright notice appear in\r
+  all copies and that both that the copyright notice and this\r
+  permission notice and warranty disclaimer appear in supporting\r
+  documentation, and that the name of the author not be used in\r
+  advertising or publicity pertaining to distribution of the\r
+  software without specific, written prior permission.\r
+\r
+  The author disclaims all warranties with regard to this\r
+  software, including all implied warranties of merchantability\r
+  and fitness.  In no event shall the author be liable for any\r
+  special, indirect or consequential damages or any damages\r
+  whatsoever resulting from loss of use, data or profits, whether\r
+  in an action of contract, negligence or other tortious action,\r
+  arising out of or in connection with the use or performance of\r
+  this software.\r
+*/\r
+\r
+; Trampolines to actual API implementations if the target address is outside the\r
+; range of a rjmp instruction (can happen with large bootloader sections)\r
+.section .apitable_trampolines, "ax"\r
+.global BootloaderAPI_Trampolines\r
+BootloaderAPI_Trampolines:\r
+\r
+       BootloaderAPI_ErasePage_Trampoline:\r
+               jmp BootloaderAPI_ErasePage\r
+       BootloaderAPI_WritePage_Trampoline:\r
+               jmp BootloaderAPI_WritePage\r
+       BootloaderAPI_FillWord_Trampoline:\r
+               jmp BootloaderAPI_FillWord\r
+       BootloaderAPI_ReadSignature_Trampoline:\r
+               jmp BootloaderAPI_ReadSignature\r
+       BootloaderAPI_ReadFuse_Trampoline:\r
+               jmp BootloaderAPI_ReadFuse\r
+       BootloaderAPI_ReadLock_Trampoline:\r
+               jmp BootloaderAPI_ReadLock\r
+       BootloaderAPI_WriteLock_Trampoline:\r
+               jmp BootloaderAPI_WriteLock\r
+       BootloaderAPU_UNUSED1:\r
+               ret\r
+       BootloaderAPU_UNUSED2:\r
+               ret\r
+       BootloaderAPU_UNUSED3:\r
+               ret\r
+       BootloaderAPU_UNUSED4:\r
+               ret\r
+       BootloaderAPU_UNUSED5:\r
+               ret\r
+\r
+\r
+\r
+; API function jump table\r
+.section .apitable_jumptable, "ax"\r
+.global BootloaderAPI_JumpTable\r
+BootloaderAPI_JumpTable:\r
+\r
+       rjmp BootloaderAPI_ErasePage_Trampoline\r
+       rjmp BootloaderAPI_WritePage_Trampoline\r
+       rjmp BootloaderAPI_FillWord_Trampoline\r
+       rjmp BootloaderAPI_ReadSignature_Trampoline\r
+       rjmp BootloaderAPI_ReadFuse_Trampoline\r
+       rjmp BootloaderAPI_ReadLock_Trampoline\r
+       rjmp BootloaderAPI_WriteLock_Trampoline\r
+       rjmp BootloaderAPU_UNUSED1 ; UNUSED ENTRY 1\r
+       rjmp BootloaderAPU_UNUSED2 ; UNUSED ENTRY 2\r
+       rjmp BootloaderAPU_UNUSED3 ; UNUSED ENTRY 3\r
+       rjmp BootloaderAPU_UNUSED4 ; UNUSED ENTRY 4\r
+       rjmp BootloaderAPU_UNUSED5 ; UNUSED ENTRY 5\r
+\r
+\r
+\r
+; Bootloader table signatures and information\r
+.section .apitable_signatures, "ax"\r
+.global BootloaderAPI_Signatures\r
+BootloaderAPI_Signatures:\r
+\r
+       .long BOOT_START_ADDR ; Start address of the bootloader\r
+       .word 0xDF30 ; Signature for the MS class bootloader, V1\r
+       .word 0xDCFB ; Signature for a LUFA class bootloader\r
index 566c47d..fca29ed 100644 (file)
@@ -20,14 +20,14 @@ OPTIMIZATION = s
 TARGET       = MassStorage\r
 SRC          = $(TARGET).c Descriptors.c Lib/SCSI.c Lib/VirtualFAT.c $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS)\r
 LUFA_PATH    = ../../../LUFA\r
-CC_FLAGS     = -DUSE_LUFA_CONFIG_HEADER -IConfig/\r
-LD_FLAGS     = -Wl,--section-start=.text=$(BOOT_START_OFFSET)\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
 \r
 # Flash size and bootloader section sizes of the target, in KB. These must\r
 # match the target's total FLASH size and the bootloader size set in the\r
 # device's fuses.\r
-FLASH_SIZE_KB        := 128\r
-BOOT_SECTION_SIZE_KB := 8\r
+FLASH_SIZE_KB         = 128\r
+BOOT_SECTION_SIZE_KB  = 8\r
 \r
 # Bootloader address calculation formulas\r
 # Do not modify these macros, but rather modify the dependent values above.\r
@@ -35,6 +35,13 @@ CALC_ADDRESS_IN_HEX   = $(shell printf "0x%X" $$(( $(1) )) )
 BOOT_START_OFFSET     = $(call CALC_ADDRESS_IN_HEX, ($(FLASH_SIZE_KB) - $(BOOT_SECTION_SIZE_KB)) * 1024 )\r
 BOOT_SEC_OFFSET       = $(call CALC_ADDRESS_IN_HEX, ($(FLASH_SIZE_KB) * 1024) - $(strip $(1)) )\r
 \r
+# Bootloader linker section flags for relocating the API table sections to\r
+# known FLASH addresses - these should not normally be user-edited.\r
+BOOT_SECTION_LD_FLAG  = -Wl,--section-start=.apitable_$(strip $(1))=$(call BOOT_SEC_OFFSET, $(3)) -Wl,--undefined=BootloaderAPI_$(strip $(2))\r
+BOOT_API_LD_FLAGS     = $(call BOOT_SECTION_LD_FLAG, trampolines, Trampolines, 96)\r
+BOOT_API_LD_FLAGS    += $(call BOOT_SECTION_LD_FLAG, jumptable,   JumpTable,   32)\r
+BOOT_API_LD_FLAGS    += $(call BOOT_SECTION_LD_FLAG, signatures,  Signatures,  8)\r
+\r
 # Default target\r
 all:\r
 \r