Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate map files if pico_add_extra_outputs is called #432

Conversation

jonathangjertsen
Copy link
Contributor

Many examples in the pico-examples repo call pico_add_extra_outputs with the comment "create map/bin/hex file etc.", so it seems like this is the intention.

Many examples in pico-examples call `pico_add_extra_outputs` with the
comment "# create map/bin/hex file etc.", so it seems like this is the
intention.
@fivdi
Copy link
Contributor

fivdi commented May 21, 2021

Is the map file not currently already created even without calling pico_add_extra_outputs?
See output file <executable_name>.elf.map
Maybe the comments "create map/bin/hex file etc." are just a little inaccurate?

@jonathangjertsen
Copy link
Contributor Author

At least on my machine the map file is generated if and only if I add this line.

@fivdi
Copy link
Contributor

fivdi commented May 21, 2021

On a Raspberry Pi 4, with pico-sdk v1.1.2 installed and PICO_SDK_PATH appropriately set, running the following commands:

git clone https://github.com/raspberrypi/pico-examples.git
cd pico-examples
mkdir build
cd build
cmake ..
make

builds all examples and creates all the appropriate output files, including the map files.

Running the following command from the build directory after building the examples:

find . -type f -name "*.elf*" | sort

displays the following:

./adc/adc_console/adc_console.elf
./adc/adc_console/adc_console.elf.map
./adc/dma_capture/adc_dma_capture.elf
./adc/dma_capture/adc_dma_capture.elf.map
./adc/hello_adc/hello_adc.elf
./adc/hello_adc/hello_adc.elf.map
./adc/joystick_display/joystick_display.elf
./adc/joystick_display/joystick_display.elf.map
./blink/blink.elf
./blink/blink.elf.map
./clocks/detached_clk_peri/clocks_detached_clk_peri.elf
./clocks/detached_clk_peri/clocks_detached_clk_peri.elf.map
./clocks/hello_48MHz/hello_48MHz.elf
./clocks/hello_48MHz/hello_48MHz.elf.map
./clocks/hello_gpout/hello_gpout.elf
./clocks/hello_gpout/hello_gpout.elf.map
./clocks/hello_resus/hello_resus.elf
./clocks/hello_resus/hello_resus.elf.map
./cmake/build_variants/build_variant1.elf
./cmake/build_variants/build_variant1.elf.map
./cmake/build_variants/build_variant2.elf
./cmake/build_variants/build_variant2.elf.map
./divider/hello_divider.elf
./divider/hello_divider.elf.map
./dma/channel_irq/dma_channel_irq.elf
./dma/channel_irq/dma_channel_irq.elf.map
./dma/control_blocks/dma_control_blocks.elf
./dma/control_blocks/dma_control_blocks.elf.map
./dma/hello_dma/hello_dma.elf
./dma/hello_dma/hello_dma.elf.map
./flash/cache_perfctr/flash_cache_perfctr.elf
./flash/cache_perfctr/flash_cache_perfctr.elf.map
./flash/nuke/flash_nuke.elf
./flash/nuke/flash_nuke.elf.map
./flash/program/flash_program.elf
./flash/program/flash_program.elf.map
./flash/ssi_dma/flash_ssi_dma.elf
./flash/ssi_dma/flash_ssi_dma.elf.map
./flash/xip_stream/flash_xip_stream.elf
./flash/xip_stream/flash_xip_stream.elf.map
./gpio/dht_sensor/dht.elf
./gpio/dht_sensor/dht.elf.map
./gpio/hello_7segment/hello_7segment.elf
./gpio/hello_7segment/hello_7segment.elf.map
./gpio/hello_gpio_irq/hello_gpio_irq.elf
./gpio/hello_gpio_irq/hello_gpio_irq.elf.map
./hello_world/serial/hello_serial.elf
./hello_world/serial/hello_serial.elf.map
./hello_world/usb/hello_usb.elf
./hello_world/usb/hello_usb.elf.map
./i2c/bus_scan/i2c_bus_scan.elf
./i2c/bus_scan/i2c_bus_scan.elf.map
./i2c/lcd_1602_i2c/lcd_1602_i2c.elf
./i2c/lcd_1602_i2c/lcd_1602_i2c.elf.map
./i2c/mpu6050_i2c/mpu6050_i2c.elf
./i2c/mpu6050_i2c/mpu6050_i2c.elf.map
./interp/hello_interp/hello_interp.elf
./interp/hello_interp/hello_interp.elf.map
./multicore/hello_multicore/hello_multicore.elf
./multicore/hello_multicore/hello_multicore.elf.map
./multicore/multicore_fifo_irqs/multicore_fifo_irqs.elf
./multicore/multicore_fifo_irqs/multicore_fifo_irqs.elf.map
./multicore/multicore_runner/multicore_runner.elf
./multicore/multicore_runner/multicore_runner.elf.map
./multicore/multicore_runner_queue/multicore_runner_queue.elf
./multicore/multicore_runner_queue/multicore_runner_queue.elf.map
./picoboard/blinky/picoboard_blinky.elf
./picoboard/blinky/picoboard_blinky.elf.map
./picoboard/button/picoboard_button.elf
./picoboard/button/picoboard_button.elf.map
./pico-sdk/src/rp2_common/boot_stage2/bs2_default.elf
./pico-sdk/src/rp2_common/boot_stage2/bs2_default.elf.map
./pio/addition/pio_addition.elf
./pio/addition/pio_addition.elf.map
./pio/apa102/pio_apa102.elf
./pio/apa102/pio_apa102.elf.map
./pio/clocked_input/pio_clocked_input.elf
./pio/clocked_input/pio_clocked_input.elf.map
./pio/differential_manchester/pio_differential_manchester.elf
./pio/differential_manchester/pio_differential_manchester.elf.map
./pio/hello_pio/hello_pio.elf
./pio/hello_pio/hello_pio.elf.map
./pio/hub75/pio_hub75.elf
./pio/hub75/pio_hub75.elf.map
./pio/i2c/pio_i2c_bus_scan.elf
./pio/i2c/pio_i2c_bus_scan.elf.map
./pio/logic_analyser/pio_logic_analyser.elf
./pio/logic_analyser/pio_logic_analyser.elf.map
./pio/manchester_encoding/pio_manchester_encoding.elf
./pio/manchester_encoding/pio_manchester_encoding.elf.map
./pio/pio_blink/pio_blink.elf
./pio/pio_blink/pio_blink.elf.map
./pio/pwm/pio_pwm.elf
./pio/pwm/pio_pwm.elf.map
./pio/spi/pio_spi_flash.elf
./pio/spi/pio_spi_flash.elf.map
./pio/spi/pio_spi_loopback.elf
./pio/spi/pio_spi_loopback.elf.map
./pio/squarewave/pio_squarewave.elf
./pio/squarewave/pio_squarewave.elf.map
./pio/st7789_lcd/pio_st7789_lcd.elf
./pio/st7789_lcd/pio_st7789_lcd.elf.map
./pio/uart_rx/pio_uart_rx.elf
./pio/uart_rx/pio_uart_rx.elf.map
./pio/uart_tx/pio_uart_tx.elf
./pio/uart_tx/pio_uart_tx.elf.map
./pio/ws2812/pio_ws2812.elf
./pio/ws2812/pio_ws2812.elf.map
./pio/ws2812/pio_ws2812_parallel.elf
./pio/ws2812/pio_ws2812_parallel.elf.map
./pwm/hello_pwm/hello_pwm.elf
./pwm/hello_pwm/hello_pwm.elf.map
./pwm/led_fade/pwm_led_fade.elf
./pwm/led_fade/pwm_led_fade.elf.map
./pwm/measure_duty_cycle/pwm_measure_duty_cycle.elf
./pwm/measure_duty_cycle/pwm_measure_duty_cycle.elf.map
./rtc/hello_rtc/hello_rtc.elf
./rtc/hello_rtc/hello_rtc.elf.map
./rtc/rtc_alarm_repeat/rtc_alarm_repeat.elf
./rtc/rtc_alarm_repeat/rtc_alarm_repeat.elf.map
./rtc/rtc_alarm/rtc_alarm.elf
./rtc/rtc_alarm/rtc_alarm.elf.map
./spi/bme280_spi/bme280_spi.elf
./spi/bme280_spi/bme280_spi.elf.map
./spi/mpu9250_spi/mpu9250_spi.elf
./spi/mpu9250_spi/mpu9250_spi.elf.map
./spi/spi_dma/spi_dma.elf
./spi/spi_dma/spi_dma.elf.map
./spi/spi_flash/spi_flash.elf
./spi/spi_flash/spi_flash.elf.map
./system/hello_double_tap/hello_double_tap.elf
./system/hello_double_tap/hello_double_tap.elf.map
./system/narrow_io_write/narrow_io_write.elf
./system/narrow_io_write/narrow_io_write.elf.map
./system/unique_board_id/unique_board_id.elf
./system/unique_board_id/unique_board_id.elf.map
./timer/hello_timer/hello_timer.elf
./timer/hello_timer/hello_timer.elf.map
./timer/periodic_sampler/periodic_sampler.elf
./timer/periodic_sampler/periodic_sampler.elf.map
./timer/timer_lowlevel/timer_lowlevel.elf
./timer/timer_lowlevel/timer_lowlevel.elf.map
./uart/hello_uart/hello_uart.elf
./uart/hello_uart/hello_uart.elf.map
./uart/uart_advanced/uart_advanced.elf
./uart/uart_advanced/uart_advanced.elf.map
./usb/device/dev_audio_headset/dev_audio_headset.elf
./usb/device/dev_audio_headset/dev_audio_headset.elf.map
./usb/device/dev_hid_composite/dev_hid_composite.elf
./usb/device/dev_hid_composite/dev_hid_composite.elf.map
./usb/device/dev_hid_generic_inout/dev_hid_generic_inout.elf
./usb/device/dev_hid_generic_inout/dev_hid_generic_inout.elf.map
./usb/device/dev_lowlevel/dev_lowlevel.elf
./usb/device/dev_lowlevel/dev_lowlevel.elf.map
./usb/host/host_hid/host_hid.elf
./usb/host/host_hid/host_hid.elf.map
./watchdog/hello_watchdog/hello_watchdog.elf
./watchdog/hello_watchdog/hello_watchdog.elf.map

