Subversion Repositories DevTools

Rev

Rev 5732 | Rev 5783 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5677 dpurdie 1
#..
2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
3
#
4
# Module name   : CORTEXM3_IAR.PL
5
# Module type   : Makefile system
6
# Compiler(s)   : ANSI C
7
# Environment(s): Atmel AVR
8
#
9
# Description:
10
#       This file provides Toolset initialisation and plugin functions
11
#       to makelib.pl2
12
#
13
# Contents:     IAR rules as used for the CORTEXM3
14
#               Similar to the AVR_IAR
15
#
16
#............................................................................#
17
 
18
use strict;
19
use JatsVersionUtils;
20
 
21
our $s;
22
our $o;
23
our $so;
24
our $exe;
25
my $ToolSetName = 'cortexm3_iar';
26
 
27
##############################################################################
28
#   ToolsetInit()
29
#       Runtime initialisation
30
#
31
##############################################################################
32
 
33
ToolsetInit();
34
 
35
sub ToolsetInit
36
{
37
    my( @args ) = @::ScmToolsetArgs;             # Toolset arguments
38
    my( $version, $product, @defines, @dirs, @flags, @asflags, @asdefines );
39
    my $productFound;
40
 
41
    #.. Parse arguments
42
    #
43
    Debug( "$ToolSetName:(@args)\n" );
44
 
45
    foreach $_ ( @args ) {
46
        if (/^--Version=(.*)/) {                # Compiler version
47
            $version = "$1";
48
        } else {
49
            Message( "$ToolSetName: unknown toolset argument $_ -- ignored\n" );
50
        }
51
    }
52
 
53
    #.. Parse Platform Arguments
54
    #
55
    @args = @::ScmPlatformArgs;                 # Platform arguments
56
    foreach $_ ( @args ) {
57
        if (/^--product=(.*)/) {                # GBE product
58
            $product = $1;
59
        } else {
60
            Message( "$ToolSetName: unknown platform argument $_ -- ignored\n" );
61
        }
62
    }
63
 
64
    #
65
    #   Definitions common to all products
66
    #   These will be picked up when no platform has been defined
67
    #
68
    push @defines, 'JATS_BUILD';
5680 dpurdie 69
    push @dirs,    '$(COMPILER_HOME_AVR)/inc/c';
5677 dpurdie 70
    push @dirs,    '$(COMPILER_HOME_AVR)/inc';
71
 
72
    #
73
    #   Platform specific definitions
74
    #
75
    if ( $product eq "MS6001" )
76
    {
77
        $productFound = $product;
5680 dpurdie 78
        #push @flags , '--eeprom_size=32768';
5677 dpurdie 79
 
80
        #   Compiler flags and definitions
5679 dpurdie 81
        push @defines, '_MS6001';
5677 dpurdie 82
 
83
        #   Assembler flags and definitions
84
        push @asdefines, '_MS6001';
85
    }
86
    elsif ( $product )
87
    {
88
        Message( "$ToolSetName: Unknown product: $product -- ignored\n" );
89
    }
90
 
91
    # common flags
92
    if ( $productFound )
93
    {
94
        #
95
        #   Compiler flags and definitions
96
        #
5680 dpurdie 97
       push @flags , '--endian=little';
98
       push @flags , '--cpu=Cortex-M3';
5726 dpurdie 99
       push @flags , '--diag_suppress=Pa050,Pa091';
5680 dpurdie 100
       push @flags , '-e';
101
       push @flags , '--fpu=None';
102
       push @flags , '-Oh';
103
       push @flags , '--vla';
104
       push @flags , '--require_prototypes';
5726 dpurdie 105
       #push @flags , '--discard_unused_publics';
106
       #push @flags , '--mfc';
107
       push @flags , '--remarks';
5680 dpurdie 108
       push @flags , '--dlib_config=DLib_Config_Normal.h';
5732 dpurdie 109
#       push @flags, '-lC $(OBJDIR)';
110
#       push @flags, '-lA $(OBJDIR)';
5677 dpurdie 111
 
5680 dpurdie 112
       # Defines
5726 dpurdie 113
       #push @defines, 'xxxxxx';
5677 dpurdie 114
 
5680 dpurdie 115
 
5677 dpurdie 116
        #
117
        #   Assembler flags and definitions
118
        #
5679 dpurdie 119
#       push @asflags , '-v6';                  # processor configuration
120
#       push @asflags , '-s+';                  # Case-sensitive user symbols
121
#       push @asflags , '-t8';                  # tab spacing...
122
#       push @asflags , '-u_enhancedCore';      # enable AVR-specific enhanced instructions
5677 dpurdie 123
 
5680 dpurdie 124
#       push @asdefines, '__MEMORY_MODEL__=2';
125
#       push @asdefines, '__HAS_ELPM__=1 ';
126
#       push @asdefines, '__HAS_ENHANCED_CORE__=1 ';
127
#       push @asdefines, 'ASSEMBLER';
5677 dpurdie 128
    }
129
 
130
    #.. Standard.rul requirements
131
    #
5732 dpurdie 132
    $s = 's';               # Assembler source file
133
    $o = 'o';               # Object file
134
    $a = 'a';               # Library file
5677 dpurdie 135
    $so = '';               # Shared library
5732 dpurdie 136
    $exe = '.srec';         # Linked binary images
5677 dpurdie 137
 
138
    AddSourceType( ".$s", '.asm' );
139
 
140
 
141
    #.. Toolset configuration
142
    #
143
    $::ScmToolsetVersion = "1.0.0";               # our version
144
    $::ScmToolsetGenerate = 0;                    # generate optional
145
    $::ScmToolsetProgDependancies = 0;            # handle Prog dependancies myself
146
 
147
#.. Cleanup rules
148
#
5680 dpurdie 149
#   Files that appear to be created by the compiler
5677 dpurdie 150
#
5680 dpurdie 151
   ToolsetGenerate( '$(OBJDIR)/tmp*' );
152
   ToolsetGenerate( '$(LIBDIR)/tmp*' );
153
   ToolsetGenerate( '$(BINDIR)/tmp*' );
5677 dpurdie 154
 
155
    #.. Define IAR environment
156
    #
157
    #
158
    #   Define initialisation targets
159
    #   These will be used to ensure that correct versions of the toolset are present
160
    #   Retain 'avr_air' so we can reuse the .RUL file
161
    #
162
    Init( "cortexm3" );
163
 
164
    ToolsetDefine ( "#################################################" );
165
    ToolsetDefine ( "# CORTEX IAR compiler version" );
166
    ToolsetDefine ( "#" );
167
    ToolsetDefine ( "avr_iar_ver         = $version" );
168
    ToolsetDefine ( "avr_iar_prod        = $product" );
169
    ToolsetDefine ( "" );
170
    ToolsetDefine ( "#" );
5679 dpurdie 171
    ToolsetDefines( "cortexm3_iar.def" );
5677 dpurdie 172
    ToolsetRules  ( "avr_iar.rul" );
173
    ToolsetRules  ( "standard.rul" );
174
 
175
    #
176
    #   Specify compiler parameters
177
    #   Note: AVR_IAR_INCLUDES is ";" seperated as it may contain spaces
178
    #         when expanded ("Program Files")
179
    #
180
 
181
    PlatformEntry( "AVR_IAR_DEFINES\t=",    "\n", "\\\n\t", "", @defines )
182
        if ( scalar @defines );
183
    PlatformEntry( "AVR_IAR_INCLUDES\t=",    "\n", "\\\n\t", ";", @dirs )
184
        if ( scalar @dirs );
185
    PlatformEntry( "AVR_IAR_FLAGS\t=",    "\n", "\\\n\t", "", @flags )
186
        if ( scalar @flags );
187
 
188
    PlatformEntry( "AVR_IAR_ASFLAGS\t=",    "\n", "\\\n\t", "", @asflags )
189
        if ( scalar @asflags );
190
    PlatformEntry( "AVR_IAR_ASDEFINES\t=",    "\n", "\\\n\t", "", @asdefines )
191
        if ( scalar @asdefines );
192
 
193
}
194
 
