Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RISC-V from scratch 1: Introduction, toolchain setup, and hello world! #7

Open
utterances-bot opened this issue May 25, 2019 · 19 comments
Labels
post comments For issues `utterances` uses to track comments on blog posts

Comments

@utterances-bot
Copy link

RISC-V from scratch 1: Introduction, toolchain setup, and hello world!

A post that discusses what RISC-V is and why it's important, teaches readers how to install the GNU RISC-V toolchain, and walks through building and running a simple C program on emulated RISC-V hardware.

https://twilco.github.io/riscv-from-scratch/2019/03/10/riscv-from-scratch-1.html

Copy link

in the code snipped change:

mkdir -p ~/usys/riscv && cd ~/usys/riscv

to

mkdir -p ~/usys/riscv

thanks for this awesome guide! I especially love part deux =)

@twilco
Copy link
Owner

twilco commented May 26, 2019

@DyslexicAtheist, thanks for the kind words! Glad you enjoyed it.

Fixed with 2f9ed76.

@twilco twilco added the post comments For issues `utterances` uses to track comments on blog posts label May 26, 2019
Copy link

Ran into the following error when running the helloword executable:

qemu: hardware error: sifive_prci_read: read: addr=0xc

CPU #0:
 pc       20403b64
 mhartid  00000000
 mstatus  00000000
 mip      00000000
 mie      00000000
 mideleg  00000000
 medeleg  00000000
 mtvec    20401af4
 mepc     00000000
 mcause   00000000
 zero 00000000 ra   2040371e sp   800013e0 gp   80001890
 tp   00000000 t0   20404c90 t1   00000000 t2   80001108
 s0   80001400 s1   00000001 a0   80001084 a1   0000000c
 a2   80000fd8 a3   20403b64 a4   10008000 a5   1000800c
 a6   0000001f a7   00000000 s2   20404c84 s3   00000000
 s4   00000000 s5   00000000 s6   00000000 s7   00000000
 s8   00000000 s9   00000000 s10  00000000 s11  00000000
 t3   00000000 t4   00000000 t5   00000000 t6   00000000
 ft0  0000000000000000 ft1  0000000000000000 ft2  0000000000000000 ft3  0000000000000000
 ft4  0000000000000000 ft5  0000000000000000 ft6  0000000000000000 ft7  0000000000000000
 fs0  0000000000000000 fs1  0000000000000000 fa0  0000000000000000 fa1  0000000000000000
 fa2  0000000000000000 fa3  0000000000000000 fa4  0000000000000000 fa5  0000000000000000
 fa6  0000000000000000 fa7  0000000000000000 fs2  0000000000000000 fs3  0000000000000000
 fs4  0000000000000000 fs5  0000000000000000 fs6  0000000000000000 fs7 ft8  0000000000000000 ft9  0000000000000000 ft10 0000000000000000 ft11 0000000000000000
[1]    10489 abort      qemu-system-riscv32 -nographic -machine sifive_e -kernel

Any suggestion?

Copy link

One little issue, according to their README.md

make software

by default compiles only the hello program, not all the example programs

@twilco
Copy link
Owner

twilco commented May 26, 2019

@limslarmo, turns out the issue you encountered is due to a bug introduced into QEMU. Someone has created a patch to fix the problem, but it hasn't yet been merged. See this comment for more information.

Getting this example running is unnecessary to progress in future posts, so don't worry too much about it. In the meantime, I've updated the post to note that the freedom-e-sdk "hello world" program won't work for now: dae59ca

Thanks for the correction on make software - I've fixed it here: f43b895

Copy link

Thanks!!

Copy link

Hey, I am having issue while using for sifive-hifive1 , the error comes like error finding bsp for sifive-hifive1 I havee also tried using the bsp directory, and simply make or make software.
nothing is working

@twilco
Copy link
Owner

twilco commented Jul 27, 2019

Hey @yashomer1994 - sorry you're having troubles. Could you post the exact error you're getting? What OS are you running?

