@@ -102,8 +102,9 @@ static void showHelp()
102102 qDebug () << " --eraseLisp : Erase lisp-script." ;
103103 qDebug () << " --uploadFirmware [path] : Upload firmware-file from path." ;
104104 qDebug () << " --uploadBootloaderBuiltin : Upload bootloader from generic included bootloaders." ;
105- qDebug () << " --createFirmwareForBootloader [fileIn:fileOut] : Generate firmware-file compatible with the bootloader. " ;
106105 qDebug () << " --writeFileToSdCard [fileLocal:pathSdcard] : Write file to SD-card." ;
106+ qDebug () << " --packFirmware [fileIn:fileOut] : Pack firmware-file for compatibility with the bootloader. " ;
107+ qDebug () << " --packLisp [fileIn:fileOut] : Pack lisp-file and the included imports." ;
107108}
108109
109110#ifdef Q_OS_LINUX
@@ -298,10 +299,12 @@ int main(int argc, char *argv[])
298299 bool eraseLisp = false ;
299300 QString firmwarePath = " " ;
300301 bool uploadBootloaderBuiltin = false ;
301- QString fwForBootloaderIn = " " ;
302- QString fwForBootloaderOut = " " ;
302+ QString fwPackIn = " " ;
303+ QString fwPackOut = " " ;
303304 QString fileForSdIn = " " ;
304305 QString fileForSdOut = " " ;
306+ QString lispPackIn = " " ;
307+ QString lispPackOut = " " ;
305308
306309 // Arguments can be hard-coded in a build like this:
307310// qmlWindowSize = QSize(400, 800);
@@ -597,13 +600,13 @@ int main(int argc, char *argv[])
597600 }
598601 }
599602
600- if (str == " --createFirmwareForBootloader " ) {
603+ if (str == " --writeFileToSdCard " ) {
601604 if ((i + 1 ) < args.size ()) {
602605 i++;
603606 auto p = args.at (i).split (" :" );
604607 if (p.size () == 2 ) {
605- fwForBootloaderIn = p.at (0 );
606- fwForBootloaderOut = p.at (1 );
608+ fileForSdIn = p.at (0 );
609+ fileForSdOut = p.at (1 );
607610 } else {
608611 qCritical () << " Invalid paths specified" ;
609612 return 1 ;
@@ -617,13 +620,33 @@ int main(int argc, char *argv[])
617620 }
618621 }
619622
620- if (str == " --writeFileToSdCard " ) {
623+ if (str == " --packFirmware " ) {
621624 if ((i + 1 ) < args.size ()) {
622625 i++;
623626 auto p = args.at (i).split (" :" );
624627 if (p.size () == 2 ) {
625- fileForSdIn = p.at (0 );
626- fileForSdOut = p.at (1 );
628+ fwPackIn = p.at (0 );
629+ fwPackOut = p.at (1 );
630+ } else {
631+ qCritical () << " Invalid paths specified" ;
632+ return 1 ;
633+ }
634+
635+ found = true ;
636+ } else {
637+ i++;
638+ qCritical () << " No paths specified" ;
639+ return 1 ;
640+ }
641+ }
642+
643+ if (str == " --packLisp" ) {
644+ if ((i + 1 ) < args.size ()) {
645+ i++;
646+ auto p = args.at (i).split (" :" );
647+ if (p.size () == 2 ) {
648+ lispPackIn = p.at (0 );
649+ lispPackOut = p.at (1 );
627650 } else {
628651 qCritical () << " Invalid paths specified" ;
629652 return 1 ;
@@ -675,16 +698,16 @@ int main(int argc, char *argv[])
675698 return 0 ;
676699 }
677700
678- if (!fwForBootloaderIn .isEmpty ()) {
679- QFile fIn (fwForBootloaderIn );
701+ if (!fwPackIn .isEmpty ()) {
702+ QFile fIn (fwPackIn );
680703 if (!fIn .open (QIODevice::ReadOnly)) {
681- qWarning () << QString (" Could not open %1 for reading." ).arg (fwForBootloaderIn );
704+ qWarning () << QString (" Could not open %1 for reading." ).arg (fwPackIn );
682705 return 1 ;
683706 }
684707
685- QFile fOut (fwForBootloaderOut );
708+ QFile fOut (fwPackOut );
686709 if (!fOut .open (QIODevice::WriteOnly)) {
687- qWarning () << QString (" Could not open %1 for writing." ).arg (fwForBootloaderOut );
710+ qWarning () << QString (" Could not open %1 for writing." ).arg (fwPackOut );
688711 return 1 ;
689712 }
690713
@@ -737,6 +760,37 @@ int main(int argc, char *argv[])
737760 return 0 ;
738761 }
739762
763+ if (!lispPackIn.isEmpty ()) {
764+ QFile fIn (lispPackIn);
765+ if (!fIn .open (QIODevice::ReadOnly)) {
766+ qWarning () << QString (" Could not open %1 for reading." ).arg (lispPackIn);
767+ return 1 ;
768+ }
769+
770+ QFile fOut (lispPackOut);
771+ if (!fOut .open (QIODevice::WriteOnly)) {
772+ qWarning () << QString (" Could not open %1 for writing." ).arg (lispPackOut);
773+ return 1 ;
774+ }
775+
776+ CodeLoader loader;
777+ QFileInfo fi (fIn );
778+ VByteArray vb = loader.lispPackImports (fIn .readAll (), fi.canonicalPath ());
779+ fIn .close ();
780+
781+ quint16 crc = Packet::crc16 ((const unsigned char *)vb.constData (), uint32_t (vb.size ()));
782+ VByteArray data;
783+ data.vbAppendUint32 (vb.size () - 2 );
784+ data.vbAppendUint16 (crc);
785+ data.append (vb);
786+
787+ fOut .write (data);
788+ fOut .close ();
789+
790+ qDebug () << " Done!" ;
791+ return 0 ;
792+ }
793+
740794 if (!pkgArgs.isEmpty ()) {
741795 if (pkgArgs.size () < 4 ) {
742796 qWarning () << " Invalid arguments" ;
0 commit comments