195
 
196
##############################################################################
197
#   ToolsetPreprocess()
198
#       Process collected data before the makefile is generated
199
#       This, optional, routine is called from within MakefileGenerate()
200
#       It allows the toolset to massage any of the collected data before
201
#       the makefile is created
202
#
203
##############################################################################
204
 
205
#sub ToolsetPreprocess
206
#{
207
#}
208
 
209
###############################################################################
210
#   ToolsetCC( $source, $obj, \@args )
211
#       This subroutine takes the user options and builds the rule(s)
212
#       required to compile the source file 'source' to 'obj'
213
#
214
###############################################################################
215
 
216
sub ToolsetCC
217
{
218
    MakePrint( "\n\t\$(CC)\n" );
219
}
220
 
221
###############################################################################
222
#   ToolsetCCDepend( $depend, \@sources )
223
#       This subroutine takes the user options and builds the
224
#       rule(s) required to build the dependencies for the source
225
#       files 'sources' to 'depend'.
226
#
227
###############################################################################
228
 
229
sub ToolsetCCDepend
230
{
231
    MakePrint( "\t\$(CCDEPEND)\n" );
232
}
233
 
234
 
235
###############################################################################
236
#   ToolsetCXX( $source, $obj, \@args )
237
#       This subroutine takes the user options and builds the rule(s)
238
#       required to compile the source file 'source' to 'obj'
239
#
240
###############################################################################
241
 