The freedom-e-sdk appears to change very quickly, making it hard to keep the instructions up to date. It might be worth opening an issue in their repository, as the instructions provided in my guide appear to mirror those they suggest.

Also, running this example is unnecessary to continue on in the series, so don't let it hold you back unless you're really keen on getting it working :)

Copy link

Hey, Ya I solved the problem redoing everything on fresh terminal, now its working perfectly emulated easily on Qemu. Thanks

Copy link

Hi, I have installed Qemu (on Linux Mint) and I have a bunch of system installed, but no risc-v ones. Is that normal ? Where should I get the qemu-system-riscv32 machine ?
Thank you for this nice tutorial !

@twilco
Copy link
Owner

twilco commented Aug 12, 2019

Hey @oliverbm67. What happens when you run qemu-system-riscv32 --version? Here is what I get:

$ qemu-system-riscv32 --version
QEMU emulator version 4.0.0
Copyright (c) 2003-2019 Fabrice Bellard and the QEMU Project developers

The RISC-V port of QEMU was upstreamed to QEMU proper, so installing QEMU via the means specified on their website should give you this command.

If this isn't the case, or if my instructions are generally unclear, let me know so I can fix them up 🙂

@oliverbm67
Copy link

oliverbm67 commented Aug 12, 2019

Hey @twilco !
qemu-system-riscv32 --version return command not found. Other system works such as qemu-system-i386 --version return :
QEMU emulator version 2.11.1(Debian 1:2.11+dfsg-1ubuntu7.15) Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developers

I installed qemu with apt-get install qemu, maybe it is a version issue ?

EDIT : I uninstalled qemu and reinstalled by compiling the latest version from source and solved the problem. The issue is on the qemu website, not in your tutorial. The version in the repo is outdated.

@twilco
Copy link
Owner

twilco commented Aug 12, 2019

Yep, according to this blog post, QEMU 2.12.0 is the first official release to contain RISC-V. Glad you got it figured out!

Copy link

I tried using file IO and I am unable to succeed.
This is what I did, in the hello world program


printf("Hello, World!\n");
FILE *fp;
fp = fopen("test_rv.txt", "w+");

if(fp==NULL)
{
printf("Unable to open the file \n");
}
printf("Testing ---- After ! \n");

The output is
Hello, World!
Unable to open the file
Testing ---- After !

How can I make to open a file and do some read/write operations ?

@twilco
Copy link
Owner

twilco commented Oct 5, 2020

Hey @balaji-ch!

When fopen fails, it sets the thread-local errno variable indicating the reason. What do you get back when checking errno?

printf("Hello, World!\n");
FILE *fp;
fp = fopen("test_rv.txt", "w+");
if (fp == NULL) {
    printf("Unable to open the file \n");
}
printf("Testing ---- After ! \n");
printf("%d\n", errno);

Copy link

I got Function not implemented error.

Code:

'
printf("Testing ---- Before ! \n");

FILE *fp;
fp = fopen("test_rv.txt", "w+");

if(fp==NULL)
{
printf("%d\n", errno);
printf("Error in opening the file. err = %s\n", strerror(errno));
}

printf("Testing ---- After ! \n");
'

Output:

Hello, World!
Testing ---- Before !
88
Error in opening the file. err = Function not implemented
Testing ---- After !

@twilco
Copy link
Owner

twilco commented Oct 6, 2020

Ah, so what you're making use of in that example is the freedom-e-sdk, and it sounds like they haven't yet implemented fopen. You may want to open an issue in their repository to find out more information.

Copy link

Could there be any other emulator where I can use FILE I/O s ?

@twilco
Copy link
Owner

twilco commented Oct 7, 2020

I'm not sure, sorry @balaji-ch. I do think your best bet is opening an issue in the freedom-e-sdk repository. I think they could tell you more about your issue with fopen, and maybe point you in another direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
post comments For issues `utterances` uses to track comments on blog posts
Projects
None yet
Development

No branches or pull requests

7 participants