Elektroda.pl
Elektroda.pl
X

Wyszukiwarki naszych partnerów

Wyszukaj w ofercie 200 tys. produktów TME
Europejski lider sprzedaży techniki i elektroniki.
Proszę, dodaj wyjątek elektroda.pl do Adblock.
Dzięki temu, że oglądasz reklamy, wspierasz portal i użytkowników.

[C]Generacja pliku ELF - makefile

master_pablo 04 Cze 2008 01:22 6767 4
  • #1 04 Cze 2008 01:22
    master_pablo
    Poziom 16  

    Witam!

    Zabralem sie pare dni temu za pisanie oprogramowania dla ATtiny45 (co akurat jest malo wazne) w C z wykorzystaniem software'owej implementacji USB pt. AVR-USB.
    Problem pojawil sie, gdy postanowilem program skompilowac. Poniewaz makefile dolaczany do projektow referencyjnych nie byl dla mnie zbyt jasny, to wykorzystalem swoj makefile, stworzony na podstawie template'u z WinAVR, z wycietymi sekcjami dotyczacymi C++. Zgodnie z readme:

    Code:

    The driver consists of the following files:
      Readme.txt ............. The file you are currently reading.
      Changelog.txt .......... Release notes for all versions of the driver.
      usbdrv.h ............... Driver interface definitions and technical docs.
    * usbdrv.c ............... High level language part of the driver. Link this
                               module to your code!
    * usbdrvasm.S ............ Assembler part of the driver. This module is mostly
                               a stub and includes one of the usbdrvasm*.S files
                               depending on processor clock. Link this module to
                               your code!
      usbdrvasm*.inc ......... Assembler routines for particular clock frequencies.
                               Included by usbdrvasm.S, don't link it directly!
      asmcommon.inc .......... Common assembler routines. Included by
                               usbdrvasm*.inc, don't link it directly!
      usbconfig-prototype.h .. Prototype for your own usbdrv.h file.
    * oddebug.c .............. Debug functions. Only used when DEBUG_LEVEL is
                               defined to a value greater than 0. Link this module
                               to your code!
      oddebug.h .............. Interface definitions of the debug module.
      iarcompat.h ............ Compatibility definitions for IAR C-compiler.
      usbdrvasm.asm .......... Compatibility stub for IAR-C-compiler. Use this
                               module instead of usbdrvasm.S when you assembler
                               with IAR's tools.
      License.txt ............ Open Source license for this driver.
      CommercialLicense.txt .. Optional commercial license for this driver.
      USBID-License.txt ...... Terms and conditions for using particular USB ID
                               values for particular purposes.

    (*) ... These files should be linked to your project.


    plik odpowiednio dostosowalem:

    Code:

    ...
    MCU = attiny45
    F_CPU = 16500000
    #caly moj kod zawiera sie w main.c
    SRC = main.c usbdrv.c oddebug.c
    ASRC = usbdrvasm.S
    #AVR-USB znajduje sie w podkatalogu usbdrv
    EXTRAINCDIRS = usbdrv
    ...


    Przy wywolaniu make all otrzymuje nastepujacy blad:

    Code:

    make.exe: *** No rule to make target `main.elf', needed by `elf'.  Stop.


    Tak wiec niby nie ma instrukcji do generacji pliku ELF. Sek w tym, ze w projekcie, z ktorego makefile pochodzi, taki plik i wszystkie inne pliki elegancko sie generowaly. Z kolei makefile z projektu referencyjnego generuje plik ELF.
    Bardzo prosze, zeby ktos na zerknal i poinstruowal mnie, co dopisac. Niestety skladnia plikow make pozostaje dla mnie dosyc niejasna...

    W zalacznikach jest moj makefile i plik referencyjny.


    >Zmieniłem tytuł tematu i przeniosłem do właściwego działu<
    https://www.elektroda.pl/.../topic1015361.html
    [zumek]

  • #2 05 Cze 2008 11:12
    szelus
    Specjalista - Mikrokontrolery

    master_pablo napisał:
    Niestety skladnia plikow make pozostaje dla mnie dosyc niejasna...


    Wiesz, gdybyś poczytał instrukcję do make-a (wiem, jest tego troche ;)), to składnia przestałaby być niejasna. Magii tam żadnej nie ma, ale przez porównanie dwóch plików makefile nie da się poznać zasad.

    Wklej makefile normalnie, jako kod, chyba nie jest taki wielki. Postaram się pomóc. Format rar nie jest uniwersalny (dostępny dla wszystkich) ;)

  • #3 05 Cze 2008 12:17
    master_pablo
    Poziom 16  

    Moze zle sie wyrazilem - nie tyle skladnia pozostaje dla mnie niejasna, co nie umiem stwierdzic, dlaczego nie jest generowany plik ELF, pomimo tego, ze w pliku make istnieje regula (chyba) za to odpowiedzialna.

    Code:

    # MCU name
    MCU = attiny45


    # Processr frequency.
    #     This will define a symbol, F_CPU, in all source code files equal to the
    #     processor frequency. You can then use this symbol in your source code to
    #     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
    #     automatically to create a 32-bit value in your source code.
    F_CPU = 16500000


    # Debug level
    DEBUG_LEVEL=0


    # Output format. (can be srec, ihex, binary)
    FORMAT = ihex


    # Target file name (without extension).
    TARGET = main


    # Object files directory
    #     To put object files in current directory, use a dot (.), do NOT make
    #     this an empty or blank macro!
    OBJDIR = .


    # List C source files here. (C dependencies are automatically generated.)
    SRC = main.c usbdrv.c oddebug.c


    # List Assembler source files here.
    #     Make them always end in a capital .S.  Files ending in a lowercase .s
    #     will not be considered source files but generated files (assembler
    #     output from the compiler), and will be deleted upon "make clean"!
    #     Even though the DOS/Win* filesystem matches both .s and .S the same,
    #     it will preserve the spelling of the filenames, and gcc itself does
    #     care about how the name is spelled on its command-line.
    ASRC = usbdrvasm.S


    # Optimization level, can be [0, 1, 2, 3, s].
    #     0 = turn off optimization. s = optimize for size.
    #     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
    OPT = s


    # Debugging format.
    #     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
    #     AVR Studio 4.10 requires dwarf-2.
    #     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
    DEBUG = dwarf-2


    # List any extra directories to look for include files here.
    #     Each directory must be seperated by a space.
    #     Use forward slashes for directory separators.
    #     For a directory that has spaces, enclose it in quotes.
    EXTRAINCDIRS = usbdrv


    # Compiler flag to set the C Standard level.
    #     c89   = "ANSI" C




    #     gnu89 = c89 plus GCC extensions
    #     c99   = ISO C99 standard (not yet fully implemented)
    #     gnu99 = c99 plus GCC extensions
    CSTANDARD = -std=gnu99


    # Place -D or -U options here for C sources
    CDEFS = -DF_CPU=$(F_CPU)UL -DDEBUG_LEVEL=$(DEBUG_LEVEL)


    # Place -D or -U options here for ASM sources
    ADEFS = -DF_CPU=$(F_CPU) -DDEBUG_LEVEL=$(DEBUG_LEVEL)



    #---------------- Compiler Options C ----------------
    #  -g*:          generate debugging information
    #  -O*:          optimization level
    #  -f...:        tuning, see GCC manual and avr-libc documentation
    #  -Wall...:     warning level
    #  -Wa,...:      tell GCC to pass this to the assembler.
    #    -adhlns...: create assembler listing
    CFLAGS = -g$(DEBUG)
    CFLAGS += $(CDEFS)
    CFLAGS += -O$(OPT)
    CFLAGS += -funsigned-char
    CFLAGS += -funsigned-bitfields
    CFLAGS += -fpack-struct
    CFLAGS += -fshort-enums
    CFLAGS += -fgnu89-inline
    #CFLAGS += -frename-registers
    CFLAGS += -Wall
    CFLAGS += -Wstrict-prototypes
    #CFLAGS += -mshort-calls
    #CFLAGS += -fno-unit-at-a-time
    #CFLAGS += -Wundef
    #CFLAGS += -Wunreachable-code
    #CFLAGS += -Wsign-compare
    CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
    CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
    CFLAGS += $(CSTANDARD)


    #---------------- Assembler Options ----------------
    #  -Wa,...:   tell GCC to pass this to the assembler.
    #  -adhlns:   create listing
    #  -gstabs:   have the assembler create line number information; note that
    #             for use in COFF files, additional information about filenames
    #             and function names needs to be present in the assembler source
    #             files -- see avr-libc docs [FIXME: not yet described there]
    #  -listing-cont-lines: Sets the maximum number of continuation lines of hex
    #       dump that will be displayed for a given single line of source input.
    ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100



    #---------------- Linker Options ----------------
    #  -Wl,...:     tell GCC to pass this to linker.
    #    -Map:      create map file
    #    --cref:    add cross reference to  map file
    LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
    LDFLAGS += $(patsubst %)
    #LDFLAGS += -T linker_script.x



    #---------------- Programming Options (avrdude) ----------------

    # Programming hardware
    # Type: avrdude -c ?
    # to get a full listing.
    #
    AVRDUDE_PROGRAMMER = usbasp

    # com1 = serial port. Use lpt1 to connect to parallel port.
    AVRDUDE_PORT = com1    # programmer connected to serial device

    AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
    #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep


    # Uncomment the following if you want avrdude's erase cycle counter.
    # Note that this counter needs to be initialized first using -Yn,
    # see avrdude manual.
    #AVRDUDE_ERASE_COUNTER = -y

    # Uncomment the following if you do /not/ wish a verification to be
    # performed after programming the device.
    #AVRDUDE_NO_VERIFY = -V

    # Increase verbosity level.  Please use this when submitting bug
    # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
    # to submit bug reports.
    #AVRDUDE_VERBOSE = -v -v

    AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
    AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
    AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
    AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)



    #============================================================================


    # Define programs and commands.
    SHELL = sh
    CC = avr-gcc
    OBJCOPY = avr-objcopy
    OBJDUMP = avr-objdump
    SIZE = avr-size
    AR = avr-ar rcs
    NM = avr-nm
    AVRDUDE = avrdude
    REMOVE = rm -f
    REMOVEDIR = rm -rf
    COPY = cp
    WINSHELL = cmd


    # Define Messages
    # English
    MSG_ERRORS_NONE = Errors: none
    MSG_BEGIN = -------- begin --------
    MSG_END = --------  end  --------
    MSG_SIZE_BEFORE = Size before:
    MSG_SIZE_AFTER = Size after:
    MSG_FLASH = Creating load file for Flash:
    MSG_EEPROM = Creating load file for EEPROM:
    MSG_EXTENDED_LISTING = Creating Extended Listing:
    MSG_SYMBOL_TABLE = Creating Symbol Table:
    MSG_LINKING = Linking:
    MSG_COMPILING = Compiling C:
    MSG_ASSEMBLING = Assembling:
    MSG_CLEANING = Cleaning project:
    MSG_CREATING_LIBRARY = Creating library:




    # Define all object files.
    OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)

    # Define all listing files.
    LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)


    # Compiler flags to generate dependency files.
    GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d


    # Combine all necessary flags and optional flags.
    # Add target processor to flags.
    ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
    ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)





    # Default target.
    all: begin gccversion sizebefore build sizeafter end

    # Change the build target to build a HEX file or a library.
    build: elf hex eep lss sym
    #build: lib


    elf: $(TARGET).elf
    hex: $(TARGET).hex
    eep: $(TARGET).eep
    lss: $(TARGET).lss
    sym: $(TARGET).sym
    LIBNAME=lib$(TARGET).a
    lib: $(LIBNAME)



    # Eye candy.
    # AVR Studio 3.x does not check make's exit code but relies on
    # the following magic strings to be generated by the compile job.
    begin:
       @echo
       @echo $(MSG_BEGIN)

    end:
       @echo $(MSG_END)
       @echo


    # Display size of file.
    HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
    ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf

    sizebefore:
       @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
       2>/dev/null; echo; fi

    sizeafter:
       @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
       2>/dev/null; echo; fi



    # Display compiler version information.
    gccversion :
       @$(CC) --version



    # Program the device.
    program: $(TARGET).hex $(TARGET).eep
       $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)



    # Create final output files (.hex, .eep) from ELF output file.
    %.hex: %.elf
       @echo
       @echo $(MSG_FLASH) $@
       $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock $< $@

    %.eep: %.elf
       @echo
       @echo $(MSG_EEPROM) $@
       -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
       --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0

    # Create extended listing file from ELF output file.
    %.lss: %.elf
       @echo
       @echo $(MSG_EXTENDED_LISTING) $@
       $(OBJDUMP) -h -S -z $< > $@

    # Create a symbol table from ELF output file.
    %.sym: %.elf
       @echo
       @echo $(MSG_SYMBOL_TABLE) $@
       $(NM) -n $< > $@



    # Create library from object files.
    .SECONDARY : $(TARGET).a
    .PRECIOUS : $(OBJ)
    %.a: $(OBJ)
       @echo
       @echo $(MSG_CREATING_LIBRARY) $@
       $(AR) $@ $(OBJ)


    # Link: create ELF output file from object files.
    .SECONDARY : $(TARGET).elf
    .PRECIOUS : $(OBJ)
    %.elf: $(OBJ)
       @echo
       @echo $(MSG_LINKING) $@
       $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)


    # Compile: create object files from C source files.
    $(OBJDIR)/%.o : %.c
       @echo
       @echo $(MSG_COMPILING) $<
       $(CC) -c $(ALL_CFLAGS) $< -o $@


    # Compile: create assembler files from C source files.
    %.s : %.c
       $(CC) -S $(ALL_CFLAGS) $< -o $@


    # Assemble: create object files from assembler source files.
    $(OBJDIR)/%.o : %.S
       @echo
       @echo $(MSG_ASSEMBLING) $<
       $(CC) -c $(ALL_ASFLAGS) $< -o $@


    # Create preprocessed source for use in sending a bug report.
    %.i : %.c
       $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@


    # Target: clean project.
    clean: begin clean_list end

    clean_list :
       @echo
       @echo $(MSG_CLEANING)
       $(REMOVE) $(TARGET).hex
       $(REMOVE) $(TARGET).eep
       $(REMOVE) $(TARGET).cof
       $(REMOVE) $(TARGET).elf
       $(REMOVE) $(TARGET).map
       $(REMOVE) $(TARGET).sym
       $(REMOVE) $(TARGET).lss
       $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
       $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
       $(REMOVE) $(SRC:.c=.s)
       $(REMOVE) $(SRC:.c=.d)
       $(REMOVE) $(SRC:.c=.i)
       $(REMOVEDIR) .dep


    # Create object files directory
    $(shell mkdir $(OBJDIR) 2>/dev/null)


    # Include the dependency files.
    -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)


    # Listing of phony targets.
    .PHONY : all begin finish end sizebefore sizeafter gccversion \
    build elf hex eep lss sym \
    clean clean_list program


    A tutaj plik, ktory dziala:

    Code:

    # Name: Makefile
    # Project: EasyLogger
    # Author: Christian Starkjohann
    # Creation Date: 2007-06-23
    # Tabsize: 4
    # Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
    # License: GPLv2.
    # This Revision: $Id: Makefile 362 2007-06-25 14:38:21Z cs $

    DEVICE=attiny45
    AVRDUDE = avrdude -c usbasp -p $(DEVICE)
    # The two lines above are for "avrdude" and the STK500 programmer connected
    # to an USB to serial converter to a Mac running Mac OS X.
    # Choose your favorite programmer and interface.

    COMPILE = avr-gcc -Wall -Os -Iusbdrv -I. -mmcu=$(DEVICE) -DF_CPU=16500000 -DDEBUG_LEVEL=0
    # NEVER compile the final product with debugging! Any debug output will
    # distort timing so that the specs can't be met.

    OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o

    # symbolic targets:
    all:   main.hex

    .c.o:
       $(COMPILE) -c $< -o $@

    .S.o:
       $(COMPILE) -x assembler-with-cpp -c $< -o $@
    # "-x assembler-with-cpp" should not be necessary since this is the default
    # file type for the .S (with capital S) extension. However, upper case
    # characters are not always preserved on Windows. To ensure WinAVR
    # compatibility define the file type manually.

    .c.s:
       $(COMPILE) -S $< -o $@

    flash:   all
       $(AVRDUDE) -U flash:w:main.hex:i


    # Fuse high byte:
    # 0xdd = 1 1 0 1   1 1 0 1
    #        ^ ^ ^ ^   ^ \-+-/
    #        | | | |   |   +------ BODLEVEL 2..0 (brownout trigger level -> 2.7V)
    #        | | | |   +---------- EESAVE (preserve EEPROM on Chip Erase -> not preserved)
    #        | | | +-------------- WDTON (watchdog timer always on -> disable)
    #        | | +---------------- SPIEN (enable serial programming -> enabled)
    #        | +------------------ DWEN (debug wire enable)
    #        +-------------------- RSTDISBL (disable external reset -> enabled)
    #
    # Fuse low byte:
    # 0xe1 = 1 1 1 0   0 0 0 1
    #        ^ ^ \+/   \--+--/
    #        | |  |       +------- CKSEL 3..0 (clock selection -> HF PLL)
    #        | |  +--------------- SUT 1..0 (BOD enabled, fast rising power)
    #        | +------------------ CKOUT (clock output on CKOUT pin -> disabled)
    #        +-------------------- CKDIV8 (divide clock by 8 -> don't divide)
    #fuse:
    #   $(AVRDUDE) -U hfuse:w:0xdd:m -U lfuse:w:0xe1:m

    readcal:
       $(AVRDUDE) -U calibration:r:/dev/stdout:i | head -1


    clean:
       rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.bin *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s

    # file targets:
    main.bin:   $(OBJECTS)
       $(COMPILE) -o main.bin $(OBJECTS)

    main.hex:   main.bin
       rm -f main.hex main.eep.hex
       avr-objcopy -j .text -j .data -O ihex main.bin main.hex

    disasm:   main.bin
       avr-objdump -d main.bin

    cpp:
       $(COMPILE) -E main.c

  • Pomocny post
    #4 05 Cze 2008 13:39
    szelus
    Specjalista - Mikrokontrolery

    Hmm...
    O ile dobrze zrozumiałem z pierwszego posta, plik main.c masz w katalogu głównym a pozostałe w usbdrv?
    Spróbuj może tak:

    Code:

    SRC = main.c usrbdrv/usbdrv.c usbdrv/oddebug.c
    ASRC = usbdrv/usbdrvasm.S

    Jest szansa, że zadziała ;)

  • #5 05 Cze 2008 14:18
    master_pablo
    Poziom 16  

    No faktycznie! Ja bylem przekonany, ze wystarczy napisac:

    Code:

    EXTRAINCDIRS = usbdrv

    zeby make automatycznie szukal tam plikow do kompilacji. A jak sie okazuje, to tylko powoduje szukanie tam plikow naglowkowych.

    Szkoda tylko, ze ten blad wypluwany przez make nijak sie mial do zrodla problemu - zamiast napisac, ze nie mozna znalezc plikow, to sygnalizuje brak odpowiednich komend.

    Dziekuje za pomoc!

 Szukaj w ofercie
Zamknij 
Wyszukaj w ofercie 200 tys. produktów TME