Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12600 Discussions

How to porting u-boot to my own board?

Altera_Forum
Honored Contributor II
2,065 Views

Hello, everyone 

 

I want to use u-boot on my board. I have two questions. 

 

1. Before I use u-boot on my board, I just try to compile u-boot first. So, I follow the readme file. 

I use  

make PK1C20_config 

make all 

But there have errors. 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

In file included from /usr/include/sys/unistd.h:9, 

                from /usr/include/unistd.h:6, 

                from img2srec.c:61: 

/usr/include/sys/types.h:106: conflicting types for `int8_t&#39; 

/usr/include/stdint.h:38: previous declaration of `int8_t&#39; 

/usr/include/sys/types.h:108: warning: redefinition of `int16_t&#39; 

/usr/include/stdint.h:39: warning: `int16_t&#39; previously declared here 

/usr/include/sys/types.h:110: warning: redefinition of `int32_t&#39; 

/usr/include/stdint.h:40: warning: `int32_t&#39; previously declared here 

/usr/include/sys/types.h:112: warning: redefinition of `int64_t&#39; 

/usr/include/stdint.h:45: warning: `int64_t&#39; previously declared here 

make[1]: *** Error 1 

make[1]: Leaving directory `/cygdrive/d/My_Project/MtxCyclone_uBoot/BootLoader/u-boot-1.1.3/tools 

make: *** [tools] Error 2[/b] 

--- Quote End ---  

 

 

I search the forum and find the answer given by smcnutt. 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

This looks like the sources directly from sourceforge.net ... this tree assumes you 

have an appropriately configured native gcc and shell environment -- which 

doesn&#39;t come with the nios2 toolchain 8-P The easiest thing to do is get the source 

tree from http://www.pysent.com/download (http://www.pysent.com/download) -- this tree has certain "nips & tucks" 

made to build cleanly with the default nios2 toolchain (under cygwin) -- and it&#39;s 

more up-to-date than the sourceforge tree (WRT Nios-II, the sourceforge tree 

has been lagging by several months).[/b] 

--- Quote End ---  

 

 

But I can not access the web link. Can give me the right link or the files? 

 

2. If I want use u-boot on my MtxCyclone Board, how can I do?  

Just what should I do according to the PK1C20.h? 

Can give me more information or detailed steps than readme file? 

 

Thank you very much, 

LiangYi
0 Kudos
36 Replies
Altera_Forum
Honored Contributor II
791 Views

Hi LiangYi, 

 

> But I can not access the web link. Can give me the right link or the files? 

 

The link is correct and working. Sadly, the problem is probably because you are in China, 

and your government prevents your free access to the Internet. 

 

It would be a pleasure to send you the source code. Please send me a PM with a valid 

email address that can accept a 1.6 MB attachment. And please feel free to distribute the 

code among your colleagues. 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
791 Views

Hi Scott, 

 

Thank you very much. 

Here is my email address  

liangyi@vip.sohu.net
0 Kudos
Altera_Forum
Honored Contributor II
791 Views

Hello Scott, 

 

I modify some code according to my board and U-boot runs on my board. It runs in sdram.  

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

U-Boot 1.1.3 (Sep 14 2005 - 16:46:34) 

 

CPU?nbsp; : Nios-II 

SYSID : 3ef94735, Wed Sep 14 08:39:42 2005 

BOARD : Microtronix MCK-1C20 

*** Warning - bad CRC, using default environment 

 

==>[/b] 

--- Quote End ---  

 

 

But I still have some questions. 

1. When I change the TEXT_BASE in config.mk, u-boot can not be made. 

Can you tell me detailed about TEXT_BASE, and how to set it? 

2. First, I creat a new directory to store the new platform.  

make xxxx_config --------OK 

make ---------error 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

make -C &#39;dirname board/microtronix/mtxkit1c20/libmtxkit1c20.a&#39; 

make[1]: Entering directory &#39;/cygdrive/....../u-boot/board/microtronix/mtxkit1c20&#39; 

make[1]:*** No rule to make target &#39;mtxkit1c20.c&#39;, needed by &#39;.depend&#39;. Stop. 

...... 

make: *** [board/microtronix/mtxkit1c20/libmtxkit1c20.a] Error 2[/b] 

--- Quote End ---  

 

But when I put the platform under altera directory, u-boot is made OK. 

Why? 

3. I run saveenv and re-run, but the warning still appear. Why? 

 

Thank you, 

LiangYi
0 Kudos
Altera_Forum
Honored Contributor II
791 Views

Hi LiangYi, 

 

> But I still have some questions. 

> 1. When I change the TEXT_BASE in config.mk, u-boot can not be made. 

 

I don&#39;t understand what you mean by "u-boot can not be made" ... please describe what 

you observe. Does the make fail? Does the link fail? 

 

> Can you tell me detailed about TEXT_BASE, and how to set it? 

 

TEXT_BASE is set to the address where the .text section is located. This is the section 

that contains all of your code. In u-boot you would typically set this to a location at the 

top of your sdram (so the bottom of your sdram is available for a kernel). 

 

> make[1]:*** No rule to make target &#39;mtxkit1c20.c&#39;, needed by &#39;.depend&#39;. Stop. 

 

> But when I put the platform under altera directory, u-boot is made OK. 

> Why? 

 

Make is looking for mtxkit1c20.c and can&#39;t find it. Check your make target in the top level 

Makefile -- and always make distclean after moving stuff around ... you might have some 

artifacts (like old .depend files) in your source tree. Your top level target should call mkconfig 

with the appropriate arguments: 

 

mkconfig BOARD ARCH CPU DIR VENDOR 

 

Based on your post, you should have: 

 

mkconfig MTXKIT1C20 nios2 nios2 mtxkit1c20 microtronix 

 

 

> I run saveenv and re-run, but the warning still appear. Why? 

 

The saveenv command writes your environment variables to a non-volatile 

memory ... which is normally a parallel flash device. If you see the warning after 

running saveenv, the save operation failed. This is usually because you don&#39;t 

have your envirnonment setup properly ... or your flash implementation is broken. 

 

Please let me know the following: 

 

What type of flash are you using? (type and geometry) 

What is its base address? 

What is the value assigned to CFG_ENV_ADDR? 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
791 Views

Hi Scott, 

 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

> 1. When I change the TEXT_BASE in config.mk, u-boot can not be made. 

 

I don&#39;t understand what you mean by "u-boot can not be made" ... please describe what 

you observe. Does the make fail? Does the link fail?[/b] 

--- Quote End ---  

 

Sorry, somewhere I make a mistake. I recheck and can build correct. 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

Make is looking for mtxkit1c20.c and can&#39;t find it¡­¡­¡­..[/b] 

--- Quote End ---  

 

Yes, the name of .c file is inconsistent with top-level Makefile. 

 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

What type of flash are you using? (type and geometry) 

What is its base address? 

What is the value assigned to CFG_ENV_ADDR?[/b] 

--- Quote End ---  

 

My flash is AM29DL323GB-90EI. 2M*16bit flash 

Base Address is 0x0. 

I find that CFG_ENV_ADDR is define in MTXKIT1C20.h file(platform description file).# define CFG_ENV_ADDR (CFG_RESET_ADDR + CFG_MONITOR_LEN)# define CFG_RESET_ADDR 0x00000000 /* Hard-reset address */# define CFG_MONITOR_LEN (256 * 1024) /* Reserve 128k */ 

 

I do not know clearly what files I need to have and how to correct them. So my board can be initialized OK. 

My system now just include NIOS2/s, SDRAM, FLAHS, EPCS4, UART, JTAG-UART, sysid and system_timer. 

 

Thanks, 

LiangYi
0 Kudos
Altera_Forum
Honored Contributor II
791 Views

Another three questions. 

 

1. Now I can run u-boot in sdram, but how can I know the hardware in my system are being initialized proper. 

 

2. I have build vmlinux.bin. I want to run it in sdram through u-boot, how to do?(I find mkimage can not be used in my u-boot directory.) 

 

3. Because I do not know clearly the detail of the nios2 application execution(for example--helloworld). 

So I want to know it. 

cpu initial->hardware initial->jump main app. What files(.S, .h, .c) do this involve? Which reference of nios2 is helpful to me to know this. 

 

Thank you, 

LiangYi
0 Kudos
Altera_Forum
Honored Contributor II
791 Views

Hi LiangYi, 

 

> Now I can run u-boot in sdram 

 

Great! :-) 

 

> but how can I know the hardware in my system are being initialized proper. 

 

Test it ... this is your responsibility ;-) u-boot only initializes what it uses: 

serial, timer, epcs. If you have custom logic or other devices you want to initialize, 

you can define CONFIG_BOARD_EARLY_INIT_F and implement the routine 

board_early_init_f() -- which gets called very ... well ... early ... in the init 

sequence. 

 

> 2. I have build vmlinux.bin. I want to run it in sdram through u-boot, how to do? 

 

If you want to compress: 

 

$ gzip --best -c vmlinux.bin > vmlinux.gz 

$ mkimage -A nios2 -O linux -T kernel -C gzip -n "Microtronix uClinux 1.4" -d vmlinux.img  

-a <whatever> -e <whatever> 

 

Then put the vmlinux.img file in flash somewhere (e.g. 0x200000) and from u-boot run: 

 

==> bootm 200000 

 

> (I find mkimage can not be used in my u-boot directory.) 

 

You have two choices: port it to cygwin or get it from the psyent download page. 

-- I&#39;ll just send mkimage to you via email. 

 

> detail of the nios2 application execution(for example--helloworld). 

 

u-boot has something similiar to the hal ... since you can write what u-boot 

refers to as "standalone applications" or "mini-applications". You need to read the 

top level README file and docs/README.standalone. I tested hello world and it 

works fine (now that several bugs are fixed). 

 

As for the whole u-boot startup sequence, you&#39;ll have to use the force here ;-) 

Life starts in cpu/nios2/start.S and quickly jumps into lib_nios2/board.c. 

 

I hope this was helpful. 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
791 Views

Hi LiangYi, 

 

Sorry, I missed the info in your earlier post: 

 

> My flash is AM29DL323GB-90EI 

 

Ok. So you have several choices here. You can implement your own flash.c file (see other 

boards for example), or you can use the u-boot CFI flash driver. To implement your own 

flash driver, just copy an existing flash.c file that supports the AM29DL323 and add it to 

your board directory. The RPXClassic, RPXlite_dw, esd/common trees have flash.c files 

that support your device. You can customize your own flash.c files as you like. 

 

The other option is to use the u-boot CFI flash driver (with fixes for avalon bus). The 

(patched) driver was reported to work fine on the UP3 board. The CFI driver increases the 

size of your u-boot image -- but should work with all CFI-compliant flash devices -- I&#39;ll send 

you the patch. 

 

To get started, the easiest thing to do is enable CFI, once this is (mostly) working you can apply 

the patch, customize, whatever you like. Remove any board-specific flash routines from your 

build, then configure for CFI. Here&#39;s a starting point: 

# define CFG_FLASH_CFI_DRIVER# define CFG_MAX_FLASH_SECT 71 /* Max# sects per bank */# define CFG_MAX_FLASH_BANKS 1 /* Max# of flash banks */# define CFG_FLASH_CFI 

 

> I do not know clearly what files I need to have and how to correct them. So my board 

> can be initialized OK. My system now just include NIOS2/s, SDRAM, FLAHS, EPCS4, UART, 

> JTAG-UART, sysid and system_timer. 

 

u-boot will initialize epcs4 (if enabled), the UART _or_ JTAG UART (but not both ... it only 

touches the device that you specify as the console), and the timer. The flash is scanned 

based on the flash driver you choose (normally your flash.c fle). The SDRAM and SYSID 

do not require initialization. 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
791 Views

Thank you Scott, 

 

So many to do according to your apply. 

I will test step by step. 

If something is wrong, I will paste. 

 

Thank you, 

LiangYi
0 Kudos
Altera_Forum
Honored Contributor II
791 Views

Hi Scott, 

 

I am in trouble now. 

 

1. My u-boot flash driver 

You said I can use flash.c. So, I browse flash.c(include /common/flash.c). I found AMDLV065D.c just have both parts of two flash.c files. So, I think I can change AMDLV065D.c to my use. 

I change CFG_MAX_FLASH_SECT and CFG_MAX_FLASH_BANKS(in board.h), change flash_id = FLASH_MAN_AMD + FLASH_AMDL323B. Is it right? 

 

2. In order to Programming U-Boot into Flash, I add 1M sram. 

But, when do as USING.TXT, it appears 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

System Analyzer for Nios® II Processor 

Serial number       

Version 1.9.4 build 0 

Copyright © 1998-2004 First Silicon Solutions, Inc. 

Communication port must be specified. 

Use openport <port> to configure the communication port 

cd d:/My_Project/MtxCyclone_uBoot/BootLoader/u-boot-src/u-boot 

1> halt 

Communication has not been established with remote unit. 

2> load bin 0x00600000 u-boot.bin 

Communication has not been established with remote unit. 

3>[/b] 

--- Quote End ---  

 

Why? 

 

3. I use NIOS_IDE Flash Programmer to download u-boot to my flash. After that I run # nios2-terminal 

Nothing happen, I do know why? 

 

Thanks, 

LiangYi
0 Kudos
Altera_Forum
Honored Contributor II
791 Views

Hi LiangYi, 

 

> You said I can use flash.c. So, I browse flash.c(include /common/flash.c). I found AMDLV065D.c 

> just have both parts of two flash.c files. So, I think I can change AMDLV065D.c to my use. 

 

I was referring to the flash.c files found in most board-specific trees. Most of the supported 

boards (see the boards directory tree) contain a file named "flash.c" -- this is a common 

convention in u-boot. The boards that show support for the AM29DL323 are for example, 

RPXClassic, RPXlite_dw, and some of the esd boards (esd/common). Those trees will 

probably have the code you can use. 

 

> use NIOS_IDE Flash Programmer to download u-boot to my flash. After that I run 

># nios2-terminal 

> Nothing happen, I do know why? 

 

You probably still have the flash programmer design loaded. Try reloading your application sof. 

 

> Communication port must be specified. 

> Use openport <port> to configure the communication port 

 

This is probably your problem ;-) 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
791 Views

Hi Scott, 

 

I have tested cfi_flash.c. 

I add<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

#define CFG_FLASH_CFI_DRIVER# define CFG_MAX_FLASH_SECT 71 /* Max# sects per bank */# define CFG_MAX_FLASH_BANKS 1 /* Max# of flash banks */# define CFG_FLASH_CFI[/b] 

--- Quote End ---  

 

to my board.h file. When I build u-boot, it has error in function flash_init(). 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

cfi_flash.c:343: undefined reference to &#39;monitor_flash_len&#39;[/b] 

--- Quote End ---  

 

Is monitor_flash_len the u-boot image file size? 

What can I do about it? 

 

Furthermore, My flash is 16-bit width, should I define FLASH_CFI_16BIT in my board.h. 

 

Thanks, 

LiangYi
0 Kudos
Altera_Forum
Honored Contributor II
791 Views

Hi LiangYi, 

 

> cfi_flash.c:343: undefined reference to &#39;monitor_flash_len&#39; 

 

Did you modify cfi_flash.c? My version has no reference to monitor_flash_len at line 343 -- it shows 

up in the statement at line 348. Just as a sanity check, your code should look like this:#if (CFG_MONITOR_BASE >= CFG_FLASH_BASE)        && (CFG_MONITOR_BASE <= CFG_FLASH_BASE + CFG_FLASH_SIZE)        flash_protect (FLAG_PROTECT_SET,                        CFG_MONITOR_BASE,                        CFG_MONITOR_BASE + monitor_flash_len  - 1,                        flash_get_info(CFG_MONITOR_BASE));# endifCheck your config macro definitions. This should not even be compiled, unless you are trying 

to run u-boot out of flash. 

 

> Furthermore, My flash is 16-bit width, should I define FLASH_CFI_16BIT in my board.h. 

 

No, it is defined in include/flash.c. The CFI code determines the width automatically. 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
791 Views

Hi Scott, 

 

I have added cfi_flash.c to my u-boot, re-compiled u-boot and it can run in sdram. 

Then, I download the u-boot to my flash at 0x0 using Flash-Programmer. I reload the app sof file, open NIOS2-SDK Shell, run nios2-terminal. Nothing happen. 

I think that nios2-terminal start with jtag-uart, but not from uart. I do not know how to do next step? 

 

Give some info. 

 

Thank you. 

LiangYi
0 Kudos
Altera_Forum
Honored Contributor II
791 Views

Hi LiangYi, 

 

> I have added cfi_flash.c to my u-boot, re-compiled u-boot and it can run in sdram. 

 

Great! 

 

> I download the u-boot to my flash at 0x0 using Flash-Programmer 

 

How did you create the flash file? Typically, you should do the following: 

 

$ elf2flash --base=0x0 --end=0x7fffffff --input=u-boot --outfile=u-boot.flash --flash=<Uxx> 

$ nios2-flash-programmer --base=0x0 --input=u-boot.flash --sof=<xxx.sof> 

 

> Shell, run nios2-terminal. Nothing happen. 

> I think that nios2-terminal start with jtag-uart, but not from uart. 

 

When you run out of sdram, do you use the jtag uart ... and did you see the command prompt? 

 

If everything works with download/go to sdram, you most likely have a problem with the u-boot 

image stored in flash (either the flash file is incorrect ... or flash memory is not correct). 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
791 Views

Hi Scott, 

 

A strange problem, so annoyed. 

In Nios SDK Shell, I type command you say under my u-boot directory. 

 

$elf2flash --base=0x0 --end=0x1fffff --input=u-boot --output=u-boot.flash --flash=U20 

 

Respond : elf2flash: No reset address provided on the command line, and none found in the ELF file 

Then, I add. 

$elf2flash --base=0x0 --end=0x1fffff --input=u-boot --output=u-boot.flash --flash=U20 --reset=0x0 

Respond: elf2flash: Boot copier file name required, error generating Flash file, exiting 

I redo, add 

$elf2flash --base=0x0 --end=0x1fffff --input=u-boot --output=u-boot.flash --flash=U20 --reset=0x0 --boot=$SOPC_KIT_NIOS2/components/altera_nios2/boot_loader_cfi.srec 

Respond: elf2flash: read error: File not found: c:/altera/kits/nios2/component/altera_nios2/boot_loader_cfi.srec 

elf2flash: Error reading boot copier 

 

Does elf2flash need all parameters?  

My path C:\altera\kits\nios2\components\altera_nios2\boot_loader_cfi.srec is right, but elf2flash can not find the file. Why? 

 

LiangYi
0 Kudos
Altera_Forum
Honored Contributor II
791 Views

Hi LiangYi, 

 

> $elf2flash --base=0x0 --end=0x1fffff --input=u-boot --output=u-boot.flash --flash=U20 

 

elf2flash is appropriate if you boot from an epcs, ... sorry for misleading you. When you are using 

parallel flash with u-boot, bin2flash is what you want (since the u-boot make will generate a 

binary image). E.g.: 

 

$ bin2flash --base=0x0 --location=0x0 --flash=U20 --input=u-boot.bin --output=u-boot.flash 

 

> $elf2flash --base=0x0 --end=0x1fffff --input=u-boot --output=u-boot.flash --flash=U20 --reset=0x0 

> --boot=$SOPC_KIT_NIOS2/components/altera_nios2/boot_loader_cfi.srec 

 

u-boot does not require the boot copier ... it will relocate itself to its run-time address. 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
791 Views

Hi Scott, 

 

It make me headache. 

My Flash progrmmer (Microtronix official Providing) can not work under Nios SDK Shell. But it works fine in Nios IDE. 

 

I re-generate my flash-programmer design, but the same. 

The infomation under Nios SDK Shell is (I copy .sof to u-boot directory) 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

> $ nios2-flash-programmer --base=0x0 --input=u-boot.flash --sof=mtx_nios_dev_board_cyclone_1c20.sof 

nios2-flash-programmer: Launching Quartus Programmer to download: 

      mtx_nios_dev_board_cyclone_1c20.sof (here download to my FPGA) 

Send <64> failed. 

Unable to synchronize with target. 

......nios2-flash-programmer: Error opening target hardware[/b] 

--- Quote End ---  

 

OR 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

......nios2-flash-programmer: Error opening target hardware 

......nios2-flash-programmer: Unable to open flash device after successfully communicating with target.[/b] 

--- Quote End ---  

 

 

Is there any difference between nios2-flash-programmer in Nios SDK Shell and Flash Programming in Nios IDE? 

 

LiangYi
0 Kudos
Altera_Forum
Honored Contributor II
791 Views

> Is there any difference between nios2-flash-programmer in Nios SDK Shell and Flash 

> Programming in Nios IDE? 

 

It is the same application ... but the parameters may be different. 

 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
731 Views

Hi Scott, 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

> $ nios2-flash-programmer --base=0x0 --input=u-boot.flash --sof=mtx_nios_dev_board_cyclone_1c20.sof 

nios2-flash-programmer: Launching Quartus Programmer to download: 

    mtx_nios_dev_board_cyclone_1c20.sof (here download to my FPGA) 

Send <64> failed. 

Unable to synchronize with target. 

nios2-flash-programmer: Error opening target hardware[/b] 

--- Quote End ---  

 

This is the error infomation displayed in Nios SDK Shell. But It runs OK in Nios IDE.  

I do not know what is wrong. Have you ever seen this problem? 

I will try again. 

 

Thanks, 

LiangYi
0 Kudos
Reply