Skip to content

Commit c7badc3

Browse files
committed
61
1 parent 5c4895a commit c7badc3

File tree

2 files changed

+28
-81
lines changed

2 files changed

+28
-81
lines changed

Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ OBJFILES = $(patsubst %.c,%.o,$(SRCFILES))
1414
OBJS = $(addprefix $(OBJDIR)/,$(OBJFILES))
1515

1616
all: $(OBJDIR)/$(OUTNAME)
17-
$(info Copying applets to ${OBJDIR}...)
18-
@cp applet-*.bin $(OBJDIR)
1917
$(info Done!)
2018

2119
$(OBJDIR)/$(OUTNAME): $(OBJS)

mdloader_common.c

Lines changed: 28 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
* along with Massdrop Loader. If not, see <https://www.gnu.org/licenses/>.
1818
*/
1919

20+
#define INCBIN_PREFIX
21+
#define INCBIN_STYLE INCBIN_STYLE_SNAKE
22+
#include "incbin/incbin.h"
23+
INCBIN(applet, "applet-mdflash.bin");
24+
2025
#include "mdloader_common.h"
2126
#include "mdloader_parser.h"
2227

@@ -751,95 +756,39 @@ int main(int argc, char *argv[])
751756
print_bootloader_version();
752757
if (verbose) printf("Device ID: %08X\n", mcu->cidr);
753758

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);
763759

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)
766762
{
767-
printf("Error: Could not open applet file: %s\n", appletfname);
763+
printf("Error: Applet info not found!\n");
768764
goto closePort;
769765
}
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-
}
800766

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+
}
824772

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);
831775

832-
free(appletbuf);
776+
if (verbose) printf("Applet size: %i\n", applet_size);
833777

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;
841782
}
842783

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+
843792
initparams.command = APPLET_CMD_INIT;
844793
initparams.status = STATUS_BUSY;
845794
initparams.argument.inputInit.bank = 0;

0 commit comments

Comments
 (0)