robertofem / CycloneVSoC-examples

Examples using the Cyclone V SoC chip
GNU General Public License v3.0
104 stars 40 forks source link

Simple Makefile to Build a minimal Baremetal Application #8

Closed LukeC8 closed 5 years ago

LukeC8 commented 5 years ago

Hi @robertofem,

Firstly, thank you for share these examples, I've learned so much trying to understand your codes.

I'm a beginner user of a DE1-SoC board, and now I'm trying to run my first bare-metal application. I've read some of your Makefiles in this repo, but, in my mind, there are some gaps in the build process of a bare-metal application.

Suppose that I have the code below:

#include <stdio.h>

int main() {

    printf("Hello!");

    return 0;
}

Could you, please, explain the steps that I need to build the file baremetal.bin from this code? All process to build and install the preloader and u-boot is not needed.

robertofem commented 5 years ago

I think I do not understand exactly what you are asking. Steps for compiling and testing are explained in any baremetal example like this one https://github.com/robertofem/CycloneVSoC-examples/tree/master/Baremetal-applications/Second_counter_PMU.

To build you need to type make from the Intel EDS console (the one installed when you install the Intel EDS tools) located in the project forlder, so the Makefile executes. To test you have to build the SD card as explained in https://github.com/robertofem/CycloneVSoC-examples/tree/master/SD-baremetal

Regarding the last sentence. You can run the baremetal app from preloader and from u-boot(it needs preloader). You can choose. I explain the 2 methods in previous link. So technically u-boot is not needed because you can run the app from preloader. But preloader is always needed I think. How do you run the baremetal app without preloader?? I dont know.

Regards

LukeC8 commented 5 years ago

Sorry, now I see that my comment was so confusing. I'll try to reformulate the question:

My goal is: I would like to write a makefile that can build the simple HelloWorld code above and generate a file named baremetal.bin to be loaded by u-boot or preloader. The process to generate/build the preloader and u-boot I already understand and we can ignore it (sorry, was what I meant by my last sentence). So, to achieve this goal, I started to read your makefiles, but some steps I did not understand. For example, the linker script used, why it was necessary? How did you realize it?

Thank you very much for helping.

robertofem commented 5 years ago

I dont remember quite well the process I followed to generate the makefile. I think I copied the makefile from some DMA example I found in Altera website. Then I modified it to generate both the files for running with uboot and preloader. Regarding the linker script, it is necessary to distribute the available memory into regions so the compiler is able to compile C language and C library. For example you need stack memory to enter in functions and be able to come back, you need heap memory for when you use dynamic memory, etc. If you program directly in assembler I dont think you need it. The linker script I also copied it from the Altera example. I dont understand it at all. The only thing I did is I think to modify the size of the different memory regions in the first lines of the file.

Thanks for checking my repo Regards

LukeC8 commented 5 years ago

Thank you for the information.

Regards