Subversion Repositories DevTools

Rev

Rev 5679 | Go to most recent revision | Details | 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;
79
        push @flags , '--eeprom_size=32768';
80
Warning("TODO: eeprom size");
81
 
82
        #   Compiler flags and definitions
83
        push @defines, '_MS6001;
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");
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';
107
 
108
        push @defines, '_EEP_EOW_MODE=IDLE_EEP_WRITE';
109
 
110
 
111
        #
112
        #   Assembler flags and definitions
113
        #
114
Warning("TODO: Assembler Flags");
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
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 ( "#" );
175
    ToolsetDefines( "CORTEX IAR.def" );
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
#
442
    push( @$pLibs, "\$(avr_linker_lib)" );
443
 
444
#
445
#   Create a ToolsetPrinter
446
#
447
    my ($io) = ToolsetPrinter::New();
448
    my $dep = $io->SetLdTarget( $name );
449
 
450
#
451
#   Determine the target output name
452
#
453
    my $root = "\$(BINDIR)/$name";
454
    my $full = $root . $::exe;
455
    my $map = $root . '.map';
456
    my $d90 = $root . '.d90';
457
    my $s19 = $root . '.s19';
458
 
459
 
460
########################################################################
461
#
462
#   Before this function was called, makelib.pl2 has generated a
463
#   partial rule consisting of:
464
#
465
#       $(BINDIR)/${name}${exe} :
466
#               All the specified object files
467
#
468
#   Add the names of all the other files required in the process
469
#   This will then serve as a target fo all things that need to be
470
#   created when a "program" is required
471
#
472
#       These are:
473
#               User linker script file
474
#               Library dependency file
475
# 
476
    $io->Label( "Program", $name );                     # label
477
    $io->Prt( "$full : \t$dep" );                       # Dependencies
478
    $io->Prt( "\\\n\t\t$script" );
479
    $io->Prt( " \\\n\t\t$loader_file" ) if ($loader_file);
480
    $io->Entry( "", "", "\\\n\t", ".$::o ", @$pObjs );  # Object Files
481
    $io->Prt( "\n\t\$(LD_IAR)\n" );
482
 
483
    #
484
    #   Insert post processing call if a program loader is needed
485
    #
486
    $io->Prt( "\t\$(call LD_IAR_PROCESS, \\" .
487
              "\n\t\t$full, \\" .
488
              "\n\t\t$loader_file)\n"
489
            ) if ($loader_file);
490
 
491
    $io->Newline();
492
 
493
    #
494
    #   Specify files created by the linker
495
    #   These will be added to the clean list
496
    #
497
    ToolsetGenerate( $d90 );
498
    ToolsetGenerate( $map );
499
    ToolsetGenerate( "$full.keep" );
500
 
501
    #
502
    #   Create a linker command file
503
    #   Piecing together a variable $(name_ld) which ends up in the command file.
504
    #   This bit of magic will be performed by the LD_IAR recipe
505
    #
506
    $io->SetTag( "${name}_ld" );                            # macro tag
507
    $io->Label( "Linker commands", $name );                 # label
508
 
509
    $io->Cmd("-S" );                                        # Silent
510
    $io->Cmd("-Omotorola=$s19" );                           # Output file
511
    $io->Cmd("-o $d90" );                                   # Output file
512
    $io->Cmd("-l $map" );                                   # Map file
513
    $io->Cmd("-r" );                                        # Output with debug
514
    $io->Cmd("-z" );                                        # Reduce segment overlap errors
515
    $io->Cmd("-xmsn" );                                     # Add info to the map file
516
    $io->Cmd("-p100" );                                     # Number of line per page
517
    $io->Cmd("-f $script" );                                # User script file
518
 
519
    $io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );      # Object files
520
 
521
    #
522
    #   Specify the library files
523
    #
524
    $io->Cmd( '"-I$(avr_linker_lib_dir)"' );                # Toolset library directory
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
    #
536
    $io->DepRules( $pLibs, \&ToolsetLibRecipe, $s19 );
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
 
545
 
546
    #
547
    #   Create the .sxml file
548
    #
549
    my $sxml = "\$(BINDIR)/${name}.sxml";
550
    my ($major, $minor, $patch, $build, $raw_patch) = SplitVersion($ScmBuildVersionFull);
551
 
552
    $io->Label( "SXML File", $name );
553
    $io->Prt( "$sxml: $s19\n");
554
    $io->Prt( "\t\$(call GENERATE_SXML, \\" .
555
              "\n\t\t\$(BINDIR)/${name}$exe, \\" .
556
              "\n\t\t$sxml,$type_text,$major,$minor,$patch,$build)\n"
557
              );
558
    $io->Newline();
559
 
560
    #
561
    #   Generated files to be added to the program file list
562
    #
563
    ToolsetGenerate( $sxml );
564
    PackageProgAddFiles( $name, $sxml, 'Class=extras' );
565
    ProgAddExtra( $name, $sxml );
566
 
567
}
568
 
569
########################################################################
570
#
571
#   Generate a linker object recipe.  This is a helper function used 
572
#   within this toolset.
573
#
574
#   Arguments:
575
#       $io         I/O stream
576
#
577
#       $target     Name of the target
578
#
579
#       $obj        Library specification
580
#
581
########################################################################
582
 
583
sub ToolsetObjRecipe
584
{
585
    my ($io, $target, $obj) = @_;
586
 
587
    $io->Cmd("$obj.$::o" );
588
}
589
 
590
########################################################################
591
#
592
#   Generate a linker/depend library recipe.  This is a helper function
593
#   used within this toolset.
594
#
595
#   Arguments:
596
#       $io         I/O stream
597
#
598
#       $target     Name of the target
599
#
600
#       $lib        Library specification
601
#
602
#       $dp         If building a depend list, the full target name.
603
#
604
########################################################################
605
 
606
sub ToolsetLibRecipe
607
{
608
    my ($io, $target, $lib, $dp) = @_;
609
 
610
    if ( !defined($dp) ) {                      # linker
611
        $io->Cmd("-C @(vpath2,\"$lib.$::a\",IAR_LIB)" );
612
    } else {                                    # depend
613
        $io->Cmd( "$dp:\t@(vlib2,\"$lib.$::a\",IAR_LIB)" );
614
    }
615
}
616
 
617
#.. Successful termination
618
1;
619