242
sub ToolsetCXX
243
{
244
    MakePrint( "\n\t\$(CXX)\n" );
245
}
246
 
247
###############################################################################
248
#   ToolsetCXXDepend( $depend, \@sources )
249
#       This subroutine takes the user options and builds the
250
#       rule(s) required to build the dependencies for the source
251
#       files 'sources' to 'depend'.
252
#
253
###############################################################################
254
 
255
sub ToolsetCXXDepend
256
{
257
    ToolsetCCDepend();
258
}
259
 
260
 
261
###############################################################################
262
#   ToolsetAS( $source, $obj, \@args )
263
#       This subroutine takes the user options and builds the rule(s)
264
#       required to compile the source file 'source' to 'obj'
265
#
266
###############################################################################
267
 
268
sub ToolsetAS
269
{
270
    MakePrint( "\n\t\$(AS)\n" );
271
}
272
 
273
sub ToolsetASDepend
274
{
275
}
276
 
277
###############################################################################
278
#   ToolsetAR( $name, \@args, \@objs )
279
#       This subroutine takes the user options and builds the rules
280
#       required to build the library 'name'.
281
 
282
#
283
#   Arguments:
284
#       --xxx                   No arguments currently defined
285
#
286
#   Output:
287
#       [ $(BINDIR)/name$.${a}:   .... ]
288
#           $(AR)
289
#
290
###############################################################################
291
 
292
sub ToolsetAR
293
{
294
    my( $name, $pArgs, $pObjs ) = @_;
295
 
296
    Debug("ToolsetAR");
297
 
298
#.. Parse arguments
299
#
300
    foreach $_ ( @$pArgs ) {
301
        if (/^--/) {
302
            Message( "AR: unknown option $_ -- ignored\n" );
303
        }
304
    }
305
 
306
#.. Target
307
#
308
    MakeEntry( "\$(LIBDIR)/$name\$(GBE_TYPE).${a}:\t", "", " \\\n\t\t", ".${o}", @$pObjs );
309
 
310
#.. Build library rule (just append to standard rule)
311
#
312
    MakePrint( "\n\t\$(AR)\n\n" );
313
}
314
 
315
 
316
###############################################################################
317
#   ToolsetARMerge()
318
#       Generate the recipe to merge libraries.
319
#       The dependency list is created by the caller.
320
#
321
###############################################################################
322
 