As can be seen, all the elf files and all the map files are there.

How can the issue that this PR fixes be reproduced?

@jonathangjertsen
Copy link
Contributor Author

jonathangjertsen commented May 21, 2021

I will try to reproduce from a fresh repo. But in that case, which part of the CMake code actually sets the linker flag that causes the map files to be made? The only place I can see is pico_add_map_output, and I don't see that being called on the targets.

@fivdi
Copy link
Contributor

fivdi commented May 21, 2021

which part of the CMake code actually sets the linker flag that causes the map files to be made?

The call to pico_add_map_output here: https://github.com/raspberrypi/pico-sdk/blob/1.1.2/src/rp2_common/pico_standard_link/CMakeLists.txt#L10

@kilograham
Copy link
Contributor

Yes, the comments are incorrect. Ideally all these would be created by default, however the UF2, DIS and BIN are created from the final executable target, and I'm not aware of any ways to do this automatically (i.e. no sort of method call) in CMake short of implementing a new compiler type.

The map file is generated by the linker, so can be added as a per target setting.

@jonathangjertsen
Copy link
Contributor Author

I did the exercise from #432 (comment) with both the master and develop branches of the SDK and with both nmake and ninja, and in all cases I see the map files are generated. So whatever the issue is it seems that I've caused it myself. Sorry for the confusion.

