summaryrefslogtreecommitdiff
path: root/ports_arch/ARMv7-A/update.ps1
blob: 5c3e9905f1dbd6d1007ac2a4a9789470293d55ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<#
.SYNOPSIS
    Update the ARMv7-A ports from the generic ARMv7-A port.

.DESCRIPTION
    Generate ports, examples and tests from common files.

.EXAMPLE
    To update the ThreadX ports for the source tree run:
    pwsh -Command .\update.ps1 -PortSets tx -CopyCommonFiles -CopyPortFiles -CopyExample -PatchFiles

    To update the ThreadX ports for the test tree run:
    pwsh -Command .\update.ps1 -PortSets tx -CopyCommonFiles -CopyPortFiles -CopyExample -CopyValidationTest -CopyRegressionTest -PatchFiles

.LINK
    https://azure.com/rtos

.NOTES
    Author: Andres Mlinar
    Date:   2021
#>

[CmdletBinding(PositionalBinding=$false)] Param(

    [string]
    #The script root directory, if not specified it defaults to this script's directory
    $ScriptDir = $PSScriptRoot,

    [Parameter(Mandatory)]
    [ValidateSet(
        "tx", "tx_smp",
        "txm", "txm_smp"
    )]
    [string[]]
    #Specify the flavor or flavors of ThreadX to generate. Options are: tx, tx_smp, txm, txm_smp
    $PortSets,

    [switch]
    #Copy common files
    $CopyCommonFiles = $false,

    [switch]
    #Copy port files
    $CopyPortFiles = $false,

    [switch]
    #Copy the example
    $CopyExample = $false,

    [switch]
    #Copy the validation tests
    $CopyValidationTest = $false,

    [switch]
    #Copy the regression tests
    $CopyRegressionTest = $false,

    [switch]
    #Copy port files
    $PatchFiles = $false,

    [string]
    #The output log directory
    $LogDir = $( Join-Path $PSScriptRoot 'log' )

)

Write-Host "Update the ARMv7-A ports"

Write-Verbose ("Script directory: $ScriptDir")
Write-Verbose ("Port sets: $PortSets")
Write-Verbose ("Copy common files: $CopyCommonFiles")
Write-Verbose ("Copy port files: $CopyPortFiles")
Write-Verbose ("Copy example: $CopyExample")
Write-Verbose ("Copy validation test: $CopyValidationTest")
Write-Verbose ("Copy regression test: $CopyRegressionTest")
Write-Verbose ("Patch files: $PatchFiles")
Write-Verbose ("LogDir: $LogDir")

$cores = @("cortex_a5", "cortex_a7", "cortex_a8", "cortex_a9", "cortex_a12", "cortex_a15", "cortex_a17")
$compilers = @("ac6", "gnu")
#$compilers = @("ac5", "ac6", "gnu", "iar")
$patches = (
    ('example_build\sample_threadx\.cproject', (
        ('value=`"cortex-a7`"', 'value=`"cortex-$($core_short_lower)`"'),
        ('Cortex-A7.NoFPU', 'Cortex-$($core_short_upper).NoFPU')
    )),
    ('example_build\tx\.cproject', (
        ('value=`"cortex-a7`"', 'value=`"cortex-$($core_short_lower)`"'),
        ('Cortex-A7.NoFPU', 'Cortex-$($core_short_upper).NoFPU')
    )),
    ('example_build\sample_threadx\sample_threadx.launch', (
        ('Debug Cortex-A7', 'Debug Cortex-$($core_short_upper)'),
        ('VE_Cortex_A7x1', 'VE_Cortex_$($core_short_upper)x1'),
        ('ve_cortex_a7x1', 've_cortex_$($core_short_lower)x1'),
		('FVP_VE_Cortex-A7x1', 'FVP_VE_Cortex-$($core_short_upper)x1')
    ))
)

# Create the log directory if it doesn't already exists
If (-Not (Test-Path -Path $LogDir -PathType Container)) {
    $LogDirObject = New-Item -Path $LogDir -ItemType Directory
}

Function Copy-FilesVerbose {
    [CmdletBinding()] Param (
        [string] $source,
        [string] $destination_directory
    )
    Write-Verbose ("Copying common files...")
    Write-Verbose ("Copy: " + $source + " -> " + $destination_directory)
    Copy-Item -Path $source -Destination $destination_directory -Recurse -Force
    Write-Verbose("Done.")
}

ForEach ($PortSet in $PortSets) {
    ForEach ($core in $cores) {
        Switch ($PortSet) {
            "tx" { $core_directory = "..\..\ports\" + $core }
            "tx_smp" { $core_directory = "..\..\ports_smp\" + $core + "_smp" }
            "txm" { $core_directory = "..\..\ports_module\" + $core }
            "txm_smp" { $core_directory = "..\..\ports_module_smp\" + $core + "_smp" }
            Default {}
        }
        ForEach ($compiler in $compilers) {
            $compiler_directory = $core_directory + "\" + $compiler
            Write-Verbose ("Compiler directory: $compiler_directory")
            $compiler_directory_object = New-Item -Path $compiler_directory -ItemType "directory" -Force

            $destination_directory = $compiler_directory

            If ($CopyCommonFiles) {
                Copy-FilesVerbose -source "threadx\common\*" -destination_directory $destination_directory
            }

            If ($CopyPortFiles) {
                Copy-FilesVerbose -source "threadx\ports\$compiler\*" -destination_directory $destination_directory
            }

            If ($PortSet -eq 'tx_smp') {
                If ($CopyCommonFiles) {
                    Copy-FilesVerbose -source "threadx_smp\common\*" -destination_directory $destination_directory
                }
                If ($CopyPortFiles) {
                    Copy-FilesVerbose -source "threadx_smp\ports\$compiler\*" -destination_directory $destination_directory
                }
            }

            If ($PortSet -eq 'txm') {
            }

            If ($PortSet -eq 'txm_smp') {
            }

            If ($PatchFiles) {
                ForEach ($patch in $patches) {
                    $core_short = $core -Replace "cortex_",""
                    $core_short_upper = $core_short.ToUpper()
                    $core_short_lower = $core_short.ToLower()
                    ForEach ($patch in $patches) {
                        $path = $destination_directory + "\" + $patch[0]
                        Write-Verbose("Patching file: $path")
                        If (Test-Path -Path $path -PathType leaf) {
                            $content = Get-Content -Path $path
                            ForEach ($replacement in $patch[1]) {
                                $original = $replacement[0]
                                $substitute = $replacement[1]
                                $original = $ExecutionContext.InvokeCommand.ExpandString($original)
                                $substitute = $ExecutionContext.InvokeCommand.ExpandString($substitute)
                                Write-Verbose("`tpatch: `"$original`" -> `"$substitute`"")
                                $content = $content -creplace $original,$substitute
                            }
                            Set-Content -Path $path -Value $content -Encoding ascii
                            Write-Verbose("Patched.")
                        } Else {
                            Write-Verbose("File not found.")
                        }
                    }
                }
            }
        }
    }
}