Files
gps/targets/fpga/genesys2/flow/vivado/scripts/write_flash.tcl
T
onur 30179df8e6 feat(gps): add timer-based assisted reacquisition
Remove the fixed pseudorange start offset, preserve per-PRN navigation assistance across RF loss and power cycles, and seed coherent navigation measurement phase on reacquisition. Add full LNAV almanac visibility scheduling, power-safe QSPI journaling, RF-domain reset isolation, and PPS Gray CDC hardening with Linux, sanitizer, RTL, and end-to-end coverage.
2026-08-04 02:58:11 +03:00

83 lines
3.7 KiB
Tcl

set script_dir [file dirname [file normalize [info script]]]
set fpga_dir [file normalize [file join $script_dir ../..]]
proc getenv_default {name default} {
if {[info exists ::env($name)] && $::env($name) ne ""} {
return $::env($name)
}
return $default
}
proc region_end {offset file} {
return [expr {$offset + [file size $file]}]
}
set bit_file [file normalize [getenv_default BIT_FILE [file join $fpga_dir out bitstream genesys2_rocket.bit]]]
set app_image [file normalize [getenv_default APP_FLASH_IMAGE [file join $fpga_dir out flash hello_uart.flash.bin]]]
set mcs_file [file normalize [getenv_default FLASH_MCS [file join $fpga_dir out flash genesys2_rocket.mcs]]]
set bin_file [file normalize [getenv_default FLASH_BIN [file join $fpga_dir out flash genesys2_rocket.bin]]]
set flash_size_mb [getenv_default FLASH_SIZE_MB 32]
set flash_interface [getenv_default FLASH_INTERFACE SPIx4]
set bitstream_offset [getenv_default BITSTREAM_OFFSET 0x00000000]
set app_flash_offset [getenv_default APP_FLASH_OFFSET 0x01800000]
set assistance_flash_offset [getenv_default ASSISTANCE_FLASH_OFFSET 0x01f80000]
set assistance_flash_size [getenv_default ASSISTANCE_FLASH_SIZE 0x00080000]
file mkdir [file dirname $mcs_file]
file mkdir [file dirname $bin_file]
if {![file exists $bit_file]} {
error "Bitstream not found: $bit_file"
}
if {![file exists $app_image]} {
error "Application flash image not found: $app_image"
}
set flash_size_bytes [expr {$flash_size_mb * 1024 * 1024}]
set bitstream_end [region_end $bitstream_offset $bit_file]
set app_end [region_end $app_flash_offset $app_image]
set assistance_end [expr {$assistance_flash_offset + $assistance_flash_size}]
if {$bitstream_end > $flash_size_bytes} {
error [format "Bitstream region exceeds flash: end=0x%08x flash_size=0x%08x" $bitstream_end $flash_size_bytes]
}
if {$app_end > $flash_size_bytes} {
error [format "App region exceeds flash: end=0x%08x flash_size=0x%08x" $app_end $flash_size_bytes]
}
if {$assistance_end > $flash_size_bytes} {
error [format "GPS assistance reservation exceeds flash: end=0x%08x flash_size=0x%08x" $assistance_end $flash_size_bytes]
}
if {$bitstream_offset < $assistance_end && $assistance_flash_offset < $bitstream_end} {
error [format "Bitstream overlaps GPS assistance reservation: bit=[0x%08x,0x%08x) assistance=[0x%08x,0x%08x)" \
$bitstream_offset $bitstream_end $assistance_flash_offset $assistance_end]
}
if {$app_flash_offset < $assistance_end && $assistance_flash_offset < $app_end} {
error [format "App overlaps GPS assistance reservation: app=[0x%08x,0x%08x) assistance=[0x%08x,0x%08x)" \
$app_flash_offset $app_end $assistance_flash_offset $assistance_end]
}
if {$bitstream_offset < $app_end && $app_flash_offset < $bitstream_end} {
error [format "Bitstream/app flash regions overlap: bit=[0x%08x,0x%08x) app=[0x%08x,0x%08x)" \
$bitstream_offset $bitstream_end $app_flash_offset $app_end]
}
puts "Generating flash MCS:"
puts " bitstream: $bit_file @ $bitstream_offset"
puts " app image: $app_image @ $app_flash_offset"
puts " size/interface: ${flash_size_mb}MiB $flash_interface"
puts [format " flash size: 0x%08x bytes" $flash_size_bytes]
puts [format " bitstream end: 0x%08x" $bitstream_end]
puts [format " app end: 0x%08x" $app_end]
puts [format " assistance reserved: 0x%08x-0x%08x" $assistance_flash_offset $assistance_end]
write_cfgmem -force -format MCS -size $flash_size_mb -interface $flash_interface \
-loadbit "up $bitstream_offset $bit_file" \
-loaddata "up $app_flash_offset $app_image" \
$mcs_file
write_cfgmem -force -format BIN -size $flash_size_mb -interface $flash_interface \
-loadbit "up $bitstream_offset $bit_file" \
-loaddata "up $app_flash_offset $app_image" \
$bin_file
puts "Wrote $mcs_file"
puts "Wrote $bin_file"