|
17 | 17 | * along with Massdrop Loader. If not, see <https://www.gnu.org/licenses/>.
|
18 | 18 | */
|
19 | 19 |
|
| 20 | +#define INCBIN_PREFIX |
| 21 | +#define INCBIN_STYLE INCBIN_STYLE_SNAKE |
| 22 | +#include "incbin/incbin.h" |
| 23 | +INCBIN(applet, "applet-mdflash.bin"); |
| 24 | + |
20 | 25 | #include "mdloader_common.h"
|
21 | 26 | #include "mdloader_parser.h"
|
22 | 27 |
|
@@ -751,95 +756,39 @@ int main(int argc, char *argv[])
|
751 | 756 | print_bootloader_version();
|
752 | 757 | if (verbose) printf("Device ID: %08X\n", mcu->cidr);
|
753 | 758 |
|
754 |
| - //Load applet |
755 |
| - FILE *fIn; |
756 |
| - char appletfname[128] = ""; |
757 |
| - strlower(mcu->name); |
758 |
| - |
759 |
| - //sprintf(appletfname, "applet-flash-%s.bin", mcu->name); |
760 |
| - sprintf(appletfname, "applet-mdflash.bin"); //make filename non-dependent upon mcu->name |
761 |
| - |
762 |
| - printf("Applet file: %s\n", appletfname); |
763 | 759 |
|
764 |
| - fIn = fopen(appletfname, "rb"); |
765 |
| - if (!fIn) |
| 760 | + memcpy(&appinfo, applet_data + applet_size - sizeof(appinfo_t), sizeof(appinfo_t)); |
| 761 | + if (appinfo.magic != 0x4142444D) |
766 | 762 | {
|
767 |
| - printf("Error: Could not open applet file: %s\n", appletfname); |
| 763 | + printf("Error: Applet info not found!\n"); |
768 | 764 | goto closePort;
|
769 | 765 | }
|
770 |
| - else |
771 |
| - { |
772 |
| - char *appletbuf; |
773 |
| - int filebytes; |
774 |
| - int readbytes; |
775 |
| - |
776 |
| - filebytes = filesize(appletfname); |
777 |
| - if (filebytes == 0) |
778 |
| - { |
779 |
| - printf("Error: Applet file is empty!\n"); |
780 |
| - fclose(fIn); |
781 |
| - goto closePort; |
782 |
| - } |
783 |
| - |
784 |
| - appletbuf = (char *)calloc(filebytes,1); |
785 |
| - if (appletbuf == NULL) |
786 |
| - { |
787 |
| - printf("Error: Could not allocate memory for applet file!\n"); |
788 |
| - fclose(fIn); |
789 |
| - goto closePort; |
790 |
| - } |
791 |
| - |
792 |
| - readbytes = (int)fread(appletbuf, 1, filebytes, fIn); |
793 |
| - fclose(fIn); |
794 |
| - |
795 |
| - if (readbytes != filebytes) |
796 |
| - { |
797 |
| - printf("Error: Applet read error!\n"); |
798 |
| - goto closePort; |
799 |
| - } |
800 | 766 |
|
801 |
| - if (readbytes < sizeof(appinfo_t)) |
802 |
| - { |
803 |
| - printf("Error: Applet binary too small!\n"); |
804 |
| - goto closePort; |
805 |
| - } |
806 |
| - |
807 |
| - memcpy(&appinfo, appletbuf + readbytes - sizeof(appinfo_t), sizeof(appinfo_t)); |
808 |
| - if (appinfo.magic != 0x4142444D) |
809 |
| - { |
810 |
| - printf("Error: Applet info not found!\n"); |
811 |
| - goto closePort; |
812 |
| - } |
813 |
| - |
814 |
| - if (verbose) |
815 |
| - { |
816 |
| - printf("Applet load address: %08X\n", appinfo.load_addr); |
817 |
| - printf("Applet mail address: %08X\n", appinfo.mail_addr); |
818 |
| - } |
819 |
| - |
820 |
| - //printf("Applet data:\n"); |
821 |
| - //print_hex_listing(appletbuf, readbytes, 0, 0); |
822 |
| - |
823 |
| - if (verbose) printf("Applet size: %i\n", readbytes); |
| 767 | + if (verbose) |
| 768 | + { |
| 769 | + printf("Applet load address: %08X\n", appinfo.load_addr); |
| 770 | + printf("Applet mail address: %08X\n", appinfo.mail_addr); |
| 771 | + } |
824 | 772 |
|
825 |
| - if (!send_file(appinfo.load_addr, readbytes, appletbuf)) |
826 |
| - { |
827 |
| - printf("Error: Could not send applet!\n"); |
828 |
| - free(appletbuf); |
829 |
| - goto closePort; |
830 |
| - } |
| 773 | + //printf("Applet data:\n"); |
| 774 | + //print_hex_listing(appletbuf, readbytes, 0, 0); |
831 | 775 |
|
832 |
| - free(appletbuf); |
| 776 | + if (verbose) printf("Applet size: %i\n", applet_size); |
833 | 777 |
|
834 |
| - //printf("Applet data in RAM:\n"); |
835 |
| - //char *data_recv = recv_file(appinfo.load_addr, readbytes); |
836 |
| - //if (data_recv) |
837 |
| - //{ |
838 |
| - // print_hex_listing(data_recv, readbytes, 0, appinfo.load_addr); |
839 |
| - // free(data_recv); //Free memory allocated in recv_file |
840 |
| - //} |
| 778 | + if (!send_file(appinfo.load_addr, applet_size, (char*)applet_data)) |
| 779 | + { |
| 780 | + printf("Error: Could not send applet!\n"); |
| 781 | + goto closePort; |
841 | 782 | }
|
842 | 783 |
|
| 784 | + //printf("Applet data in RAM:\n"); |
| 785 | + //char *data_recv = recv_file(appinfo.load_addr, readbytes); |
| 786 | + //if (data_recv) |
| 787 | + //{ |
| 788 | + // print_hex_listing(data_recv, readbytes, 0, appinfo.load_addr); |
| 789 | + // free(data_recv); //Free memory allocated in recv_file |
| 790 | + //} |
| 791 | + |
843 | 792 | initparams.command = APPLET_CMD_INIT;
|
844 | 793 | initparams.status = STATUS_BUSY;
|
845 | 794 | initparams.argument.inputInit.bank = 0;
|
|
0 commit comments