323
sub ToolsetARMerge
324
{
325
    MakePrint( "\n\t\$(ARMERGE)\n\n" );
326
}
327
 
328
 
329
###############################################################################
330
#   ToolsetLD( $name, \@args, \@objs, \@libraries )
331
#       This subroutine takes the user options and builds the rules
332
#       required to link the program 'name'.
333
#
334
#   Arguments:
335
#       --xxx                   No Arguments currently specified
336
#
337
#       Linker specific:
338
#       --LinkScript=filename   Specify the name of a linker script file
339
#       --Loader=filename       Specify a loader file to be merged
340
#                               This will be a program
341
#       --Type=typetext         Text to be placed in type field
5726 dpurdie 342
#       --Entry=Name            Alternate Program Entry Point
5757 dpurdie 343
#       --CrcRange=Text         Text used in the elftool command for fill and checksum ranges
344
#                               ie: app_start-app_checksum_end+3
5677 dpurdie 345
#
346
#   Output:
347
#
348
#       name.map                - Loadable module
5726 dpurdie 349
#       name.out                - Output from the linker
350
#       name.srec               - Output from the elftool
5677 dpurdie 351
#       name.d90                -
5726 dpurdie 352
#       name.sxml               - Wrapped srec file
5677 dpurdie 353
#
354
###############################################################################
355
 
