Slot 0 Upgrade (Work in Progress)

WARNING: This procedure is work in progress and currently requires a core from the 683-cartflash branch. It is also recommended to currently only test it if you own a JTAG interface, so you are able to reverse a soft-brick state of your MEGA65.

IMPORTANT: before testing the TESTING NO-JTAG Recovery process, make sure you can start your MEGA65 with a 683-cartflash core and can follow the Soft-Brick Recovery Procedure (using 683-cartflash core).

 

WARNING: the core of 683-cartflash currently has hyperram problems (test_585 fails), but this does not to affect flashing. If you try out a 683 core in slot 0, be aware that you will need to update again, after this problem has been fixed! But you probably will do this anyways, as you want to replace the branch slot 0 with the release slot 0, after it has been released…

 

Requirements (Test Phase)

Note: The current requirements are for the test phase of this feature!

  • JTAG Interface for soft-brick recovery (this gets your MEGA65 running if everything else fails)

  • Core and bitstream that supports secure slot 0 flashing (get it here: 683-cartflash)
    The release package 7zip archive also includes the upgrade0.prg tool.
    Note: if this page refers to a bitstream or a core, and does not specify one explicitly, it always means the test core/bitstream from the 683-cartflash branch.
    Important: Please make sure to note the build number or git commit hash of the core your are testing with!

Requirements (Production)

  • Core and bitstream that supports secure slot 0 flashing (this will be the Batch 3 Release)
    The release package 7zip archive also includes the upgrade0.prg tool.
    Note: if this page refers to a bitstream or a core, and does not specify one explicitly, it always means the test core/bitstream from the release package.

Note: it is not possible to eliminate all risk of soft-bricking the MEGA65! In that case a JTAG adapter, which allows pushing a bitstream to the system, can resurrect it. If you follow these instructions, the risk should be negligible.

Preparing the SD-Card

For using the slot 0 upgrade procedure you need to put the core you want to flash as your new slot 0 onto your SD-Card as UPGRADE0.COR. This is because the slot 0 flasher won’t let you select a core file but just use the one named that way.
To do this, take the mega65-*-.cor file that you can find in the release package 7zip archive, rename it to UPGRADE0.COR and transfer it to your internal SD-Card.

Important: NEVER use the external SD-Card slot! The way it is connected may create problems while flashing and soft-brick your system.

Initial Procedure (using core flash menu)

This procedure is required if you don’t have yet a slot 0 flashing capable core installed in slot 0.

  1. Flash the slot 0 flashing capable core (see requirements above) to slot 1. In “Preparing the SD-Card” you did put it as UPGRADE0.COR onto your internal SD-Card.
    Important: this must be slot 1! Don’t use any other slot!

  2. Hold down <NO SCROLL>, then power on your MEGA65

  3. In the MEGAFLASH menu, prepare to hold down <NO SCROLL>, press 1 to start slot 1, and immediately hold down <NO SCROLL>

  4. Back in the MEGAFLASH menu (of slot 1 now), press <MEGA>-<KOMMA> (the komma ‘,' key with the tilde '~’ on it's front) to start flashing slot 0 (this is equal to step 1 of the next section).

Soft-Brick Recovery Procedure (using 683-cartflash core)

This requires a JTAG interface and the m65 tool. It can also be used in place of the Initial Procedure above.

  1. power on MEGA65

  2. use m65 to push a bitstream to the MEGA65 holding <NO SCROLL>:
    m65 --bitonly mega65r3.bit

  3. in the MEGAFLASH menu, press <MEGA>-<KOMMA> (the komma ‘,' key with the tilde '~’ on it's front) to start flashing slot 0

Soft-Brick Recovery Procedure (using upgrade0.prg)

This requires a JTAG interface and the m65 tool. It can also be used in place of the Initial Procedure above.

  1. enable DIP Switch #3 on your (powered off) MEGA65 board

  2. power on MEGA65

  3. use m65 to push a bitstream to the MEGA65:
    m65 --bitonly mega65r3.bit

  4. wait until HYPPO informs you that DIP Switch #3 is enabled, and then press <RUN/STOP> to confirm.

  5. exit the MONITOR by entering X and pressing <RETURN>

  6. Send upgrade0.prg to your MEGA65 using m65 tool (note: this can also be done using ethload)
    m65 -4 -r upgrade0.prg

  7. MEGAFLASH (yes, upgrade0.prg is a special MEGAFLASH version, build from the same code) will now show you some debug information, and possibly tell you that you are not in the correct mode. This means that you did not follow the steps above as written, and you need to start over, doing it correctly this time!

  8. The upgrade program will now search for UPGRADE0.COR on your SD-Card and start loading and validating it. If everything checks out it will tell you so and flashing can start. If something is wrong, it will also tell you so and abort. Fix what is wrong and do the process again.

  9. If you have reached this step, slot 0 has been flashed and you can restart your system!

Using etherload instead of m65 for pushing PRGs

You can replace m65 tool and the JTAG UART with etherload and an ethernet cable.

  1. enable ethernet mode by flipping dip switch #2 to on

  2. connect your MEGA65 to your local LAN. Make sure that PC and MEGA65 are connected with ethernet cables and that they are in the same LAN. Note that the MEGA65 always uses the .65 and assumes that you are in a /24 network!

  3. Press <SHIFT>+<POUND> to enable ethernet receive mode

  4. use the following command to send a PRG to your MEGA65 via ethernet (replace 192.168.1 with the three octets of your /24 LAN Network address!)
    etherload -i 192.168.1.255 -4 -r upgrade0.prg

TESTING NO-JTAG Recovery

Do this without using the JTAG (at least starting from step 2)!

  1. flash a slot 0 flashing capable core to slot 1

  2. start flashing slot 0 afterwards, interrupt power in the middle of the process
    (you can go wild here and try different ways of interruption)

  3. see if after power on slot 1 will start (takes about 30 sec of ambulance lights)

  4. reflash slot 0 to see if you can recover.

Important: make sure to document your process, so you can report what you have done, if something goes wrong. This will help iron out problems for the users that don’t own a JTAG.

FAQ

What is MEGAFLASH?

MEGAFLASH is a piece of software written in C and ASM which is integrated into the MEGA65 bitstream initial memory. It is always started when the MEGA65 starts up and has the job to determine which core has to be started or provide the user with an interface to select a core from QSPI Flash or flash core files into it.

Why does there need to be a MEGA65 core in slot 1 for the upgrade procedure?

The upgrade process for slot 0 makes sure that the bitstream header in slot 0 is erased first and written last (see https://mega65.atlassian.net/l/cp/oXegKAWq ). That way the FPGA won’t recognize a broken slot 0 as a bitstream and search the flash until it finds and starts slot 1 automatically.
That you you are able to recover a soft-bricked MEGA65 even without having to use a JTAG interface.

Why does the core to flash need to be named UPGRADE0.COR?

This is done this way, so that there is less possibility of choosing the wrong file (goal: reducing user interaction to reduce user side errors).

How do you manage to put all this into the already big MEGAFLASH?

One part is refactoring existing code and making it smaller. Another part was understanding the memory layout and changing the cc65 config file.