blob: 4e343b71ffcf42409eb8b8c9cc1ef99abcefd4c3 [file] [log] [blame]
yu.dongc33b3072024-08-21 23:14:49 -07001#!/usr/bin/perl
2#
3# Copyright Statement:
4# --------------------
5# This software is protected by Copyright and the information contained
6# herein is confidential. The software may not be copied and the information
7# contained herein may not be used or disclosed except with the written
8# permission of MediaTek Inc. (C) 2006
9#
10# BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
11# THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
12# RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
13# AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
14# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
15# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
16# NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
17# SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
18# SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
19# THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
20# NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
21# SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
22#
23# BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
24# LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
25# AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
26# OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
27# MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
28#
29# THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
30# WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
31# LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
32# RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
33# THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
34#
35#*****************************************************************************
36#*
37#* Filename:
38#* ---------
39#* scatGenFOTA.pl
40#*
41#* Project:
42#* --------
43#*
44#*
45#* Description:
46#* ------------
47#* This script designed as module to be include by top level perl script
48#*
49#* Author:
50#* -------
51#* Claudia Lo (mtk01876)
52#*
53#*
54#****************************************************************************/
55#use strict;
56BEGIN { push @INC, "pcore/" , './pcore/tools/' } # add additional library path
57use sysGenUtility; #pm file name without case sensitivity
58
59my $nfb;
60my $scatter_maui;
61my $fota_cfg_href;
62
631;
64
65#****************************************************************************
66# MAIN INTERFACE
67# input:
68#****************************************************************************
69sub scatGenFOTA_main
70{
71 my ($func, $bb, $rs, $fota_cfg, $bb_path, $scatter) = @_;
72
73 my $nand_flash_booting = &$func('nand_flash_booting');
74 my $emmc_booting = &$func('emmc_booting');
75 $nfb = "NONE";
76 if ((defined $nand_flash_booting) and ($nand_flash_booting ne "NONE"))
77 {
78 $nfb = $nand_flash_booting;
79 }
80 elsif ((defined $emmc_booting) and ($emmc_booting ne "NONE"))
81 {
82 $nfb = $emmc_booting;
83 }
84 $scatter_maui = $scatter;
85 $fota_cfg_href = $fota_cfg;
86
87 # SW Feature dispatch decision tree
88 my $output_result = &layout_fota($bb, $rs, $nfb);
89
90 # Finally , return output
91 return $output_result;
92}
93
94#****************************************************************************
95# subroutine: FOTA Scatter Layout <Class>
96# return: the body strings
97#****************************************************************************
98sub layout_fota
99{
100 my ($bb, $rs, $nfb) = @_;
101
102 # --- --- ---
103 my ($emiinitcode_base, $intsram_base, $itcm_base, $dtcm_base, $sysram_base, $sysram_size, $hidden_secure_mac_base);
104 open (SCATTER_H, "<$scatter_maui") or &sysUtil::sysgen_die("$scatter_maui: file error!", __FILE__, __LINE__);
105 while (<SCATTER_H>)
106 {
107 if (/\s*EMIINIT_CODE\s*(0x\w+)\s*\w*\s*(0x\w+)*/)
108 {
109 $emiinitcode_base = $1;
110 }
111 if (/\s*INTSRAM\s*(0x\w+)\s*\w*\s*(0x\w+)/)
112 {
113 $intsram_base = $1;
114 }
115 if (/\s*INTSRAM_CODE\s*(0x\w+)\s*\w*\s*(0x\w+)/)
116 {
117 $itcm_base = $1;
118 }
119 if (/\s*INTSRAM_DATA\s*(0x\w+)\s*\w*\s*(0x\w+)/)
120 {
121 $dtcm_base = $1;
122 }
123 if (/\s*INTSRAM_MULTIMEDIA\s*(0x\w+)\s*\w*\s*(0x\w+)/)
124 {
125 $sysram_base = $1;
126 $sysram_size = $2;
127 }
128 if (/^__HIDDEN_SECURE_MAC\s*(0x\w+)\s*\w*/ or /^__HIDDEN_SECURE_MAC\s*(\+0x\w+)\s*\w*/)
129 {
130 $hidden_secure_mac_base = $1;
131 }
132 }
133 close (SCATTER_H) or &sysUtil::sysgen_die("$scatter_maui: file error!", __FILE__, __LINE__);
134
135 # --- --- ---
136 my $ua_rom_base = $fota_cfg_href->{'FOTA_UE_EXECUTION_BASE'};
137 my $ua_rom_size = $fota_cfg_href->{'CONFIG_FOTA_UE_FLASH_SPACE'};
138
139 # --- --- ---
140 my ($ua_intsram_code_base, $ua_intsram_data_base);
141 if (defined $emiinitcode_base)
142 {
143 $ua_intsram_code_base = $emiinitcode_base;
144 if ((defined $sysram_base) and ($nfb eq 'NONE'))
145 {
146 $ua_intsram_data_base = sprintf("0x%08X", hex($sysram_base));
147 }
148 elsif (defined $dtcm_base)
149 {
150 $ua_intsram_data_base = $dtcm_base
151 }
152 }
153 elsif (defined $itcm_base)
154 {
155 $ua_intsram_code_base = $itcm_base;
156 if ((defined $sysram_base) and ($nfb eq 'NONE'))
157 {
158 $ua_intsram_data_base = sprintf("0x%08X", hex($sysram_base));
159 }
160 elsif (defined $dtcm_base)
161 {
162 $ua_intsram_data_base = $dtcm_base
163 }
164 else
165 {
166 $ua_intsram_data_base = sprintf("0x%08X", hex($itcm_base) + hex('0x8000'));
167 }
168 }
169 elsif (defined $intsram_base)
170 {
171 $ua_intsram_code_base = $intsram_base;
172 if ((defined $sysram_base) and ($nfb eq 'NONE'))
173 {
174 $ua_intsram_data_base = sprintf("0x%08X", hex($sysram_base));
175 }
176 else
177 {
178 $ua_intsram_data_base = sprintf("0x%08X", hex($intsram_base) + hex('0x8000'));
179 }
180 }
181 elsif (defined $sysram_base)
182 {
183 $ua_intsram_code_base = sprintf("0x%08X", hex($sysram_base));
184 $ua_intsram_data_base = sprintf("0x%08X", hex($sysram_base) + hex('0x8000'));
185 }
186
187 # --- --- ---
188 my ($bl_ua_shared_sys_ram_base, $ua_maui_shared_sys_ram_base);
189 if (defined $sysram_base)
190 {
191 $bl_ua_shared_sys_ram_base = $sysram_base;
192 $ua_maui_shared_sys_ram_base = sprintf("0x%08X", hex($sysram_base) + hex($sysram_size) - hex('0x1000'));
193 }
194 else
195 {
196 &sysUtil::sysgen_die("pcore/tools/scatGenFOTA.pl: No SysRAM to put BL_UA_SHARED_SYS_RAM and UA_MAUI_SHARED_SYS_RAM!", __FILE__, __LINE__)
197 if ($nfb ne 'NONE');
198 }
199
200 # --- --- ---
201 my $ev_ua_rom = &layout_ua_rom_ev($nfb, $bb, $ua_rom_base, $ua_rom_size, $ua_intsram_code_base, $ua_intsram_data_base, $bl_ua_shared_sys_ram_base, $ua_maui_shared_sys_ram_base);
202 my $hidden_secure_mac = &layout_hidden_secure_mac($bb, $hidden_secure_mac_base);
203 chomp $hidden_secure_mac;
204
205 # --- --- ---
206 my $layout = <<"__LAYOUT";
207UA_ROM $ua_rom_base $ua_rom_size
208{
209$ev_ua_rom
210}
211
212$hidden_secure_mac
213
214__LAYOUT
215
216 return $layout;
217}
218
219#****************************************************************************
220# subroutine: FOTA Layout :: UA_ROM :: Exec View
221# input: BB chip, ram size [value]
222#****************************************************************************
223sub layout_ua_rom_ev
224{
225 my ($nfb, $bb, $ua_rom_base, $ua_rom_size, $ua_intsram_code_base, $ua_intsram_data_base, $bl_ua_shared_sys_ram_base, $ua_maui_shared_sys_ram_base) = @_;
226
227 # --- --- ---
228 my $ua_noncached_base;
229 if ($nfb ne 'NONE')
230 {
231 $ua_noncached_base = sprintf("0x%08X", hex($ua_rom_base) - hex('0x200000')); # The last 2MB of UA_ROM
232 }
233 else
234 {
235 $ua_noncached_base = sprintf("0x%08X", hex($ua_rom_base) - hex('0x100000')); # The last 1MB of UA_ROM
236 }
237
238 # --- --- ---
239 # In TCM only platform (Arm7), the UA_INTSRAM_CODE and UA_INTSRAM_DATA are from MAUI. FUE may fail to link if the partition for MAUI is not suitable for FUE.
240 # So FUE CODE/DATA partition should be independent from MAUI
241 my ($ua_intsram_code_base_final, $ua_intsram_code_size_final, $ua_intsram_data_base_final, $ua_intsram_data_size_final);
242 if (&sysUtil::is_arm9($bb) == 1 or &sysUtil::is_arm11($bb)==1 )
243 {
244 $ua_intsram_code_base_final = $ua_intsram_code_base;
245 $ua_intsram_code_size_final = '0x8000';
246 $ua_intsram_data_base_final = $ua_intsram_data_base;
247 $ua_intsram_data_size_final = '0x2000';
248 }
249 else
250 {
251 $ua_intsram_code_base_final = $ua_intsram_code_base;
252 $ua_intsram_code_size_final = undef;
253 $ua_intsram_data_base_final = '+0x0';
254 $ua_intsram_data_size_final = undef;
255 }
256
257 # --- --- ---
258 my @ua_init_libs = split("\n", &UA_INIT_EV());
259 map { s/^\s+//; } @ua_init_libs;
260
261 my @ua_rom_libs = split("\n", &UA_ROM_EV());
262 map { s/^\s+//; } @ua_rom_libs;
263
264 my @ua_noncached_libs = split("\n", &UA_NONCACHED_EV());
265 map { s/^\s+//; } @ua_noncached_libs;
266
267 my @ua_rw_libs = split("\n", &UA_RW_EV());
268 map { s/^\s+//; } @ua_rw_libs;
269
270 my @ua_intsram_code_libs = split("\n", &UA_INTSRAM_CODE_EV());
271 map { s/^\s+//; } @ua_intsram_code_libs;
272
273 my @ua_intsram_data_libs = split("\n", &UA_INTSRAM_DATA_EV());
274 map { s/^\s+//; } @ua_intsram_data_libs;
275
276 my @bl_ua_shared_sys_ram_libs = split("\n", &BL_UA_SHARED_SYS_RAM_EV());
277 map { s/^\s+//; } @bl_ua_shared_sys_ram_libs;
278
279 # --- --- ---
280 my $template;
281 if (&sysUtil::is_sv5($bb) == 1)
282 {
283 $template .= &format_execution_view('UA_GFH_SECTION',
284 '+0x0',
285 undef,
286 ["* (FUE_GFH, +First)"]);
287 }
288 $template .= &format_execution_view('UA_INIT',
289 '+0x0',
290 '0x400',
291 \@ua_init_libs);
292 $template .= &format_execution_view('UA_ROM',
293 '+0x0',
294 undef,
295 \@ua_rom_libs);
296 $template .= &format_execution_view('UA_RW',
297 '+0x1000',
298 undef,
299 \@ua_rw_libs);
300 $template .= &format_execution_view('UA_NONCACHED',
301 $ua_noncached_base,
302 undef,
303 \@ua_noncached_libs);
304 $template .= &format_execution_view('UA_CUSTOM_ZI',
305 '0x1000',
306 undef,
307 ["*.obj (FOTA_CUSTOM_POOL)"]);
308 $template .= &format_execution_view('UA_BL_INFO',
309 '0x0',
310 '0x80',
311 ["*.obj (FOTA_BL_INFO)"]);
312 $template .= &format_execution_view('UA_INTSRAM_CODE',
313 $ua_intsram_code_base_final,
314 $ua_intsram_code_size_final,
315 \@ua_intsram_code_libs);
316 $template .= &format_execution_view('UA_RESIDENT_PART',
317 '+0x0',
318 undef,
319 ["*.obj (FOTA_RESIDENT_PART) ;for codes that are used to load Primary ROM image"]);
320 $template .= &format_execution_view('UA_INTSRAM_DATA',
321 $ua_intsram_data_base_final,
322 $ua_intsram_data_size_final,
323 \@ua_intsram_data_libs);
324 if ($nfb ne 'NONE')
325 {
326 $template .= &format_execution_view('BL_UA_SHARED_SYS_RAM',
327 $bl_ua_shared_sys_ram_base,
328 '0x2000',
329 \@bl_ua_shared_sys_ram_libs);
330 $template .= &format_execution_view('UA_MAUI_SHARED_SYS_RAM',
331 $ua_maui_shared_sys_ram_base,
332 '0x1000',
333 ["fue_partial_fota.obj (FUE_NFB_SHARED_ZI)"]);
334 }
335 if (&sysUtil::is_sv5($bb) == 1)
336 {
337 $template .= &format_execution_view('UA_GFH_SIGNATURE_SECTION',
338 '+0x0',
339 undef,
340 ["* (FUE_SIGNATURE_SECTION)"]);
341 }
342 chomp $template;
343 return $template;
344}
345
346#****************************************************************************
347# subroutine: Layout :: __HIDDEN_SECURE_MAC :: Load View
348# input: BB chip, ram size [value]
349#****************************************************************************
350sub layout_hidden_secure_mac
351{
352 my ($bb, $base_str) = @_;
353
354 return if (&sysUtil::is_sv5($bb) == 1 or $base_str eq "");
355
356 my $layout = <<"__LAYOUT";
357;=========================================================================
358; This load region must be behind all the protected load region
359;=========================================================================
360; do NOT modify load region naming and pragma naming!
361;=========================================================================
362
363__HIDDEN_SECURE_MAC $base_str
364{
365 __HIDDEN_SECURE_MAC_CONTENT +0x0
366 {
367 *.obj (SECURE_MAC_CONTENT)
368 }
369 __HIDDEN_SECURE_MAC +0x0
370 {
371 *.obj (SECURE_MAC_SIZE)
372 }
373}
374__LAYOUT
375
376 return $layout;
377}
378
379#****************************************************************************
380# subroutine: Layout :: UA_INIT
381# return: the body strings
382#****************************************************************************
383sub UA_INIT_EV
384{
385 my $template = <<"__TEMPLATE";
386 fue_bootarm.obj (C\$\$code, +First)
387 fue_bootarm.obj (+RO)
388 *.obj (FOTA_SECINFO)
389__TEMPLATE
390
391 return $template;
392}
393
394#****************************************************************************
395# subroutine: Layout :: UA_ROM
396# return: the body strings
397#****************************************************************************
398sub UA_ROM_EV
399{
400 my $template = <<"__TEMPLATE";
401 *.obj (UA_HEAD, +First)
402 * (+RO)
403 libmprove610_MTKarm7_tcc.a (+RO)
404__TEMPLATE
405
406 return $template;
407}
408
409#****************************************************************************
410# subroutine: Layout :: UA_NONCACHED
411# return: the body strings
412#****************************************************************************
413sub UA_NONCACHED_EV
414{
415 my $template = <<"__TEMPLATE";
416 *.obj (PAGETABLE)
417 *.obj (NONCACHEDZI)
418__TEMPLATE
419
420 return $template;
421}
422
423#****************************************************************************
424# subroutine: Layout :: UA_RW
425# return: the body strings
426#****************************************************************************
427sub UA_RW_EV
428{
429 my $template = <<"__TEMPLATE";
430 * (+RW, +ZI)
431 libmprove610_MTKarm7_tcc.a (+RW, +ZI)
432 *.obj (FUE_EXT_SRAM)
433__TEMPLATE
434
435 return $template;
436}
437
438#****************************************************************************
439# subroutine: Layout :: UA_INTSRAM_CODE
440# return: the body strings
441#****************************************************************************
442sub UA_INTSRAM_CODE_EV
443{
444 my $template = <<"__TEMPLATE";
445 flash_mtd.obj (+RO)
446 flash_mtd.amd.obj (+RO)
447 flash_mtd.intel.obj (+RO)
448 *.obj (INTERNCODE) ;for codes that are used to load Primary ROM image
449__TEMPLATE
450
451 return $template;
452}
453
454#****************************************************************************
455# subroutine: Layout :: UA_INTSRAM_DATA
456# return: the body strings
457#****************************************************************************
458sub UA_INTSRAM_DATA_EV
459{
460 my $template = <<"__TEMPLATE";
461 fue_bootarm.obj (STACK_POOL_INTSRAM)
462 *.obj (INTERNZI)
463__TEMPLATE
464
465 return $template;
466}
467
468#****************************************************************************
469# subroutine: NFB Layout :: BL_UA_SHARED_SYS_RAM
470# return: the body strings
471#****************************************************************************
472sub BL_UA_SHARED_SYS_RAM_EV
473{
474 my $template = <<"__TEMPLATE";
475 *.obj (BL_FUE_SHARED_ZI, +First)
476__TEMPLATE
477
478 return $template;
479}
480#****************************************************************************
481# subroutine: Get TCM information
482# input: BB chip
483# return: ITCM: base address, size DTCM: base address size
484#****************************************************************************
485sub Get_TCM_info
486{
487 my ($bb) = @_;
488 my ($strCODEBase, $strCODESize, $strDATABase, $strDATASize);
489 my %BB_INTSRAM_tbl =
490 ( # $bb => [INTSRAM_CODE_Base, INTSRAM_CODE_Size, INTSRAM_DATA_Base, INTSRAM_DATA_Size]
491 'MT6235' => ["0x50000000", "0x0000C000", "0x50100000", "0x00014000"],
492 'MT6235B' => ["0x50000000", "0x0000C000", "0x50100000", "0x00014000"], #MT6235
493 'MT6236' => ["0x50000000", "0x00010000", "0x50100000", "0x0002B000"],
494 'MT6236B' => ["0x50000000", "0x00010000", "0x50100000", "0x0002B000"], #MT6236
495 'MT6268' => ["0x50000000", "0x00026000", "0x50100000", "0x0001B000"],
496 'MT6255' => ["0x50000000", "0x00010000", "0x50100000", "0x0002B000"],
497 );
498 if(exists $BB_INTSRAM_tbl{$bb})
499 {
500 $strCODEBase = $BB_INTSRAM_tbl{$bb}[0];
501 $strCODESize = $BB_INTSRAM_tbl{$bb}[1];
502 $strDATABase = $BB_INTSRAM_tbl{$bb}[2];
503 $strDATASize = $BB_INTSRAM_tbl{$bb}[3];
504 }
505 else
506 {
507 ($strCODEBase, $strCODESize, $strDATABase, $strDATASize) = &sysUtil::GetIntsramInfo($bb);
508 }
509 $strCODEBase = "(kal_uint32)&Image\$\$UA_INTSRAM_CODE\$\$Base" if (&sysUtil::is_CR4($bb));
510 $strCODESize = "(kal_uint32)&Image\$\$UA_INTSRAM_CODE\$\$Length" if (&sysUtil::is_CR4($bb));
511 $strDATABase = "(kal_uint32)&Image\$\$UA_INTSRAM_DATA\$\$Base" if (&sysUtil::is_CR4($bb));
512 $strDATASize = "(kal_uint32)&Image\$\$UA_INTSRAM_DATA\$\$Length" if (&sysUtil::is_CR4($bb));
513
514 return ($strCODEBase, $strCODESize, $strDATABase, $strDATASize);
515}
516#****************************************************************************
517# subroutine: Execution View Generator
518# input: Region name [string], Begin [string], Length [string], Content [Array Reference]
519# output: execution view body string
520#****************************************************************************
521sub format_execution_view
522{
523 my ($name, $begin, $length, $ar) = @_;
524 my $formated_string = ' ' x 4 . $name . " $begin $length\n";
525 $formated_string .= ' ' x 4 . "{\n";
526 foreach (@$ar)
527 {
528 $formated_string .= ' ' x 9 . $_ . "\n";
529 }
530 $formated_string .= ' ' x 4 . "}\n";
531 return $formated_string;
532}