# Copyright 2022 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. source [find mem_helper.tcl] set _ENDIAN little if { [info exists CHIPNAME] } { set _CHIPNAME $CHIPNAME } else { set _CHIPNAME NPCX99nF } if { [info exists WORKAREAADDR] } { set _WORKAREAADDR $WORKAREAADDR } else { set _WORKAREAADDR 0 } if { [info exists WORKAREASIZE] } { set _WORKAREASIZE $WORKAREASIZE } else { set _WORKAREASIZE 0 } if { [info exists CPUTAPID ] } { set _CPUTAPID $CPUTAPID } else { set _CPUTAPID 0x2ba01477 } if { [info exists FLASHADDR] } { set _FLASHADDR $FLASHADDR } else { set _FLASHADDR 0x64000000 } adapter speed 600 swd newdap $_CHIPNAME cpu -enable dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu set _TARGETNAME $_CHIPNAME.cpu target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap # Work area in RAM used during flashing $_TARGETNAME configure -work-area-phys $_WORKAREAADDR -work-area-size $_WORKAREASIZE -work-area-backup 0 # The npcx driver detects and autoconfigures various flash parameters set _FLASHNAME $_CHIPNAME.internal_flash flash bank $_FLASHNAME npcx $_FLASHADDR 0 0 0 $_TARGETNAME # use sysresetreq to perform a system reset cortex_m reset_config sysresetreq adapter srst delay 100 # Freeze various clocks, counters and destructive reads # Otherwise something like the watchdog time can interfere with debugging/flashing proc debug_freeze { } { mwb 0x400C3078 0x7F } proc handle_gdb_attach { } { halt debug_freeze # Read the address of the reset handler from the vector table # The bootloader runs first, but it's not a good place to halt # as it sets up various things, including debug support set RESET_HANDLER [mrw 0x10080004] bp $RESET_HANDLER 2 hw reset run # Wait to hit the reset handler bp wait_halt 250 # OpenOCD can get stuck in the reset handler # removing the BP prevents that rbp $RESET_HANDLER } proc handle_gdb_detach { } { shutdown } proc flash_target { image verify } { global _FLASHADDR echo "Resetting and halting target..." reset halt echo "Flashing image..." flash write_image erase $image $_FLASHADDR bin if { $verify == 1} { echo "Verifying image..." flash verify_image $image $_FLASHADDR bin } echo "Resuming target..." reset run } $_TARGETNAME configure -event halted debug_freeze # GDB connection config $_TARGETNAME configure -event gdb-attach handle_gdb_attach $_TARGETNAME configure -event gdb-detach handle_gdb_detach gdb_memory_map enable