Skip to content

Commit

Permalink
🔨 Firmware rename followup (#25966)
Browse files Browse the repository at this point in the history
Followup to #25957
  • Loading branch information
thisiskeithb authored Jun 11, 2023
1 parent b5d3d01 commit 00ab015
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions ini/stm32f1-maple.ini
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ extends = env:STM32F103RE_maple
build_flags = ${env:STM32F103RE_maple.build_flags} -DTEMP_TIMER_CHAN=4
board_build.address = 0x08007000
board_build.ldscript = creality.ld
board_build.rename = firmware-{date}-{time}
board_build.rename = firmware-{date}-{time}.bin
debug_tool = jlink
upload_protocol = jlink

Expand All @@ -130,7 +130,7 @@ extends = env:STM32F103RC_maple
build_flags = ${env:STM32F103RC_maple.build_flags} -DTEMP_TIMER_CHAN=4
board_build.address = 0x08007000
board_build.ldscript = creality.ld
board_build.rename = firmware-{date}-{time}
board_build.rename = firmware-{date}-{time}.bin
debug_tool = jlink
upload_protocol = jlink

Expand Down Expand Up @@ -398,7 +398,7 @@ extends = env:STM32F103RE_maple
build_flags = ${STM32F1_maple.build_flags} -DTEMP_TIMER_CHAN=4
board_build.address = 0x08007000
board_build.ldscript = sovol.ld
board_build.rename = firmware-{date}-{time}
board_build.rename = firmware-{date}-{time}.bin
extra_scripts = ${STM32F1_maple.extra_scripts}
buildroot/share/PlatformIO/scripts/custom_board.py
debug_tool = jlink
Expand Down
2 changes: 1 addition & 1 deletion ini/stm32f1.ini
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ debug_tool = stlink
extends = stm32_variant
board_build.variant = MARLIN_F103Rx
board_build.offset = 0x7000
board_build.rename = firmware-{date}-{time}
board_build.rename = firmware-{date}-{time}.bin
board_upload.offset_address = 0x08007000
build_flags = ${stm32_variant.build_flags}
-DMCU_STM32F103RE -DHAL_SD_MODULE_ENABLED
Expand Down
4 changes: 2 additions & 2 deletions ini/stm32f4.ini
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ board = genericSTM32F401RC
board_build.variant = MARLIN_CREALITY_STM32F401RC
board_build.offset = 0x10000
board_upload.offset_address = 0x08010000
board_build.rename = firmware-{date}-{time}
board_build.rename = firmware-{date}-{time}.bin
build_flags = ${stm32_variant.build_flags} -DMCU_STM32F401RC -DSTM32F4
-DSS_TIMER=4 -DTIMER_SERVO=TIM5
-DENABLE_HWSERIAL3 -DTRANSFER_CLOCK_DIV=8
Expand All @@ -709,7 +709,7 @@ extends = stm32_variant
board = marlin_CREALITY_STM32F401RE
board_build.offset = 0x10000
board_upload.offset_address = 0x08010000
board_build.rename = firmware-{date}-{time}
board_build.rename = firmware-{date}-{time}.bin
build_flags = ${stm32_variant.build_flags} -DSTM32F401xE -DSTM32F4 -DSTM32F4_UPDATE_FOLDER
build_unflags = ${stm32_variant.build_unflags} -DUSBCON -DUSBD_USE_CDC
monitor_speed = 115200
Expand Down

16 comments on commit 00ab015

@ThomasToka
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .elf binary is not renamed. it stays firmware.elf.

@ellensp
Copy link
Contributor

@ellensp ellensp commented on 00ab015 Jun 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elf is not just binary, binary is extracted from elf file and renamed.
elf file is not renamed.
https://en.wikipedia.org/wiki/Executable_and_Linkable_Format

@ThomasToka
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for saying "binary".

the problem stays the same. the .elf file is not renamed.

@ellensp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The elf file is not renamed. never has been, is not meant to be renamed. You should not be looking at or touching the elf file in any way

@ellensp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You Compile and it spits out this at the end

Building .pio/build/STM32F103RE_creality/firmware.bin
rename_target([".pio/build/STM32F103RE_creality/firmware.bin"], [".pio/build/STM32F103RE_creality/firmware.elf"])

resulting in many directories and files in .pio/build including

firmware-20230612-011742.bin
firmware.elf

you use the firmware-20230612-011742.bin file

@ThomasToka
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never has been,

this is a good catch. i used till now this:

import pioutil
if pioutil.is_pio_build():
    from datetime import datetime
    Import("env")
    env['PROGNAME'] = datetime.now().strftime("firmware-%Y%m%d-%H%M%S-E3S1Pro-abl5x5-LA-F1")

so this did it.. so i not knew that "default" it is not renamed.

but that would be great.

i naturally know that the elf file is not needed and that i install the .bin.

but if there is a .elf file. i would prefer it should match the .bin file that is build as it belongs to this particular build.

if not possible i dont mind.

@thisiskeithb
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not possible i dont mind.

@ThomasToka: That's outside the scope of these fixes/repo. Feel free to hop on our Discord for help with scripting or one of the other support options below:

@classicrocker883
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThomasToka I know what you're saying. personally I feel the same way, leaving the files to be named the same before the commit. also in the terminal it doesn't print out the name change, so like if you wanted to see what you just compiled, you don't know. I have a sort of "fix" I'll share.

and I see you want the firmware. bin file named a certain way, may I suggest making a Workflows with GitHub actions?

it took me some time to figure out but there's a way to make it so you can compile your own firmware automatically and have it do multiple files and options.

check it out here it's how I can make all my versions at once.

basically when i create a release it does it automatically.

@ThomasToka
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you @classicrocker883 . thank you @thisiskeithb .

just for the records and if someone struggles on this:

the change breaks also building/renaming with a script in a variant.

extra_scripts               = ${stm32_variant.extra_scripts}
                              pre:buildroot/share/PlatformIO/scripts/random-bin-e3s1pro-abl5x5-F4.py

something like this does not work anymore if the filename is forced in the "parent"..

@classicrocker883
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThomasToka found your fix

        def rename_target(source, target, env):
            from pathlib import Path

            from datetime import datetime

            BIN_NAME = Path(target[0].path).replace(Path(target[0].dir.path, datetime.now().strftime(new_name.replace('{date}', '%Y%m%d').replace('{time}', '%H%M%S'))))
            ELF_NAME = Path(source[0].path).replace(Path(source[0].dir.path, datetime.now().strftime("firmware-%Y%m%d-%H%M%S.elf")))
            print("FIRMWARE ELF: %s" % ELF_NAME)
            print("FIRMWARE BIN: %s" % BIN_NAME)

in File: \buildroot\share\PlatformIO\scripts\offset_and_rename.py

just added a second call to rename the "source" which is "firnware.elf" and changed to like the .bin

also adding the print function shows the name

@thinkyhead
Copy link
Member

@thinkyhead thinkyhead commented on 00ab015 Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like this does not work anymore if the filename is forced in the "parent"..

Of course that was the whole point. To eliminate the need to specify so many renaming scripts and provide a general approach using the existing rename facility. Instead of using an extra_scripts field you will use board_build.rename with the desired name pattern. The one you provide overrides any that exists in the parent env.

@ThomasToka
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThomasToka found your fix

thanks. maybe @thisiskeithb can add this also? then the circle closes.

@ThomasToka
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i did it like i was able to with my humble knowledge compared to you all here. ;) naturally the way like it is now is way better.

