Subversion Repositories DevTools

Rev

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