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
|
param(
[Parameter(Mandatory = $true)]
[string] $RascExe
)
$ErrorActionPreference = "Stop"
$bspRoot = $PSScriptRoot
$solutionPath = Join-Path $bspRoot "solution.xml"
$cpu0Bundle = Join-Path $bspRoot "m85\Objects\template.sbd"
$cpu1Bundle = Join-Path $bspRoot "m33\Objects\template.sbd"
$secureXmlPath = Join-Path $bspRoot ".secure_xml"
$secureAzonePath = Join-Path $bspRoot ".secure_azone"
$secureRzonePath = Join-Path $bspRoot ".secure_rzone"
$outputPath = Join-Path $bspRoot "build\ra8p1_titan_dualcore.sbd"
Add-Type -AssemblyName System.IO.Compression.FileSystem
function Save-XmlDocument
{
param(
[System.Xml.XmlDocument] $Document,
[string] $Path
)
$settings = New-Object System.Xml.XmlWriterSettings
$settings.Encoding = New-Object System.Text.UTF8Encoding($false)
$settings.Indent = $true
$settings.NewLineChars = "`r`n"
$writer = [System.Xml.XmlWriter]::Create($Path, $settings)
try
{
$Document.Save($writer)
}
finally
{
$writer.Dispose()
}
}
function Assert-SmartBundle
{
param(
[string] $Path,
[string] $ExpectedCore,
[string] $ExpectedTarget,
[string] $ExpectedFspVersion
)
$archive = [System.IO.Compression.ZipFile]::OpenRead($Path)
try
{
$entry = $archive.GetEntry("cfg/secure.xml")
if ($null -eq $entry)
{
throw "Smart Bundle '$Path' does not contain cfg/secure.xml."
}
$stream = $entry.Open()
$reader = New-Object System.IO.StreamReader($stream)
try
{
[xml] $configuration = $reader.ReadToEnd()
}
finally
{
$reader.Dispose()
$stream.Dispose()
}
$settings = $configuration.raConfiguration.generalSettings.option
$core = ($settings | Where-Object key -eq "Core").value
$target = ($settings | Where-Object key -eq "#TargetName#").value
$fspVersion = ($settings | Where-Object key -eq "#FSPVersion#").value
if ($core -ne $ExpectedCore -or $target -ne $ExpectedTarget -or $fspVersion -ne $ExpectedFspVersion)
{
throw "Smart Bundle '$Path' is $core/$target/FSP $fspVersion; expected $ExpectedCore/$ExpectedTarget/FSP $ExpectedFspVersion."
}
}
finally
{
$archive.Dispose()
}
}
if (-not (Test-Path -LiteralPath $cpu0Bundle))
{
throw "CPU0 Smart Bundle '$cpu0Bundle' does not exist. Build the m85 Keil project first."
}
if (-not (Test-Path -LiteralPath $cpu1Bundle))
{
throw "CPU1 Smart Bundle '$cpu1Bundle' does not exist. Build the m33 Keil project first."
}
[xml] $solution = Get-Content -Raw -LiteralPath $solutionPath
$targetName = ($solution.raSolution.generalSettings.option | Where-Object key -eq "#TargetName#").value
$fspVersion = ($solution.raSolution.generalSettings.option | Where-Object key -eq "#FSPVersion#").value
Assert-SmartBundle -Path $cpu0Bundle -ExpectedCore "CPU0" -ExpectedTarget $targetName -ExpectedFspVersion $fspVersion
Assert-SmartBundle -Path $cpu1Bundle -ExpectedCore "CPU1" -ExpectedTarget $targetName -ExpectedFspVersion $fspVersion
$secureXml = New-Object System.Xml.XmlDocument
$null = $secureXml.AppendChild($secureXml.CreateXmlDeclaration("1.0", "UTF-8", "no"))
$secureSolution = $secureXml.CreateElement("raSolution")
$secureSolution.SetAttribute("version", "12")
$null = $secureXml.AppendChild($secureSolution)
$null = $secureSolution.AppendChild($secureXml.ImportNode($solution.raSolution.generalSettings, $true))
$secureAzone = New-Object System.Xml.XmlDocument
$null = $secureAzone.AppendChild($secureAzone.CreateXmlDeclaration("1.0", "UTF-8", "yes"))
$azone = $secureAzone.CreateElement("azone")
$null = $secureAzone.AppendChild($azone)
$rzone = $secureAzone.CreateElement("rzone")
$rzone.SetAttribute("name", "$targetName.rzone")
$null = $azone.AppendChild($rzone)
$partition = $secureAzone.CreateElement("partition")
$null = $azone.AppendChild($partition)
foreach ($sourceMemory in $solution.raSolution.raPartitions.memory)
{
$memory = $secureAzone.CreateElement("memory")
foreach ($attributeName in @("parent", "name", "size", "offset", "security", "Pname"))
{
$memory.SetAttribute($attributeName, $sourceMemory.$attributeName)
}
if ($sourceMemory.userDefined -eq "true")
{
$memory.SetAttribute("info", "@user")
}
$null = $partition.AppendChild($memory)
}
$archive = [System.IO.Compression.ZipFile]::OpenRead($cpu0Bundle)
try
{
$entry = $archive.GetEntry("cfg/$targetName.rzone")
if ($null -eq $entry)
{
throw "Device resource '$targetName.rzone' is missing from '$cpu0Bundle'."
}
$inputStream = $entry.Open()
$outputStream = [System.IO.File]::Create($secureRzonePath)
try
{
$inputStream.CopyTo($outputStream)
}
finally
{
$outputStream.Dispose()
$inputStream.Dispose()
}
}
finally
{
$archive.Dispose()
}
try
{
Save-XmlDocument -Document $secureXml -Path $secureXmlPath
Save-XmlDocument -Document $secureAzone -Path $secureAzonePath
& $RascExe -nosplash --launcher.suppressErrors --gensolutionbundle --compiler ARMv6 --devicefamily ra --projectname ra8p1_titan_dualcore $solutionPath
if ($LASTEXITCODE -ne 0)
{
throw "FSP Smart Configurator failed with exit code $LASTEXITCODE."
}
if (-not (Test-Path -LiteralPath $outputPath))
{
throw "Solution Smart Bundle '$outputPath' was not generated."
}
Write-Output "Generated '$outputPath'."
}
finally
{
Remove-Item -LiteralPath $secureXmlPath, $secureAzonePath, $secureRzonePath -Force -ErrorAction SilentlyContinue
}
|