Subversion Repositories DevTools

Rev

Rev 5679 | Rev 5726 | 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
        #
97
Warning("TODO: Compiler Flags");
5680 dpurdie 98
       push @flags , '--endian=little';
99
       push @flags , '--cpu=Cortex-M3';
100
       push @flags , '--diag_suppress=Pa050';
101
       push @flags , '-e';
102
       push @flags , '--fpu=None';
103
       push @flags , '-Oh';
104
       push @flags , '--vla';
105
       push @flags , '--require_prototypes';
106
#       push @flags , '--dlib_config=$(COMPILER_HOME_AVR)\INC\c\DLib_Config_Normal.h';
107
       push @flags , '--dlib_config=DLib_Config_Normal.h';
5677 dpurdie 108
 
109
 
5680 dpurdie 110
       # Defines
111
       #push @defines, '_EEP_EOW_MODE=IDLE_EEP_WRITE';
5677 dpurdie 112
 
5680 dpurdie 113
 
5677 dpurdie 114
        #
115
        #   Assembler flags and definitions
116
        #
117
Warning("TODO: Assembler Flags");
5679 dpurdie 118
#       push @asflags , '-v6';                  # processor configuration
119
#       push @asflags , '-s+';                  # Case-sensitive user symbols
120
#       push @asflags , '-t8';                  # tab spacing...
121
#       push @asflags , '-u_enhancedCore';      # enable AVR-specific enhanced instructions
5677 dpurdie 122
 
5680 dpurdie 123
#       push @asdefines, '__MEMORY_MODEL__=2';
124
#       push @asdefines, '__HAS_ELPM__=1 ';
125
#       push @asdefines, '__HAS_ENHANCED_CORE__=1 ';
126
#       push @asdefines, 'ASSEMBLER';
5677 dpurdie 127
    }
128
 
129
    #.. Standard.rul requirements
130
    #
131
    $s = 's90';             # Assembler source file
132
    $o = 'r90';             # Object file
133
    $a = 'r90';             # Library file
134
    $so = '';               # Shared library
135
    $exe = '.s19';          # Linked binary images
136
 
137
    AddSourceType( ".$s", '.asm' );
138
 
139
 
140
    #.. Toolset configuration
141
    #
142
    $::ScmToolsetVersion = "1.0.0";               # our version
143
    $::ScmToolsetGenerate = 0;                    # generate optional
144
    $::ScmToolsetProgDependancies = 0;            # handle Prog dependancies myself
145
 
146
#.. Cleanup rules
147
#
5680 dpurdie 148
#   Files that appear to be created by the compiler
5677 dpurdie 149
#
150
Warning("TODO: Generated File List");
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
342
#
343
#   Output:
344
#
345
#       name.map                - Loadable module
346
#       name.s19                -
347
#       name.d90                -
348
#       name.sxml               - Wrapped s19 file
349
#
350
#   Linker Flags
351
#
352
#       -O[format]=filename         Specify output filename and format
353
#       -o filename                 Specify an output file
354
#       -r                          Output file indebug format
355
#       -z                          Reduce segment overlap errors
356
#       -l filename                 Generate a listing file
357
#       -xmsn                       Add info to the map file
358
#       -Pnnn                       Number of line per page
359
#       -Ipath                      Specify a path to search for object files
360
#       -f filename                 Read arguments from file
361
#       -C filename                 Load filename as a library
362
 
363
###############################################################################
364
 
