| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- #
- # Copyright (C) <2019-2021>
- # <Cypress Semiconductor Corporation (an Infineon company)>
- #
- source [find target/mxs40/cympn_parser.cfg]
- #
- # extracts number of large and small sectors from passed geometry
- #
- # arguments:
- # geometry - the geometry to be parsed
- # large_sect_tbl - the table that represents large sector coding
- # small_sect_tbl - the table that represents small sector coding
- #
- # return:
- # number of large and small sectors in form [Large_sect_count << 16 | Small_sect_count]
- #
- proc get_sectors_from_geom { geometry large_sect_tbl small_sect_tbl } {
- set geometry_msk [expr {$geometry & 0x07}]
- set num_sup_comb [llength $large_sect_tbl]
- if { $geometry_msk >= $num_sup_comb } {
- puts stderr "Error: Cannot get sector count for Flash Geometry = $geometry_msk"
- return -1
- }
- set large_sect_num [lindex $large_sect_tbl $geometry_msk]
- set small_sect_num [lindex $small_sect_tbl $geometry_msk]
- set ret_value [expr {($large_sect_num << 16) | $small_sect_num}]
- return $ret_value
- }
- #
- # converts flash size to geometry
- #
- # arguments:
- # size_kb - the flash size in kb
- # size_tbl - the table that represents flash size to geometry coding
- #
- # return:
- # flash geometry that represents passed flash size
- #
- proc get_geom_from_size {size_kb size_tbl} {
- set num_elements [llength $size_tbl]
- set geometry -1
- for {set i 0} { $i < $num_elements } {incr i} {
- set size [lindex $size_tbl $i]
- if {$size_kb == $size} {
- set geometry $i
- break
- }
- }
- return $geometry
- }
- #
- # detects flash geometry of TRAVEO™II devices
- #
- # tryies to get TRAVEO™II geometry from the:
- # 1. $MAIN_FLASH_SIZE_OVERRIDE and $WORK_FLASH_SIZE_OVERRIDE if defined
- # 2. Flash GEOMETRY register
- # 3. UDD
- #
- # arguments:
- # main_reg_name - the name of main region to be set
- # work_reg_name - the name of work region to be set
- #
- proc traveo2_detect_geometry { target_arch main_reg_name work_reg_name} {
- set tgt [target current]
- set CHIPNAME [string range ${tgt} 0 [expr {[string first "." ${tgt}] - 1}]]
- global ${CHIPNAME}::MAIN_FLASH_SIZE_OVERRIDE
- global ${CHIPNAME}::WORK_FLASH_SIZE_OVERRIDE
- set detected_main_sectors -1
- set detected_work_sectors -1
- # main / work size where index corresponds to flash geometry
- set main_size_kb_tbl { 576 1088 2112 4160 6336 8384 }
- set work_size_kb_tbl { 0 64 96 128 256 512 }
- # main flash geometry decoding
- # main size kb 576 1088 2112 4160 6336 8384
- set main_large_sect_num_tbl { 14 30 62 126 190 254 }
- set main_small_sect_num_tbl { 16 16 16 16 32 32 }
- # work flash geometry decoding
- # work size kb 0 64 96 128 256 512
- set work_large_sect_num_tbl { 0 24 36 48 96 192 }
- set work_small_sect_num_tbl { 0 128 192 256 512 1024 }
- # 1. Checking ${CHIPNAME}::MAIN_FLASH_SIZE_OVERRIDE / ${CHIPNAME}::WORK_FLASH_SIZE_OVERRIDE
- if { [info exists ${CHIPNAME}::MAIN_FLASH_SIZE_OVERRIDE] } {
- if { [set ${CHIPNAME}::MAIN_FLASH_SIZE_OVERRIDE] } {
- set detected_main_sectors [set ${CHIPNAME}::MAIN_FLASH_SIZE_OVERRIDE]
- #each large sector conatins 32 KB
- set m_size_large [expr {([set ${CHIPNAME}::MAIN_FLASH_SIZE_OVERRIDE] >> 16) << 5}]
- #each small sector conatins 8 KB
- set m_size_small [expr {([set ${CHIPNAME}::MAIN_FLASH_SIZE_OVERRIDE] & 0xFFFF) << 3}]
- echo "** Use overriden Main Flash size, kb: [expr {$m_size_large + $m_size_small}]"
- }
- }
- if { [info exists ${CHIPNAME}::WORK_FLASH_SIZE_OVERRIDE] } {
- if { [set ${CHIPNAME}::WORK_FLASH_SIZE_OVERRIDE] } {
- set detected_work_sectors [set ${CHIPNAME}::WORK_FLASH_SIZE_OVERRIDE]
- #each large sector conatins 2 KB
- set w_size_large [expr {([set ${CHIPNAME}::WORK_FLASH_SIZE_OVERRIDE] >> 16) << 1}]
- #each small sector conatins 128 B
- set w_size_small [expr {([set ${CHIPNAME}::WORK_FLASH_SIZE_OVERRIDE] & 0xFFFF) >> 3}]
- echo "** Use overriden Work Flash size, kb: [expr {$w_size_large + $w_size_small}]"
- }
- }
- # print MPN
- set main_work_size [cyp_get_mpn_work_main_size "traveo2"]
- set flash_geom 0
- if { $detected_main_sectors == -1 || $detected_work_sectors == -1 } {
- # 2. Use UDD if flash size is not overriden
- if { [llength $main_work_size] == 2} {
- if { $detected_main_sectors == -1 } {
- set main_size [lindex $main_work_size 0]
- echo "** Detected Main Flash size, kb: $main_size"
- set geom [get_geom_from_size $main_size $main_size_kb_tbl]
- if { $geom == -1 } {
- puts stderr "Error: Cannot get geometry for main size kb = $main_size"
- return
- }
- set flash_geom [expr {($flash_geom & 0xF8) | $geom} ]
- }
- if { $detected_work_sectors == -1 } {
- set work_size [lindex $main_work_size 1]
- echo "** Detected Work Flash size, kb: $work_size"
- set geom [get_geom_from_size $work_size $work_size_kb_tbl]
- if { $geom == -1 } {
- puts stderr "Error: Cannot get geometry for work size kb = $work_size"
- return
- }
- set flash_geom [expr {($flash_geom & 0xC7) | ($geom << 3)}]
- }
- }
- if {!$flash_geom} {
- # 3. Read Flash GEOMETRY register if main/works sectors are not detected yet
- set MEM_SPCIF3_GEOMETRY 0x4024F00C
- catch { set flash_geom [expr {[mrw $MEM_SPCIF3_GEOMETRY] & 0x3F}] }
- if {$flash_geom} {
- if { $detected_main_sectors == -1 } {
- set m_size [lindex $main_size_kb_tbl [expr {$flash_geom & 0x07}]]
- echo "** Detected Main Flash size from geometry register, kb: $m_size"
- }
- if { $detected_work_sectors == -1 } {
- set w_size [lindex $work_size_kb_tbl [expr {$flash_geom >> 3}]]
- echo "** Detected Work Flash size from geometry register, kb: $w_size"
- }
- }
- }
- if { !$flash_geom} {
- puts stderr "Error: Flash geometry was not detected"
- return
- }
- # get main/works sectors from geometry if they are not detected yet
- if { $detected_main_sectors == -1 } {
- set detected_main_sectors [get_sectors_from_geom $flash_geom $main_large_sect_num_tbl $main_small_sect_num_tbl]
- if { $detected_main_sectors == -1 } {
- puts stderr "Error: Cannot get sectors for main flash from geometry = $flash_geom"
- return
- }
- }
- if { $detected_work_sectors == -1 } {
- set work_geom [expr {$flash_geom >> 3}]
- set detected_work_sectors [get_sectors_from_geom $work_geom $work_large_sect_num_tbl $work_small_sect_num_tbl]
- if { $detected_work_sectors == -1 } {
- puts stderr "Error: Cannot get sectors for work flash from geometry = $work_geom"
- return
- }
- }
- }
- if { $detected_main_sectors == -1 } {
- puts stderr "Error: Main Flash geometry was not detected"
- return
- }
- if { $detected_work_sectors == -1 } {
- puts stderr "Error: Work Flash geometry was not detected"
- return
- }
- if { ${main_reg_name} != "" } { traveo2 set_region_size ${main_reg_name} $detected_main_sectors }
- if { ${work_reg_name} != "" } { traveo2 set_region_size ${work_reg_name} $detected_work_sectors }
- }
|