10 ‐ Basic idea and operation - losehu/uv-k5-bootloader-custom GitHub Wiki

Basic idea

Customize the radio so that a :sparkles:Selection of multiple firmwares:sparkles: is possible.

Working memories of the radio

  • Built-in 64K bytes FLASH memory for program storage area
  • Built-in 16K bytes of RAM as data storage area
  • External 64K bytes Eeprom for Configuration and Callibration storage area

Challenge: 'Flash' size cannot be expanded

The radio has a limited internal memory (64K) of 4K is which is occupied for the bootloader, so 60K is available to store the radio working program (firmware). This size of the 'flash' cannot be increased because the 'flash' is intern to the processor.

The solution: 'Trick'

Booting the radio from Eeprom is not possible, but reading/writing data from it is possible. We achieve this in several steps.

  1. To fill the library, a "Special firmware" is needed that can "address 4Mb" instead of 64Kb.
  2. In order to be able to choose which firmware is selected from Eeprom, the bootloader is modified.
  3. The new bootloader must be uploaded into the processor via an ST-link interface.
  4. The selection choice only becomes available if the M-key is pressed during power ON

How to Expand memory?

The flash memory is located in the processor and cannot be expanded. What can be adjusted is the external Eeprom. This contains the channel list. After enlarging the Eeprom, there is more space and a library for multiple firmwares can be placed behind the channel list. You cannot boot the radio from Eeprom, but you can read/write data from it.

This is how the idea came about ... Replace the BL24C64 with an even bigger Eeprom and store multiple firmwares, and write a bootloader allowing you to flash them from Eeprom to chip flash on the fly.

Bootloader

The original behavior

  • When you turn on the UVK5, it boots via a _bootloader _to the firmware in the flash memory.
  • If you hold the PTT while turning on, the bootloader does not continue to the firmware, but you can load other firmware into flash-memory.
  • Hidden menu is activated by holding PTT + SIDE BUTTON 1 while turning on the radio and then Release All Keys. This enables additional menu items in the firmware.

The NEW behavior

The same as Original, but with :sparkles:Selection of multiple firmwares:sparkles: when M-key is pressed during power ON.

NEW Bootloader for Firmware Switching

Function Description

  • Capable of reading firmware from Eeprom and writing it to flash, allowing switching between different firmware versions.
  • Reads valid firmware from Eeprom and allows selection via button press for loading.

Principle Description

  • Rewrite the UV-K5 bootloader to load Bootloader B into RAM from Eeprom on startup, then jump to Bootloader B in RAM.
  • Bootloader B:
    • Reads firmware from Eeprom and writes it to FLASH.
    • Supports traditional burning communication protocols.

Requirements

  • Due to language requirements (Chinese input method), approximately 150KB is needed, so this bootloader is only suitable for UVK5 with 4Mib (512KB) Eeprom.
  • Due to flash size limitations, individual firmware size should not exceed 60KB.
  • Requires ST-Link(or J-Link)to flash the new bootloader into UVK5's flash.

Instructions

The principle of this bootloader in detail

Bootloader A (4KB)

  • LOSEHU_BASE_BOOT is the base bootloader used to replace the official Quansheng bootloader.
    • Stored in Flash. First 4KB.
    • Programmed using STLINK to replace the original bootloader.
    • Main functions:
      • If No key is pressed, start actual firmware in flash memory at address +4Kb
      • If Pressed PTT while powering on, Enable firmware upgrade via the serial port.
        • Programm code is "Read the key. If PTT is held down, 2 will be written at 0X01FF0".
      • If Pressed MENU while powering on, no extra enabling
      • Load Bootloader B from Eeprom into RAM.
      • Execute Bootloader B in RAM.

Bootloader B (about 12KB)

  • L_BLXXX.bin performs functions such as serial port firmware flashing and firmware switching.
    • Stored in beginning of the Eeprom.
    • Programming in Eeprom requires special Online Web interface Multi-booting Bootloader B
    • Main functions:
      • Serial port firmware flashing (original code).
      • Select the firmware to load via the UI.
      • Read the selected firmware from Eeprom and write it to flash memory for the next boot.
        • Programm code is
          • Read 0X01FF0. If it is 2, enter the firmware flash mode, otherwise
          • Enter Menu to switch the firmware
          • Read the starting address of the firmware from (0x40010 + 32 * n ) (n>=1)
          • Reads the termination address of the firmware from (0x40010 + 32 * n+4) (n>=1)
          • Write (0x40010 + 32 * n)~(0x40010 + 32 * n+4) to flash

Configuration File Management for Each Firmware (not implemented yet)

At this moment All the firmware(s) share the same Configuration.

  1. Backing up individual configuration files to Eeprom for each firmware is a good idea. But not yet implemented
  2. However, the backup process takes a long time, meaning that switching firmware would take a long time, which does not align with my design concept. Currently, switching only takes 7 seconds.
  3. The size of each firmware’s configuration file is uncertain and difficult to manage. If possible, I would only consider backing up the first 8KB of content.

Eeprom Distribution for Firmware

  1. We have developed a web page called K5WEB, which supports both Chinese and English. The URL is: https://k5.vicicode.com/#/tool/bl.
  2. We divided the Eeprom into several 40B blocks, and users can decide which blocks to store each firmware in.
  3. Our multi-firmware only supports a 512KB Eeprom because we placed Bootloader B and other firmware in the 256-512KB region.