OpenCores

* Amber ARM-compatible core

Issue List
Method to initialize boot memory with executable code for Altera users #31
Closed ccollineau opened this issue over 9 years ago
ccollineau commented over 9 years ago

To be able to run Amber on Altera FPGAs, you need to transform your ELF executable code into an Altera memory compatible HEX file. Below is presented a method to achieve this.

A/ Modify file "sw\include\common.mk":

1/ Add these two lines at the beginning of the file:
HEX32  = $(addsuffix _32.hex,  $(basename $(TGT)))
HEX128 = $(addsuffix _128.hex, $(basename $(TGT)))
HEXCV  = ../tools/convert_hex.awk

2/ Modify lines 95 and 97 accordingly:
ifdef USE_MINI_LIBC
debug:  mini-libc $(ELF) $(MMP32) $(MMP128) $(DIS) $(HEX32) $(HEX128)
else
debug:  $(ELF) $(MMP32) $(MMP128) $(DIS) $(HEX32) $(HEX128)
endif

3/ Then, add the following lines ("--gap-fill" option is important since it forces bytes in generated HEX file to be contiguous):
$(HEX128): $(TGT)
  $(OC) -O ihex --gap-fill 0 --pad-to 0x4000 $^ tmp.hex
  $(HEXCV) -v width=16 tmp.hex > $@
  rm -f tmp.hex
  
$(HEX32): $(TGT)
  $(OC) -O ihex --gap-fill 0 --pad-to 0x4000 $^ tmp.hex
  $(HEXCV) -v width=4 tmp.hex > $@
  rm -f tmp.hex

4/ Modify line 131 accordingly:
@rm -rfv *.o *.elf *.flt *.gdb *.dis *.map *.mem *.v $(MMP32) $(MMP128) $(HEX32) $(HEX128)

B/ Below is the "convert_hex.awk" source code to be put in "sw/tools/directory" (This file will parse objcopy-generated HEX file and will convert it to Altera memory HEX compatible format):


#!/bin/awk -f

BEGIN { k=0; line = ""; crc = 0; addr = 0; }

substr($0,8,2) == "00" {

size  = strtonum( "0x" substr($0,2,2) );

for ( i=0; i<size; i++ ) {

  j   = 10 + i * 2;
  str = substr($0,j,2);
  crc += strtonum( "0x" str );
  line = ( str line ); #swap bytes
  k++;
  if( ( k % width ) == 0 ) { printf ( ":%02X%04X00%s%02X\n",  width, addr, line, and( -( addr/256 + addr + width + crc ), 0xFF )  ); crc = 0; line = ""; addr += width; }
}

}

END { print ":00000001FF"; }

C/ Create and instantiate your Altera boot memory:

1/ In file "boot_mem32.v" if you use a23:

  altera_sram_4096x32_byte_en u_mem( 
   .address ( address     ),  // 4096 words, 32 bits
   .clock   ( i_wb_clk    ),
   .wren    ( start_write ),
   .byteena ( byte_enable ),
   .data    ( write_data  ),
   .q       ( read_data   )
 );

2/ Or in file "boot_mem128.v" if you use a25:

 altera_sram_1024x128_byte_en u_mem( 
  .address ( address     ),  // 1024 words, 128 bits
  .clock   ( i_wb_clk    ),
  .wren    ( start_write ),
  .byteena ( byte_enable ),
  .data    ( write_data  ),
  .q       ( read_data   )
);

When creating the memory component with the Altera Mega Wizard, specify "rom_32.hex" for a23 initialization file and "rom_128.hex" for a25.

D/ Simulation:

Before simulating your design, copy the generated HEX files "<your_code_name>_128.hex" or "<your_code_name>_32.hex" to "rom_128.hex" and "rom_32.hex" respectively into you simulation directory.

E/ Synthesis:

Copy files "rom_128.hex" or "rom_32.hex" into the Quartus project directory.

For people interested, I will provide soon a complete Amber port on Cyclone IV for the low cost BeMicro SDK platform (https://www.altera.com/b/bemicro-sdk.html) with LPDDR2 and Ethernet support.

Enjoy :-)

