1/1

|
File I/O on bare metal OpenRISC?
by jylai1982 on Sep 1, 2011 |
jylai1982
Posts: 10 Joined: Feb 21, 2011 Last seen: Apr 22, 2015 |
||
|
Hi,
I would like to ask if there is anyone ever executed test programs with file usage on a bare metal or32-elf-sim? For example, the following is a test program (open_file.c): #include "stdio.h" int main(){ Â FILE *fp = NULL; Â fp = fopen("test.txt", "w"); Â if(fp == NULL){ Â Â printf("Open file failed\n"); Â } Â else{ Â Â printf("Open file succeed\n"); Â Â fprintf(fp, "test string\n"); Â } Â return 0; } I compiled this program with: or32-elf-gcc open_file.c -g -O2 -o open_file.elf and execute this program with a bare metal or32-elf-sim: or32-elf-sim -f refdesign.cfg open_file.elf However, I always got "Open file failed". Is there any possible solution? Thanks a lot in advance. |
|||
|
RE: File I/O on bare metal OpenRISC?
by julius on Sep 1, 2011 |
julius
Posts: 363 Joined: Jul 1, 2008 Last seen: May 17, 2021 |
||
|
I would like to ask if there is anyone ever executed test programs
with file usage on a bare metal or32-elf-sim? Can I ask, are you expecting a file to be accessed within the simulated system, or on your host PC? In either case it won't work, though. The or32-elf-gcc compiler uses the newlib C library. As it's currently just for bare metal (ie. you've not got an operating system under you) the standard system calls the operating system usually manages for you are mostly not implemented. There's just read and write which access the UART. So file I/O, which relies on a few other system calls I think, will certainly not work. I'm not sure what is standard in a bare metal library, but if you want to add some sort-of basic file I/O support I would look at the libgloss part of newlib, which implements the system call support. Jeremy's application note on the newlib port on his Embecosm site covers this in detail. Find it here: http://www.embecosm.com/appnotes/ean9/ean9-howto-newlib-1.0.html |
|||
|
RE: File I/O on bare metal OpenRISC?
by jeremybennett on Sep 1, 2011 |
jeremybennett
Posts: 815 Joined: May 29, 2008 Last seen: Jun 13, 2019 |
||
|
hi jylai1982, By bare metal, I think you mean "with newlib". Unless you explicitly exclude libraries, or32-elf-gcc links in newlib. Default simulation newlib only supports stdout and stderr. The version that simulates with a UART (or1ksim-uart) also supports stdin. It would not be difficult to use host I/O to support general file handling. A useful project for someone to undertake and contribute. HTH Jeremy
-- |
|||
|
RE: File I/O on bare metal OpenRISC?
by jylai1982 on Sep 1, 2011 |
jylai1982
Posts: 10 Joined: Feb 21, 2011 Last seen: Apr 22, 2015 |
||
|
Hi, Julius and Jeremy,
I expect to access a file on the host machine. More specifically, I would like to know if there is any possible way for the bare metal or1ksim simulation (or or1200 RTL simulation) to access a file on the host machine. Is it possible to insert host file I/O routines to the simulated program? Thanks a lot. |
|||
|
RE: File I/O on bare metal OpenRISC?
by jeremybennett on Sep 2, 2011 |
jeremybennett
Posts: 815 Joined: May 29, 2008 Last seen: Jun 13, 2019 |
||
|
Hi, Julius and Jeremy, I expect to access a file on the host machine. More specifically, I would like to know if there is any possible way for the bare metal or1ksim simulation (or or1200 RTL simulation) to access a file on the host machine. Is it possible to insert host file I/O routines to the simulated program? Thanks a lot. Hi jylai1982, It's a community project. Feel free to extend newlib to add this functionality for everyone. Lot's of other architectures do this in simulation, so you should fine plenty of examples to copy. Best wishes, Jeremy |
|||
1/1

