mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-08-14 03:43:44 +00:00
39424632bb
* Initial commit and pr for HackRF Pro (praline) arch-port to mayhem-firmware. Please see https://github.com/portapack-mayhem/mayhem-firmware/issues/2957. Added flash specifics for -DBOARD=PRALINE. This firmware only builds with toolchain v9.2.1 if hackrf codebase has -B arm in firmware/hackrf_usb/CMakeLists.txt. * Updated CMakeLists.txt per coordination with @HtoToo. For -DBOARD=PRALINE FLASH_MB_SIZE and FLASH_MB_LIMIT_SIZE are now 4. Removed praline specific variable for FLASH limits. * Updated chibios-portapack's board.cpp to support initialization of the HachRF-Pro (praline) FPGA. Added append_fpga_bitstream.py tool to ensure that praline_fgpa.bin bitstream can be appended to -DBOARD=PRALINE produced firmware. In order to ensure successful execution of append_fpga_bitstream.py to append the fpga bitstream we should expect that the bistsream will be located at 0x180000 in flash. This requires that FLASH_MB_LIMIT_SIZE must be 1.5, and FLASH_BYTES_LIMIT_SIZE must be 1535 * 1024. If we want to allow more or less space for the base firmware image sans the fpga bitstream the location of the bistream must be moved to a location other than 0x180000. * Updated location of praline_fpga.bin bitstream to 0x380000 to allow more room for firmware. Firmware now has 3.5MB, or 2MB more available than before as coordinated with @HTotoo. * Expanded #ifndef PRALINE to include og and r9 gpio and pin setup as coordinated with @HTotoo. * Added note for PRALINE FLASH_MB_LIMIT_SIZE and FLASH_BYTES_LIMIT_SIZE to explain why we are using the 3.5 and 3584 values respectively as coordinated with @HTotoo. * Next round of modifications derived heavily, if not entirely from work done by @banandana at https://github.com/Banandana/mayhem-firmware. This commit should power on the HackRF Pro (praline) display, power on the fpga, and enable gpio, and provide debug utilties. There is still a lot of work to be done to fully enable the new praline board with this build and firmware architectural porting effort. However, hackrf-one boards do not seem to be adversely impacted by the #ifdef PRALINE statements, and CMakeLists updates, as far as I have been able to test. * Ran format-code.sh. Updates for this commit are only due to formatting. Tested builds and they seem to work as exptected. * Addressed fixes in firmware/application and firmware/baseband. Stream now flows to capture and looking glass. Issues were related to thread management. Issues were originally addressed by @banandana. * Ran format-code.sh to allow for consistency with autoamted clang checks. * Update hackrf ref repo to mayhem-portapack-hackrf next from https://github.com/portapack-mayhem/hackrf * Addressed format edits necessary to pass clang-format check. * Starting addressing Si5351 Clocks for radio sampling. These updates correctly set the Si5351 clock at start up. There appears to be an issue during runtime when testing with RX Test Init, Capture and Looking glass. * Updated clock_manager.cpp to restore correct function introduced by @banandana when testing with Rx Test Init. * Switched to using decimation for setting the sample rate without changing the Si5351 clock. This assumes that for the praline board Si5351 CLK0 runs at fixed 8 MHz (constant) and the FPGA decimates to get the desired sample rate. For example, for a 1 MHz sample rate -> Si5351 outputs 8 MHz, FPGA decimates by 8. There is still more work needed here, and potential verification that this is the correct way to operate with this new archteitecture. * After deliberating on hackrf_usb hackrf_core.c and radio.c, and reviewing firmware/application/hw/si5351.cpp the original approach of using the aproach detailed in hackrf_core.c sample_rate_frac_set() lines 580-582, via the implementation in firmware/application/hw/si5351.cpp seems like the best place to continue testing efforts. * Tested at ~2.4GHz (2.3 - 2.5) with lookgin glass and was able to receive signals. Added a Signal Path debug app to test gains, and readio mode (receive/transmit). * Added two debug apps for the RFFC507x. Status View and Tuning View. This helped debug some of the potential issues with tuning. * update submodule * format code * Small touch up merging latest next and ensuring build for HackRF One. * Reverted edits to re: firmware/baseband/sd_over_usb/scsi.c and firmware/application/portapack.cpp. Source now builds, had to pull latest hackrf submodule. * Skipped detect hardware for praline board to avoid backscreen in HackRF Pro praline board. --------- Co-authored-by: gullradriel <gullradriel@users.noreply.github.com>
110 lines
3.7 KiB
Python
110 lines
3.7 KiB
Python
#!/usr/bin/env python3
|
|
#
|
|
# Append FPGA bitstream to PRALINE firmware
|
|
#
|
|
# This script takes a PortaPack firmware.bin and appends the PRALINE FPGA
|
|
# bitstream at offset 0x100000 (1MB), then recalculates the checksum.
|
|
#
|
|
# Usage: append_fpga_bitstream.py <firmware.bin> <fpga.bin> <output.bin> <total_size>
|
|
#
|
|
|
|
import sys
|
|
import os
|
|
|
|
def read_image(path):
|
|
with open(path, 'rb') as f:
|
|
return bytearray(f.read())
|
|
|
|
def write_image(data, path):
|
|
with open(path, 'wb') as f:
|
|
f.write(data)
|
|
|
|
def main():
|
|
if len(sys.argv) != 5:
|
|
print("Usage: append_fpga_bitstream.py <firmware.bin> <fpga.bin> <output.bin> <total_size>")
|
|
print(" firmware.bin: Input PortaPack firmware (1MB with checksum)")
|
|
print(" fpga.bin: PRALINE FPGA bitstream (LZ4 compressed)")
|
|
print(" output.bin: Output combined firmware")
|
|
print(" total_size: Total flash size in bytes (e.g., 2097152 for 2MB)")
|
|
sys.exit(1)
|
|
|
|
firmware_path = sys.argv[1]
|
|
fpga_path = sys.argv[2]
|
|
output_path = sys.argv[3]
|
|
total_size = int(sys.argv[4], 0)
|
|
|
|
# FPGA bitstream offset in flash
|
|
# PRALINE: Moved to 3.5MB to allow larger base firmware
|
|
FPGA_OFFSET = 0x380000 # 3.5MB (was 0x180000 = 1.5MB)
|
|
|
|
# Read input files
|
|
firmware = read_image(firmware_path)
|
|
fpga = read_image(fpga_path)
|
|
|
|
print(f"Firmware size: {len(firmware)} bytes")
|
|
print(f"FPGA bitstream size: {len(fpga)} bytes")
|
|
print(f"Target total size: {total_size} bytes")
|
|
|
|
# The firmware has a 4-byte checksum at the end
|
|
# Remove it - we'll recalculate after adding FPGA bitstream
|
|
firmware_content = firmware[:-4]
|
|
|
|
# Check that firmware content fits before FPGA offset
|
|
if len(firmware_content) > FPGA_OFFSET:
|
|
print(f"ERROR: Firmware content ({len(firmware_content)} bytes) exceeds FPGA offset ({FPGA_OFFSET})")
|
|
sys.exit(1)
|
|
|
|
# Create output image
|
|
output = bytearray()
|
|
|
|
# Add firmware content (padded to FPGA_OFFSET with 0xFF)
|
|
output.extend(firmware_content)
|
|
pad_size = FPGA_OFFSET - len(firmware_content)
|
|
output.extend(bytes([0xFF] * pad_size))
|
|
|
|
print(f"Padded firmware to {len(output)} bytes (FPGA offset)")
|
|
|
|
# Add FPGA bitstream
|
|
output.extend(fpga)
|
|
print(f"Added FPGA bitstream, total now {len(output)} bytes")
|
|
|
|
# Check total size
|
|
if len(output) > total_size - 4:
|
|
print(f"ERROR: Combined image ({len(output)} bytes) exceeds max size ({total_size - 4} bytes)")
|
|
sys.exit(1)
|
|
|
|
# Pad to total_size - 4 (leaving room for checksum)
|
|
pad_size = total_size - 4 - len(output)
|
|
output.extend(bytes([0xFF] * pad_size))
|
|
print(f"Padded to {len(output)} bytes (before checksum)")
|
|
|
|
# Calculate checksum (same algorithm as make_spi_image.py)
|
|
checksum = 0
|
|
for i in range(0, len(output), 4):
|
|
snippet = output[i:i + 4]
|
|
if len(snippet) == 4:
|
|
val = int.from_bytes(snippet, byteorder='little')
|
|
checksum += val
|
|
|
|
final_checksum = 0
|
|
checksum = (final_checksum - checksum) & 0xFFFFFFFF
|
|
output.extend(checksum.to_bytes(4, 'little'))
|
|
|
|
print(f"Final image size: {len(output)} bytes")
|
|
print(f"Checksum: 0x{checksum:08X}")
|
|
|
|
# Write output
|
|
write_image(output, output_path)
|
|
print(f"Written to {output_path}")
|
|
|
|
# Report space usage
|
|
fpga_end = FPGA_OFFSET + len(fpga)
|
|
space_after_fpga = total_size - 4 - fpga_end
|
|
print(f"\nSpace usage:")
|
|
print(f" Firmware: 0x000000 - 0x{len(firmware_content):06X} ({len(firmware_content)} bytes)")
|
|
print(f" FPGA: 0x{FPGA_OFFSET:06X} - 0x{fpga_end:06X} ({len(fpga)} bytes)")
|
|
print(f" Free: 0x{fpga_end:06X} - 0x{total_size-4:06X} ({space_after_fpga} bytes)")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|