4

I'm using a standalone atmega328p with a 16MHz crystal.

I'm programming it via avrdude on a raspberry pi, using the SPI and RESET pins.

When I compile my program, this is what I see at the end of the output:

----------------
Device: atmega328p

Program:    4152 bytes (12.7% Full)
(.text + .data + .bootloader)

Data:        253 bytes (12.4% Full)
(.data + .bss + .noinit)

As far as I understand, the bootloader is used to program the chip via UART, which I do not need(?). I'm assuming that the bootloader is still being compiled because of the output above containing .bootloader in the program part.

My program is compiled using the arduino SDK, with the following Makefile

ARDUINO_DIR = /usr/share/arduino
BOARD_TAG = uno

include /usr/share/arduino/Arduino.mk

I went through Arduino.mk and found this on line 1626:

ifndef AVRDUDE_ISP_BURN_BOOTLOADER
    ifneq ($(strip $(BOOTLOADER_FILE)),)
        AVRDUDE_ISP_BURN_BOOTLOADER += -U flash:w:$(BOOTLOADER_PARENT)/$(BOOTLOADER_PATH)/$(BOOTLOADER_FILE):i
    endif
endif

Which supposedly provides an option to turn off adding the bootloader but I couldn't figure out how to use it, so I just commented the line out:

ifndef AVRDUDE_ISP_BURN_BOOTLOADER
    ifneq ($(strip $(BOOTLOADER_FILE)),)
        # AVRDUDE_ISP_BURN_BOOTLOADER += -U flash:w:$(BOOTLOADER_PARENT)/$(BOOTLOADER_PATH)/$(BOOTLOADER_FILE):i
    endif
endif

But still, after compiling i see the .bootloader part and the program size remains the same.

Is it possible to tell it to skip adding the bootloader?

And yes, this is completely unnecessary for my application, I just want it, I want it bad.

3 Answers 3

4

Seeing .bootloader section in size output doesn't mean it's really present. It just means the sum of all three is 4152 bytes.

You can check the hex file if it contains large block of data at the bootloader address space. The main program starts at the lower adresses and then there should be big gap and at the end bigger chunk of data with adresses in bootloader section (but only if you really have a bootloader).

But unless you program also BOOTRST fuse, it won't start in bootloader anyway.

Usage of AVRDUDE_ISP_BURN_BOOTLOADER is normal environment variable (can be also set inside of Makefile) and as it's tested for not being present so you can just check if it's not being set somewhere in Makefile

1
  • 1
    Is there any tool that allows for easier preview of the whole address space?
    – php_nub_qq
    Commented Nov 8, 2023 at 23:39
2

I found this question which shows that the bootloader's address space is 7800 to 7FF0. I also confirmed that by taking a look at atmega328p's bootloader hex file stored in /usr/share/arduino/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex and indeed the first line is this:

:107800000C94343C0C94513C0C94513C0C94513CE1

Hex file format explained here.

So I then went back to my compiled hex file and checked whether there's anything at this address and there wasn't.

So apparently my program does not contain the bootloader.

I'm adding this as a separate answer with all the details because it took me some time to figure it out after reading KIIV's answer, credit goes to him.

2

I strongly doubt the compiler adds the bootloader. What that message is probably trying to tell you is that the bootloader is being included in its assumed address space.

There are various bootloaders, Optiboot is only 512 bytes. If you are programming directly (not via a bootloader) then the bootloader isn't required, of course.

If you program via SPI and set the BOOTRST flag appropriately then the processor will boot directly into your code which will save a small amount of time as the bootloader waits to see if there is any serial input for reprogramming. Plus, you get another 512 bytes for your code.

In your case, it hardly matters as the reported 4152 bytes is way short of 32 KB.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.