One curious difference between nmake and ninja is that nmake places the map files in the same directory as the elf, while ninja places all the map files at the top level of the build folder. 🤷

Ideally all these would be created by default, however the UF2, DIS and BIN are created from the final executable target, and I'm not aware of any ways to do this automatically (i.e. no sort of method call) in CMake short of implementing a new compiler type.

I suppose a new function could be added:

function(pico_add_executable target)
    add_executable(${target} ${ARGN})
    pico_add_extra_outputs(${target})
endfunction()

@kilograham
Copy link
Contributor

I suppose a new function could be added:

Yeah, perhaps worth doing; had considered it in the past, but was trying to avoid requiring something other than add_executable, add_library, because it seems it might be easier to get confused when you forget to do pico_add_executable vs add_executable.

The issue was really did I want to change all the examples to use pico_add_executable, and given the above the answer was no; that said, it doesn't hurt to add as a convenience

@kilograham
Copy link
Contributor

One curious difference between nmake and ninja is that nmake places the map files in the same directory as the elf, while ninja places all the map files at the top level of the build folder. 🤷

Interesting, i hadn't noticed... perhaps including CMAKE_BINARY_DIR in the map file path works in both cases?

@kilograham kilograham added this to the 1.2.1 milestone May 24, 2021
@kilograham
Copy link
Contributor

closing this; feel free to open a new PR either for fixing the comments, or adding a new method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants