1#!/usr/bin/env omake 2#---------------------------------------------------------------------------- 3# Project: Horizon 4# File: debuggerdefs.partner.om 5# 6# Copyright 2007-2009 Nintendo. All rights reserved. 7# 8# These coded instructions, statements, and computer programs contain 9# proprietary information of Nintendo of America Inc. and/or Nintendo 10# Company Ltd., and are protected by Federal copyright law. They may 11# not be disclosed to third parties or copied or duplicated in any form, 12# in whole or in part, without the prior written consent of Nintendo. 13# 14# $Date:: 2010-11-17#$ 15# $Rev: 31533 $ 16# $Author: takiguchi_shinichi $ 17#---------------------------------------------------------------------------- 18 19PYTHON = python 20RUBY = ruby 21PARTNER_PARTNER = $(absname $(ROOT_TOOLS)$(DIRSEP)CommandLineTools$(DIRSEP)partner_partner.rb) 22private.RUNNER_CORE_0_2 = $(file $(ROOT_BUILD)/runner/run-core_0_2.py) 23LOADRUN = $(absname $(ROOT_TOOLS)$(DIRSEP)CommandLineTools$(DIRSEP)ctr_loadrunf32.exe) 24LOADRUN_SPI = $(absname $(ROOT_TOOLS)$(DIRSEP)CommandLineTools$(DIRSEP)ctr_loadrun32.exe) 25 26public.PartnerMCR(axf, process) = 27 export depend_files 28 depend_files = 29 if $(not $(SKIP_BUILD)) 30 depend_files += $(axf) $(process) 31 32 export basefile 33 export axf_symbol 34 if $(not $(equal $(process), $(EMPTY))) 35 basefile = $(process) 36 axf_symbol = $(removesuffix $(process)).axf 37 else 38 basefile = $(axf) 39 40 mcr = $(addsuffix .mcr,$(removesuffix $(basefile))) 41 log = $(removesuffix $(absname $(basefile))).log 42 basedir = $(dirname $(absname $(basefile))) 43 44 $(mcr): $(dirname $(mcr)) $(ROOT_OMAKE)/debuggerdefs.partner.om $(depend_files) 45 section 46 f = $(fopen $(@), w) 47 fprintln($(f),ESC) 48 fprintln($(f),INITA) 49 fprintln($(f),CORE 0) 50 fprintln($(f),L "$(absname $(axf))") 51 if $(axf_symbol) 52 fprintln($(f),LSA "$(absname $(axf_symbol))") 53 54 fprintln($(f),CD "$(basedir)") 55 if $(not $(equal $(log),$(EMPTY))) 56 fprintln($(f),$">" "$(absname $(log))") 57 fprintln($(f),G) 58 close($(f)) 59 60 if $(and $(defined TEST_ENVIRONMENT_PROCESSLIST), $(TEST_ENVIRONMENT_PROCESSLIST)) 61 $(log): $(mcr) $(depend_files) $(RUNNER) :effects: $(RUNNER_LOCK) 62 bash $(RUNNER) $(mcr) 63 64 return $(mcr) 65 66private.IsEmpty(seq) = 67 return $(eq 0, $(length $(seq))) 68 69public.FilterTestAttributes(process) = 70 71 if $(not $(defined TEST_ATTRIBUTES)) 72 TEST_ATTRIBUTES = 73 export 74 75 if $(not $(defined TEST_INCLUDE)) 76 TEST_INCLUDE = BASIC 77 export 78 else 79 TEST_INCLUDE = $(split $",",$(TEST_INCLUDE)) 80 export 81 82 if $(not $(defined TEST_EXCLUDE)) 83 TEST_EXCLUDE = 84 export 85 else 86 TEST_EXCLUDE = $(split $",",$(TEST_EXCLUDE)) 87 export 88 89 attributes = $(ParseDependProcess null, $(rootname $(process)), $(TEST_ATTRIBUTES)) 90 91 if $(IsEmpty $(attributes)) 92 attributes = BASIC 93 export 94 95 has_includes = $(filter $(TEST_INCLUDE), $(attributes)) 96 has_excludes = $(filter $(TEST_EXCLUDE), $(attributes)) 97 98 if $(and $(IsEmpty $(has_excludes)), $(not $(IsEmpty $(has_includes)))) 99 return $(process) 100 101 return 102 103public.FilterTest(sources) = 104 105 filtered_sources = $(sources) 106 107 if $(defined TEST_FILTER) 108 regex = $(compileToRegex $(TEST_FILTER)) 109 110 filtered_sources = 111 112 foreach( source, $(sources) ) 113 if $(isFilterMatch $(regex), $(rootname $(basename $(source)))) 114 filtered_sources += $(source) 115 export filtered_sources 116 export filtered_sources 117 export filtered_sources 118 119 return $(filtered_sources) 120 121private.RunProgramBeforeTest(options, logfile) = 122 if $(defined BEFORE_TEST) 123 foreach(runner, $(BEFORE_TEST)) 124 runner.run($(options), logfile) 125 126private.GetDependsBeforeTest() = 127 ret = 128 if $(defined BEFORE_TEST) 129 foreach(runner, $(BEFORE_TEST)) 130 value $(runner.GetDepends) 131 return $(ret) 132 133private.RunProgramAfterTest(options, logfile) = 134 if $(defined AFTER_TEST) 135 foreach(runner, $(AFTER_TEST)) 136 runner.run($(options), logfile) 137 138private.GetDependsAfterTest() = 139 ret = 140 if $(defined AFTER_TEST) 141 foreach(runner, $(AFTER_TEST)) 142 value $(runner.GetDepends) 143 return $(ret) 144 145private.ParseDependProcesses(process, processlist) = 146 processes = 147 basedir = $(dirname $(absname $(process))) 148 149 foreach(proc, $(DEPEND_PROCESSES)) 150 if $(not $(proc)) 151 continue 152 153 if $(findstring $(proc),$"^@") 154 processes += $(removeprefix $"@", $(proc)) 155 export 156 157 elseif $(findstring $(proc),$"^\.") 158 processes += $(absname $(proc)) 159 export 160 161 else 162 tmp_image_dir = $(dirname $(proc)) 163 tmp_image_dir = $(absname $(addprefix $(basedir)$(DIRSEP)..$(DIRSEP)..$(DIRSEP),$(tmp_image_dir))) 164 tmp_image = $(addsuffix $(EXT_CDI),$(basename $(proc))) 165 tmp_image = $(addprefix $(config.getTargetSubDirectory false)$(DIRSEP),$(tmp_image)) 166 processes += $(addprefix $(tmp_image_dir)$(DIRSEP),$(tmp_image)) 167 export 168 export 169 170 return $(processes) 171 172public.GetLoadrunOptions() = 173 options = 174 175 if $(and $(not $(defined RUN_TIMEOUT)), $(not $(IsEmpty $(filter dotests-%, $(TARGETS))))) 176 RUN_TIMEOUT = 60 177 export RUN_TIMEOUT 178 179 if $(and $(not $(defined EXIT_PATTERN)), $(not $(IsEmpty $(filter dotests-%, $(TARGETS))))) 180 EXIT_PATTERN="CU_TEST_EXIT|KernelPanic|nn::svc::Break\\(" 181 export EXIT_PATTERN 182 183 if $(and $(defined RUN_NOWAIT), $(RUN_NOWAIT)) 184 options += --no-wait 185 export options 186 187 if $(defined EXIT_PATTERN) 188 options += --exit-pattern $(EXIT_PATTERN) 189 export options 190 191 if $(defined RUN_TIMEOUT) 192 options += --timeout $(RUN_TIMEOUT) 193 export options 194 195 if $(defined RUN_DEVICE) 196 options += -d $(RUN_DEVICE) 197 export options 198 199 return $(options) 200 201public.GetLoadrunOptionsForTool() = 202 options = 203 204 if $(and $(defined RUN_NOWAIT), $(RUN_NOWAIT)) 205 options += --no-wait 206 export options 207 208 return $(options) 209 210public.FilesToRunProcessList(config, process) = 211 process = $(filter %.cdi,$(process)) 212 if $(eq 0,$(length $(process))) 213 return 214 process = $(nth 0,$(process)) 215 216 export depend_files 217 depend_files = 218 219 export processes 220 processes = 221 222 kernel = $(config.getSuitableKernelFilename) 223 kernel_core0 = $(gsub $(kernel),Kernel\.ARM946ES\.,Kernel.MPCore.) 224 kernel_core2 = $(gsub $(kernel),Kernel\.MPCore\.,Kernel.ARM946ES.) 225 226 if $(not $(and $(defined TEST_DEBUG_ARM9), $(TEST_DEBUG_ARM9))) 227 kernel_core2 = $(gsub $(kernel_core2),Development,Release) 228 kernel_core2 = $(gsub $(kernel_core2),Debug,Release) 229 export 230 231 log = $(addsuffix .proclist.log,$(removesuffix $(process))) 232 setuplog = $(addsuffix .proclist.setup.log,$(removesuffix $(process))) 233 teardownlog = $(addsuffix .proclist.teardown.log,$(removesuffix $(process))) 234 basedir = $(dirname $(absname $(process))) 235 236 if $(defined DEPEND_PROCESSES) 237 DEPEND_PROCESSES = $(ParseDependProcess $(config), $(removesuffix $(basename $(process))), $(DEPEND_PROCESSES)) 238 processes += $(ParseDependProcesses $(process), $(DEPEND_PROCESSES)) 239 export 240 processes += $(absname $(process)) 241 242 if $(not $(SKIP_BUILD)) 243 depend_files += $(kernel_core0) $(kernel_core2) 244 depend_files += $(processes) 245 246 processes = $(addprefix @,$(processes)) 247 248 process_list = $(dirname $(kernel_core0))$(DIRSEP)process.list 249 250 tooloptions = -c0 esc -c0 init -k11 $(kernel_core0) -k9 $(kernel_core2) -pl $(process_list) $(GetLoadrunOptionsForTool) 251 252 if $(not $(and $(defined SKIP_RUN), $(SKIP_RUN))) 253 if $(and $(defined TEST_ENVIRONMENT_PROCESSLIST), $(TEST_ENVIRONMENT_PROCESSLIST)) 254 $(log): $(LOADRUN) $(depend_files) $(GetDependsBeforeTest) $(GetDependsAfterTest) :effects: $(LOADRUN) :value: $(random) 255 if $(and $(defined LOGLIST), $(LOGLIST)) 256 echo $(log) >> $(LOGLIST) 257 if $(defined RUN_HOSTPROGRAM) 258 RUN_HOSTPROGRAM.run() 259 RunProgramBeforeTest($(tooloptions), $(setuplog)) 260 section 261 f = $(fopen $(process_list), w) 262 foreach(filename, $(processes)) 263 fprintln($(f), $(filename)) 264 close($(f)) 265 266 $(LOADRUN) -c0 esc -c0 init -k11 $(kernel_core0) -k9 $(kernel_core2) $(GetLoadrunOptions) | tee $(absname $(log)) 267 RunProgramAfterTest($(tooloptions), $(teardownlog)) 268 depend_files += $(log) 269 270 if $(filter run-proclist, $(TARGETS)) 271 $(log): $(LOADRUN) $(depend_files) $(GetDependsBeforeTest) $(GetDependsAfterTest) :effects: $(LOADRUN) :value: $(random) 272 section 273 f = $(fopen $(process_list), w) 274 foreach(filename, $(processes)) 275 fprintln($(f), $(filename)) 276 close($(f)) 277 $(LOADRUN) -c0 esc -c0 init -k11 $(kernel_core0) -k9 $(kernel_core2) $(GetLoadrunOptions) | tee $(absname $(log)) 278 depend_files += $(log) 279 export 280 export 281 return $(depend_files) 282 283public.FilesToRunEmulationMemory(config, process) = 284 285 process = $(filter %.cci %.csu,$(process)) 286 if $(eq 0,$(length $(process))) 287 return 288 process = $(nth 0,$(process)) 289 290 kernel = $(config.getSuitableKernelFilename) 291 kernel_core0 = $(gsub $(kernel),Kernel\.ARM946ES\.,Kernel.MPCore.) 292 kernel_core2 = $(gsub $(kernel),Kernel\.MPCore\.,Kernel.ARM946ES.) 293 294 if $(not $(and $(defined TEST_DEBUG_ARM9), $(TEST_DEBUG_ARM9))) 295 kernel_core2 = $(gsub $(kernel_core2),Development,Release) 296 kernel_core2 = $(gsub $(kernel_core2),Debug,Release) 297 export 298 299 if $(and $(defined RUN_FAST_KERNEL), $(RUN_FAST_KERNEL)) 300 kernel_core0 = $(gsub $(kernel_core0),.small,.fast) 301 kernel_core2 = $(gsub $(kernel_core2),.small,.fast) 302 export 303 304 export processes 305 processes = 306 307 export options 308 options = 309 310 export depend_files 311 depend_files = 312 313 if $(defined DEPEND_PROCESSES) 314 DEPEND_PROCESSES = $(ParseDependProcess $(config), $(removesuffix $(basename $(process))), $(DEPEND_PROCESSES)) 315 processes += $(ParseDependProcesses $(process), $(DEPEND_PROCESSES)) 316 export 317 318 if $(not $(SKIP_BUILD)) 319 depend_files += $(process) $(kernel_core0) $(kernel_core2) 320 depend_files += $(processes) 321 322 foreach(proc, $(processes)) 323 options += -rp $(proc) 324 325 if $(and $(defined RUN_FROMTESTMENU), $(RUN_FROMTESTMENU)) 326 #options += -c0 "zn ID2_2=0x20" 327 options += -c0 "rdc $(process),0" 328 options += -rid 0004013000008002 329 export 330 else 331 options += -re $(process) 332 export 333 334 log = $(addsuffix .emumem.log,$(removesuffix $(process))) 335 setuplog = $(addsuffix .proclist.setup.log,$(removesuffix $(process))) 336 teardownlog = $(addsuffix .proclist.teardown.log,$(removesuffix $(process))) 337 basedir = $(dirname $(absname $(process))) 338 339 process_list = $(dirname $(kernel_core0))$(DIRSEP)process.list 340 341 tooloptions = -c0 esc -c0 init -k11 $(kernel_core0) -k9 $(kernel_core2) -pl $(process_list) $(GetLoadrunOptionsForTool) 342 343 if $(not $(and $(defined SKIP_RUN), $(SKIP_RUN))) 344 if $(or $(and $(defined TEST_ENVIRONMENT_EMUMEM), $(TEST_ENVIRONMENT_EMUMEM))\ 345 $(and $(defined TEST_ENVIRONMENT_IMPORT), $(TEST_ENVIRONMENT_IMPORT))) 346 $(log): $(LOADRUN) $(depend_files) $(GetDependsBeforeTest) $(GetDependsAfterTest) :effects: $(LOADRUN) :value: $(random) 347 if $(and $(defined LOGLIST), $(LOGLIST)) 348 echo $(log) >> $(LOGLIST) 349 if $(defined RUN_HOSTPROGRAM) 350 RUN_HOSTPROGRAM.run() 351 RunProgramBeforeTest($(tooloptions), $(setuplog)) 352 echo $(LOADRUN) -c0 esc -c0 init -k11 $(kernel_core0) -k9 $(kernel_core2) -pl $(process_list) $(options) $(GetLoadrunOptions) 353 $(LOADRUN) -c0 esc -c0 init -k11 $(kernel_core0) -k9 $(kernel_core2) -pl $(process_list) $(options) $(GetLoadrunOptions) | tee $(absname $(log)) 354 RunProgramAfterTest($(tooloptions), $(teardownlog)) 355 depend_files += $(log) 356 export 357 export 358 359 if $(filter run-emumem, $(TARGETS)) 360 $(log): $(LOADRUN) $(depend_files) $(GetDependsBeforeTest) $(GetDependsAfterTest) :effects: $(LOADRUN) :value: $(random) 361 $(LOADRUN) -c0 esc -c0 init -k11 $(kernel_core0) -k9 $(kernel_core2) -pl $(process_list) $(options) $(GetLoadrunOptions) | tee $(absname $(log)) 362 depend_files += $(log) 363 export 364 export 365 366 return $(depend_files) 367 368public.FilesToRunSPI(config, process) = 369 process = $(filter %.cci,$(process)) 370 if $(eq 0,$(length $(process))) 371 return 372 process = $(nth 0,$(process)) 373 374 export depend_files 375 depend_files = 376 if $(not $(SKIP_BUILD)) 377 depend_files += $(process) 378 379 log = $(addsuffix .spi.log,$(removesuffix $(process))) 380 381 commands = -c esc -c reset 382 commands += -c "RDC \"$(process)\",0" 383 commands += -c NEWP 384 385 if $(and $(defined TEST_ENVIRONMENT_SPI), $(TEST_ENVIRONMENT_SPI)) 386 $(log): $(LOADRUN_SPI) $(depend_files) :effects: $(LOADRUN_SPI) :value: $(random) 387 $(LOADRUN_SPI) $(commands) $(GetLoadrunOptions) | tee $(absname $(log)) 388 depend_files += $(log) 389 390 if $(filter run-spi, $(TARGETS)) 391 $(log): $(LOADRUN_SPI) $(depend_files) :effects: $(LOADRUN_SPI) :value: $(random) 392 $(LOADRUN_SPI) $(commands) $(GetLoadrunOptions) | tee $(absname $(log)) 393 depend_files += $(log) 394 395 return $(depend_files) 396 397public.UserRunProcess(config, name, files) = 398 TARGET_FILE = $(UserProcess $(config), $(name), $(files)) 399 LIST_PREFIX = $(removesuffix $(basename $(TARGET_FILE))) 400 CCIFile = $(replacesuffixes $(EXT_ELF), $(EXT_CCI), $(TARGET_FILE)) 401 CIPFile = $(replacesuffixes $(EXT_ELF), $(EXT_CIP), $(TARGET_FILE)) 402 403 RUN_PROCLIST_FILES = $(FilesToRunProcessList $(config),$(absname $(TARGET_FILE))) 404 RUN_EMUMEM_FILES = $(FilesToRunEmulationMemory $(config),$(absname $(TARGET_FILE))) 405 RUN_SPI_FILES = $(FilesToRunSPI $(config),$(absname $(TARGET_FILE))) 406 407 if $(not $(defined RUN_FILTER)) 408 RUN_FILTER= * 409 export 410 411 if $(isFilterMatch $(compileToRegex $(RUN_FILTER)), $(config.getScannerName)) 412 run-proclist: $(RUN_PROCLIST_FILES) 413 run-scripts: $(RUN_PROCLIST_FILES) 414 run-emumem: $(RUN_EMUMEM_FILES) 415 run-spi: $(RUN_SPI_FILES) 416 417 return $(TARGET_FILE) 418