From 38ec34815fd90f5172b9f66a5111276e3e7b4e85 Mon Sep 17 00:00:00 2001 From: Philipp Seiler Date: Fri, 14 May 2021 13:36:29 +0200 Subject: [PATCH 1/4] Reworked readme * some grammar and typo fixes * using markdown instead of pseudo-formatting * updated a lot of informations and generalized them * properly explain every step needed to build your own payload --- README.md | 119 +++++++++++++++++++++++++----------------------------- 1 file changed, 54 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index 4f48b9e..bf8a953 100644 --- a/README.md +++ b/README.md @@ -1,94 +1,83 @@ # SwitchME - -******** This is NOT an Piracy device to circumvent anti-piracy mesures ******** -******** The SiwtcME comes blank and YOU choose what to install on it ******** - All the SwitchME does is make it more convient to launch a payload -So you do not have to connect up a usb cable to your computer and launch your payload - There is no way to pirate anything with the SwithME - ******** Again the SwitchME is not a circumvention device! ******** -_________________________________________________________________________________________ - -*** If you have Auto RCM enabled DISABLE it until you flash the SwitchME for the first time (Use CTCaer 4.1 *** - -*** If you flash any other payload other than CTCaer 4.1 after enabling Auto RCM you will not have a way to flash -the SwitchME unless you can boot into Horizon because there is no usb data comms while in RCM (for now) *** - -*** If you get stuck because of Auto RCM and only booting to say BISkeydump, the way around this is to disconnect either D+ or D- Boot into Horizon, reconnect the line and than flash the SwitchME bootloader *** - -*** Again this is only if you have Auto RCM enabled *** - -*** We highly suggest you only use CTCaer 4.1 and put whatever payload you want to boot in the payloads dir from the SDCard files *** - -*** We have included some for you *** - -After Wiring in the SwitchME you can access the bootloader by conecting a usb-c cable directly to the switch. -Make sure you have a compliant ucb-c cable first though! -A compliant cable will have a 56k Ohm resistor (check where you perchased your cable from) -Really shouldnt be an issue if you are just flashing the SwitchMe directly from your computer, but be on the safe side as plenty of people have burned up their charge IC using 3rd party docks and cheap usb-c cables. - +## Preamble ## +**This is NOT an Piracy device to circumvent anti-piracy mesures** +**The SwitchME comes blank and YOU choose what to install on it** + +The SwitchMe is intended to have a more convient way to launch a payload on four device. +So you do not have to connect a usb cable to your computer and launch your payload. +There is no way to pirate anything with the SwithME. +**Again the SwitchME is not a circumvention device!** + +## Important informations ## +* If you have Auto RCM enabled DISABLE it until you flash the SwitchME for the first time (Use HekateCTCaer) +* If you flash any other payload other than Hekate CTCaer after enabling Auto RCM you will not have a way to flash +the SwitchME unless you can boot into Horizon because there is no usb data comms while in RCM (for now) +* If you get stuck because of Auto RCM and only booting to say BISkeydump, the way around this is to disconnect either D+ or D- Boot into Horizon, reconnect the line and than flash the SwitchME bootloader +* Again this is only if you have Auto RCM enabled +* We highly suggest you only use Hekate CTCaer and put whatever payload you want to boot in the payloads directory of hekate. +* After Wiring in the SwitchME you can access the bootloader by conecting a USB-C cable directly to the switch. Make sure you have a compliant USB-C cable first though! +* A compliant cable will have a 56k Ohm resistor (check where you perchased your cable from). Really shouldnt be an issue if you are just flashing the SwitchMe directly from your computer, but be on the safe side as plenty of people have burned up their charge IC using 3rd party docks and cheap usb-c cables. + +## Preflashing from a Computer ## If you want to preflash the SwitchME connect a usb cable directly to the the board (D+ green) (D- white) (5v red) (gnd black) On first connect to your computer it will already be in bootloader mode ready to be flashed. After you have flashed the device for the very first time you will need to double press the button to go into bootloader mode again if you want to reflash the device, or if you connect the reset line you can do the same. - -_________________________________________________________________________________________ +Also don't get confused. As soon as you successfully copied the *\*.uf2* file onto your SwitchMe device it will stop serving the disk and you don't have a change to successfully eject/umount it. It's the usual behaviour and everything should work as expected. For Pre-Compiled payloads check UF2_SwitchME_Payloads -_________________________________________________________________________________________ - +## Compile payloads on your own ## To compile payloads for SwitchME you will need to install the Arduino IDE https://www.arduino.cc/en/Main/Software +### Install the board manager for the SwitchME -~ Next you must install the board manager for SwitchME ~ - -Open Arduino IDE > Preferances > Additional Boards Manager URLs > Add The URL Below -https://raw.githubusercontent.com/Aboshi/SwitchME/master/package_switchme_index.json +1. Open Arduino IDE > Preferances > Additional Boards Manager URLs > Add The URL Below ```https://raw.githubusercontent.com/Aboshi/SwitchME/master/package_switchme_index.json``` +1. Next go to *Tools > Board > Boards Manager > Type SAMD > Select Arduino SAMD Boards* and Install version 1.6.21 +1. Next search for *rebug* and install it +1. You can now select *SwitchME m0* in the board programmer -Next go to Tools > Board > Boards Manager > Type SAMD > Select Arduino SAMD Boards and Install version 1.6.21 +### Compiling the payload ### +To compile different payoads you must first convert your payload.bin to hex +The easiest way is to use binConverter.py (you can find it in *Payload2UF2/main*). +Just use the following command line ```python2 binConverter.py ```. You need python2 for it. +A ```.h``` should be generated. -Next search for rebug and install +Next open *SwitchME.ino* in *Payload2UF2/main* in the arduion application. +Change *ctcaer\_4.0\_hekate.h* in the arduino sketchbook/project to whatever you named you payload. Make sure ```.h``` is in the same directory as the *SwitchMe.ino* file. +If you want to upload directly to your SwitchME just click on upload (your SwitchME is ready for use). +If you want to compile to make a .bin for converting to UF2 select *Sketch > Export compiled Binary*. -You can now select SwitchME m0 in the board programmer +The final step is to convert the compiled *\*.bin* into the UF2 format. You can do this with *uf2conv.py* also located in *Payload2UF2/main*. +In this case you need python3. Here is the command line examle. ```python3 uf2conv.py main.ino.rebug_m0.bin```. Make sure the filename matches the generated *\*.bin*. -_________________________________________________________________________________________ +We try to keep all important payloads up to date. So in most cases you don't need to create your own *\*.uf2* files. -To compile different payoads you must first convert your payload.bin to hex -The easiest way is to use binConverter.py (you can find it under releases) -Open SwitchME.ino -Change ctcaer_4.0_hekate.h to whatever you named you payload -If you want to upload directly to your SwitchME just click on upload (your SwitchME is ready for use) -If you want to compile to make a .bin for converting to UF2 select Sketch > Export compiled Binary - -You can find all the tools you need in the releases section of this git as well as pre compiled payloads in UF2 format -We will provide plenty of payloads in UF2 format and keep them updated with new releases. - -_________________________________________________________________________________________ - -Wiring Diagrams: -Check wiring dir -4_wire_always_on (Do not use this method any longer) Leaving it in the git for reference only -4_wire_on_at_powerup (when used with auto rcm you will get instant bootup to whatever you flahed the SwitchME with) We highly suggest CTCaer payloads! -More diagrams will be added soon with auto rcm line strapping, emmc cutoff (another auto rcm) and many others. +## Wiring Diagrams ## +Check the directory *wiring/4\_wire\_on\_at\_powerup* (when used with auto rcm you will get instant bootup to whatever you flahed the SwitchME with) We highly suggest CTCaer payloads! +More diagrams could be added soon with auto rcm line strapping, emmc cutoff (another auto rcm) and many others. For now you can check this thread for other wiring methods that suit your needs: https://gbatemp.net/threads/internal-modchip-samd21-trinket-m0-gemma-m0-itsybitsy-m0-express-guide-files-support.508068/ Huge thanks to @mattytrog for adding the SwitchMe to the current list! -_________________________________________________________________________________________ -Custom Firmware and Emulators: +## Generic Informations +The SwitchME also has 3.5mb of storage space. You can access it by putting the SwitchME into bootloader mode (double press the button). + +## Credits ## +### Custom Firmware and Emulators ### -Roll your own: +Create your own customized CFW and choose all included compontents: https://www.sdsetup.com/ -^^ -Thanks to @noahc3 & @tomGER +Thanks to @noahc3, @tomGER and all other contributers Or Download an AIO package: -https://github.com/tumGER/SDFilesSwitch/releases -^^ Tkanks to @tomGER for keeping things up to date -_________________________________________________________________________________________ +https://github.com/Team-Neptune/DeepSea/releases +Thanks to @Team-Neptune for keeping things up to date -The SwitchME also has 3.5mb of storage space. You can access it by putting the SwitchME into bootloader mode (double press the button) +Also have a look at this homebrew to automatically update all components (except the payload for the SwitchMe) automatically directly from the Switch. +https://github.com/HamletDuFromage/aio-switch-updater/releases +### Switch Scene Greets to all the devs in the Switch scene without them none of this would be possible: @SciresM @hexkyz @naewhert @oct0xor @ktemkin @CTCaer @rajkosto @Reisyukaku @atlas44 @noemu @st4rk and countless others From 24976f7237b9adf33de18d7a13fff59d483be777 Mon Sep 17 00:00:00 2001 From: Philipp Seiler Date: Fri, 14 May 2021 14:31:19 +0200 Subject: [PATCH 2/4] added a replacement to convert arduino bins into uf2 format * also add some more credits to the readme --- Payload2UF2/main/uf2conv.py | 300 +++++++++++++++++++++++++++++++++++ Payload2UF2/main/uf2conv_mac | Bin 8976 -> 0 bytes README.md | 6 +- 3 files changed, 305 insertions(+), 1 deletion(-) create mode 100755 Payload2UF2/main/uf2conv.py delete mode 100755 Payload2UF2/main/uf2conv_mac diff --git a/Payload2UF2/main/uf2conv.py b/Payload2UF2/main/uf2conv.py new file mode 100755 index 0000000..d12c610 --- /dev/null +++ b/Payload2UF2/main/uf2conv.py @@ -0,0 +1,300 @@ +#!/usr/bin/env python3 +#command python uf2conv.py -o end_file_name.uf2 start_file_name.bin +import sys +import struct +import subprocess +import re +import os +import os.path +import argparse + + +UF2_MAGIC_START0 = 0x0A324655 # "UF2\n" +UF2_MAGIC_START1 = 0x9E5D5157 # Randomly selected +UF2_MAGIC_END = 0x0AB16F30 # Ditto + +families = { + 'SAMD21': 0x68ed2b88, + 'SAMD51': 0x55114460, + 'NRF52': 0x1b57745f, + 'STM32F1': 0x5ee21072, + 'STM32F4': 0x57755a57, + 'ATMEGA32': 0x16573617, +} + +INFO_FILE = "/INFO_UF2.TXT" + +appstartaddr = 0x2000 +familyid = 0x0 + + +def is_uf2(buf): + w = struct.unpack(" 476: + assert False, "Invalid UF2 data size at " + ptr + newaddr = hd[3] + if curraddr == None: + appstartaddr = newaddr + curraddr = newaddr + padding = newaddr - curraddr + if padding < 0: + assert False, "Block out of order at " + ptr + if padding > 10*1024*1024: + assert False, "More than 10M of padding needed at " + ptr + if padding % 4 != 0: + assert False, "Non-word padding size at " + ptr + while padding > 0: + padding -= 4 + outp += b"\x00\x00\x00\x00" + outp += block[32 : 32 + datalen] + curraddr = newaddr + datalen + return outp + +def convert_to_carray(file_content): + outp = "const unsigned char bindata[] __attribute__((aligned(16))) = {" + for i in range(len(file_content)): + if i % 16 == 0: + outp += "\n" + outp += "0x%02x, " % ord(file_content[i]) + outp += "\n};\n" + return outp + +def convert_to_uf2(file_content): + global familyid + datapadding = b"" + while len(datapadding) < 512 - 256 - 32 - 4: + datapadding += b"\x00\x00\x00\x00" + numblocks = (len(file_content) + 255) // 256 + outp = b"" + for blockno in range(numblocks): + ptr = 256 * blockno + chunk = file_content[ptr:ptr + 256] + flags = 0x0 + if familyid: + flags |= 0x2000 + hd = struct.pack(b"= 3 and words[1] == "2" and words[2] == "FAT": + drives.append(words[0]) + else: + rootpath = "/media" + if sys.platform == "darwin": + rootpath = "/Volumes" + elif sys.platform == "linux": + tmp = rootpath + "/" + os.environ["USER"] + if os.path.isdir(tmp): + rootpath = tmp + for d in os.listdir(rootpath): + drives.append(os.path.join(rootpath, d)) + + + def has_info(d): + try: + return os.path.isfile(d + INFO_FILE) + except: + return False + + return list(filter(has_info, drives)) + + +def board_id(path): + with open(path + INFO_FILE, mode='r') as file: + file_content = file.read() + return re.search("Board-ID: ([^\r\n]*)", file_content).group(1) + + +def list_drives(): + for d in get_drives(): + print(d, board_id(d)) + + +def write_file(name, buf): + with open(name, "wb") as f: + f.write(buf) + print("Wrote %d bytes to %s." % (len(buf), name)) + + +def main(): + global appstartaddr, familyid + def error(msg): + print(msg) + sys.exit(1) + parser = argparse.ArgumentParser(description='Convert to UF2 or flash directly.') + parser.add_argument('input', metavar='INPUT', type=str, nargs='?', + help='input file (HEX, BIN or UF2)') + parser.add_argument('-b' , '--base', dest='base', type=str, + default="0x2000", + help='set base address of application for BIN format (default: 0x2000)') + parser.add_argument('-o' , '--output', metavar="FILE", dest='output', type=str, + help='write output to named file; defaults to "flash.uf2" or "flash.bin" where sensible') + parser.add_argument('-d' , '--device', dest="device_path", + help='select a device path to flash') + parser.add_argument('-l' , '--list', action='store_true', + help='list connected devices') + parser.add_argument('-c' , '--convert', action='store_true', + help='do not flash, just convert') + parser.add_argument('-D' , '--deploy', action='store_true', + help='just flash, do not convert') + parser.add_argument('-f' , '--family', dest='family', type=str, + default="0x0", + help='specify familyID - number or name (default: 0x0)') + parser.add_argument('-C' , '--carray', action='store_true', + help='convert binary file to a C array, not UF2') + args = parser.parse_args() + appstartaddr = int(args.base, 0) + + if args.family.upper() in families: + familyid = families[args.family.upper()] + else: + try: + familyid = int(args.family, 0) + except ValueError: + error("Family ID needs to be a number or one of: " + ", ".join(families.keys())) + + if args.list: + list_drives() + else: + if not args.input: + error("Need input file") + with open(args.input, mode='rb') as f: + inpbuf = f.read() + from_uf2 = is_uf2(inpbuf) + ext = "uf2" + if args.deploy: + outbuf = inpbuf + elif from_uf2: + outbuf = convert_from_uf2(inpbuf) + ext = "bin" + elif is_hex(inpbuf): + outbuf = convert_from_hex_to_uf2(inpbuf.decode("utf-8")) + elif args.carray: + outbuf = convert_to_carray(inpbuf) + ext = "h" + else: + outbuf = convert_to_uf2(inpbuf) + print("Converting to %s, output size: %d, start address: 0x%x" % + (ext, len(outbuf), appstartaddr)) + if args.convert or ext != "uf2": + drives = [] + if args.output == None: + args.output = "flash." + ext + else: + drives = get_drives() + + if args.output: + write_file(args.output, outbuf) + else: + if len(drives) == 0: + error("No drive to deploy.") + for d in drives: + print("Flashing %s (%s)" % (d, board_id(d))) + write_file(d + "/NEW.UF2", outbuf) + + +if __name__ == "__main__": + main() diff --git a/Payload2UF2/main/uf2conv_mac b/Payload2UF2/main/uf2conv_mac deleted file mode 100755 index acc068638987746be8fd9aaf3599d8d4ab258c1a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8976 zcmeHNU2GIp6ut{ZmkPFMf*K$hh$X186cnrklD27ekOm5+p#jO*ZKv#}+ude=Y)g=| zmN86*H8nv(Vq$nw;u9K3K&hcXDEfl(VASxy1Db832{8m4qSWuZb7#9dCBzrr<|Ox? z^PO|e{%bwXj}#&l$(hhb#Qfea;={PBjKz+zyk!h%S|Wv=M< zWn!op8b&&kjid`If4tA0bmMJQ9v=1vgjKx9l){Z?M9p}gnS#zA@0N<^ErFPIFVL*~ zI@6g{EU`~H_~W%>!?@mdWhXAClGrd9MmEtOOLQ5rM0Zl+()~E4;&IPO#Qqqr#qGJT zwQ^q@>vz@{S+IZ1%iBjk=e}}_)HWfneMzq-9A+2~j#oG)5WKPUXZ_15C^C#h+(-}h zMv`%(FO!-TuTtgb#Uu8|Ti^u)H;j14!{TWwUW*z-TpW+<#a0(+=DBL#ymd=c<7V%f z(0p|RCRM6nj3etRwL+}G5wD@F2@wVhgV%w3q-#PP2e=7NKkntT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$N7 zUbXUmmG{8>mV|H3-d%Rx{~f2{27UG(7;+CvPM$nBB^viEN|k#Iz4N3_QsE4#)1%If TIx*f^@lJ_%K4zU{EDH1=`!Ewz diff --git a/README.md b/README.md index bf8a953..d7bf5c5 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,11 @@ Thanks to @Team-Neptune for keeping things up to date Also have a look at this homebrew to automatically update all components (except the payload for the SwitchMe) automatically directly from the Switch. https://github.com/HamletDuFromage/aio-switch-updater/releases -### Switch Scene +### Switch Scene ### Greets to all the devs in the Switch scene without them none of this would be possible: @SciresM @hexkyz @naewhert @oct0xor @ktemkin @CTCaer @rajkosto @Reisyukaku @atlas44 @noemu @st4rk and countless others + +### tools used ### +* [Euclala](https://github.com/euclala/) for the *binConverter.py* +* [Microsoft](https://github.com/microsoft/) for the *uf2conv.py* From 1d3a340d8976a9d5c3c31c9c3c6ad580b3ca8f45 Mon Sep 17 00:00:00 2001 From: Philipp Seiler Date: Sun, 18 Jul 2021 22:41:26 +0200 Subject: [PATCH 3/4] fixed command line parameter missing. Also fixed a typo and added more informations regarding the generated uf filename --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d7bf5c5..06dfc73 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ The easiest way is to use binConverter.py (you can find it in *Payload2UF2/main* Just use the following command line ```python2 binConverter.py ```. You need python2 for it. A ```.h``` should be generated. -Next open *SwitchME.ino* in *Payload2UF2/main* in the arduion application. +Next open *SwitchME.ino* in *Payload2UF2/main* in the arduino application. Change *ctcaer\_4.0\_hekate.h* in the arduino sketchbook/project to whatever you named you payload. Make sure ```.h``` is in the same directory as the *SwitchMe.ino* file. If you want to upload directly to your SwitchME just click on upload (your SwitchME is ready for use). If you want to compile to make a .bin for converting to UF2 select *Sketch > Export compiled Binary*. The final step is to convert the compiled *\*.bin* into the UF2 format. You can do this with *uf2conv.py* also located in *Payload2UF2/main*. -In this case you need python3. Here is the command line examle. ```python3 uf2conv.py main.ino.rebug_m0.bin```. Make sure the filename matches the generated *\*.bin*. +In this case you need python3. Here is the command line examle. ```python3 uf2conv.py -c main.ino.rebug_m0.bin```. Make sure the filename matches the generated *\*.bin*. A file named *flash.uf2* should be generated. We try to keep all important payloads up to date. So in most cases you don't need to create your own *\*.uf2* files. From 7712528253eb86c0274caa6948cb07b76ab50e4a Mon Sep 17 00:00:00 2001 From: Philipp Seiler Date: Thu, 5 Aug 2021 04:51:57 +0200 Subject: [PATCH 4/4] fixed a tiny little typo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 06dfc73..393c9a8 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,13 @@ **This is NOT an Piracy device to circumvent anti-piracy mesures** **The SwitchME comes blank and YOU choose what to install on it** -The SwitchMe is intended to have a more convient way to launch a payload on four device. +The SwitchMe is intended to have a more convient way to launch a payload on your device. So you do not have to connect a usb cable to your computer and launch your payload. There is no way to pirate anything with the SwithME. **Again the SwitchME is not a circumvention device!** ## Important informations ## -* If you have Auto RCM enabled DISABLE it until you flash the SwitchME for the first time (Use HekateCTCaer) +* If you have Auto RCM enabled DISABLE, it until you flash the SwitchME for the first time (Use HekateCTCaer) * If you flash any other payload other than Hekate CTCaer after enabling Auto RCM you will not have a way to flash the SwitchME unless you can boot into Horizon because there is no usb data comms while in RCM (for now) * If you get stuck because of Auto RCM and only booting to say BISkeydump, the way around this is to disconnect either D+ or D- Boot into Horizon, reconnect the line and than flash the SwitchME bootloader