Nios® V Processor Software Developer Handbook

ID 743810
Date 10/12/2024
Public
Document Table of Contents

5.2.3.2. Modifying Linker Memory Regions

If the default linker memory regions do not meet your needs, BSP Tcl commands let you modify the memory regions as you prefer.

Suppose you have a memory region named onchip_ram. The following Tcl script example separates the top 1024 bytes of onchip_ram to create a new region named onchip_special.

For more information about an explanation of each Tcl command used in this example, refer to the Board Support Package Tcl Commands .

# Get region information for onchip_ram memory region.
# Returned as a list.
set region_info [get_memory_region onchip_ram]

# Extract fields from region information list.
set region_name [lindex $region_info 0]
set slave_desc [lindex $region_info 1]
set offset [lindex $region_info 2]
set span [lindex $region_info 3]

# Remove the existing memory region.
delete_memory_region $region_name

# Compute memory ranges for replacement regions.
set split_span 1024
set new_span [expr $span-$split_span]
set split_offset [expr $offset+$new_span]

# Create two memory regions out of the original region.
add_memory_region onchip_ram $slave_desc $offset $new_span
add_memory_region onchip_special $slave_desc $split_offset $split_span

If you pass this Tcl script to niosv-bsp, it runs after the default Tcl script runs and sets up two memory regions named onchip_ram and onchip_special. Pass the Tcl script to niosv-bsp as follows:

When creating a new BSP:
niosv-bsp --create –-qsys=<Platform Designer system> --type=hal 
--script=reserve_1024_onchip_ram.tcl settings.bsp
When updating an existing BSP:
niosv-bsp --update --script=reserve_1024_onchip_ram.tcl settings.bsp

If you update your BSP without providing the --script option, your BSP reverts to the default linker memory regions and the onchip_special memory region disappears. To preserve it, please provide the --script option to your Tcl script.

For more information about using the --script argument, refer to the Calling a Custom BSP Tcl Script.