356
sub ToolsetLD
357
{
358
    my( $name, $pArgs, $pObjs, $pLibs ) = @_;
359
    my( $script );
360
    my( $loader, $loader_file);
361
    my  $type_text = '';
5726 dpurdie 362
    my  $entyPoint = '__iar_program_start';
5757 dpurdie 363
    my $crcRange;
5677 dpurdie 364
 
365
 
366
#.. Parse arguments
367
#
368
    foreach $_ ( @$pArgs )
369
    {
370
    #.. Target specific
371
    #
372
 
373
    #.. Toolset specific
374
    #
375
        if (/^--Script=(.*)/) {           # External file
376
            $script = $1;
5726 dpurdie 377
            $script .= ".icf" unless ( $script =~ m~\.icf$~ );
5677 dpurdie 378
 
379
        } elsif ( /^--ProgLoader=(.*)/ ) {   # Loader/Burner file
380
            $loader = $1;
381
            $loader =~ s~$exe$~~;
382
 
383
        } elsif ( /^--Type=(.*)/ ) {        # Type of Payload
384
            $type_text = $1;
385
 
5726 dpurdie 386
        } elsif ( /^--Entry=(.*)/ ) {        # Entry Point
387
            $entyPoint = $1;
388
 
5757 dpurdie 389
        } elsif ( /^--CrcRange=(.*)/ ) {     # Crc Range
390
            $crcRange = $1;
391
 
5677 dpurdie 392
        } else {
393
            Message( "Prog: unknown option $_ -- ignored\n" );
394
        }
395
    }
396
 
397
#
398
#   Sanity check
399
#       - Ensure a linker script has been provided
400
#
401
unless ( $script )
402
{
5726 dpurdie 403
    $script = "$name.icf";
5677 dpurdie 404
    Warning( "Prog: Linker Script file not provided. Using $script" );
405
}
406
 
407
#
408
#   Locate the true path of the provided script file
409
#   If it is a generate file so it will be in the SRCS hash
410
#   Other wise the use will have to use Src to locate the file
411
#
412
    $script = MakeSrcResolve ( $script );
413
 
414
#
415
#   Locate the loader file, if it has been provided
416
#   The file must be a program and should be created within this makefile
417
#
418
if ( $loader )
419
{
420
    if ( $::PROGS->Get( $loader) )
421
    {
422
        $loader_file = "\$(BINDIR)/$loader$exe";
423
    }
424
    elsif ( $::SRCS{$loader} )
425
    {
426
        $loader_file = $::SRCS{$loader};
427
    }
428
    else
429
    {
430
        Error ("Prog: ProgLoader file not found" );
431
    }
432
}
433
 
434
#
435
#   Extend the list of libraries with compiler specific libraries
436
#
5679 dpurdie 437
#    push( @$pLibs, "\$(avr_linker_lib)" );
5677 dpurdie 438
 
439
#
440
#   Create a ToolsetPrinter
441
#
442
    my ($io) = ToolsetPrinter::New();
443
    my $dep = $io->SetLdTarget( $name );
444
 
445
#
446
#   Determine the target output name
447
#
448
    my $root = "\$(BINDIR)/$name";
449
    my $full = $root . $::exe;
450
    my $map = $root . '.map';
5726 dpurdie 451
    my $log = $root . '.log';
452
    my $out = $root . '.out';
453
    my $srec = $root . '.srec';
5677 dpurdie 454
 
455
 
456
########################################################################
457
#
458
#   Before this function was called, makelib.pl2 has generated a
459
#   partial rule consisting of:
460
#
461
#       $(BINDIR)/${name}${exe} :
462
#               All the specified object files
463
#
464
#   Add the names of all the other files required in the process
465
#   This will then serve as a target fo all things that need to be
466
#   created when a "program" is required
467
#
468
#       These are:
469
#               User linker script file
470
#               Library dependency file
471
# 
472
    $io->Label( "Program", $name );                     # label
5726 dpurdie 473
    $io->Prt( "$out : \t$dep" );                       # Dependencies
5677 dpurdie 474
    $io->Prt( "\\\n\t\t$script" );
475
    $io->Prt( " \\\n\t\t$loader_file" ) if ($loader_file);
476
    $io->Entry( "", "", "\\\n\t", ".$::o ", @$pObjs );  # Object Files
477
    $io->Prt( "\n\t\$(LD_IAR)\n" );
478
 
479
    #
480
    #   Insert post processing call if a program loader is needed
481
    #
482
    $io->Prt( "\t\$(call LD_IAR_PROCESS, \\" .
483
              "\n\t\t$full, \\" .
484
              "\n\t\t$loader_file)\n"
485
            ) if ($loader_file);
486
 
487
    $io->Newline();
488
 
489
    #
490
    #   Specify files created by the linker
491
    #   These will be added to the clean list
492
    #
493
    ToolsetGenerate( $map );
5726 dpurdie 494
    ToolsetGenerate( $log );
495
    ToolsetGenerate( $out );
496
    ToolsetGenerate( $srec );
5677 dpurdie 497
    ToolsetGenerate( "$full.keep" );
498
 
499
    #
500
    #   Create a linker command file
501
    #   Piecing together a variable $(name_ld) which ends up in the command file.
502
    #   This bit of magic will be performed by the LD_IAR recipe
503
    #
504
    $io->SetTag( "${name}_ld" );                            # macro tag
505
    $io->Label( "Linker commands", $name );                 # label
506
 
5726 dpurdie 507
#    $io->Cmd("-S" );                                       # Silent
508
    $io->Cmd("-o $out" );                                   # Output file
509
    $io->Cmd("--map $map" );                                # Map file
510
                                                            # Configue Logging
511
    $io->Cmd("--log libraries,initialization,modules,redirects,sections,veneers,unused_fragments,call_graph" );
512
    $io->Cmd("--log_file $log" );                           # Log file
513
    $io->Cmd("--semihosting" );
514
    $io->Cmd("--entry $entyPoint" );
515
    $io->Cmd("--inline" );
516
    $io->Cmd("--vfe" );
517
    $io->Cmd("--config $script" );                          # User script file
5677 dpurdie 518
 
519
    $io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );      # Object files
520
 
521
    #
522
    #   Specify the library files
523
    #
5679 dpurdie 524
#    $io->Cmd( '"-I$(avr_linker_lib_dir)"' );                # Toolset library directory
5677 dpurdie 525
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );      # Specify the libraries too
526
    $io->Newline();
527
 
528
    #.. Dependency link,
529
    #   Create a library dependency file
530
    #       Create command file to build applicaton dependency list