ccollineau commented over 9 years ago

Correctly reformatted (I hope): To be able to run Amber on Altera FPGAs, you need to transform your ELF executable code into an memory compatible HEX file. Below is presented a method to achieve this.

A/ Modify file "sw\include\common.mk":

1/ Add these two lines at the beginning of the file:
HEX32  = $(addsuffix _32.hex,  $(basename $(TGT)))
HEX128 = $(addsuffix _128.hex, $(basename $(TGT)))
HEXCV  = ../tools/convert_hex.awk

2/ Modify lines 95 and 97 accordingly:
ifdef USE_MINI_LIBC
debug:  mini-libc $(ELF) $(MMP32) $(MMP128) $(DIS) $(HEX32) $(HEX128)
else
debug:  $(ELF) $(MMP32) $(MMP128) $(DIS) $(HEX32) $(HEX128)
endif

3/ Then, add the following lines ("--gap-fill" option is important since it forces bytes in generated HEX file to be contiguous):
$(HEX128): $(TGT)
  $(OC) -O ihex --gap-fill 0 --pad-to 0x4000 $^ tmp.hex
  $(HEXCV) -v width=16 tmp.hex > $@
  rm -f tmp.hex
  
$(HEX32): $(TGT)
  $(OC) -O ihex --gap-fill 0 --pad-to 0x4000 $^ tmp.hex
  $(HEXCV) -v width=4 tmp.hex > $@
  rm -f tmp.hex

4/ Modify line 131 accordingly:
@rm -rfv *.o *.elf *.flt *.gdb *.dis *.map *.mem *.v $(MMP32) $(MMP128) $(HEX32) $(HEX128)

B/ Below is the "convert_hex.awk" source code to be put in "sw/tools/directory" (This file will parse objcopy-generated HEX file and will convert it to Altera memory compatible format):


#!/bin/awk -f

BEGIN { k=0; line = ""; crc = 0; addr = 0; }

substr($0,8,2) == "00" {

size  = strtonum( "0x" substr($0,2,2) );

for ( i=0; i<size; i++ ) {

  j   = 10 + i * 2;
  str = substr($0,j,2);
  crc += strtonum( "0x" str );
  line = ( str line ); #swap bytes
  k++;
  if( ( k % width ) == 0 ) { printf ( ":%02X%04X00%s%02X\n",  width, addr, line, and( -( addr/256 + addr + width + crc ), 0xFF )  ); crc = 0; line = ""; addr += width; }
}

}

END { print ":00000001FF"; }

C/ Create and instantiate your Altera boot memory:

1/ In file "boot_mem32.v" if you use a23:

  altera_sram_4096x32_byte_en u_mem( 
   .address ( address     ),  // 4096 words, 32 bits
   .clock   ( i_wb_clk    ),
   .wren    ( start_write ),
   .byteena ( byte_enable ),
   .data    ( write_data  ),
   .q       ( read_data   )
 );

2/ Or in file "boot_mem128.v" if you use a25:

 altera_sram_1024x128_byte_en u_mem( 
  .address ( address     ),  // 1024 words, 128 bits
  .clock   ( i_wb_clk    ),
  .wren    ( start_write ),
  .byteena ( byte_enable ),
  .data    ( write_data  ),
  .q       ( read_data   )
);

When creating the memory component with the Altera Mega Wizard, specify "rom_32.hex" for a23 initialization file and "rom_128.hex" for a25.

D/ Simulation:

Before simulating your design, copy the generated HEX files "<your_code_name>_128.hex" or "<your_code_name>_32.hex" to "rom_128.hex" and "rom_32.hex" respectively into you simulation directory.

E/ Synthesis:

Copy files "rom_128.hex" or "rom_32.hex" into the Quartus project directory.

For people interested, I will provide soon a complete Amber port on Cyclone IV for the low cost BeMicro SDK platform (https://www.altera.com/b/bemicro-sdk.html) with LPDDR2 and Ethernet support.

Enjoy :-)

