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