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

Hello example in Nuttx kernel build #21

Closed
TaiJuWu opened this issue Nov 12, 2023 · 9 comments
Closed

Hello example in Nuttx kernel build #21

TaiJuWu opened this issue Nov 12, 2023 · 9 comments

Comments

@TaiJuWu
Copy link

TaiJuWu commented Nov 12, 2023

First I want to thanks your articles, they help me to start up this project a lot and it's really excellent.

Currently, I read this article and build Nuttx for RISC-V successfully.
But there is a little problem, when I run Nuttx with Qemu, it should can run hello example but this operation failed.

@lupyuen
Copy link
Owner

lupyuen commented Nov 13, 2023

Hi: Thank you so much for your sponsorship, it really means a lot to me :-)

May I know which operation failed for NuttX on QEMU? A screenshot or log capture would be helpful too. Thanks!

@TaiJuWu
Copy link
Author

TaiJuWu commented Nov 13, 2023

Thanks for your reply and hope you can write more excellent article to help others.

You can see there is a program named hello.
image

But this program does not show at help command and we can't run hello program.
image

@lupyuen
Copy link
Owner

lupyuen commented Nov 13, 2023

Ah OK, this happens because the hello app is disabled. To enable it:

  1. Run make menuconfig
  2. Browse to Application Configuration > Examples > "Hello World" Example
  3. Press Space to select, until "M" turns to "*"
  4. Save and exit
  5. Run make

Lemme know if it works. Thanks :-)

@TaiJuWu
Copy link
Author

TaiJuWu commented Nov 13, 2023

enable

It's already set as below.
image

@lupyuen
Copy link
Owner

lupyuen commented Nov 14, 2023

Hi: Could you confirm that these are the steps we ran:

mkdir nuttx
cd nuttx
git clone https://github.com/apache/nuttx nuttx
git clone https://github.com/apache/nuttx-apps apps
cd nuttx
tools/configure.sh rv-virt:nsh64
grep HELLO= .config
## Shows: CONFIG_EXAMPLES_HELLO=m

make menuconfig
## Browse to `Application Configuration > Examples > "Hello World" Example`
## Press Space to select, until "M" turns to "*"
## Save and Exit

grep HELLO= .config
## Shows: CONFIG_EXAMPLES_HELLO=y

make
qemu-system-riscv64 \
  -semihosting \
  -M virt,aclint=on \
  -cpu rv64 \
  -smp 8 \
  -bios none \
  -kernel nuttx \
  -nographic

When I run this with the latest version of NuttX, the hello app works OK. Wonder if there's something different about the build environment? (I'm using macOS x64)

NuttShell (NSH) NuttX-12.3.0-RC1
nsh> uname -a
NuttX 12.3.0-RC1 d92a701 Nov 14 2023 08:11:31 risc-v rv-virt

nsh> help
help usage:  help [-v] [<cmd>]

    .           cp          exit        mkrd        set         unset
    [           cmp         false       mount       sleep       uptime
    ?           dirname     fdinfo      mv          source      usleep
    alias       dd          free        pidof       test        xd
    unalias     df          help        printf      time
    basename    dmesg       hexdump     ps          true
    break       echo        kill        pwd         truncate
    cat         env         ls          rm          uname
    cd          exec        mkdir       rmdir       umount

Builtin Apps:
    hello     nsh       ostest    sh

nsh> hello
Hello, World!!

@TaiJuWu TaiJuWu closed this as completed Nov 16, 2023
@TaiJuWu
Copy link
Author

TaiJuWu commented Nov 16, 2023

Hi: Could you confirm that these are the steps we ran:

mkdir nuttx
cd nuttx
git clone https://github.com/apache/nuttx nuttx
git clone https://github.com/apache/nuttx-apps apps
cd nuttx
tools/configure.sh rv-virt:nsh64
grep HELLO= .config
## Shows: CONFIG_EXAMPLES_HELLO=m

make menuconfig
## Browse to `Application Configuration > Examples > "Hello World" Example`
## Press Space to select, until "M" turns to "*"
## Save and Exit

grep HELLO= .config
## Shows: CONFIG_EXAMPLES_HELLO=y

make
qemu-system-riscv64 \
  -semihosting \
  -M virt,aclint=on \
  -cpu rv64 \
  -smp 8 \
  -bios none \
  -kernel nuttx \
  -nographic

When I run this with the latest version of NuttX, the hello app works OK. Wonder if there's something different about the build environment? (I'm using macOS x64)

NuttShell (NSH) NuttX-12.3.0-RC1
nsh> uname -a
NuttX 12.3.0-RC1 d92a701 Nov 14 2023 08:11:31 risc-v rv-virt