ccollineau commented over 9 years ago

(Third attempt. Seems to have kind of HTML tag inside my comment...)

To be able to run Amber on Altera FPGAs, you need to transform your ELF executable code into an memory compatible HEX file. Below is presented a method to achieve this.

A/ Modify file "sw\include\common.mk":

1/ Add these two lines at the beginning of the file:
HEX32  = $(addsuffix _32.hex,  $(basename $(TGT)))
HEX128 = $(addsuffix _128.hex, $(basename $(TGT)))
HEXCV  = ../tools/convert_hex.awk

2/ Modify lines 95 and 97 accordingly:
ifdef USE_MINI_LIBC
debug:  mini-libc $(ELF) $(MMP32) $(MMP128) $(DIS) $(HEX32) $(HEX128)
else
debug:  $(ELF) $(MMP32) $(MMP128) $(DIS) $(HEX32) $(HEX128)
endif

3/ Then, add the following lines ("--gap-fill" option is important since it forces bytes in generated HEX file to be contiguous):
$(HEX128): $(TGT)
  $(OC) -O ihex --gap-fill 0 --pad-to 0x4000 $^ tmp.hex
  $(HEXCV) -v width=16 tmp.hex > $@
  rm -f tmp.hex
  
$(HEX32): $(TGT)
  $(OC) -O ihex --gap-fill 0 --pad-to 0x4000 $^ tmp.hex
  $(HEXCV) -v width=4 tmp.hex > $@
  rm -f tmp.hex

4/ Modify line 131 accordingly:
@rm -rfv *.o *.elf *.flt *.gdb *.dis *.map *.mem *.v $(MMP32) $(MMP128) $(HEX32) $(HEX128)

B/ Below is the "convert_hex.awk" source code to be put in "sw/tools/directory" (This file will parse objcopy-generated HEX file and will convert it to Altera memory compatible format):


#!/bin/awk -f

BEGIN { k=0; line = ""; crc = 0; addr = 0; }

substr($0,8,2) == "00" {

length  = strtonum( "0x" substr($0,2,2) );

for ( i=0; i< length; i++ ) {

  j   = 10 + i * 2;
  str = substr($0,j,2);
  crc += strtonum( "0x" str );
  line = ( str line ); #swap bytes
  k++;
  if( ( k % width ) == 0 ) { printf ( ":%02X%04X00%s%02X\n",  width, addr, line, and( -( addr/256 + addr + width + crc ), 0xFF )  ); crc = 0; line = ""; addr += width; }
}

}

END { print ":00000001FF"; }

C/ Create and instantiate your Altera boot memory:

1/ In file "boot_mem32.v" if you use a23:

  altera_sram_4096x32_byte_en u_mem( 
   .address ( address     ),  // 4096 words, 32 bits
   .clock   ( i_wb_clk    ),
   .wren    ( start_write ),
   .byteena ( byte_enable ),
   .data    ( write_data  ),
   .q       ( read_data   )
 );

2/ Or in file "boot_mem128.v" if you use a25:

 altera_sram_1024x128_byte_en u_mem( 
  .address ( address     ),  // 1024 words, 128 bits
  .clock   ( i_wb_clk    ),
  .wren    ( start_write ),
  .byteena ( byte_enable ),
  .data    ( write_data  ),
  .q       ( read_data   )
);

When creating the memory component with the Altera Mega Wizard, specify "rom_32.hex" for a23 initialization file and "rom_128.hex" for a25.

D/ Simulation:

Before simulating your design, copy the generated HEX files "<your_code_name>_128.hex" or "<your_code_name>_32.hex" to "rom_128.hex" and "rom_32.hex" respectively into you simulation directory.

E/ Synthesis:

Copy files "rom_128.hex" or "rom_32.hex" into the Quartus project directory.

For people interested, I will provide soon a complete Amber port on Cyclone IV for the low cost BeMicro SDK platform (https://www.altera.com/b/bemicro-sdk.html) with LPDDR2 and Ethernet support.

Enjoy :-)

ccollineau commented over 9 years ago