thanks for the patience. we have all the same goal.

@ThomasToka
Copy link
Contributor

@ThomasToka ThomasToka commented on 00ab015 Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so i had a look at this. and implemented it for me like this to have the name consistent for my fork.

BIN_NAME = Path(target[0].path).replace(Path(target[0].dir.path, datetime.now().strftime(new_name.replace('{date}', '%Y%m%d').replace('{time}', '%H%M%S'))))
ELF_NAME = Path(source[0].path).replace(Path(source[0].dir.path, datetime.now().strftime(new_name.replace('{date}', '%Y%m%d').replace('{time}', '%H%M%S').replace('.bin', '.elf'))))
print("FIRMWARE ELF: %s" % ELF_NAME)
print("FIRMWARE BIN: %s" % BIN_NAME)

this does the job dynamically as your suggestion lead to:

FIRMWARE ELF: .pio\build\STM32F401RC_creality_e3s1pro_abl5x5_personal\firmware-20230613-200411.elf
FIRMWARE BIN: .pio\build\STM32F401RC_creality_e3s1pro_abl5x5_personal\firmware-20230613-200411-E3S1Pro-abl5x5-LA-personal-F4.bin

so the elf name was not the same as the .bin

now it is consistent:

FIRMWARE ELF: .pio\build\STM32F401RC_creality_e3s1pro_abl5x5_personal\firmware-20230613-200718-E3S1Pro-abl5x5-LA-personal-F4.elf
FIRMWARE BIN: .pio\build\STM32F401RC_creality_e3s1pro_abl5x5_personal\firmware-20230613-200718-E3S1Pro-abl5x5-LA-personal-F4.bin

thank your for pointing out where to look.

@classicrocker883
Copy link
Contributor

@classicrocker883 classicrocker883 commented on 00ab015 Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThomasToka well the point was so you can edit the name in the .ini file.

add -E3S1Pro-abl5x5-LA-personal-F4 before .bin (remove ".bin" following the edit below) where it says firmware-{date}-{time}

edit: oh I see what you want to do, so you can remove .bin from the .ini file and add to the end of BIN_NAME = Path(target[0]... ', '%H%M%S.bin'))))


followup edit:
or replace that line with

ELF_NAME = Path(source[0].path).replace(Path(source[0].dir.path, datetime.now().strftime(new_name.replace('{date}', '%Y%m%d').replace('{time}', '%H%M%S').replace('.bin', '.elf'))))

this is probably the best solution, so you just change whatever board_build.rename = firmware.... to whatever you like.

@ThomasToka
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or replace that line with

thats what i did if you look at my solution.. all good. thank you.

Please sign in to comment.