531
    #       from the list of dependent libraries
532
    #
533
    #       Create makefile directives to include the dependency
534
    #       list into the makefile.
535
    #
5726 dpurdie 536
    $io->DepRules( $pLibs, \&ToolsetLibRecipe, $out );
5677 dpurdie 537
    $io->LDDEPEND(); 
538
 
539
    #
540
    #   Add the MAP file to the program package
541
    #
542
    PackageProgAddFiles ( $name, $full );
543
    PackageProgAddFiles ( $name, $map , 'Class=map' );
544
 
5726 dpurdie 545
    #
546
    #   Create the .srec file
5757 dpurdie 547
    #   (if $3,--fill 0xFF;$3 --checksum checksum:4\,crc32\,0xFFFFFFFF;$3)
5726 dpurdie 548
    #
5757 dpurdie 549
    my  $sRecRange = '';
550
    if ($crcRange)
551
    {
552
        $sRecRange = "--fill \"0xFF;$crcRange\" --checksum \"checksum:4\$(comma)crc32\$(comma)0xFFFFFFFF;$crcRange\"" 
553
    }
5726 dpurdie 554
    $io->Label( "SREC File", $name );
555
    $io->Prt( "$srec: $out\n");
5757 dpurdie 556
    $io->Prt( "\t\$(call GENERATE_SREC,$out,$srec,$sRecRange)\n");
5726 dpurdie 557
    $io->Newline();
5677 dpurdie 558
 
5726 dpurdie 559
 
5677 dpurdie 560
    #
561
    #   Create the .sxml file
562
    #
563
    my $sxml = "\$(BINDIR)/${name}.sxml";
564
    my ($major, $minor, $patch, $build, $raw_patch) = SplitVersion($ScmBuildVersionFull);
565
 
566
    $io->Label( "SXML File", $name );
5726 dpurdie 567
    $io->Prt( "$sxml: $srec\n");
5677 dpurdie 568
    $io->Prt( "\t\$(call GENERATE_SXML, \\" .
569
              "\n\t\t\$(BINDIR)/${name}$exe, \\" .
5679 dpurdie 570
              "\n\t\t$sxml,$type_text,$major,$minor,$patch,$build,InsideSecure)\n"
5677 dpurdie 571
              );
572
    $io->Newline();
573
 
574
    #
575
    #   Generated files to be added to the program file list
576
    #
577
    ToolsetGenerate( $sxml );
578
    PackageProgAddFiles( $name, $sxml, 'Class=extras' );
579
    ProgAddExtra( $name, $sxml );
580
 
581
}
582
 
583
########################################################################
584
#
585
#   Generate a linker object recipe.  This is a helper function used 
586
#   within this toolset.
587
#
588
#   Arguments:
589
#       $io         I/O stream
590
#
591
#       $target     Name of the target
592
#
593
#       $obj        Library specification
594
#
595
########################################################################
596
 
597
sub ToolsetObjRecipe
598
{
599
    my ($io, $target, $obj) = @_;
600
 
601
    $io->Cmd("$obj.$::o" );
602
}
603
 
604
########################################################################
605
#
606
#   Generate a linker/depend library recipe.  This is a helper function
607
#   used within this toolset.
608
#
609
#   Arguments:
610
#       $io         I/O stream
611
#
612
#       $target     Name of the target
613
#
614
#       $lib        Library specification
615
#
616
#       $dp         If building a depend list, the full target name.
617
#
618
########################################################################
619
 
620
sub ToolsetLibRecipe
621
{
622
    my ($io, $target, $lib, $dp) = @_;
623
 
624
    if ( !defined($dp) ) {                      # linker
5726 dpurdie 625
        $io->Cmd("--search @(vpath2,\"$lib.$::a\",IAR_LIB)" );
5677 dpurdie 626
    } else {                                    # depend
627
        $io->Cmd( "$dp:\t@(vlib2,\"$lib.$::a\",IAR_LIB)" );
628
    }
629
}
630
 
631
#.. Successful termination
632
1;
633