From c2b99b18bb9aaefcd55cba8e08f2a56e7c9098ab Mon Sep 17 00:00:00 2001 From: just-another-jxliu Date: Fri, 7 Sep 2018 11:17:27 -0700 Subject: [PATCH 01/21] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a2e5ca7..87d2d4b 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,12 @@ 4. In your terminal, change to the directory where you downloaded the executable. 5. **Windows** - Run `mdloader_windows.exe --list`. Copy the port name, e.g. `/dev/ttyACM0`, `/dev/ttyS23`, `/dev/cu.usbmodem234411`. -**Linux** - Run `mdloader_linux --list`. Copy the port name as described above. -**Mac** - Run `mdloader_mac --list`. If you downloaded with Mac Safari, run `mdloader_mac.dms --list`. Copy the port name as described above. +**Linux** - Run `./mdloader_linux --list`. Copy the port name as described above. +**Mac** - Run `./mdloader_mac --list`. If you downloaded with Mac Safari, run `./mdloader_mac.dms --list`. Copy the port name as described above. 6. **Windows** - Run `mdloader_windows.exe --port PORT_NAME --download FILE_NAME --restart`. Replace "PORT_NAME" with the port name you copied in the previous step. Replace "FILE_NAME" with the filename of your compiled firmware. -**Linux** - Run `mdloader_linux --port PORT_NAME --download FILE_NAME --restart`. Replace "PORT_NAME" and "FILE_NAME" in the command as instructed above. -**Mac** - Run `mdloader_mac --port PORT_NAME --download FILE_NAME --restart`. If you downloaded with Mac Safari, run `mdloader_mac.dms --port PORT_NAME --download FILE_NAME --restart`. Replace "PORT_NAME" and "FILE_NAME" in the command as instructed above. +**Linux** - Run `./mdloader_linux --port PORT_NAME --download FILE_NAME --restart`. Replace "PORT_NAME" and "FILE_NAME" in the command as instructed above. +**Mac** - Run `./mdloader_mac --port PORT_NAME --download FILE_NAME --restart`. If you downloaded with Mac Safari, run `./mdloader_mac.dms --port PORT_NAME --download FILE_NAME --restart`. Replace "PORT_NAME" and "FILE_NAME" in the command as instructed above. 7. Enjoy (important) From 0492244fcfaa4be7de74d19c3ee4e42a484ab7df Mon Sep 17 00:00:00 2001 From: just-another-jxliu Date: Tue, 6 Aug 2019 14:22:00 -0700 Subject: [PATCH 02/21] Update README.md --- README.md | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 175779f..4f0aedf 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,38 @@ -### tl;dr +### User instructions 1. Follow the instructions here to download the executable for your operating system: https://github.com/Massdrop/mdloader/releases 2. Plug in your keyboard. -3. Press the reset button on your keyboard. +3. In your terminal, change to the directory where you downloaded the executable and applet-*.bin file(s). -4. In your terminal, change to the directory where you downloaded the executable and applet-*.bin file(s). - -5. **Windows** - Run `mdloader_windows.exe --first --download FILE_NAME --restart`. Replace "FILE_NAME" with the filename of your compiled firmware. +4. **Windows** - Run `mdloader_windows.exe --first --download FILE_NAME --restart`. Replace "FILE_NAME" with the filename of your compiled firmware. **Linux** - Run `mdloader_linux --first --download FILE_NAME --restart`. Replace "FILE_NAME" with the filename of your compiled firmware. -**Mac** - Run `mdloader_mac --first --download FILE_NAME --restart`. If you downloaded with Mac Safari, run `mdloader_mac.dms --first --download FILE_NAME --restart`. Replace "FILE_NAME" with the filename of your compiled firmware. +**Mac** - Run `mdloader_mac --first --download FILE_NAME --restart`. If you downloaded with Mac Safari, run `mdloader_mac.dms --first --download FILE_NAME --restart`. Replace "FILE_NAME" with the filename of your compiled firmware. + +5. You should see the message: +``` +Scanning for device for 60 seconds +..... +``` + +6. Within 60 seconds, press the reset button on your keyboard. For most keyboards running the default firmware, you can hold `Fn` + `b` for half a second and release to reset your keyboard (you will see the LEDs turn off). For CTRL keyboards in the first production run running original firmware or of the first method does not work for you, you will need to use a pin to press the reset button through the hole in the bottom of the keyboard. + +7. You should see a series of messages similar to: +``` +Device port: /dev/cu.usbmodem234431 (SAMD51J18A) + +Opening port '/dev/cu.usbmodem234431'... Success! +Found MCU: SAMD51J18A +Bootloader version: v2.18Sep 4 2018 16:48:28 +Applet file: applet-flash-samd51j18a.bin +Applet Version: 1 +Writing firmware... Complete! +Booting device... Success! +Closing port... Success! +``` -6. Enjoy (important) +8. Afterwards, you should see the keyboard's LEDs light up again (if your configuration has LEDs enabled) and the keyboard should respond to typing. Your keyboard is now running the new firmware you specified. ----- @@ -79,4 +99,4 @@ Test mode also allows viewing of binary data from a read instead of writing to a ## Troubleshooting -Linux: User may need to be added to group dialout to access programming port +**Linux**: User may need to be added to group dialout to access programming port From caa03ede129d53ba48cdb28e11c7a6e197d595e4 Mon Sep 17 00:00:00 2001 From: just-another-jxliu Date: Tue, 6 Aug 2019 14:26:09 -0700 Subject: [PATCH 03/21] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4f0aedf..84e3bd7 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ 3. In your terminal, change to the directory where you downloaded the executable and applet-*.bin file(s). 4. **Windows** - Run `mdloader_windows.exe --first --download FILE_NAME --restart`. Replace "FILE_NAME" with the filename of your compiled firmware. -**Linux** - Run `mdloader_linux --first --download FILE_NAME --restart`. Replace "FILE_NAME" with the filename of your compiled firmware. +**Linux** - Run `mdloader_linux --first --download FILE_NAME --restart`. Replace "FILE_NAME" with the filename of your compiled firmware. Depending on your user's permissions, you might have to add your user to the `dialout` group or use `sudo` on the command. **Mac** - Run `mdloader_mac --first --download FILE_NAME --restart`. If you downloaded with Mac Safari, run `mdloader_mac.dms --first --download FILE_NAME --restart`. Replace "FILE_NAME" with the filename of your compiled firmware. 5. You should see the message: From fcef3c437e1c283ea6009435399ebfb2004b4c31 Mon Sep 17 00:00:00 2001 From: Shailendra Govardhan Date: Thu, 16 Jul 2020 07:05:25 +0530 Subject: [PATCH 04/21] Added die revision id mask in chip identification Changes to be committed: modified: mdloader_common.c modified: mdloader_common.h Added die revision mask to chip id. Now mdloader shall work for all die revision ids as per chip datasheet. --- mdloader_common.c | 2 +- mdloader_common.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mdloader_common.c b/mdloader_common.c index bfe8b0d..e96b9e4 100644 --- a/mdloader_common.c +++ b/mdloader_common.c @@ -336,7 +336,7 @@ int test_mcu(char silent) continue; } - if (deviceid == mcu->cidr) + if ((deviceid & CIDR_DIE_REVISION_MASK) == mcu->cidr) { if (!silent && verbose) printf("Found supported device ID: %08X\n", deviceid); break; diff --git a/mdloader_common.h b/mdloader_common.h index 5d4ffa3..379c00d 100644 --- a/mdloader_common.h +++ b/mdloader_common.h @@ -22,7 +22,7 @@ #define PROGRAM_NAME "Massdrop Loader" #define VERSION_MAJOR 1 -#define VERSION_MINOR 3 //0-99 +#define VERSION_MINOR 4 //0-99 #ifdef _WIN32 #define INITGUID @@ -102,6 +102,8 @@ extern mailbox_t initparams; extern mailbox_t appletinfo; extern appinfo_t appinfo; +#define CIDR_DIE_REVISION_MASK 0xFFFFF0FF + typedef struct mcu_s { char name[20]; //MCU Name int cidr_addr; //Chip ID Address From 591b431ca26353ef10aa7c60c8a90dedcfeaf756 Mon Sep 17 00:00:00 2001 From: dropfelix <71285757+dropfelix@users.noreply.github.com> Date: Thu, 1 Oct 2020 00:33:12 -0700 Subject: [PATCH 05/21] Update mdloader_common.c Expanded MCU chip ID definitions. --- mdloader_common.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/mdloader_common.c b/mdloader_common.c index e96b9e4..7560534 100644 --- a/mdloader_common.c +++ b/mdloader_common.c @@ -35,7 +35,32 @@ appinfo_t appinfo; //Applet application information from end of applet bina mcu_t mcus[] = { //Name, Chip ID Chip ID, Program Memory, Data Memory, Program Addr, Data Addr // Address (FLASH_SIZE) (HSRAM_SIZE) (FLASH_ADDR) (HSRAM_ADDR) - { "SAMD51J18A", 0x41002018, 0x60060006, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAME54P19A", 0x41002018, 0x61840001, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAME54P20A", 0x41002018, 0x61840000, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAME54N19A", 0x41002018, 0x61840003, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAME54N20A", 0x41002018, 0x61840002, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAME53N20A", 0x41002018, 0x61830002, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAME53N19A", 0x41002018, 0x61830003, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAME53J18A", 0x41002018, 0x61830006, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAME53J19A", 0x41002018, 0x61830005, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAME53J20A", 0x41002018, 0x61830004, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAME51N19A", 0x41002018, 0x61810001, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAME51N20A", 0x41002018, 0x61810000, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAME51J18A", 0x41002018, 0x61810003, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAME51J19A", 0x41002018, 0x61810002, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAME51J20A", 0x41002018, 0x61810004, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAMD51P20A", 0x41002018, 0x60060000, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAMD51P19A", 0x41002018, 0x60060001, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAMD51N19A", 0x41002018, 0x60060003, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAMD51N20A", 0x41002018, 0x60060002, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAMD51J18A", 0x41002018, 0x60060006, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAMD51J19A", 0x41002018, 0x60060005, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAMD51J20A", 0x41002018, 0x60060004, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAMD51G18A", 0x41002018, 0x60060008, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAMD51G19A", 0x41002018, 0x60060007, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAME51G18A", 0x41002018, 0x61810306, 0x40000, 0x20000, 0x00000000, 0x20000000}, +{"SAME51G19A", 0x41002018, 0x61810305, 0x40000, 0x20000, 0x00000000, 0x20000000}, + }; mcu_t *mcu; //Pointer to mcus entry if found From f47c341accfaabc4562174fa85c2c3502029757b Mon Sep 17 00:00:00 2001 From: dropfelix <71285757+dropfelix@users.noreply.github.com> Date: Thu, 1 Oct 2020 12:09:25 -0700 Subject: [PATCH 06/21] Update mdloader_common.c Copyright notice refresh --- mdloader_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mdloader_common.c b/mdloader_common.c index 7560534..0a6b926 100644 --- a/mdloader_common.c +++ b/mdloader_common.c @@ -470,7 +470,7 @@ void display_version(void) //Display program copyright void display_copyright(void) { - printf(PROGRAM_NAME " Copyright (C) 2018 Massdrop Inc.\n"); + printf(PROGRAM_NAME " Copyright (C) 2018-2020 Massdrop Inc.\n"); printf("This program is Free Software and has ABSOLUTELY NO WARRANTY\n"); printf("\n"); } From c06abbf9623ef09d966428735f7f33ff65cb51da Mon Sep 17 00:00:00 2001 From: dropfelix <71285757+dropfelix@users.noreply.github.com> Date: Thu, 1 Oct 2020 12:10:33 -0700 Subject: [PATCH 07/21] Update mdloader_common.c --- mdloader_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mdloader_common.c b/mdloader_common.c index 0a6b926..2348268 100644 --- a/mdloader_common.c +++ b/mdloader_common.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 Massdrop Inc. + * Copyright (C) 2018-2020 Massdrop Inc. * * This file is part of Massdrop Loader. * From c14ec9561d0a02a996e519a78d41bdf1d9897f44 Mon Sep 17 00:00:00 2001 From: dropfelix <71285757+dropfelix@users.noreply.github.com> Date: Thu, 1 Oct 2020 17:10:12 -0700 Subject: [PATCH 08/21] Update mdloader_common.c New MCU definitions are breaking applet filename dependency. Putting in this quick fix until a more formal solution is implemented. --- mdloader_common.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mdloader_common.c b/mdloader_common.c index 2348268..6316f6f 100644 --- a/mdloader_common.c +++ b/mdloader_common.c @@ -756,7 +756,9 @@ int main(int argc, char *argv[]) char appletfname[128] = ""; strlower(mcu->name); - sprintf(appletfname, "applet-flash-%s.bin", mcu->name); + //sprintf(appletfname, "applet-flash-%s.bin", mcu->name); + sprintf(appletfname, "applet-flash-samd51j19a.bin", mcu->name); //temporary fix + printf("Applet file: %s\n", appletfname); fIn = fopen(appletfname, "rb"); From 04eafd940112c02b64d58a8435f7d88675b6f897 Mon Sep 17 00:00:00 2001 From: dropfelix <71285757+dropfelix@users.noreply.github.com> Date: Tue, 6 Oct 2020 14:54:02 -0700 Subject: [PATCH 09/21] Update mdloader_common.c Changing applet flash name to be chipset ID agnostic. --- mdloader_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mdloader_common.c b/mdloader_common.c index 6316f6f..4321de2 100644 --- a/mdloader_common.c +++ b/mdloader_common.c @@ -757,7 +757,7 @@ int main(int argc, char *argv[]) strlower(mcu->name); //sprintf(appletfname, "applet-flash-%s.bin", mcu->name); - sprintf(appletfname, "applet-flash-samd51j19a.bin", mcu->name); //temporary fix + sprintf(appletfname, "applet-mdflash.bin"); //make filename non-dependent upon mcu->name printf("Applet file: %s\n", appletfname); From e3ee607e120886dc2cda0f8dc951d6a298054d76 Mon Sep 17 00:00:00 2001 From: dropfelix <71285757+dropfelix@users.noreply.github.com> Date: Tue, 6 Oct 2020 14:54:52 -0700 Subject: [PATCH 10/21] Add files via upload --- applet-mdflash.bin | Bin 0 -> 1504 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 applet-mdflash.bin diff --git a/applet-mdflash.bin b/applet-mdflash.bin new file mode 100644 index 0000000000000000000000000000000000000000..2fd3e18f4e63332522f4329b048c61bb0450e17e GIT binary patch literal 1504 zcmdT@O>7%Q6rS;JVyAJ59hW9{DV}E2Vq(<^X#}l(S?{`Qk|nkHRa%7DEfU(Lf?6#| zL0q=^L69g?rCg#!oJ^rrIJAy}nuBGkHgNUYDN2#QDLg40D*9_j=VmMD?LCDj5_AQ<{`|f~8J#;Iba=1Fo97_&;U%u3o0$&5E=~Z` zYR=5G30q9+HQbp7Tvfkk+|V$ofE`{l`LklO*QcBN4!Y z)FJA)r{E(~=_}w_(Nubz`?-La`ej?FOJ6WuT2SF*GZigC=Mj^VY|J~-{^fx3tg>J_ zFGfUsEE?;Mu`x@P2YNsWDlhc%v8D7(b+Ghioxl3|<}rbdU5?)}9T!pHx-LnKvcxme z@gq-XLt<^q<9v4136~qxR7p zYHxOebHRtYj_cXpZz%>?N>_%h+Jlx`w4zF$b8@d}r3~Ogr zxBQt^FFPzG<1d?Zf-`CHz5)Mw1A1|MipgE*#p-9roRDLopZx=v3<=S7M0tu7^}f!A zqXl4yz&nooS0fwFCYZ&nHLw2a^_C QZ;Xo~(9hCv>mR;90C`Xbpa1{> literal 0 HcmV?d00001 From 8c4896330a7c29db5dbd2f99fa849c30d2d1197e Mon Sep 17 00:00:00 2001 From: dropfelix <71285757+dropfelix@users.noreply.github.com> Date: Tue, 6 Oct 2020 15:19:08 -0700 Subject: [PATCH 11/21] Delete applet-flash-samd51j18a.bin --- applet-flash-samd51j18a.bin | Bin 1504 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 applet-flash-samd51j18a.bin diff --git a/applet-flash-samd51j18a.bin b/applet-flash-samd51j18a.bin deleted file mode 100644 index 2fd3e18f4e63332522f4329b048c61bb0450e17e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1504 zcmdT@O>7%Q6rS;JVyAJ59hW9{DV}E2Vq(<^X#}l(S?{`Qk|nkHRa%7DEfU(Lf?6#| zL0q=^L69g?rCg#!oJ^rrIJAy}nuBGkHgNUYDN2#QDLg40D*9_j=VmMD?LCDj5_AQ<{`|f~8J#;Iba=1Fo97_&;U%u3o0$&5E=~Z` zYR=5G30q9+HQbp7Tvfkk+|V$ofE`{l`LklO*QcBN4!Y z)FJA)r{E(~=_}w_(Nubz`?-La`ej?FOJ6WuT2SF*GZigC=Mj^VY|J~-{^fx3tg>J_ zFGfUsEE?;Mu`x@P2YNsWDlhc%v8D7(b+Ghioxl3|<}rbdU5?)}9T!pHx-LnKvcxme z@gq-XLt<^q<9v4136~qxR7p zYHxOebHRtYj_cXpZz%>?N>_%h+Jlx`w4zF$b8@d}r3~Ogr zxBQt^FFPzG<1d?Zf-`CHz5)Mw1A1|MipgE*#p-9roRDLopZx=v3<=S7M0tu7^}f!A zqXl4yz&nooS0fwFCYZ&nHLw2a^_C QZ;Xo~(9hCv>mR;90C`Xbpa1{> From 9df711a7c2df36ad9efae34fb7302ecbfa49c0a6 Mon Sep 17 00:00:00 2001 From: dropfelix <71285757+dropfelix@users.noreply.github.com> Date: Tue, 6 Oct 2020 15:38:18 -0700 Subject: [PATCH 12/21] Update mdloader_common.h --- mdloader_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mdloader_common.h b/mdloader_common.h index 379c00d..0bd8575 100644 --- a/mdloader_common.h +++ b/mdloader_common.h @@ -22,7 +22,7 @@ #define PROGRAM_NAME "Massdrop Loader" #define VERSION_MAJOR 1 -#define VERSION_MINOR 4 //0-99 +#define VERSION_MINOR 5 //0-99 #ifdef _WIN32 #define INITGUID From 5c4895affadd93d5b6879abd3735f196034c332a Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Fri, 1 Oct 2021 01:01:38 +0100 Subject: [PATCH 13/21] Build via GitHub Actions (#60) * Initial CI workflow * bind more events --- .github/workflows/build.yml | 72 +++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..25880bf --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,72 @@ +name: CI + +on: + push: + branches: + - master + release: + types: + - published + pull_request: + +jobs: + build: + name: Build + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [macos-latest, windows-2016, ubuntu-latest] + + steps: + - uses: actions/checkout@v2 + + - name: Compile and Package + shell: bash + run: | + make clean all + 7z a ./build/mdloader-${RUNNER_OS}.zip ./build/mdloader* + + - uses: actions/upload-artifact@v2 + with: + name: ${{ matrix.os }} + path: build/mdloader*.zip + + publish_release: + name: Publish (Release) + runs-on: ubuntu-latest + + needs: [build] + + if: github.event.release.tag_name + + steps: + - uses: actions/download-artifact@v2 + + - uses: softprops/action-gh-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + name: ${{ github.event.release.name }} + files: | + ./*/mdloader* + + publish_beta: + name: Publish (Beta) + runs-on: ubuntu-latest + + needs: [build] + + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} + + steps: + - uses: actions/download-artifact@v2 + + - uses: marvinpinto/action-automatic-releases@latest + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + automatic_release_tag: "beta" + prerelease: true + title: "Latest Beta" + files: | + ./*/mdloader* From 81765349cdfc4c16959d834b523bfce5775452d1 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Tue, 5 Oct 2021 06:12:27 +0100 Subject: [PATCH 14/21] Bundle applet-mdflash.bin into executable (#61) * Bundle applet-mdflash.bin into exe * incbin * fix read logic * strip out alloc+copy logic --- Makefile | 2 - incbin/.travis.yml | 12 ++ incbin/README.md | 167 +++++++++++++++++ incbin/UNLICENSE | 24 +++ incbin/incbin.c | 291 +++++++++++++++++++++++++++++ incbin/incbin.h | 368 +++++++++++++++++++++++++++++++++++++ incbin/test/.gitignore | 1 + incbin/test/Makefile | 5 + incbin/test/asserts.c | 20 ++ incbin/test/loremipsum.txt | 1 + incbin/test/onebyte.txt | 1 + incbin/test/sevenbytes.txt | 1 + mdloader_common.c | 107 +++-------- 13 files changed, 919 insertions(+), 81 deletions(-) create mode 100644 incbin/.travis.yml create mode 100644 incbin/README.md create mode 100644 incbin/UNLICENSE create mode 100644 incbin/incbin.c create mode 100644 incbin/incbin.h create mode 100644 incbin/test/.gitignore create mode 100644 incbin/test/Makefile create mode 100644 incbin/test/asserts.c create mode 100644 incbin/test/loremipsum.txt create mode 100644 incbin/test/onebyte.txt create mode 100644 incbin/test/sevenbytes.txt diff --git a/Makefile b/Makefile index cbffc63..599496b 100644 --- a/Makefile +++ b/Makefile @@ -14,8 +14,6 @@ OBJFILES = $(patsubst %.c,%.o,$(SRCFILES)) OBJS = $(addprefix $(OBJDIR)/,$(OBJFILES)) all: $(OBJDIR)/$(OUTNAME) - $(info Copying applets to ${OBJDIR}...) - @cp applet-*.bin $(OBJDIR) $(info Done!) $(OBJDIR)/$(OUTNAME): $(OBJS) diff --git a/incbin/.travis.yml b/incbin/.travis.yml new file mode 100644 index 0000000..4337da6 --- /dev/null +++ b/incbin/.travis.yml @@ -0,0 +1,12 @@ +language: c + +os: +- linux +- osx + +compiler: +- gcc +- clang + +script: +- make -C test test diff --git a/incbin/README.md b/incbin/README.md new file mode 100644 index 0000000..cada41f --- /dev/null +++ b/incbin/README.md @@ -0,0 +1,167 @@ +# incbin + +Include binary files in your C/C++ applications with ease + +## Example + +``` c + #include "incbin.h" + + INCBIN(Icon, "icon.png"); + + // This translation unit now has three symbols + // const unsigned char gIconData[]; + // const unsigned char *const gIconEnd; // a marker to the end, take the address to get the ending pointer + // const unsigned int gIconSize; + + // Reference in other translation units like this + INCBIN_EXTERN(Icon); + + // This translation unit now has three extern symbols + // Use `extern "C"` in case of writing C++ code + // extern const unsigned char gIconData[]; + // extern const unsigned char *const gIconEnd; // a marker to the end, take the address to get the ending pointer + // extern const unsigned int gIconSize; +``` + +## Portability + +Known to work on the following compilers + +* GCC +* Clang +* PathScale +* Intel +* Solaris & Sun Studio +* Green Hills +* SNC (ProDG) +* Diab C++ (WindRiver) +* XCode +* ArmCC +* RealView +* ImageCraft +* Stratus VOS C +* TinyCC +* cparser & libfirm +* LCC +* MSVC _See MSVC below_ + +If your compiler is not listed, as long as it supports GCC inline assembler, this +should work. + +## MISRA +INCBIN can be used in MISRA C setting. However it should be independently checked +due to its use of inline assembly to achieve what it does. Independent verification +of the header has been done several times based on commit: 7e327a28ba5467c4202ec37874beca7084e4b08c + +## Alignment + +The data included by this tool will be aligned on the architectures word boundary +unless some variant of SIMD is detected, then it's aligned on a byte boundary that +respects SIMD convention just incase your binary data may be used in vectorized +code. The table of the alignments for SIMD this header recognizes is as follows: + +| SIMD | Alignment | +|-----------------------------------------|-----------| +| SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2 | 16 | +| Neon | 16 | +| AVX, AVX2 | 32 | +| AVX512 | 64 | + +## Prefix +By default, `incbin.h` emits symbols with a `g` prefix. This can be adjusted by +defining `INCBIN_PREFIX` before including `incbin.h` with a desired prefix. For +instance + +``` c + #define INCBIN_PREFIX g_ + #include "incbin.h" + INCBIN(test, "test.txt"); + + // This translation unit now has three symbols + // const unsigned char g_testData[]; + // const unsigned char *const g_testEnd; + // const unsigned int g_testSize; +``` + +You can also choose to have no prefix by defining the prefix with nothing, for example: + +``` c + #define INCBIN_PREFIX + #include "incbin.h" + INCBIN(test, "test.txt"); + + // This translation unit now has three symbols + // const unsigned char testData[]; + // const unsigned char *const testEnd; + // const unsigned int testSize; +``` + +## Style +By default, `incbin.h` emits symbols with `CamelCase` style. This can be adjusted +by defining `INCBIN_STYLE` before including `incbin.h` to change the style. There +are two possible styles to choose from + +* INCBIN_STYLE_CAMEL (CamelCase) +* INCBIN_STYLE_SNAKE (snake_case) + +For instance: + +``` c + #define INCBIN_STYLE INCBIN_STYLE_SNAKE + #include "incbin.h" + INCBIN(test, "test.txt"); + + // This translation unit now has three symbols + // const unsigned char gtest_data[]; + // const unsigned char *const gtest_end; + // const unsigned int gtest_size; +``` + +Combining both the style and prefix allows for you to adjust `incbin.h` to suite +your existing style and practices. + +## Overriding Linker Output section +By default, `incbin.h` emits into the read-only linker output section used on +the detected platform. If you need to override this for whatever reason, you +can manually specify the linker output section. + +For example, to emit data into program memory for +[esp8266/Arduino](github.com/esp8266/Arduino): + +``` c +#define INCBIN_OUTPUT_SECTION ".irom.text" +#include "incbin.h" +INCBIN(Foo, "foo.txt"); +// Data is emitted into program memory that never gets copied to RAM +``` + +## Explanation + +`INCBIN` is a macro which uses the inline assembler provided by almost all +compilers to include binary files. It achieves this by utilizing the `.incbin` +directive of the inline assembler. It then uses the assembler to calculate the +size of the included binary and exports two global symbols that can be externally +referenced in other translation units which contain the data and size of the +included binary data respectively. + +## MSVC + +Supporting MSVC is slightly harder as MSVC lacks an inline assembler which can +include data. To support this we ship a tool which can process source files +containing `INCBIN` macro usage and generate an external source file containing +the data of all of them combined. This file is named `data.c` by default. +Just include it into your build and use the `incbin.h` to reference data as +needed. It's suggested you integrate this tool as part of your projects's +pre-build events so that this can be automated. A more comprehensive list of +options for this tool can be viewed by invoking the tool with `-help` + +If you're using a custom prefix, be sure to specify the prefix on the command +line with `-p ` so that everything matches up; similarly, if you're +using a custom style, be sure to specify the style on the command line with +`-S