1 <#
2 .SYNOPSIS
3 Update the ARMv7-A ports from the generic ARMv7-A port.
4
5 .DESCRIPTION
6 Generate ports, examples and tests from common files.
7
8 .EXAMPLE
9 To update the ThreadX ports for the source tree run:
10 pwsh -Command .\update.ps1 -PortSets tx -CopyCommonFiles -CopyPortFiles -CopyExample -PatchFiles
11
12 To update the ThreadX ports for the test tree run:
13 pwsh -Command .\update.ps1 -PortSets tx -CopyCommonFiles -CopyPortFiles -CopyExample -CopyValidationTest -CopyRegressionTest -PatchFiles
14
15 .LINK
16 https://azure.com/rtos
17
18 .NOTES
19 Author: Andres Mlinar
20 Date: 2021
21 #>
22
23 [CmdletBinding(PositionalBinding=$false)] Param(
24
25 [string]
26 #The script root directory, if not specified it defaults to this script's directory
27 $ScriptDir = $PSScriptRoot,
28
29 [Parameter(Mandatory)]
30 [ValidateSet(
31 "tx", "tx_smp",
32 "txm", "txm_smp"
33 )]
34 [string[]]
35 #Specify the flavor or flavors of ThreadX to generate. Options are: tx, tx_smp, txm, txm_smp
36 $PortSets,
37
38 [switch]
39 #Copy common files
40 $CopyCommonFiles = $false,
41
42 [switch]
43 #Copy port files
44 $CopyPortFiles = $false,
45
46 [switch]
47 #Copy the example
48 $CopyExample = $false,
49
50 [switch]
51 #Copy the validation tests
52 $CopyValidationTest = $false,
53
54 [switch]
55 #Copy the regression tests
56 $CopyRegressionTest = $false,
57
58 [switch]
59 #Copy port files
60 $PatchFiles = $false,
61
62 [string]
63 #The output log directory
64 $LogDir = $( Join-Path $PSScriptRoot 'log' )
65
66 )
67
68 Write-Host "Update the ARMv7-A ports"
69
70 Write-Verbose ("Script directory: $ScriptDir")
71 Write-Verbose ("Port sets: $PortSets")
72 Write-Verbose ("Copy common files: $CopyCommonFiles")
73 Write-Verbose ("Copy port files: $CopyPortFiles")
74 Write-Verbose ("Copy example: $CopyExample")
75 Write-Verbose ("Copy validation test: $CopyValidationTest")
76 Write-Verbose ("Copy regression test: $CopyRegressionTest")
77 Write-Verbose ("Patch files: $PatchFiles")
78 Write-Verbose ("LogDir: $LogDir")
79
80 $cores = @("cortex_a5", "cortex_a7", "cortex_a8", "cortex_a9", "cortex_a12", "cortex_a15", "cortex_a17")
81 $compilers = @("ac6", "gnu")
82 #$compilers = @("ac5", "ac6", "gnu", "iar")
83 $patches = (
84 ('example_build\sample_threadx\.cproject', (
85 ('value=`"cortex-a7`"', 'value=`"cortex-$($core_short_lower)`"'),
86 ('Cortex-A7.NoFPU', 'Cortex-$($core_short_upper).NoFPU')
87 )),
88 ('example_build\tx\.cproject', (
89 ('value=`"cortex-a7`"', 'value=`"cortex-$($core_short_lower)`"'),
90 ('Cortex-A7.NoFPU', 'Cortex-$($core_short_upper).NoFPU')
91 )),
92 ('example_build\sample_threadx\sample_threadx.launch', (
93 ('Debug Cortex-A7', 'Debug Cortex-$($core_short_upper)'),
94 ('VE_Cortex_A7x1', 'VE_Cortex_$($core_short_upper)x1'),
95 ('ve_cortex_a7x1', 've_cortex_$($core_short_lower)x1'),
96 ('FVP_VE_Cortex-A7x1', 'FVP_VE_Cortex-$($core_short_upper)x1')
97 ))
98 )
99
100 # Create the log directory if it doesn't already exists
101 If (-Not (Test-Path -Path $LogDir -PathType Container)) {
102 $LogDirObject = New-Item -Path $LogDir -ItemType Directory
103 }
104
Copy-FilesVerbosenull105 Function Copy-FilesVerbose {
106 [CmdletBinding()] Param (
107 [string] $source,
108 [string] $destination_directory
109 )
110 Write-Verbose ("Copying common files...")
111 Write-Verbose ("Copy: " + $source + " -> " + $destination_directory)
112 Copy-Item -Path $source -Destination $destination_directory -Recurse -Force
113 Write-Verbose("Done.")
114 }
115
116 ForEach ($PortSet in $PortSets) {
117 ForEach ($core in $cores) {
118 Switch ($PortSet) {
119 "tx" { $core_directory = "..\..\ports\" + $core }
120 "tx_smp" { $core_directory = "..\..\ports_smp\" + $core + "_smp" }
121 "txm" { $core_directory = "..\..\ports_module\" + $core }
122 "txm_smp" { $core_directory = "..\..\ports_module_smp\" + $core + "_smp" }
123 Default {}
124 }
125 ForEach ($compiler in $compilers) {
126 $compiler_directory = $core_directory + "\" + $compiler
127 Write-Verbose ("Compiler directory: $compiler_directory")
128 $compiler_directory_object = New-Item -Path $compiler_directory -ItemType "directory" -Force
129
130 $destination_directory = $compiler_directory
131
132 If ($CopyCommonFiles) {
133 Copy-FilesVerbose -source "threadx\common\*" -destination_directory $destination_directory
134 }
135
136 If ($CopyPortFiles) {
137 Copy-FilesVerbose -source "threadx\ports\$compiler\*" -destination_directory $destination_directory
138 }
139
140 If ($PortSet -eq 'tx_smp') {
141 If ($CopyCommonFiles) {
142 Copy-FilesVerbose -source "threadx_smp\common\*" -destination_directory $destination_directory
143 }
144 If ($CopyPortFiles) {
145 Copy-FilesVerbose -source "threadx_smp\ports\$compiler\*" -destination_directory $destination_directory
146 }
147 }
148
149 If ($PortSet -eq 'txm') {
150 }
151
152 If ($PortSet -eq 'txm_smp') {
153 }
154
155 If ($PatchFiles) {
156 ForEach ($patch in $patches) {
157 $core_short = $core -Replace "cortex_",""
158 $core_short_upper = $core_short.ToUpper()
159 $core_short_lower = $core_short.ToLower()
160 ForEach ($patch in $patches) {
161 $path = $destination_directory + "\" + $patch[0]
162 Write-Verbose("Patching file: $path")
163 If (Test-Path -Path $path -PathType leaf) {
164 $content = Get-Content -Path $path
165 ForEach ($replacement in $patch[1]) {
166 $original = $replacement[0]
167 $substitute = $replacement[1]
168 $original = $ExecutionContext.InvokeCommand.ExpandString($original)
169 $substitute = $ExecutionContext.InvokeCommand.ExpandString($substitute)
170 Write-Verbose("`tpatch: `"$original`" -> `"$substitute`"")
171 $content = $content -creplace $original,$substitute
172 }
173 Set-Content -Path $path -Value $content -Encoding ascii
174 Write-Verbose("Patched.")
175 } Else {
176 Write-Verbose("File not found.")
177 }
178 }
179 }
180 }
181 }
182 }
183 }
184