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

Uboot with no mmu booting standalone application

Altera_Forum
Honored Contributor II
1,212 Views

Hello, 

 

I'm trying to get u-boot starts my standalone "Hello World" application. So this is what I did: 

 

1) Create Application in Nios IDE 

2) Create a binary from elf 

nios2-linux-gnu-objcopy -O binary testNiosUboot.elf testNiosUboot.bin 

I did not remove any section from the elf... 

3) check the elf disassembly code to see if it match with the binary i just generated: 

 

testNiosUboot.elf: file format elf32-littlenios2 Disassembly of section .exceptions: 00000020 <alt_exception>: 20: deffed04 addi sp,sp,-76 24: dfc00015 stw ra,0(sp) 28: d8400215 stw at,8(sp) ... 000000ec <alt_irq_handler>: ec: defff904 addi sp,sp,-28 f0: dfc00615 stw ra,24(sp) f4: df000515 stw fp,20(sp) f8: df000504 addi fp,sp,20 ... Disassembly of section .text: 000001c4 <_start>: 1c4: 00880014 movui r2,8192 1c8: 10000033 initd 0(r2) 1cc: 10bff804 addi r2,r2,-32 1d0: 00bffd16 blt zero,r2,1c8 <_start+0x4> ...  

 

Binary output: 

Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F 00000000 04 ED FF DE 15 00 C0 DF 15 02 40 D8 15 03 80 D8 00000010 15 04 C0 D8 15 05 00 D9 15 06 40 D9 15 07 80 D9 00000020 15 08 C0 D9 7A 30 0B 00 15 09 00 DA 15 0A 40 DA ... 00000180 15 FB BF E0 17 FB BF E0 3A 00 05 10 1E 01 00 10 00000190 06 D8 3F 00 17 06 C0 DF 17 05 00 DF 04 07 C0 DE 000001A0 3A 28 00 F8 14 00 88 00 33 00 00 10 04 F8 BF 10 000001B0 16 FD BF 00 34 80 C0 06 14 00 C0 DE 74 00 80 06 ...  

 

4) Create u-boot image 

 

mkimage -A nios2 -O linux -T standalone -C none -a 0x00000020 -e 0x000001C4 -n "testNiosUboot" -d testNiosUboot.bin uImageTest  

 

I set the loadin address to 0x20 because my binary first byte is the exception entry first byte. And starting address to 0x1C4. 

 

5) Try it... 

 

UBOOT>tftpboot 1000000 uImageTest Using ALTERA_TSE-0 device TFTP from server 192.168.1.113; our IP address is 192.168.1.85 Filename 'uImageTest'. Load address: 0x1000000 Loading:# ############ done Bytes transferred = 62780 (f53c hex) UBOOT>bootm 1000000# # Booting kernel from Legacy Image at 01000000 ... Image Name: testNiosUboot Image Type: NIOS II Linux Standalone Program (uncompressed) Data Size: 62716 Bytes = 61.2 KiB Load Address: 00000020 Entry Point: 000001c4 Verifying Checksum ... OK Loading Standalone Program ... OK OK 

 

It hangs.... 

 

6) Look at u-boot code and make dirty patches: 

 

In cmd_bootm.c, I uncomment enable_interrupts because it stops execution and we never go to bootm_start_standalone : 

if (images.os.type == IH_TYPE_STANDALONE) { printf("iflag = %x\n", iflag); /*if (iflag) enable_interrupts();*/ /* This may return when 'autostart' is 'no' */ bootm_start_standalone(iflag, argc, argv); return 0; }  

Then I cutout lot of stuff here to test it quickly: 

static int bootm_start_standalone(ulong iflag, int argc, char *argv) { char *s; int (*appl)(int, char *); /* Don't start if "autostart" is set to "no" */ /* if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) { char buf; sprintf(buf, "%lX", images.os.image_len); setenv("filesize", buf); return 0; }*/ appl = (int (*)(int, char *))/*ntohl*/(images.ep); printf("Jump to 0x%08lx\n", appl); (*appl)(argc-1, &argv); return 0; }  

 

I got "Jump to 0x000001c4" printed out but nothing happens....I don't have my Hello World.... 

 

Am I wrong somewhere ?? 

 

Thanks, 

Franck.
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
451 Views

I think I messed something up last time. It works. However I had to keep my patches I order to make it works....

0 Kudos
Altera_Forum
Honored Contributor II
451 Views

Hi,  

 

Was your hello world application a u-boot standalone application (i mean compiled with u-boot source) or a generic linux application. 

 

I have a doubt that a linux application would be having printf(...) calling some syscalls to write string on UART, and syscall implementations would not be available in standalone environment. 

 

Secondly, is there a better way to configure/find the load address of a compiled application? 

 

Regards 

Manik
0 Kudos
Altera_Forum
Honored Contributor II
451 Views

It was a loooong time ago :) 

 

It was a Nios2 executable (not a linux image or uboot stuff). 

 

The common way of starting an elf file is bootelf. However, for testing purpose I wanted to put this program in a uboot image.... 

 

If you want to find the linked address of an elf program you can use objdump. 

 

Best regards, 

Franck.
0 Kudos
Altera_Forum
Honored Contributor II
451 Views

Thanks for the information.

0 Kudos
Reply