diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 0f79a78d..30e5c0b6 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -970,6 +970,35 @@ void erase_eeprom_section(uint16_t offset, uint16_t bytes) for (int i = offset; i < (offset+bytes); i++) eeprom_write_byte((uint8_t*)i, 0xFF); } +#include "bootapp.h" + +void __test() +{ + cli(); + boot_app_magic = 0x55aa55aa; + boot_app_flags = BOOT_APP_FLG_USER0; + boot_reserved = 0x00; + wdt_enable(WDTO_15MS); + while(1); +} + +void upgrade_sec_lang_from_external_flash() +{ + if ((boot_app_magic == 0x55aa55aa) && (boot_app_flags & BOOT_APP_FLG_USER0)) + { + fprintf_P(lcdout, PSTR(ESC_2J ESC_H(1,1) "TEST %d"), boot_reserved); + boot_reserved++; + if (boot_reserved < 4) + { + _delay_ms(1000); + cli(); + wdt_enable(WDTO_15MS); + while(1); + } + } + boot_app_flags &= ~BOOT_APP_FLG_USER0; +} + // "Setup" function is called by the Arduino framework on startup. // Before startup, the Timers-functions (PWM)/Analog RW and HardwareSerial provided by the Arduino-code // are initialized by the main() routine provided by the Arduino framework. @@ -977,6 +1006,9 @@ void setup() { lcd_init(); fdev_setup_stream(lcdout, lcd_putchar, NULL, _FDEV_SETUP_WRITE); //setup lcdout stream + +// upgrade_sec_lang_from_external_flash(); + lcd_splash(); setup_killpin(); setup_powerhold(); diff --git a/Firmware/bootapp.c b/Firmware/bootapp.c new file mode 100644 index 00000000..0f652921 --- /dev/null +++ b/Firmware/bootapp.c @@ -0,0 +1,32 @@ +//bootapp.c +#include "bootapp.h" +#include +#include +#include + + +/* +void bootapp_print_vars() +{ + printf_P(_n("boot_src_addr =0x%08lx\n"), boot_src_addr); + printf_P(_n("boot_dst_addr =0x%08lx\n"), boot_dst_addr); + printf_P(_n("boot_copy_size =0x%04x\n"), boot_copy_size); + printf_P(_n("boot_reserved =0x%02x\n"), boot_reserved); + printf_P(_n("boot_app_flags =0x%02x\n"), boot_app_flags); + printf_P(_n("boot_app_magic =0x%08lx\n"), boot_app_magic); +} +*/ + +void bootapp_ram2flash(uint16_t rptr, uint16_t fptr, uint16_t size) +{ + cli(); +// uint16_t ui; for (ui = 0; ui < size; ui++) +// ram_array[ui+rptr] = 0xff; + boot_app_magic = 0x55aa55aa; + boot_app_flags = BOOT_APP_FLG_ERASE | BOOT_APP_FLG_COPY; + boot_copy_size = (uint16_t)size; + boot_src_addr = (uint32_t)rptr; + boot_dst_addr = (uint32_t)fptr; + wdt_enable(WDTO_15MS); + while(1); +} diff --git a/Firmware/bootapp.h b/Firmware/bootapp.h new file mode 100644 index 00000000..dc0006e4 --- /dev/null +++ b/Firmware/bootapp.h @@ -0,0 +1,36 @@ +//language.h +#ifndef BOOTAPP_H +#define BOOTAPP_H + +#include "config.h" +#include + + +#define RAMSIZE 0x2000 +#define ram_array ((uint8_t*)(0)) +#define boot_src_addr (*((uint32_t*)(RAMSIZE - 16))) +#define boot_dst_addr (*((uint32_t*)(RAMSIZE - 12))) +#define boot_copy_size (*((uint16_t*)(RAMSIZE - 8))) +#define boot_reserved (*((uint8_t*)(RAMSIZE - 6))) +#define boot_app_flags (*((uint8_t*)(RAMSIZE - 5))) +#define boot_app_magic (*((uint32_t*)(RAMSIZE - 4))) +#define BOOT_APP_FLG_ERASE 0x01 +#define BOOT_APP_FLG_COPY 0x02 +#define BOOT_APP_FLG_FLASH 0x04 + +#define BOOT_APP_FLG_USER0 0x80 + + +#if defined(__cplusplus) +extern "C" { +#endif //defined(__cplusplus) + + +extern void bootapp_ram2flash(uint16_t rptr, uint16_t fptr, uint16_t size); + + +#if defined(__cplusplus) +} +#endif //defined(__cplusplus) + +#endif //BOOTAPP_H diff --git a/Firmware/language.c b/Firmware/language.c index c51fc60e..1e2f3024 100644 --- a/Firmware/language.c +++ b/Firmware/language.c @@ -2,6 +2,7 @@ #include "language.h" #include #include +#include "bootapp.h" // Currectly active language selection. @@ -93,3 +94,4 @@ const char* lang_get_name(unsigned char lang) } const char MSG_LANGUAGE_NAME[] PROGMEM_I1 = ISTR("English"); ////c=0 r=0 + diff --git a/Firmware/language.h b/Firmware/language.h index ec641334..b768bdb3 100644 --- a/Firmware/language.h +++ b/Firmware/language.h @@ -76,6 +76,7 @@ extern const char* lang_select(unsigned char lang); extern unsigned char lang_get_count(); extern const char* lang_get_name(unsigned char lang); + #if defined(__cplusplus) } #endif //defined(__cplusplus) @@ -88,5 +89,5 @@ extern const char MSG_LANGUAGE_NAME[]; #include "messages.h" -#endif //__LANGUAGE_H +#endif //LANGUAGE_H