Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
#..
2
# Copyright (C) 1998-2004 ERG Transit Systems, All rights reserved
3
#
4
# Module name   : avr_air
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 AVR
14
#
15
# Revision History:
16
#       16-Aug-04   DDP     Created
17
#       13-Jul-06   DCP     Added AT90SC7272C chipset
18
#............................................................................#
19
 
20
use strict;
21
use JatsVersionUtils;
22
 
23
our $s;
24
our $o;
25
our $so;
26
our $exe;
27
our $ScmBuildVersionFull;
28
 
29
##############################################################################
30
#   ToolsetInit()
31
#       Runtime initialisation
32
#
33
##############################################################################
34
 
35
ToolsetInit();
36
 
37
sub ToolsetInit
38
{
39
    my( @args ) = @::ScmToolsetArgs;             # Toolset arguments
40
    my( $version, $product, @defines, @dirs, @flags, @asflags, @asdefines );
41
    my $productFound;
42
 
43
    #.. Parse arguments
44
    #
45
    Debug( "avr_iar(@args)\n" );
46
 
47
    foreach $_ ( @args ) {
48
        if (/^--Version=(.*)/) {                # Compiler version
49
            $version = "$1";
50
        } else {
51
            Message( "avr_iar: unknown toolset argument $_ -- ignored\n" );
52
        }
53
    }
54
 
55
    #.. Parse Platform Arguments
56
    #
57
    my( @args ) = @::ScmPlatformArgs;           # Platform arguments
58
    foreach $_ ( @args ) {
59
        if (/^--product=(.*)/) {                # GBE product
60
            $product = $1;
61
        } else {
62
            Message( "avr_iar: unknown platform argument $_ -- ignored\n" );
63
        }
64
    }
65
 
66
    #
67
    #   Definitions common to all products
68
    #   These will be picked up when no platform has been defined
69
    #
70
 
71
    push @defines, 'JATS_BUILD';
72
    push @dirs,    '$(COMPILER_HOME_AVR)/inc/clib';
73
    push @dirs,    '$(COMPILER_HOME_AVR)/inc';
74
 
75
    #
76
    #   Platform specific definitions
77
    #
78
    if ( $product eq "AT3232" || $product eq "AT90SC3232CS" )
79
    {
80
        $productFound = $product;
81
        push @flags , '--eeprom_size=32768';
82
 
83
        #   Compiler flags and definitions
84
        push @defines, '_AT90SC3232CS';
85
 
86
        #   Assembler flags and definitions
87
        push @asdefines, '_AT90SC3232CS';
88
    }
89
    elsif ( $product eq "AT90SC7272C" )
90
    {
91
        $productFound = $product;
92
        push @flags , '--eeprom_size=65536';    # maximum size allowed by IAR
93
 
94
        #   Compiler flags and definitions
95
        push @defines, '_AT90SC7272C';
96
 
97
        #   Assembler flags and definitions
98
        push @asdefines, '_AT90SC7272C';
99
    }
100
    elsif ( $product )
101
    {
102
        Message( "avr_iar: Unknown product: $product -- ignored\n" );
103
    }
104
 
105
    # common flags
106
    if ( $productFound )
107
    {
108
        #
109
        #   Compiler flags and definitions
110
        #
111
        push @flags , '-v6';
112
        push @flags , '-ms';
113
        push @flags , '-y';
114
        push @flags , '--enhanced_core';
115
        push @flags , '--diag_suppress=pa050';
116
        push @flags , '--initializers_in_flash';
117
        push @flags , '--require_prototypes';
118
 
119
        push @defines, '_EEP_EOW_MODE=IDLE_EEP_WRITE';
120
 
121
 
122
        #
123
        #   Assembler flags and definitions
124
        #
125
        push @asflags , '-v6';                  # processor configuration
126
        push @asflags , '-s+';                  # Case-sensitive user symbols
127
        push @asflags , '-t8';                  # tab spacing...
128
        push @asflags , '-u_enhancedCore';      # enable AVR-specific enhanced instructions
129
 
130
        push @asdefines, '__MEMORY_MODEL__=2';
131
        push @asdefines, '__HAS_ELPM__=1 ';
132
        push @asdefines, '__HAS_ENHANCED_CORE__=1 ';
133
        push @asdefines, 'ASSEMBLER';
134
    }
135
 
136
    #.. Standard.rul requirements
137
    #
138
    $s = 's90';             # Assembler source file
139
    $o = 'r90';             # Object file
140
    $a = 'r90';             # Library file
141
    $so = '';               # Shared library
142
    $exe = '.s19';          # Linked binary images
143
 
144
    AddSourceType( ".$s", '.asm' );
145
 
146
 
147
    #.. Toolset configuration
148
    #
149
    $::ScmToolsetVersion = "1.0.0";               # our version
150
    $::ScmToolsetGenerate = 0;                    # generate optional
151
    $::ScmToolsetIFLAG3 = 1;                      # supports IFLAG3
152
 
153
#.. Cleanup rules
154
#
155
#   9 Files that appear to be created by the USB licsence dongle
156
#
157
    ToolsetGenerate( "clauth1.dll" );
158
    ToolsetGenerate( "clauth2.dll" );
159
    ToolsetGenerate( "lsprst7.dll" );
160
    ToolsetGenerate( "lsprst7.tgz" );
161
    ToolsetGenerate( "ssprs.dll" );
162
    ToolsetGenerate( "ssprs.tgz" );
163
    ToolsetGenerate( "sysprs7.dll" );
164
    ToolsetGenerate( "sysprs7.tgz" );
165
    ToolsetGenerate( "tmpPrst.tgz" );
166
 
167
 
168
    #.. Define IAR environment
169
    #
170
    #
171
    #   Define initialisation targets
172
    #   These will be used to ensure that correct versions of the toolset are present
173
    #
174
    Init( "iar" );
175
 
176
    ToolsetDefine ( "#################################################" );
177
    ToolsetDefine ( "# AVR IAR compiler version" );
178
    ToolsetDefine ( "#" );
179
    ToolsetDefine ( "avr_iar_ver         = $version" );
180
    ToolsetDefine ( "avr_iar_prod        = $product" );
181
    ToolsetDefine ( "" );
182
    ToolsetDefine ( "#" );
183
    ToolsetDefines( "avr_iar.def" );
184
    ToolsetRules  ( "avr_iar.rul" );
185
    ToolsetRules  ( "standard.rul" );
186
 
187
    #
188
    #   Specify compiler parameters
189
    #   Note: AVR_IAR_INCLUDES is ";" seperated as it may contain spaces
190
    #         when expanded ("Program Files")
191
    #
192
 
193
    PlatformEntry( "AVR_IAR_DEFINES\t=",    "\n", "\\\n\t", "", @defines )
194
        if ( scalar @defines );
195
    PlatformEntry( "AVR_IAR_INCLUDES\t=",    "\n", "\\\n\t", ";", @dirs )
196
        if ( scalar @dirs );
197
    PlatformEntry( "AVR_IAR_FLAGS\t=",    "\n", "\\\n\t", "", @flags )
198
        if ( scalar @flags );
199
 
200
    PlatformEntry( "AVR_IAR_ASFLAGS\t=",    "\n", "\\\n\t", "", @asflags )
201
        if ( scalar @asflags );
202
    PlatformEntry( "AVR_IAR_ASDEFINES\t=",    "\n", "\\\n\t", "", @asdefines )
203
        if ( scalar @asdefines );
204
 
205
}
206
 
