Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unpack/mkrbf produce incorrect rbf files for MakeCode uf2/elf files #37

Closed
germanicianus opened this issue Mar 29, 2021 · 4 comments · Fixed by #38
Closed

unpack/mkrbf produce incorrect rbf files for MakeCode uf2/elf files #37

germanicianus opened this issue Mar 29, 2021 · 4 comments · Fixed by #38

Comments

@germanicianus
Copy link

germanicianus commented Mar 29, 2021

I stumbled over that problem when trying to upload a uf2 file to the EV3 (via Bluetooth on Linux).

How to reproduce:

  1. Open https://makecode.mindstorms.com/#editor in a browser and create a really simple program like the following.
    simplistic_makecode_program
  2. Download the uf2 file of the just created program, e.g. lego-Untitled.uf2.
  3. Unpack the uf2 file with the following command.
    ev3duder uf2 unpack lego-Untitled.uf2
  4. Upload the unpacked files with the following commands to the EV3 (here via Bluetooth - rfcomm0).
ev3duder --serial=/dev/rfcomm0 up Untitled.elf ../prjs/BrkProg_SAVE/Untitled.elf
ev3duder --serial=/dev/rfcomm0 up Untitled.rbf ../prjs/BrkProg_SAVE/Untitled.rbf
  1. Execute the program on the EV3 via it's menu.
    After starting the program, the EV3 will show a blank screen until it's return button is pressed.

I compared the correct rbf file, which is created by the EV3 when putting the uf2 file on it via USB, with the rbf file created by unpack. To achieve that, I downloaded the working rbf file via ev3duder Bluetooth from the brick. The only difference is the file length - the file created by the brick is 256 bytes long - which is 144 null bytes longer than the one created by unpack. Appending null bytes to the file created by unpack can be achieved with the following command.
truncate -s +144 Untitled.rbf

mkrbf creates a non-working rbf file which differs in content as well as in size from the working one.
ev3duder mkrbf ../prjs/BrkProg_SAVE/Untitled.elf Untitled.rbf

For OpenRoberta uf2 files, both means produce a working rbf file - unpack as well as mkrbf.

Some more remarks:

@germanicianus
Copy link
Author

@JakubVanek, you may be able to quickly fix this issue as you added the unpack functionality :) .

@a3f
Copy link
Member

a3f commented Apr 2, 2021

I've never used this uf2 feature, so I am afraid I can't help. If you got patches, I can merge them though.

@JakubVanek
Copy link
Contributor

Hi,

I'm sorry for a late reply, I'll take a look at it today.

With regards

Jakub

JakubVanek added a commit to JakubVanek/ev3duder that referenced this issue Apr 3, 2021
See c4ev3#37. Microsoft
MakeCode creates strange UF2 files - they contain extra
payload data that need to be in the file even though they
overrun the specified file size.
@JakubVanek
Copy link
Contributor

I think I've found the problem. Unfortunately, the files produced by MakeCode are somewhat buggy and they trigger a sanity check in the current ev3duder code.

The issue is the fileSize field in the UF2 header. For the RBF file, its value is 112. However, the file still contains 256 bytes worth of data as indicated by the payloadSize field. Ev3duder checked for this and it dropped the extra data at the end. However, uf2d (UF2 unpacking daemon running on the brick) and files2uf2 handle this differently. In uf2d, the size in fileSize field is used to resize the file before the next data block is written. The following write may then make the file larger and this is what we're seeing with the 256 vs 112 bytes.

PR #38 should fix this.

@a3f a3f closed this as completed in #38 Apr 5, 2021
a3f pushed a commit that referenced this issue Apr 5, 2021
See #37. Microsoft
MakeCode creates strange UF2 files - they contain extra
payload data that need to be in the file even though they
overrun the specified file size.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants