Build: Fix incorrect build target for Ubuntu CI builds.
[pub/USBasp.git] / Bootloaders / Printer / BootloaderAPI.c
index 5e8083e..21d13bb 100644 (file)
@@ -1,13 +1,13 @@
 /*
              LUFA Library
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2018.
+     Copyright (C) Dean Camera, 2019.
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
-  Copyright 2018  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2019  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
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
 
 #include "BootloaderAPI.h"
 
 
 #include "BootloaderAPI.h"
 
+static bool IsPageAddressValid(const uint32_t Address)
+{
+       /* Determine if the given page address is correctly aligned to the
+          start of a flash page. */
+       bool PageAddressIsAligned = !(Address & (SPM_PAGESIZE - 1));
+
+       return (Address < BOOT_START_ADDR) && PageAddressIsAligned;
+}
+
 void BootloaderAPI_ErasePage(const uint32_t Address)
 {
 void BootloaderAPI_ErasePage(const uint32_t Address)
 {
+       if (! IsPageAddressValid(Address))
+               return;
+
        ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
        {
                boot_page_erase_safe(Address);
        ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
        {
                boot_page_erase_safe(Address);
@@ -47,6 +59,9 @@ void BootloaderAPI_ErasePage(const uint32_t Address)
 
 void BootloaderAPI_WritePage(const uint32_t Address)
 {
 
 void BootloaderAPI_WritePage(const uint32_t Address)
 {
+       if (! IsPageAddressValid(Address))
+               return;
+
        ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
        {
                boot_page_write_safe(Address);
        ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
        {
                boot_page_write_safe(Address);