207
 
208
##############################################################################
209
#   ToolsetPreprocess()
210
#       Process collected data before the makefile is generated
211
#       This, optional, routine is called from within MakefileGenerate()
212
#       It allows the toolset to massage any of the collected data before
213
#       the makefile is created
214
#
215
##############################################################################
216
 
217
#sub ToolsetPreprocess
218
#{
219
#}
220
 
221
###############################################################################
222
#   ToolsetCC( $source, $obj, \@args )
223
#       This subroutine takes the user options and builds the rule(s)
224
#       required to compile the source file 'source' to 'obj'
225
#
226
###############################################################################
227
 
228
sub ToolsetCC
229
{
230
    MakePrint( "\n\t\$(CC)\n" );
231
}
232
 
233
###############################################################################
234
#   ToolsetCCDepend( $depend, \@sources )
235
#       This subroutine takes the user options and builds the
236
#       rule(s) required to build the dependencies for the source
237
#       files 'sources' to 'depend'.
238
#
239
###############################################################################
240
 
241
sub ToolsetCCDepend
242
{
243
    MakePrint( "\t\$(CCDEPEND)\n" );
244
}
245
 
246
 
247
###############################################################################
248
#   ToolsetCXX( $source, $obj, \@args )
249
#       This subroutine takes the user options and builds the rule(s)
250
#       required to compile the source file 'source' to 'obj'
251
#
252
###############################################################################
253
 
