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:: 2011-01-28#$ 15# $Rev: 33911 $ 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 $(EMPTY) 102 103public.FilterTest(sources) = 104 105 filtered_sources = $(sources) 106 107 if $(defined TEST_FILTER) 108 regex = $"^\("$(compileToRegex $(TEST_FILTER))$"\)"\$ 109 filtered_sources = 110 111 foreach( source, $(sources) ) 112 if $(isFilterMatch $(regex), $(rootname $(basename $(source)))) 113 filtered_sources += $(source) 114 export filtered_sources 115 export filtered_sources 116 export filtered_sources 117 118 return $(filtered_sources) 119 120private.RunProgramBeforeTest(options, logfile) = 121 if $(defined BEFORE_TEST) 122 foreach(runner, $(BEFORE_TEST)) 123 runner.run($(options), logfile) 124 125private.GetDependsBeforeTest() = 126 ret = 127 if $(defined BEFORE_TEST) 128 foreach(runner, $(BEFORE_TEST)) 129 value $(runner.GetDepends) 130 return $(ret) 131 132private.RunProgramAfterTest(options, logfile) = 133 if $(defined AFTER_TEST) 134 foreach(runner, $(AFTER_TEST)) 135 runner.run($(options), logfile) 136 137private.GetDependsAfterTest() = 138 ret = 139 if $(defined AFTER_TEST) 140 foreach(runner, $(AFTER_TEST)) 141 value $(runner.GetDepends) 142 return $(ret) 143 144private.ParseDependProcesses(process, processlist) = 145 processes = 146 basedir = $(dirname $(absname $(process))) 147 148 foreach(proc, $(DEPEND_PROCESSES)) 149 if $(not $(proc)) 150 continue 151 152 if $(findstring $(proc),$"^@") 153 processes += $(absname $(file $(removeprefix $"@", $(proc)))) 154 export 155 156 elseif $(findstring $(proc),$"^\.") 157 processes += $(file $(absname $(proc))) 158 export 159 160 else 161 tmp_image_dir = $(dirname $(proc)) 162 tmp_image_dir = $(absname $(addprefix $(basedir)$(DIRSEP)..$(DIRSEP)..$(DIRSEP),$(tmp_image_dir))) 163 tmp_image = $(addsuffix $(EXT_CDI),$(basename $(proc))) 164 tmp_image = $(addprefix $(config.getTargetSubDirectory false)$(DIRSEP),$(tmp_image)) 165 processes += $(file $(addprefix $(tmp_image_dir)$(DIRSEP),$(tmp_image))) 166 export 167 export 168 169 return $(processes) 170 171public.GetLoadrunOptions() = 172 options = 173 174 if $(and $(not $(defined RUN_TIMEOUT)), $(not $(IsEmpty $(filter dotests-%, $(TARGETS))))) 175 RUN_TIMEOUT = 60 176 export RUN_TIMEOUT 177 178 if $(and $(not $(defined EXIT_PATTERN)), $(not $(IsEmpty $(filter dotests-%, $(TARGETS))))) 179 EXIT_PATTERN=$"CU_TEST_EXIT|KernelPanic|nn::svc::Break\(" 180 export EXIT_PATTERN 181 182 if $(and $(defined RUN_NOWAIT), $(RUN_NOWAIT)) 183 options += --no-wait 184 export options 185 186 if $(defined EXIT_PATTERN) 187 options += --exit-pattern $(string $(EXIT_PATTERN)) 188 export options 189 190 if $(defined RUN_TIMEOUT) 191 options += --timeout $(RUN_TIMEOUT) 192 export options 193 194 if $(and $(defined-env CTR_RUN_DEVICE), $(not $(defined RUN_DEVICE))) 195 RUN_DEVICE = $(getenv CTR_RUN_DEVICE) 196 export 197 198 if $(defined RUN_DEVICE) 199 options += -d $(RUN_DEVICE) 200 export options 201 202 if $(and $(defined RUN_VARBOSE), $(RUN_VARBOSE)) 203 options += --varbose 204 export options 205 206 return $(options) 207 208public.GetLoadrunOptionsForTool() = 209 options = 210 211 if $(and $(defined RUN_NOWAIT), $(RUN_NOWAIT)) 212 options += --no-wait 213 export options 214 215 return $(options) 216 217public.FilesToRunProcessList(config, process) = 218 process = $(filter %.cdi,$(process)) 219 if $(eq 0,$(length $(process))) 220 return 221 process = $(nth 0,$(process)) 222 223 export depend_files 224 depend_files = 225 226 export processes 227 processes = 228 229 kernel = $(config.getSuitableKernelFilename) 230 kernel_core0 = $(gsub $(kernel),Kernel\.ARM946ES\.,Kernel.MPCore.) 231 kernel_core2 = $(gsub $(kernel),Kernel\.MPCore\.,Kernel.ARM946ES.) 232 233 if $(not $(and $(defined TEST_DEBUG_ARM9), $(TEST_DEBUG_ARM9))) 234 kernel_core2 = $(gsub $(kernel_core2),Development,Release) 235 kernel_core2 = $(gsub $(kernel_core2),Debug,Release) 236 export 237 238 log = $(addsuffix .proclist.log,$(removesuffix $(process))) 239 setuplog = $(addsuffix .proclist.setup.log,$(removesuffix $(process))) 240 teardownlog = $(addsuffix .proclist.teardown.log,$(removesuffix $(process))) 241 basedir = $(dirname $(absname $(process))) 242 243 if $(defined DEPEND_PROCESSES) 244 DEPEND_PROCESSES = $(ParseDependProcess $(config), $(removesuffix $(basename $(process))), $(DEPEND_PROCESSES)) 245 processes += $(ParseDependProcesses $(process), $(DEPEND_PROCESSES)) 246 export 247 processes += $(absname $(process)) 248 249 if $(not $(SKIP_BUILD)) 250 depend_files += $(kernel_core0) $(kernel_core2) 251 depend_files += $(processes) 252 253 processes = $(addprefix @,$(processes)) 254 255 process_list = $(dirname $(kernel_core0))$(DIRSEP)process.list 256 257 tooloptions = -c0 esc -c0 init -k11 $(kernel_core0) -k9 $(kernel_core2) -pl $(process_list) $(GetLoadrunOptionsForTool) 258 259 if $(not $(and $(defined SKIP_RUN), $(SKIP_RUN))) 260 if $(and $(defined TEST_ENVIRONMENT_PROCESSLIST), $(TEST_ENVIRONMENT_PROCESSLIST)) 261 $(log): $(LOADRUN) $(depend_files) $(GetDependsBeforeTest) $(GetDependsAfterTest) :effects: $(LOADRUN) :value: $(random) 262 if $(and $(defined LOGLIST), $(LOGLIST)) 263 echo $(log) >> $(LOGLIST) 264 if $(defined RUN_HOSTPROGRAM) 265 RUN_HOSTPROGRAM.run() 266 RunProgramBeforeTest($(tooloptions), $(setuplog)) 267 section 268 f = $(fopen $(process_list), w) 269 foreach(filename, $(processes)) 270 fprintln($(f), $(filename)) 271 close($(f)) 272 273 $(LOADRUN) -c0 esc -c0 init -k11 $(kernel_core0) -k9 $(kernel_core2) $(GetLoadrunOptions) | tee $(absname $(log)) 274 RunProgramAfterTest($(tooloptions), $(teardownlog)) 275 depend_files += $(log) 276 277 if $(filter run-proclist, $(TARGETS)) 278 $(log): $(LOADRUN) $(depend_files) $(GetDependsBeforeTest) $(GetDependsAfterTest) :effects: $(LOADRUN) :value: $(random) 279 section 280 f = $(fopen $(process_list), w) 281 foreach(filename, $(processes)) 282 fprintln($(f), $(filename)) 283 close($(f)) 284 $(LOADRUN) -c0 esc -c0 init -k11 $(kernel_core0) -k9 $(kernel_core2) $(GetLoadrunOptions) | tee $(absname $(log)) 285 depend_files += $(log) 286 export 287 export 288 return $(depend_files) 289 290public.FilesToRunEmulationMemory(config, process) = 291 292 process = $(filter %.cci %.csu,$(process)) 293 if $(eq 0,$(length $(process))) 294 return 295 process = $(nth 0,$(process)) 296 297 kernel = $(config.getSuitableKernelFilename) 298 kernel_core0 = $(gsub $(kernel),Kernel\.ARM946ES\.,Kernel.MPCore.) 299 kernel_core2 = $(gsub $(kernel),Kernel\.MPCore\.,Kernel.ARM946ES.) 300 301 if $(not $(and $(defined TEST_DEBUG_ARM9), $(TEST_DEBUG_ARM9))) 302 kernel_core2 = $(gsub $(kernel_core2),Development,Release) 303 kernel_core2 = $(gsub $(kernel_core2),Debug,Release) 304 export 305 306 if $(and $(defined RUN_FAST_KERNEL), $(RUN_FAST_KERNEL)) 307 kernel_core0 = $(gsub $(kernel_core0),.small,.fast) 308 kernel_core2 = $(gsub $(kernel_core2),.small,.fast) 309 export 310 311 export processes 312 processes = 313 314 export options 315 options = 316 317 export depend_files 318 depend_files = 319 320 if $(defined DEPEND_PROCESSES) 321 DEPEND_PROCESSES = $(ParseDependProcess $(config), $(removesuffix $(basename $(process))), $(DEPEND_PROCESSES)) 322 processes += $(ParseDependProcesses $(process), $(DEPEND_PROCESSES)) 323 export 324 325 if $(not $(SKIP_BUILD)) 326 depend_files += $(process) $(kernel_core0) $(kernel_core2) 327 depend_files += $(processes) 328 329 foreach(proc, $(processes)) 330 options += -rp $(proc) 331 332 if $(and $(defined RUN_FROMTESTMENU), $(RUN_FROMTESTMENU)) 333 options += -c0 "rdc $(process),0" 334 options += -c0 "zn ID2_2=0x20" 335 options += -rid 0004013000008002 336 export 337 else 338 options += -re $(process) 339 export 340 341 log = $(addsuffix .emumem.log,$(removesuffix $(process))) 342 setuplog = $(addsuffix .proclist.setup.log,$(removesuffix $(process))) 343 teardownlog = $(addsuffix .proclist.teardown.log,$(removesuffix $(process))) 344 basedir = $(dirname $(absname $(process))) 345 346 process_list = $(dirname $(kernel_core0))$(DIRSEP)process.list 347 348 tooloptions = -c0 esc -c0 init -k11 $(kernel_core0) -k9 $(kernel_core2) -pl $(process_list) $(GetLoadrunOptionsForTool) 349 350 if $(not $(and $(defined SKIP_RUN), $(SKIP_RUN))) 351 if $(or $(and $(defined TEST_ENVIRONMENT_EMUMEM), $(TEST_ENVIRONMENT_EMUMEM))\ 352 $(and $(defined TEST_ENVIRONMENT_IMPORT), $(TEST_ENVIRONMENT_IMPORT))) 353 $(log): $(LOADRUN) $(depend_files) $(GetDependsBeforeTest) $(GetDependsAfterTest) :effects: $(LOADRUN) :value: $(random) 354 if $(and $(defined LOGLIST), $(LOGLIST)) 355 echo $(log) >> $(LOGLIST) 356 if $(defined RUN_HOSTPROGRAM) 357 RUN_HOSTPROGRAM.run() 358 RunProgramBeforeTest($(tooloptions), $(setuplog)) 359 echo $(LOADRUN) -c0 esc -c0 init -k11 $(kernel_core0) -k9 $(kernel_core2) -pl $(process_list) $(options) $(GetLoadrunOptions) 360 $(LOADRUN) -c0 esc -c0 init -k11 $(kernel_core0) -k9 $(kernel_core2) -pl $(process_list) $(options) $(GetLoadrunOptions) | tee $(absname $(log)) 361 RunProgramAfterTest($(tooloptions), $(teardownlog)) 362 depend_files += $(log) 363 export 364 export 365 366 if $(filter run-emumem, $(TARGETS)) 367 $(log): $(LOADRUN) $(depend_files) $(GetDependsBeforeTest) $(GetDependsAfterTest) :effects: $(LOADRUN) :value: $(random) 368 $(LOADRUN) -c0 esc -c0 init -k11 $(kernel_core0) -k9 $(kernel_core2) -pl $(process_list) $(options) $(GetLoadrunOptions) | tee $(absname $(log)) 369 depend_files += $(log) 370 export 371 export 372 373 return $(depend_files) 374 375public.FilesToRunSPI(config, process) = 376 process = $(filter %.cci,$(process)) 377 if $(eq 0,$(length $(process))) 378 return 379 process = $(nth 0,$(process)) 380 381 export depend_files 382 depend_files = 383 if $(not $(SKIP_BUILD)) 384 depend_files += $(process) 385 386 log = $(addsuffix .spi.log,$(removesuffix $(process))) 387 388 commands = -c esc -c reset 389 commands += -c "RDC \"$(process)\",0" 390 commands += -c NEWP 391 392 if $(and $(defined TEST_ENVIRONMENT_SPI), $(TEST_ENVIRONMENT_SPI)) 393 $(log): $(LOADRUN_SPI) $(depend_files) :effects: $(LOADRUN_SPI) :value: $(random) 394 $(LOADRUN_SPI) $(commands) $(GetLoadrunOptions) | tee $(absname $(log)) 395 depend_files += $(log) 396 397 if $(filter run-spi, $(TARGETS)) 398 $(log): $(LOADRUN_SPI) $(depend_files) :effects: $(LOADRUN_SPI) :value: $(random) 399 $(LOADRUN_SPI) $(commands) $(GetLoadrunOptions) | tee $(absname $(log)) 400 depend_files += $(log) 401 402 return $(depend_files) 403 404public.UserRunProcess(config, name, files) = 405 TARGET_FILE = $(UserProcess $(config), $(name), $(files)) 406 LIST_PREFIX = $(removesuffix $(basename $(TARGET_FILE))) 407 CCIFile = $(replacesuffixes $(EXT_ELF), $(EXT_CCI), $(TARGET_FILE)) 408 CIPFile = $(replacesuffixes $(EXT_ELF), $(EXT_CIP), $(TARGET_FILE)) 409 410 RUN_PROCLIST_FILES = $(FilesToRunProcessList $(config),$(absname $(TARGET_FILE))) 411 RUN_EMUMEM_FILES = $(FilesToRunEmulationMemory $(config),$(absname $(TARGET_FILE))) 412 RUN_SPI_FILES = $(FilesToRunSPI $(config),$(absname $(TARGET_FILE))) 413 414 if $(not $(defined RUN_FILTER)) 415 RUN_FILTER= * 416 export 417 418 if $(isFilterMatch $(compileToRegex $(RUN_FILTER)), $(config.getScannerName)) 419 run-proclist: $(RUN_PROCLIST_FILES) 420 run-scripts: $(RUN_PROCLIST_FILES) 421 run-emumem: $(RUN_EMUMEM_FILES) 422 run-spi: $(RUN_SPI_FILES) 423 424 return $(TARGET_FILE) 425