Hacking Question UF2 files - what are they? 512Kb R4s dongle?

Fehniix

Member
OP
Newcomer
Joined
Aug 22, 2019
Messages
18
Trophies
0
Age
26
XP
73
Country
Australia
Hello everyone.

I would like to know what *.UF2 files are to be eventually able to compile my own to run the latest version of Atmosphere, Reinx etc.
I have updated the Nintendo Switch to the latest firmware, 8.1.0, and the R4s dongle stopped launching Atmosphere; I have started all over again.

The R4s dongle seems to accept only 512Kb UF2 files content of which seem completely different than common payload binaries.
I suspected the R4s checked for the "CURRENT.UF2" file to be exactly 512Kb to be able to upload it, and thus check only its size; I would expect that file, then, to contain the payload binary (Atmo, Reinx etc.) and a series of 0's making up to 512Kb but that's apparently not the case.

How could I go around getting Atmosphere or anything else back running on the dongle, considering the Switch is updated to 8.1.0?

Thank you!
 

Fehniix

Member
OP
Newcomer
Joined
Aug 22, 2019
Messages
18
Trophies
0
Age
26
XP
73
Country
Australia
What I have already tried:

  • Downloading the latest version of Hekate
  • Setting up the Arduino IDE with all the necessary Adafruit Trinket M0 board (which I suppose the R4s runs on) libraries
  • Converted the Hekate payload .bin file to .h using the Sam-Fuseé binConverter.py script
  • Compiled and exported Sam-Fuseé launcher sketch with the Arduino IDE (importing the new .h file from the payload)
  • Converted the sketch to UF2 with default base address (0x2000) with this ([Github]/lancaster-university/codal/blob/master/utils/uf2conv.py) Python script

The output file seems to be 289Kb which the R4s dongle won't accept. Is there anything I'm missing?

Reference: [GBATemp]/threads/how-to-compile-bin-payloads-to-uf2.518516/
 
Last edited by Fehniix,

The Real Jdbye

*is birb*
Member
Joined
Mar 17, 2010
Messages
22,211
Trophies
4
Location
Space
XP
11,723
Country
Norway
What I have already tried:

  • Downloading the latest version of Hekate
  • Setting up the Arduino IDE with all the necessary Adafruit Trinket M0 board (which I suppose the R4s runs on) libraries
  • Converted the Hekate payload .bin file to .h using the Sam-Fuseé binConverter.py script
  • Compiled and exported Sam-Fuseé launcher sketch with the Arduino IDE (importing the new .h file from the payload)
  • Converted the sketch to UF2 with default base address (0x2000) with this ([Github]/lancaster-university/codal/blob/master/utils/uf2conv.py) Python script

The output file seems to be 289Kb which the R4s dongle won't accept. Is there anything I'm missing?

Reference: [GBATemp]/threads/how-to-compile-bin-payloads-to-uf2.518516/
No, I don't think it uses a Trinket M0, they are using something custom, but it may be using the same chip. Trinkets are only used for homebrew (not that kind of homebrew) solutions.

Edit: https://learn.adafruit.com/adafruit...t-python-circuitpython/uf2-bootloader-details
Looks like Microsoft MakeCode might be what you need.
UF2 is a format developed by Microsoft for firmware flashing.
 
Last edited by The Real Jdbye,
  • Like
Reactions: Fehniix

Fehniix

Member
OP
Newcomer
Joined
Aug 22, 2019
Messages
18
Trophies
0
Age
26
XP
73
Country
Australia
No, I don't think it uses a Trinket M0, they are using something custom, but it may be using the same chip. Trinkets are only used for homebrew (not that kind of homebrew) solutions.

Edit: adafruit-feather-m0-express-designed-for-circuit-python-circuitpython/uf2-bootloader-details
Looks like Microsoft MakeCode might be what you need.
UF2 is a format developed by Microsoft for firmware flashing.
This is great news, I looked into it.