254
sub ToolsetCXX
255
{
256
    MakePrint( "\n\t\$(CXX)\n" );
257
}
258
 
259
###############################################################################
260
#   ToolsetCXXDepend( $depend, \@sources )
261
#       This subroutine takes the user options and builds the
262
#       rule(s) required to build the dependencies for the source
263
#       files 'sources' to 'depend'.
264
#
265
###############################################################################
266
 
267
sub ToolsetCXXDepend
268
{
269
    #ToolsetCCDepend() handles both CC and CXX source
270
}
271
 
272
 
273
###############################################################################
274
#   ToolsetAS( $source, $obj, \@args )
275
#       This subroutine takes the user options and builds the rule(s)
276
#       required to compile the source file 'source' to 'obj'
277
#
278
###############################################################################
279
 
280
sub ToolsetAS
281
{
282
    MakePrint( "\n\t\$(AS)\n" );
283
}
284
 
285
sub ToolsetASDepend
286
{
287
}
288
 
289
###############################################################################
290
#   ToolsetAR( $name, \@args, \@objs )
291
#       This subroutine takes the user options and builds the rules
292
#       required to build the library 'name'.
293
 
294
#
295
#   Arguments:
296
#       --xxx                   No arguments currently defined
297
#
298
#   Output:
299
#       [ $(BINDIR)/name$.${a}:   .... ]
300
#           $(AR)
301
#
302
###############################################################################
303
 
304
sub ToolsetAR
305
{
306
    my( $name, $pArgs, $pObjs ) = @_;
307
 
308
    Debug("ToolsetAR");
309
 
310
#.. Parse arguments
311
#
312
    foreach $_ ( @$pArgs ) {
313
        if (/^--/) {
314
            Message( "AR: unknown option $_ -- ignored\n" );
315
        }
316
    }
317
 
318
#.. Target
319
#
320
    MakeEntry( "\$(LIBDIR)/$name\$(GBE_TYPE).${a}:\t", "", " \\\n\t\t", ".${o}", @$pObjs );
321
 
322
#.. Build library rule (just append to standard rule)
323
#
324
    MakePrint( "\n\t\$(AR)\n\n" );
325
}
326
 
327
 
328
###############################################################################
329
#   ToolsetARMerge()
330
#       Generate the recipe to merge libraries.
331
#       The dependency list is created by the caller.
332
#
333
###############################################################################
334
 
335
sub ToolsetARMerge
336
{
337
    MakePrint( "\n\t\$(ARMERGE)\n\n" );
338
}
339
 
340
 
341
###############################################################################
342
#   ToolsetLD( $name, \@args, \@objs, \@libraries )
343
#       This subroutine takes the user options and builds the rules
344
#       required to link the program 'name'.
345
#
346
#   Arguments:
347
#       --xxx                   No Arguments currently specified
348
#
349
#       Linker specific:
350
#       --LinkScript=filename   Specify the name of a linker script file
351
#       --Loader=filename       Specify a loader file to be merged
352
#                               This will be a program
353
#       --Type=typetext         Text to be placed in type field
354
#
355
#   Output:
356
#
357
#       name.map                - Loadable module
358
#       name.s19                -
359
#       name.d90                -
360
#       name.sxml               - Wrapped s19 file
361
#
362
#   Linker Flags
363
#
364
#       -O[format]=filename         Specify output filename and format
365
#       -o filename                 Specify an output file
366
#       -r                          Output file indebug format
367
#       -z                          Reduce segment overlap errors
368
#       -l filename                 Generate a listing file
369
#       -xmsn                       Add info to the map file
370
#       -Pnnn                       Number of line per page
371
#       -Ipath                      Specify a path to search for object files
372
#       -f filename                 Read arguments from file
373
#       -C filename                 Load filename as a library
374
 
375
###############################################################################
376
 