365
sub ToolsetLD
366
{
367
    my( $name, $pArgs, $pObjs, $pLibs ) = @_;
368
    my( $script );
369
    my( $loader, $loader_file);
370
    my  $type_text = '';
371
 
372
 
373
#.. Parse arguments
374
#
375
    foreach $_ ( @$pArgs )
376
    {
377
    #.. Target specific
378
    #
379
 
380
    #.. Toolset specific
381
    #
382
        if (/^--Script=(.*)/) {           # External file
383
            $script = $1;
384
            $script .= ".xcl" unless ( $script =~ m~\.xcl$~ );
385
 
386
        } elsif ( /^--ProgLoader=(.*)/ ) {   # Loader/Burner file
387
            $loader = $1;
388
            $loader =~ s~$exe$~~;
389
 
390
        } elsif ( /^--Type=(.*)/ ) {        # Type of Payload
391
            $type_text = $1;
392
 
393
        } else {
394
            Message( "Prog: unknown option $_ -- ignored\n" );
395
        }
396
    }
397
 
398
#
399
#   Sanity check
400
#       - Ensure a linker script has been provided
401
#
402
unless ( $script )
403
{
404
    $script = "$name.xcl";
405
    Warning( "Prog: Linker Script file not provided. Using $script" );
406
}
407
 
408
#
409
#   Locate the true path of the provided script file
410
#   If it is a generate file so it will be in the SRCS hash
411
#   Other wise the use will have to use Src to locate the file
412
#
413
    $script = MakeSrcResolve ( $script );
414
 
415
#
416
#   Locate the loader file, if it has been provided
417
#   The file must be a program and should be created within this makefile
418
#
419
if ( $loader )
420
{
421
    if ( $::PROGS->Get( $loader) )
422
    {
423
        $loader_file = "\$(BINDIR)/$loader$exe";
424
    }
425
    elsif ( $::SRCS{$loader} )
426
    {
427
        $loader_file = $::SRCS{$loader};
428
    }
429
    else
430
    {
431
        Error ("Prog: ProgLoader file not found" );
432
    }
433
}
434
 
435
#
436
#   Extend the list of libraries with compiler specific libraries
437
#
5679 dpurdie 438
#    push( @$pLibs, "\$(avr_linker_lib)" );
439
Warning("TODO: Add toolset library-1");
5677 dpurdie 440
 
441
#
442
#   Create a ToolsetPrinter
443
#
444
    my ($io) = ToolsetPrinter::New();
445
    my $dep = $io->SetLdTarget( $name );
446
 
447
#
448
#   Determine the target output name
449
#
450
    my $root = "\$(BINDIR)/$name";
451
    my $full = $root . $::exe;
452
    my $map = $root . '.map';
453
    my $d90 = $root . '.d90';
454
    my $s19 = $root . '.s19';
455
 
456
 
457
########################################################################
458
#
459
#   Before this function was called, makelib.pl2 has generated a
460
#   partial rule consisting of:
461
#
462
#       $(BINDIR)/${name}${exe} :
463
#               All the specified object files
464
#
465
#   Add the names of all the other files required in the process
466
#   This will then serve as a target fo all things that need to be
467
#   created when a "program" is required
468
#
469
#       These are:
470
#               User linker script file
471
#               Library dependency file
472
# 
473
    $io->Label( "Program", $name );                     # label
474
    $io->Prt( "$full : \t$dep" );                       # Dependencies
475
    $io->Prt( "\\\n\t\t$script" );
476
    $io->Prt( " \\\n\t\t$loader_file" ) if ($loader_file);
477
    $io->Entry( "", "", "\\\n\t", ".$::o ", @$pObjs );  # Object Files
478
    $io->Prt( "\n\t\$(LD_IAR)\n" );
479
 
480
    #
481
    #   Insert post processing call if a program loader is needed
482
    #
483
    $io->Prt( "\t\$(call LD_IAR_PROCESS, \\" .
484
              "\n\t\t$full, \\" .
485
              "\n\t\t$loader_file)\n"
486
            ) if ($loader_file);
487
 
488
    $io->Newline();
489
 
490
    #
491
    #   Specify files created by the linker
492
    #   These will be added to the clean list
493
    #
494
    ToolsetGenerate( $d90 );
495
    ToolsetGenerate( $map );
496
    ToolsetGenerate( "$full.keep" );
497
 
498
    #
499
    #   Create a linker command file
500
    #   Piecing together a variable $(name_ld) which ends up in the command file.
501
    #   This bit of magic will be performed by the LD_IAR recipe
502
    #
503
    $io->SetTag( "${name}_ld" );                            # macro tag
504
    $io->Label( "Linker commands", $name );                 # label
505
 
5679 dpurdie 506
#    $io->Cmd("-S" );                                        # Silent
507
#    $io->Cmd("-Omotorola=$s19" );                           # Output file
5677 dpurdie 508
    $io->Cmd("-o $d90" );                                   # Output file
509
    $io->Cmd("-l $map" );                                   # Map file
5679 dpurdie 510
#    $io->Cmd("-r" );                                        # Output with debug
511
#    $io->Cmd("-z" );                                        # Reduce segment overlap errors
5677 dpurdie 512
    $io->Cmd("-xmsn" );                                     # Add info to the map file
5679 dpurdie 513
#    $io->Cmd("-p100" );                                     # Number of line per page
5677 dpurdie 514
    $io->Cmd("-f $script" );                                # User script file
5679 dpurdie 515
Warning("TODO: Add Linker commands");
5677 dpurdie 516
 
517
    $io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );      # Object files