Still seems very odd that the Python script would output a file with arbitrary size and not what the fixed, 512Kb, size should be.
 

The Real Jdbye

*is birb*
Member
Joined
Mar 17, 2010
Messages
22,211
Trophies
4
Location
Space
XP
11,723
Country
Norway
This is great news, I looked into it.

Still seems very odd that the Python script would output a file with arbitrary size and not what the fixed, 512Kb, size should be.
That's the magic of UF2. When you copy an UF2 file to the drive, it's actually being flashed as firmware to the microcontroller. The UF2 file itself tells it which address to flash the file to. It will be using some constant size simply because they have set apart a certain amount of space for each payload so the firmware area of the file is padded out to fill that space. Flashing a smaller file probably wouldn't do any harm though as the data at the end probably isn't necessary.
For that reason, you need to make sure that the flash address and other info matches what is in the existing UF2 file(s) so they get flashed in the correct way.
It would be much easier if the drive acted as more conventional storage so you could just copy payloads across directly, like how it works with the RCMLoader One dongle. Which costs about $10 just FYI. I would gladly pay that to not have to deal with UF2 files myself. :P
 
Last edited by The Real Jdbye,
  • Like
Reactions: Fehniix

TariqSoftDev

~Zexceil
Member
Joined
Sep 18, 2013
Messages
716
Trophies
0
Location
London
XP
984
Country
UF2 is a bootloader found here: https://github.com/microsoft/uf2-nrf5
They're compiled for custom boards using the ARM M0/M4 chips, they're all specific and custom configurable.
UF2 Files are used to reprogram the UF2 bootloader with another program, you can't recreate it yourself unless you open it up, check the MCU and map out the hardware it uses.
 

tivanh

Well-Known Member
Member
Joined
Sep 14, 2009
Messages
148
Trophies
0
XP
285
Country
Hello everyone.

I would like to know what *.UF2 files are to be eventually able to compile my own to run the latest version of Atmosphere, Reinx etc.
I have updated the Nintendo Switch to the latest firmware, 8.1.0, and the R4s dongle stopped launching Atmosphere; I have started all over again.

The R4s dongle seems to accept only 512Kb UF2 files content of which seem completely different than common payload binaries.
I suspected the R4s checked for the "CURRENT.UF2" file to be exactly 512Kb to be able to upload it, and thus check only its size; I would expect that file, then, to contain the payload binary (Atmo, Reinx etc.) and a series of 0's making up to 512Kb but that's apparently not the case.

How could I go around getting Atmosphere or anything else back running on the dongle, considering the Switch is updated to 8.1.0?

Thank you!


When Argon NX is injected, it automatically launches the payload.bin loacted at argon directory on your SD Card root.

If payload.bin is not present or VOLUME DOWN button is pressed on payload injection, Argon NX will list all payloads located at argon/payloads, and you will be able to select one of them to launch it.

Have you updated the payload in the argon directory on the sd?
 
Last edited by tivanh,
  • Like
Reactions: Fehniix

Fehniix

Member
OP
Newcomer
Joined
Aug 22, 2019
Messages
18
Trophies
0
Age
26
XP
73
Country
Australia
When Argon NX is injected, it automatically launches the payload.bin loacted at argon directory on your SD Card root.

If payload.bin is not present or VOLUME DOWN button is pressed on payload injection, Argon NX will list all payloads located at argon/payloads, and you will be able to select one of them to launch it.

Have you updated the payload in the argon directory on the sd?
So it doesn't really matter what firmware the Switch runs on, a payload will always be able to be injected because ArgonNX functions similarly to Hekate? It's a payload injector the dongle runs natively on?

I have replaced the bootloader with one I have found here in the forums, compiled by tom[...] if I remember correctly, which I believe either launches Atmosphere found on the SD card or has Atmosphere 0.9.3 embedded in it which gets launched.

