How to convert elf to bin?

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
Dreamcastfreak2004
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 19
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Mon Aug 30, 2021 6:42 pm
Has thanked: 0
Been thanked: 0

How to convert elf to bin?

Post by Dreamcastfreak2004 »

Hey yall, so anyways i want to compile one of the example programs, but how do i convert the .elf to a .bin file on kallistios on WSL?
User avatar
ThePerfectK
Insane DCEmu
Insane DCEmu
Posts: 147
Joined: Thu Apr 27, 2006 10:15 am
Has thanked: 27 times
Been thanked: 35 times

Re: How to convert elf to bin?

Post by ThePerfectK »

the KOS toolchain should have built sh-elf-objcopy. Use the following command to convert the elf to an unscrambled binary:

Code: Select all

sh-elf-objcopy -R .stack -O binary file.elf file.bin
If you wish to run the binary from an actual CD, you'll need to scramble the bin first using scramble from the KOS utils folder. Otherwise, you can just send the built binary across using dc-load ip or dc-load serial.
Still Thinking!~~
Dreamcastfreak2004
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 19
Joined: Mon Aug 30, 2021 6:42 pm
Has thanked: 0
Been thanked: 0

Re: How to convert elf to bin?

Post by Dreamcastfreak2004 »

Thanks For your output But, when I type the command you tell me to type in the terminal, it gives me a error message. the error says prog.bin No such file idk what to do about this error.
User avatar
ThePerfectK
Insane DCEmu
Insane DCEmu
Posts: 147
Joined: Thu Apr 27, 2006 10:15 am
Has thanked: 27 times
Been thanked: 35 times

Re: How to convert elf to bin?

Post by ThePerfectK »

I see you are having problems in this and the other topic you made, and both stem from the same misunderstanding. Let me give you a quick primer on folders and command line interfaces in both windows and linux.

When you issue a command from the terminal, what you are doing is calling out to a specific folder where an executable resides. sh-elf-objcopy is an executable. Normally, to run it from the command line, you would type the folder where the program resides prior to the name of the program. That is called giving an absolute path.

The KOS install scripts should install sh-elf-objcopy to the folder /opt/toolchains/dc/sh-elf/bin/ by default. Thus, the full path to the executable is /opt/toolchains/dc/sh-elf/bin/sh-elf-objcopy. Programs in linux typically do not have a file extension after them, where in windows it would probably be followed by .exe.

Now, in both windows and linux, if you don't provide a file path when you list an executable (or file) for a command, it will run through a list of assumptions for you. First, it will assume that you implied the current working folder. So, if you were already in the folder /opt/toolchains/dc/bin/ and ran the command, "sh-elf-objcopy," it would invisibly append the current directory to the command.

If it looks in the implied current directory and does not find the executable you called, it will then run through a couple of other folders where programs are typically installed to. In linux, this is usually the /usr/bin folder or similar. In windows, this is usually the system32 folder on the C drive. These folders hold binary (read: executable) programs that are needed system wide, so you don't need to append the folder directory to call them.

If the CLI still can't find the executable after looking in the system binaries folder, the next step is that it will look through a list of user-defined environment variables which could provide a working path to the executable. That is what doing environ.sh in linux does. It's setting an environment variable for a path that tells our CLI to look in /opt/toolchains/dc/sh-elf/bin/ for commands we are calling (done in the makefile). In windows, there is actually a program built into windows where you can manually set environment variables and paths. The CLI will run through all these environment variable paths to see if the executable (or file) is in any of those directories.

If it can't find it in any of those, it gives you the error you are getting. It outright doesn't know where the program or file you are calling is. In the case of this topic, it looks like the argument you are passing (prog.bin, the binary you want to scramble) isn't located in the folder you are calling sh-elf-objcopy from. To solve this, provide the full path to prog.bin. With regards to your other topic, it's the opposite. It couldn't find the executable, not the argument. The solution is still the same, provide the full file path to the executable.

You can see all the currently set environment variables from a terminal in linux by using the env command from CLI. There are similar commands in windows to do the same thing, but I can't recall them offhand at the moment.
Still Thinking!~~
Post Reply