Subversion Repositories DevTools

Rev

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