377
sub ToolsetLD
378
{
379
    my( $name, $pArgs, $pObjs, $pLibs ) = @_;
380
    my( $script );
381
    my( $loader, $loader_file);
382
    my  $type_text = '';
383
 
384
 
385
#.. Parse arguments
386
#
387
    foreach $_ ( @$pArgs )
388
    {
389
    #.. Target specific
390
    #
391
 
392
    #.. Toolset specific
393
    #
394
        if (/^--Script=(.*)/) {           # External file
395
            $script = $1;
396
            $script .= ".xcl" unless ( $script =~ m~\.xcl$~ );
397
 
398
        } elsif ( /^--ProgLoader=(.*)/ ) {   # Loader/Burner file
399
            $loader = $1;
400
            $loader =~ s~$exe$~~;
401
 
402
        } elsif ( /^--Type=(.*)/ ) {        # Type of Payload
403
            $type_text = $1;
404
 
405
        } else {
406
            Message( "Prog: unknown option $_ -- ignored\n" );
407
        }
408
    }
409
 
410
#
411
#   Sanity check
412
#       - Ensure a linker script has been provided
413
#
414
unless ( $script )
415
{
416
    $script = "$name.xcl";
417
    Warning( "Prog: Linker Script file not provided. Using $script" );
418
}
419
 
420
#
421
#   Locate the true path of the provided script file
422
#   If it is a generate file so it will be in the SRCS hash
423
#   Other wise the use will have to use Src to locate the file
424
#
425
    $script = MakeSrcResolve ( $script );
426
 
427
#
428
#   Locate the loader file, if it has been provided
429
#   The file must be a program and should be created within this makefile
430
#
431
if ( $loader )
432
{
433
    if ( exists $::PROG_OBJS{$loader} || exists $::PROG_LIBS{$loader} )
434
    {
435
        $loader_file = "\$(BINDIR)/$loader$exe";
436
    }
437
    elsif ( $::SRCS{$loader} )
438
    {
439
        $loader_file = $::SRCS{$loader};
440
    }
441
    else
442
    {
443
        Error ("Prog: ProgLoader file not found" );
444
    }
445
}
446
 
447
#
448
#   Extend the list of libraries with compiler specific libraries
449
#
450
    push( @$pLibs, "\$(avr_linker_lib)" );
451
 
452
#
453
#   Create a ToolsetPrinter
454
#
455
    my ($io) = ToolsetPrinter::New();
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
#               Loader file ( optional )
473
 
474
    $io->Prt( "\\\n\t\t$script" .
475
              " \\\n\t\t\$(BINDIR)/${name}.dep" );
476
    $io->Prt( " \\\n\t\t$loader_file" ) if ($loader_file);
477
    $io->Prt( "\n" .
478
              "\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\$(BINDIR)/${name}$exe, \\" .
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( "\$(BINDIR)/${name}.d90" );
495
    ToolsetGenerate( "\$(BINDIR)/${name}.map" );
496
    ToolsetGenerate( "\$(BINDIR)/${name}.dep" );
497
    ToolsetGenerate( "\$(BINDIR)/${name}$exe.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
 
507
    $io->Cmd("-S" );                                        # Silent
508
    $io->Cmd("-Omotorola=\$(BINDIR)/${name}.s19" );         # Output file
509
    $io->Cmd("-o \$(BINDIR)/${name}.d90" );                 # Output file
510
    $io->Cmd("-l \$(BINDIR)/${name}.map" );                 # Map file
511
    $io->Cmd("-r" );                                        # Output with debug
512
    $io->Cmd("-z" );                                        # Reduce segment overlap errors
513
    $io->Cmd("-xmsn" );                                     # Add info to the map file
514
    $io->Cmd("-p100" );                                     # Number of line per page
515
    $io->Cmd("-f $script" );                                # User script file
516
 
517
    $io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );      # Object files
518
 
519
    #
520
    #   Specify the library files
521
    #
522
    $io->Cmd( '"-I$(avr_linker_lib_dir)"' );                # Toolset library directory
523
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );      # Specify the libraries too
524
    $io->Newline();
525
 
526
    #
527
    #   Create a library dependency file
528
    #   Rules and recipe to create the .dep file
529
    #
530
    #       Now piece together a variable $(name_dp) which ends up in
531
    #       the command file building the application dependency list.
532
    #
533
    $io->SetTag( "${name}_dp" );                            # macro tag
534
    $io->DepRules( $name, $pLibs,                           # library depends rules
535
            \&ToolsetLibRecipe, "\$(BINDIR)/${name}.s19" );
536
    $io->LDDEPEND( $name );                                 # std LDDEPEND rules
537
 
538
 
539
    #
540
    #   Add the MAP file to the program package
541
    #
542
    PackageProgAddFiles( $name, "\$(BINDIR)/${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: \$(BINDIR)/${name}.s19\n");
553
    $io->Prt( "\t\$(call GENERATE_SXML, \\" .
554
              "\n\t\t\$(BINDIR)/${name}$exe, \\" .
555
              "\n\t\t$sxml,$type_text,$major,$minor,$patch,$build)\n"
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