518
 
519
    #
520
    #   Specify the library files
521
    #
5679 dpurdie 522
#    $io->Cmd( '"-I$(avr_linker_lib_dir)"' );                # Toolset library directory
523
Warning("TODO: Add toolset library-2");
5677 dpurdie 524
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );      # Specify the libraries too
525
    $io->Newline();
526
 
527
    #.. Dependency link,
528
    #   Create a library dependency file
529
    #       Create command file to build applicaton dependency list
530
    #       from the list of dependent libraries
531
    #
532
    #       Create makefile directives to include the dependency
533
    #       list into the makefile.
534
    #
535
    $io->DepRules( $pLibs, \&ToolsetLibRecipe, $s19 );
536
    $io->LDDEPEND(); 
537
 
538
    #
539
    #   Add the MAP file to the program package
540
    #
541
    PackageProgAddFiles ( $name, $full );
542
    PackageProgAddFiles ( $name, $map , 'Class=map' );
543
 
544
 
545
    #
546
    #   Create the .sxml file
547
    #
548
    my $sxml = "\$(BINDIR)/${name}.sxml";
549
    my ($major, $minor, $patch, $build, $raw_patch) = SplitVersion($ScmBuildVersionFull);
550
 
551
    $io->Label( "SXML File", $name );
552
    $io->Prt( "$sxml: $s19\n");
553
    $io->Prt( "\t\$(call GENERATE_SXML, \\" .
554
              "\n\t\t\$(BINDIR)/${name}$exe, \\" .
5679 dpurdie 555
              "\n\t\t$sxml,$type_text,$major,$minor,$patch,$build,InsideSecure)\n"
5677 dpurdie 556
              );
557
    $io->Newline();
558
 
559
    #
560
    #   Generated files to be added to the program file list
561
    #
562
    ToolsetGenerate( $sxml );
563
    PackageProgAddFiles( $name, $sxml, 'Class=extras' );
564
    ProgAddExtra( $name, $sxml );
565
 
566
}
567
 
568
########################################################################
569
#
570
#   Generate a linker object recipe.  This is a helper function used 
571
#   within this toolset.
572
#
573
#   Arguments:
574
#       $io         I/O stream
575
#
576
#       $target     Name of the target
577
#
578
#       $obj        Library specification
579
#
580
########################################################################
581
 
582
sub ToolsetObjRecipe
583
{
584
    my ($io, $target, $obj) = @_;
585
 
586
    $io->Cmd("$obj.$::o" );
587
}
588
 
589
########################################################################
590
#
591
#   Generate a linker/depend library recipe.  This is a helper function
592
#   used within this toolset.
593
#
594
#   Arguments:
595
#       $io         I/O stream
596
#
597
#       $target     Name of the target
598
#
599
#       $lib        Library specification
600
#
601
#       $dp         If building a depend list, the full target name.
602
#
603
########################################################################
604
 
605
sub ToolsetLibRecipe
606
{
607
    my ($io, $target, $lib, $dp) = @_;
608
 
609
    if ( !defined($dp) ) {                      # linker
610
        $io->Cmd("-C @(vpath2,\"$lib.$::a\",IAR_LIB)" );
611
    } else {                                    # depend
612
        $io->Cmd( "$dp:\t@(vlib2,\"$lib.$::a\",IAR_LIB)" );
613
    }
614
}
615
 
616
#.. Successful termination
617
1;
618