Reformatted again:

To be able to run Amber on Altera FPGAs, you need to transform your ELF executable code into Altera memory compatible hex file. Below is presented a method to achieve this.

A/ Modify file "sw\include\common.mk":

1/ Add these two lines at the beginning of the file:
HEX32  = $(addsuffix _32.hex,  $(basename $(TGT)))
HEX128 = $(addsuffix _128.hex, $(basename $(TGT)))
HEXCV  = ../tools/convert_hex.awk

2/ Modify lines 95 and 97 accordingly:
ifdef USE_MINI_LIBC
debug:  mini-libc $(ELF) $(MMP32) $(MMP128) $(DIS) $(HEX32) $(HEX128)
else
debug:  $(ELF) $(MMP32) $(MMP128) $(DIS) $(HEX32) $(HEX128)
endif

3/ Then, add the following lines ("--gap-fill" option is important since it forces bytes in generated hex file to be contiguous):
$(HEX128): $(TGT)
  $(OC) -O ihex --gap-fill 0 --pad-to 0x4000 $^ tmp.hex
  $(HEXCV) -v width=16 tmp.hex > $@
  rm -f tmp.hex
  
$(HEX32): $(TGT)
  $(OC) -O ihex --gap-fill 0 --pad-to 0x4000 $^ tmp.hex
  $(HEXCV) -v width=4 tmp.hex > $@
  rm -f tmp.hex

4/ Modify line 131 accordingly:
@rm -rfv *.o *.elf *.flt *.gdb *.dis *.map *.mem *.v $(MMP32) $(MMP128) $(HEX32) $(HEX128)

B/ Below is the "convert_hex.awk" source code to be put in "sw/tools/directory" (This file will parse objcopy-generated hex file and will convert it to Altera memory compatible format):


#!/bin/awk -f

BEGIN { k=0; line = ""; crc = 0; addr = 0; }

substr($0,8,2) == "00" {

size  = strtonum( "0x" substr($0,2,2) );

for ( i=0; i<size; i++ ) {

  j   = 10 + i * 2;
  str = substr($0,j,2);
  crc += strtonum( "0x" str );
  line = ( str line ); #swap bytes
  k++;
  if( ( k % width ) == 0 ) { printf ( ":%02X%04X00%s%02X\n",  width, addr, line, and( -( addr/256 + addr + width + crc ), 0xFF )  ); crc = 0; line = ""; addr += width; }
}

}

END { print ":00000001FF"; }

C/ Create and instantiate your Altera boot memory:

1/ In file "boot_mem32.v" if you use a23:

ifdef ALTERA_FPGA altera_sram_4096x32_byte_en u_mem( .address ( address ), // 4096 words, 32 bits .clock ( i_wb_clk ), .wren ( start_write ), .byteena ( byte_enable ), .data ( write_data ), .q ( read_data ) );endif

2/ Or in file "boot_mem128.v" if you use a25:

ifdef ALTERA_FPGA altera_sram_1024x128_byte_en u_mem( .address ( address ), // 1024 words, 128 bits .clock ( i_wb_clk ), .wren ( start_write ), .byteena ( byte_enable ), .data ( write_data ), .q ( read_data ) );endif

When creating the memory component with the Altera Mega Wizard, specify "rom_32.hex" for a23 initialization file and "rom_128.hex" for a25.

D/ Simulation:

Before simulating your design, copy the generated hex files "your_code_name_128.hex" or "your_code_name_32.hex" to "rom_128.hex" and "rom_32.hex" respectively into you simulation directory.

E/ Synthesis:

Copy files "rom_128.hex" or "rom_32.hex" into the Quartus project directory.

For people interested, I will provide soon a complete Amber port on cyclone IV FPGA for the low cost BeMicro platform (https://www.altera.com/b/bemicro-sdk.html) with LPDDR2 and ethernet support.

Enjoy :-)

csantifort closed this over 9 years ago
lennie commented almost 8 years ago

Is the Amber port to cyclone posted anywhere yet?


Assignee
No one
Labels
Idea