nsh> help
help usage:  help [-v] [<cmd>]

    .           cp          exit        mkrd        set         unset
    [           cmp         false       mount       sleep       uptime
    ?           dirname     fdinfo      mv          source      usleep
    alias       dd          free        pidof       test        xd
    unalias     df          help        printf      time
    basename    dmesg       hexdump     ps          true
    break       echo        kill        pwd         truncate
    cat         env         ls          rm          uname
    cd          exec        mkdir       rmdir       umount

Builtin Apps:
    hello     nsh       ostest    sh

nsh> hello
Hello, World!!

This method can work. Thank you a lot.

@lupyuen
Copy link
Owner

lupyuen commented Nov 16, 2023

Ah yes NuttX Kernel Mode requires a few more steps, as explained here: https://nuttx.apache.org/docs/latest/platforms/risc-v/qemu-rv/boards/rv-virt/index.html

NuttX Kernel Mode uses Semihosting to access the apps, so we need to build the NuttX Apps Filesystem: https://lupyuen.github.io/articles/semihost#nuttx-calls-semihosting

Here are the steps I tested:

mkdir nuttx
cd nuttx
git clone https://github.com/apache/nuttx nuttx
git clone https://github.com/apache/nuttx-apps apps
cd nuttx

## Configure NuttX for QEMU Kernel Mode
tools/configure.sh rv-virt:knsh64
grep HELLO= .config
## Shows: CONFIG_EXAMPLES_HELLO=m
## This is OK for Kernel Mode

## Build the NuttX Kernel
make

## Build the NuttX Apps Filesystem
make V=1 -j7
make export V=1
cd ../apps
./tools/mkimport.sh -z -x ../nuttx/nuttx-export-*.tar.gz
make import V=1
cd ../nuttx

## Start NuttX in QEMU
## (Uses Semihosting to access the NuttX Apps Filesystem)
qemu-system-riscv64 \
  -semihosting \
  -M virt,aclint=on \
  -cpu rv64 \
  -smp 8 \
  -bios none \
  -kernel nuttx \
  -nographic

And the hello app runs OK (without setting menuconfig):

→ qemu-system-riscv64 \
  -semihosting \
  -M virt,aclint=on \
  -cpu rv64 \
  -smp 8 \
  -bios none \
  -kernel nuttx \
  -nographic

ABC
NuttShell (NSH) NuttX-12.3.0-RC1
nsh> uname -a
NuttX 12.3.0-RC1 479dda9 Nov 16 2023 19:50:58 risc-v rv-virt
nsh> help
help usage:  help [-v] [<cmd>]

    .           cp          exit        mkrd        set         unset
    [           cmp         false       mount       sleep       uptime
    ?           dirname     fdinfo      mv          source      usleep
    alias       dd          free        pidof       test        xd
    unalias     df          help        printf      time
    basename    dmesg       hexdump     ps          true
    break       echo        kill        pwd         truncate
    cat         env         ls          rm          uname
    cd          exec        mkdir       rmdir       umount
nsh> hello
Hello, World!!

The hello executable is located here:

nsh> ls -l /system/bin/hello
 -rwxrwxrwx      534672 /system/bin/hello
nsh> /system/bin/hello
Hello, World!!

@TaiJuWu
Copy link
Author

TaiJuWu commented Nov 16, 2023

Ah yes NuttX Kernel Mode requires a few more steps, as explained here: https://nuttx.apache.org/docs/latest/platforms/risc-v/qemu-rv/boards/rv-virt/index.html

NuttX Kernel Mode uses Semihosting to access the apps, so we need to build the NuttX Apps Filesystem: https://lupyuen.github.io/articles/semihost#nuttx-calls-semihosting

Here are the steps I tested:

mkdir nuttx
cd nuttx
git clone https://github.com/apache/nuttx nuttx
git clone https://github.com/apache/nuttx-apps apps
cd nuttx

## Configure NuttX for QEMU Kernel Mode
tools/configure.sh rv-virt:knsh64
grep HELLO= .config
## Shows: CONFIG_EXAMPLES_HELLO=m
## This is OK for Kernel Mode

## Build the NuttX Kernel
make

## Build the NuttX Apps Filesystem
make V=1 -j7
make export V=1
cd ../apps
./tools/mkimport.sh -z -x ../nuttx/nuttx-export-*.tar.gz
make import V=1
cd ../nuttx

## Start NuttX in QEMU
## (Uses Semihosting to access the NuttX Apps Filesystem)
qemu-system-riscv64 \
  -semihosting \
  -M virt,aclint=on \
  -cpu rv64 \
  -smp 8 \
  -bios none \
  -kernel nuttx \
  -nographic

And the hello app runs OK (without setting menuconfig):

→ qemu-system-riscv64 \
  -semihosting \
  -M virt,aclint=on \
  -cpu rv64 \
  -smp 8 \
  -bios none \
  -kernel nuttx \
  -nographic

ABC
NuttShell (NSH) NuttX-12.3.0-RC1
nsh> uname -a
NuttX 12.3.0-RC1 479dda9 Nov 16 2023 19:50:58 risc-v rv-virt
nsh> help
help usage:  help [-v] [<cmd>]

    .           cp          exit        mkrd        set         unset
    [           cmp         false       mount       sleep       uptime
    ?           dirname     fdinfo      mv          source      usleep
    alias       dd          free        pidof       test        xd
    unalias     df          help        printf      time
    basename    dmesg       hexdump     ps          true
    break       echo        kill        pwd         truncate
    cat         env         ls          rm          uname
    cd          exec        mkdir       rmdir       umount
nsh> hello
Hello, World!!

The hello executable is located here:

nsh> ls -l /system/bin/hello
 -rwxrwxrwx      534672 /system/bin/hello
nsh> /system/bin/hello
Hello, World!!

This is I need!!!!
Thanks a lot.

@lupyuen
Copy link
Owner

lupyuen commented Nov 16, 2023

Cool! Lemme know if you have any questions :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants