diff --git a/firmware/application/m4_startup.cpp b/firmware/application/m4_startup.cpp index 59fc511a1..0e493f1b7 100644 --- a/firmware/application/m4_startup.cpp +++ b/firmware/application/m4_startup.cpp @@ -55,6 +55,7 @@ int m4_load_image(void) { uint32_t mod_size; UINT bw; uint8_t i; + uint16_t cnt; char md5sum[16]; FILINFO modinfo; FIL modfile; @@ -77,9 +78,11 @@ int m4_load_image(void) { f_lseek(&modfile, 6); f_read(&modfile, &mod_size, 4, &bw); f_lseek(&modfile, 256); - f_read(&modfile, reinterpret_cast(portapack::memory::map::m4_code.base()), mod_size, &bw); - LPC_RGU->RESET_CTRL[0] = (1 << 13); + // For some reason, f_read > 512 bytes at once crashes everything... :/ + for (cnt=0;cnt<256;cnt++) + f_read(&modfile, reinterpret_cast(portapack::memory::map::m4_code.base()+(cnt*256)), 256, &bw); f_close(&modfile); + LPC_RGU->RESET_CTRL[0] = (1 << 13); return 1; } f_close(&modfile); diff --git a/firmware/application/ui_lcr.cpp b/firmware/application/ui_lcr.cpp index d2d9e64b4..098095d0a 100644 --- a/firmware/application/ui_lcr.cpp +++ b/firmware/application/ui_lcr.cpp @@ -290,16 +290,17 @@ LCRView::LCRView( memcpy(shared_memory.lcrdata, lcrframe_f, 256); shared_memory.afsk_transmit_done = false; - shared_memory.afsk_repeat = ((portapack::persistent_memory::afsk_config() >> 8) & 0xFF); + shared_memory.afsk_repeat = (portapack::persistent_memory::afsk_config() >> 8) & 0xFF; message_map.register_handler(Message::ID::TXDone, [this,&transmitter_model](Message* const p) { + char str[8]; const auto message = static_cast(p); if (message->n > 0) { - char str[8]; + text_status.set(" "); strcpy(str, to_string_dec_int(message->n).c_str()); strcat(str, "/"); - strcat(str, to_string_dec_int(shared_memory.afsk_repeat).c_str()); + strcat(str, to_string_dec_int((portapack::persistent_memory::afsk_config() >> 8) & 0xFF).c_str()); text_status.set(str); } else { text_status.set("Done ! "); diff --git a/firmware/application/ui_loadmodule.cpp b/firmware/application/ui_loadmodule.cpp index d5dafdab1..36569ed9d 100644 --- a/firmware/application/ui_loadmodule.cpp +++ b/firmware/application/ui_loadmodule.cpp @@ -26,7 +26,7 @@ #include "ff.h" #include "hackrf_gpio.hpp" #include "portapack.hpp" - +#include "portapack_shared_memory.hpp" #include "hackrf_hal.hpp" #include @@ -50,11 +50,39 @@ void LoadModuleView::on_hide() { } void LoadModuleView::on_show() { + // Ask for MD5 signature and compare + ModuleIDMessage message; + auto& message_map = context().message_map(); + + message_map.unregister_handler(Message::ID::ModuleID); + + message_map.register_handler(Message::ID::ModuleID, + [this](Message* const p) { + uint8_t c; + const auto message = static_cast(p); + if (message->query == false) { // Shouldn't be needed + for (c=0;c<16;c++) { + if (message->md5_signature[c] != _hash[c]) break; + } + if (c == 16) { + text_info.set("Module already loaded :)"); + _mod_loaded = true; + } else { + loadmodule(); + } + } + } + ); + + message.query = true; + shared_memory.baseband_queue.push(message); +} + +void LoadModuleView::loadmodule() { auto& message_map = context().message_map(); message_map.register_handler(Message::ID::ReadyForSwitch, [this](Message* const p) { (void)p; - // const auto message = static_cast(p); if (m4_load_image()) { text_info.set("Module loaded :)"); _mod_loaded = true; diff --git a/firmware/application/ui_loadmodule.hpp b/firmware/application/ui_loadmodule.hpp index f3bc99c3b..ab2dfc67d 100644 --- a/firmware/application/ui_loadmodule.hpp +++ b/firmware/application/ui_loadmodule.hpp @@ -32,6 +32,7 @@ namespace ui { class LoadModuleView : public View { public: LoadModuleView(NavigationView& nav, const char * hash, View* new_view); + void loadmodule(); void on_show() override; void on_hide() override; diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index 49a9a92f7..35021536c 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -111,19 +111,19 @@ void NavigationView::focus() { /* SystemMenuView ********************************************************/ SystemMenuView::SystemMenuView(NavigationView& nav) { - add_items<10>({ { + add_items<11>({ { { "Play dead", ui::Color::red(), [&nav](){ nav.push(new PlayDeadView { nav, false }); } }, - { "Receiver", ui::Color::cyan(), [&nav](){ nav.push(new ReceiverView { nav, receiver_model }); } }, + { "Receiver", ui::Color::cyan(), [&nav](){ nav.push(new LoadModuleView { nav, md5_baseband, new ReceiverView { nav, receiver_model }}); } }, //{ "Nordic/BTLE RX", ui::Color::cyan(), [&nav](){ nav.push(new NotImplementedView { nav }); } }, - { "Jammer", ui::Color::white(), [&nav](){ nav.push(new JammerView { nav, transmitter_model }); } }, + { "Jammer", ui::Color::white(), [&nav](){ nav.push(new LoadModuleView { nav, md5_baseband, new JammerView { nav, transmitter_model }}); } }, //{ "Audio file TX", ui::Color::white(), [&nav](){ nav.push(new NotImplementedView { nav }); } }, //{ "Encoder TX", ui::Color::green(), [&nav](){ nav.push(new NotImplementedView { nav }); } }, - { "Whistle", ui::Color::purple(), [&nav](){ nav.push(new WhistleView { nav, transmitter_model }); } }, - //{ "SIGFOX RX", ui::Color::orange(), [&nav](){ nav.push(new SIGFRXView { nav, receiver_model }); } }, - //{ "RDS TX", ui::Color::yellow(), [&nav](){ nav.push(new LoadModuleView { nav, md5_baseband_tx, new RDSView { nav, transmitter_model }}; } }, - { "Xylos TX", ui::Color::orange(), [&nav](){ nav.push(new XylosView { nav, transmitter_model }); } }, - //{ "AFSK RX", ui::Color::cyan(), [&nav](){ nav.push(new AFSKRXView { nav, receiver_model }); } }, - { "TEDI/LCR TX", ui::Color::yellow(), [&nav](){ nav.push(new LCRView { nav, transmitter_model }); } }, + { "Whistle", ui::Color::purple(), [&nav](){ nav.push(new LoadModuleView { nav, md5_baseband, new WhistleView { nav, transmitter_model }}); } }, + //{ "SIGFOX RX", ui::Color::orange(), [&nav](){ nav.push(new LoadModuleView { nav, md5_baseband, new SIGFRXView { nav, receiver_model }}); } }, + { "RDS TX", ui::Color::yellow(), [&nav](){ nav.push(new LoadModuleView { nav, md5_baseband_tx, new RDSView { nav, transmitter_model }}); } }, + { "Xylos TX", ui::Color::orange(), [&nav](){ nav.push(new LoadModuleView { nav, md5_baseband_tx, new XylosView { nav, transmitter_model }}); } }, + //{ "AFSK RX", ui::Color::cyan(), [&nav](){ nav.push(new LoadModuleView { nav, md5_baseband, new AFSKRXView { nav, receiver_model }}); } }, + { "TEDI/LCR TX", ui::Color::yellow(), [&nav](){ nav.push(new LoadModuleView { nav, md5_baseband_tx, new LCRView { nav, transmitter_model }}); } }, { "Setup", ui::Color::white(), [&nav](){ nav.push(new SetupMenuView { nav }); } }, { "About", ui::Color::white(), [&nav](){ nav.push(new AboutView { nav }); } }, { "Debug", ui::Color::white(), [&nav](){ nav.push(new DebugMenuView { nav }); } }, diff --git a/firmware/application/ui_xylos.cpp b/firmware/application/ui_xylos.cpp index 1083b615d..ef011df77 100644 --- a/firmware/application/ui_xylos.cpp +++ b/firmware/application/ui_xylos.cpp @@ -1,6 +1,7 @@ /* * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. - * + * Copyright (C) 2016 Furrtek + * * This file is part of PortaPack. * * This program is free software; you can redistribute it and/or modify @@ -106,6 +107,8 @@ void XylosView::upd_message() { else ccirmessage[c] -= 0x30; } + + ccirmessage[20] = 0xFF; } void XylosView::journuit() { diff --git a/firmware/application/ui_xylos.hpp b/firmware/application/ui_xylos.hpp index 93b560c4d..59525eaec 100644 --- a/firmware/application/ui_xylos.hpp +++ b/firmware/application/ui_xylos.hpp @@ -1,6 +1,7 @@ /* * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. - * + * Copyright (C) 2016 Furrtek + * * This file is part of PortaPack. * * This program is free software; you can redistribute it and/or modify diff --git a/firmware/baseband-tx.bin b/firmware/baseband-tx.bin index cd98095ec..8b0ee7fc9 100644 Binary files a/firmware/baseband-tx.bin and b/firmware/baseband-tx.bin differ diff --git a/firmware/baseband-tx/main.cpp b/firmware/baseband-tx/main.cpp index 30ce1c29d..5ec8e4f97 100755 --- a/firmware/baseband-tx/main.cpp +++ b/firmware/baseband-tx/main.cpp @@ -485,7 +485,6 @@ void wait_for_switch(void) { ReadyForSwitchMessage message; shared_memory.application_queue.push(message); (*loop_ptr)(); - return; } int main(void) { @@ -496,6 +495,18 @@ int main(void) { EventDispatcher event_dispatcher; auto& message_handlers = event_dispatcher.message_handlers(); + + message_handlers.register_handler(Message::ID::ModuleID, + [&message_handlers](Message* p) { + ModuleIDMessage reply; + auto message = static_cast(p); + if (message->query == true) { // Shouldn't be needed + memcpy(reply.md5_signature, (const void *)(0x10087FF0), 16); + reply.query = false; + shared_memory.application_queue.push(reply); + } + } + ); message_handlers.register_handler(Message::ID::BasebandConfiguration, [&message_handlers](const Message* const p) { @@ -538,7 +549,7 @@ int main(void) { baseband_thread.baseband_processor = new XylosProcessor(); break; - case 0xFF: + case SWITCH: wait_for_switch(); default: diff --git a/firmware/baseband-tx/proc_xylos.cpp b/firmware/baseband-tx/proc_xylos.cpp index b97089d30..f0528ddbe 100644 --- a/firmware/baseband-tx/proc_xylos.cpp +++ b/firmware/baseband-tx/proc_xylos.cpp @@ -1,7 +1,7 @@ /* - * Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc. + * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. * Copyright (C) 2016 Furrtek - * + * * This file is part of PortaPack. * * This program is free software; you can redistribute it and/or modify @@ -45,11 +45,10 @@ void XylosProcessor::execute(buffer_c8_t buffer) { digit = shared_memory.xylosdata[byte_pos++]; } - if (!digit) { + if (digit == 0xFF) { message.n = 25; // End of message code shared_memory.xylos_transmit_done = true; shared_memory.application_queue.push(message); - digit = 0; } sample_count = 0; diff --git a/firmware/baseband-tx/proc_xylos.hpp b/firmware/baseband-tx/proc_xylos.hpp index a9e2458dc..933d3cb4c 100644 --- a/firmware/baseband-tx/proc_xylos.hpp +++ b/firmware/baseband-tx/proc_xylos.hpp @@ -1,7 +1,7 @@ /* - * Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc. + * Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. * Copyright (C) 2016 Furrtek - * + * * This file is part of PortaPack. * * This program is free software; you can redistribute it and/or modify diff --git a/firmware/baseband.bin b/firmware/baseband.bin index 99a0ae2d3..36ce9db2f 100644 Binary files a/firmware/baseband.bin and b/firmware/baseband.bin differ diff --git a/firmware/baseband/main.cpp b/firmware/baseband/main.cpp index bdf520b56..439b38313 100755 --- a/firmware/baseband/main.cpp +++ b/firmware/baseband/main.cpp @@ -348,7 +348,7 @@ private: const auto baseband_buffer = new std::array(); - + char ram_loop[32]; typedef int (*fn_ptr)(void); fn_ptr loop_ptr; @@ -363,7 +363,6 @@ void wait_for_switch(void) { ReadyForSwitchMessage message; shared_memory.application_queue.push(message); (*loop_ptr)(); - return; } int main(void) { @@ -374,6 +373,18 @@ int main(void) { EventDispatcher event_dispatcher; auto& message_handlers = event_dispatcher.message_handlers(); + + message_handlers.register_handler(Message::ID::ModuleID, + [&message_handlers](Message* p) { + ModuleIDMessage reply; + auto message = static_cast(p); + if (message->query == true) { // Shouldn't be needed + memcpy(reply.md5_signature, (const void *)(0x10087FF0), 16); + reply.query = false; + shared_memory.application_queue.push(reply); + } + } + ); message_handlers.register_handler(Message::ID::BasebandConfiguration, [&message_handlers](const Message* const p) { diff --git a/firmware/chibios-portapack/os/ports/GCC/ARMCMx/LPC43xx_M0/ld/LPC43xx_M0.ld b/firmware/chibios-portapack/os/ports/GCC/ARMCMx/LPC43xx_M0/ld/LPC43xx_M0.ld index 6331b9bd1..249511821 100755 --- a/firmware/chibios-portapack/os/ports/GCC/ARMCMx/LPC43xx_M0/ld/LPC43xx_M0.ld +++ b/firmware/chibios-portapack/os/ports/GCC/ARMCMx/LPC43xx_M0/ld/LPC43xx_M0.ld @@ -23,7 +23,7 @@ __process_stack_size__ = 0x1000; /* main() stack */ MEMORY { - flash : org = 0x00000000, len = 128k /* SPIFI flash @ 0x140????? */ + flash : org = 0x00000000, len = 256k /* SPIFI flash @ 0x140????? */ ram : org = 0x20000000, len = 64k /* AHB SRAM @ 0x20000000 */ } diff --git a/firmware/chibios-portapack/os/ports/GCC/ARMCMx/LPC43xx_M4/ld/LPC43xx_M4.ld b/firmware/chibios-portapack/os/ports/GCC/ARMCMx/LPC43xx_M4/ld/LPC43xx_M4.ld index df7b22d14..6a9bdea90 100755 --- a/firmware/chibios-portapack/os/ports/GCC/ARMCMx/LPC43xx_M4/ld/LPC43xx_M4.ld +++ b/firmware/chibios-portapack/os/ports/GCC/ARMCMx/LPC43xx_M4/ld/LPC43xx_M4.ld @@ -23,7 +23,7 @@ __process_stack_size__ = 0x1000; /* main() stack */ MEMORY { - flash : org = 0x00000000, len = 32k /* Local SRAM @ 0x10080000 */ + flash : org = 0x00000000, len = 32752 /* Local SRAM @ 0x10080000 */ ram : org = 0x10000000, len = 96k /* Local SRAM @ 0x10000000 */ } diff --git a/firmware/common/message.hpp b/firmware/common/message.hpp index 77181b94f..e45512c53 100644 --- a/firmware/common/message.hpp +++ b/firmware/common/message.hpp @@ -51,6 +51,7 @@ public: Retune = 11, ReadyForSwitch = 12, AFSKData = 13, + ModuleID = 14, MAX }; @@ -297,6 +298,17 @@ public: int n = 0; }; +class ModuleIDMessage : public Message { +public: + ModuleIDMessage( + ) : Message { ID::ModuleID } + { + } + + bool query; + char md5_signature[16]; +}; + class ReadyForSwitchMessage : public Message { public: ReadyForSwitchMessage( diff --git a/firmware/common/modules.h b/firmware/common/modules.h index 26dd39776..36889193f 100644 --- a/firmware/common/modules.h +++ b/firmware/common/modules.h @@ -1,2 +1,2 @@ -const char md5_baseband[16] = {0x20,0xb7,0x1a,0x68,0x28,0xda,0xc9,0xb8,0x01,0xb0,0xbd,0x68,0x0d,0xd5,0xd6,0xa7,}; -const char md5_baseband_tx[16] = {0xe5,0x29,0xb9,0xf0,0x81,0x50,0x45,0x69,0x24,0xaf,0xdd,0x4e,0xdb,0xaf,0xd8,0x97,}; +const char md5_baseband[16] = {0xef,0xc2,0x85,0x1d,0x83,0x0d,0x5c,0x18,0x55,0x7b,0x80,0x75,0xc9,0x6a,0x54,0xe1,}; +const char md5_baseband_tx[16] = {0xad,0xc6,0x44,0x4e,0xf4,0xe1,0xb8,0xb2,0x29,0x52,0x1d,0x33,0x1f,0xda,0x5d,0xd6,}; diff --git a/firmware/portapack-h1-firmware.bin b/firmware/portapack-h1-firmware.bin index 53acde85f..69c06fdf2 100644 Binary files a/firmware/portapack-h1-firmware.bin and b/firmware/portapack-h1-firmware.bin differ diff --git a/firmware/tools/make_baseband_file.py b/firmware/tools/make_baseband_file.py index 078db063b..7f7415699 100755 --- a/firmware/tools/make_baseband_file.py +++ b/firmware/tools/make_baseband_file.py @@ -1,6 +1,5 @@ #!/usr/bin/env python -# # Copyright (C) 2016 Furrtek # # This program is free software; you can redistribute it and/or modify @@ -56,35 +55,59 @@ sys.argv = sys.argv[1:] # Format for module file: # Magic (4), Version (2), Length (4), Name (16), MD5 (16), Description (214) -# Unpadded module binary... +# Module binary... +# MD5 (16) for args in sys.argv: data = read_image(args + '/build/' + args + '.bin') + data_r = data + + # Magic bytes info = 'PPM ' + + # Version info += struct.pack('H', 1) + + # Length info += struct.pack('I', len(data)) + + # Module name name = read_image(args + '/name') if len(name) > 16: name = name[0:15] pad_size = 16 - len(name) name += (data_default_byte * pad_size) info += name + + # Module MD5 footprint m.update(data) digest = m.digest() pad_size = 16 - len(digest) digest += (data_default_byte * pad_size) info += digest + + # Module description description = read_image(args + '/description') if len(description) > 214: description = description[0:213] pad_size = 214 - len(description) description += (data_default_byte * pad_size) info += description + + # Padding data = info + data + pad_size = (32768 + 256 - 16) - len(data) + data += (data_default_byte * pad_size) + data += digest write_file(data, args + '.bin') + + # Add to modules.h md5sum = '' for byte in digest: md5sum += '0x' + format(byte, '02x') + ',' h_data += 'const char md5_' + args.replace('-','_') + '[16] = {' + md5sum + '};\n' + + # Update original binary with MD5 footprint + write_file(data[256:(32768+256)], args + '/build/' + args + '.bin') write_file(h_data, 'common/modules.h')