UF2 is a bootloader found here: [Github]/microsoft/uf2-nrf5
They're compiled for custom boards using the ARM M0/M4 chips, they're all specific and custom configurable.
UF2 Files are used to reprogram the UF2 bootloader with another program, you can't recreate it yourself unless you open it up, check the MCU and map out the hardware it uses.
Why would it be necessary to additionally map the hardware it uses?

That's the magic of UF2. When you copy an UF2 file to the drive, it's actually being flashed as firmware to the microcontroller. The UF2 file itself tells it which address to flash the file to. It will be using some constant size simply because they have set apart a certain amount of space for each payload so the firmware area of the file is padded out to fill that space. Flashing a smaller file probably wouldn't do any harm though as the data at the end probably isn't necessary.
For that reason, you need to make sure that the flash address and other info matches what is in the existing UF2 file(s) so they get flashed in the correct way.
It would be much easier if the drive acted as more conventional storage so you could just copy payloads across directly, like how it works with the RCMLoader One dongle. Which costs about $10 just FYI. I would gladly pay that to not have to deal with UF2 files myself. :P
Thank you! For curiousity's sake, would you ever attempt building an injector dongle and deal with bootloader yourself? I have just started out fiddling around with Arduino and electronics in general, this might be a pretty interesting project.
 

TariqSoftDev

~Zexceil
Member
Joined
Sep 18, 2013
Messages
716
Trophies
0
Location
London
XP
984
Country
So it doesn't really matter what firmware the Switch runs on, a payload will always be able to be injected because ArgonNX functions similarly to Hekate? It's a payload injector the dongle runs natively on?

I have replaced the bootloader with one I have found here in the forums, compiled by tom[...] if I remember correctly, which I believe either launches Atmosphere found on the SD card or has Atmosphere 0.9.3 embedded in it which gets launched.


Why would it be necessary to additionally map the hardware it uses?


Thank you! For curiousity's sake, would you ever attempt building an injector dongle and deal with bootloader yourself? I have just started out fiddling around with Arduino and electronics in general, this might be a pretty interesting project.
Because you got GPIO's, memory mappings and etc; I had to rewrite some UF2 stuff so it would support my MCU.
 

Fehniix

Member
OP
Newcomer
Joined
Aug 22, 2019
Messages
18
Trophies
0
Age
26
XP
73
Country
Australia
Because you got GPIO's, memory mappings and etc; I had to rewrite some UF2 stuff so it would support my MCU.
Interesting. I suppose then you built your own device to inject payloads, correct? If so, may I ask you what you used, how you did it etc.? I'm very curious and would to do something like this on my own as well.
 

TariqSoftDev

~Zexceil
Member
Joined
Sep 18, 2013
Messages
716
Trophies
0
Location
London
XP
984
Country
Interesting. I suppose then you built your own device to inject payloads, correct? If so, may I ask you what you used, how you did it etc.? I'm very curious and would to do something like this on my own as well.
Just check this forum for the ReLOAD mochip thread, there'll be a Discord there; I prefer discord over this.
 

The Real Jdbye

*is birb*
Member
Joined
Mar 17, 2010
Messages
22,211
Trophies
4
Location
Space
XP
11,723
Country
Norway
So it doesn't really matter what firmware the Switch runs on, a payload will always be able to be injected because ArgonNX functions similarly to Hekate? It's a payload injector the dongle runs natively on?

I have replaced the bootloader with one I have found here in the forums, compiled by tom[...] if I remember correctly, which I believe either launches Atmosphere found on the SD card or has Atmosphere 0.9.3 embedded in it which gets launched.


Why would it be necessary to additionally map the hardware it uses?


Thank you! For curiousity's sake, would you ever attempt building an injector dongle and deal with bootloader yourself? I have just started out fiddling around with Arduino and electronics in general, this might be a pretty interesting project.
I would probably stick with the Arduino bootloader since it's easy enough to flash firmware with that.
 

You may also like...

General chit-chat
Help Users
    K3N1 @ K3N1: Won't be long before SAK starts singing to jd