How to write Hello World for OpenWRT and/or dd-wrt - openwrt

I'm working on running a Hello World program on the Linksys WRT54G-V4 running either dd-wrt or OpenWRT.
Right now this router is running dd-wrt for reasons I'll explain below. I'd like to switch this router to OpenWRT, because I've not been able to build dd-wrt or its toolchain. I 'assume' that the OpenWRT toolchain should produce executable binaries that will run on dd-wrt also.
OpenWRT was pretty straightforward to build, since it has a nice menu driven make system. Using this handy tool I built a toolchain that will cross compile from my x86 Ubuntu box to a MIPS target.
Following the instructions I've been able to build OpenWRT and produce images for brcm47xx and brcm63xx.
For example, here is a successful compile of my little Hello World program:
jim#ubuntu:~/Desktop/tests$ cat helloC.c
#include <stdio.h>
int main (int argc, char **argv)
{
printf("Hello World\n");
return 0;
}
jim#ubuntu:~/Desktop/tests$
jim#ubuntu:~/Desktop/tests$ mipsel-openwrt-linux-gcc -o HelloWorld helloC.c
jim#ubuntu:~/Desktop/tests$
jim#ubuntu:~/Desktop/tests$ file HelloWorld
HelloWorld: ELF 32-bit LSB executable, MIPS, MIPS32 version 1, dynamically linked (uses shared libs), with unknown capability 0xf41 = 0x756e6700, with unknown capability 0x70100 = 0x3040000, not stripped
jim#ubuntu:~/Desktop/tests$
Sadly, when I try to run HelloWorld on my WRT54G-V4 running dd-wrt I get a seg fault.
Looking at Wikipedia, I see that this router uses the Broadcom BCM5352.
When I run make menuconfig in by OpenWRT/trunk directory I don't see an option for the BCM5352, which is why I'm reluctant to flash my router with one of the images I've created in the brcm47xx or brcm63xx directories. I don't want to guess wrong and brick the router.
Question 1 - Which Broadcom configuration should I select using make menuconfig to target my WRT54G-V4 with its BCM5352 chipset?
Question 2 - Should my 'HelloWorld' executable file I generated above run directly from the command line on the 54G, or must I make it a package per http://www.gargoyle-router.com/wiki/doku.php?id=openwrt_coding ?
TIA

You can follow the official howto (from: http://www.dd-wrt.com/forum/viewtopic.php?p=21499&sid=de90601a8d51747d1c8ccec29284127d)
1. The helloworld.c source
Code:
#include <stdio.h>
int main ( void ) {
printf( "Hello world!\n" );
}
2. Get and unpack the toolchain in your homedir
Code:
cd ~
wget ftp://ftp.dd-wrt.com/sourcecode/toolchains.x86.debian.sp1.tar.bz2
tar -jxf toolchains.x86.debian.sp1.tar.bz2
3. Add the path to your cross-compiler executable to your path environment variable and compile helloworld.c
Code:
PATH=~/toolchains/4.1.0-uclibc-0.9.28/bin:$PATH mipsel-linux-uclibc-gcc helloworld.c -o helloworld
4. Check if its correctly compiled with the cross-compiler
Code:
file helloworld
helloworld: ELF 32-bit LSB executable, MIPS, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
5. Finally, transfer the helloworld binary file to your router, set the executable bit and run it.
Tested with Ubuntu 6.06.1 LTS.

Related

Unable to build the library using cargo lipo --release

Unable to build the library using cargo lipo --release
I am trying to make a cross-platform library using rust for ios target. I am following this article (Building and Deploying a Rust library on iOS).
*Note: I followed the same steps and my project structure also looks the same *
After completing the code and project setup the last step is to build the library. When I try to build the library using cargo lipo --release. It throws this error:
[ERROR cargo_lipo] No library target found for "my-project-name"
Also, note that I am only able to install support for two platforms. (aarch64-apple-ios and x86_64-apple-darwin). I think the reason is that they have dropped the support for 32-bit architectures.
So, when I run
rustup target add aarch64-apple-ios armv7-apple-ios armv7s-apple-ios x86_64-apple-ios i386-apple-ios.
It throws error: error: component 'rust-std' for target 'armv7-apple-ios' is unavailable for download for channel stable
Cargo.toml
[package]
name = "rustylib"
version = "0.1.0"
edition = "2018"
crate-type = ["staticlib", "cdylib"]
rustylib.rs
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
char *hello(const char *to);
void hello_release(char *s);
The rest of the project structure is the usual rust code.
The output of rustup show
Default host: x86_64-apple-darwin
rustup home: /Users/my-username/.rustup
installed toolchains
stable-x86_64-apple-darwin
nightly-x86_64-apple-darwin (default)
installed targets for active toolchain
aarch64-apple-ios
x86_64-apple-darwin
active toolchain
nightly-x86_64-apple-darwin (default)
rustc 1.52.0-nightly (acca81892 2021-03-13)
OS & Rust
Rust: rustc 1.50.0 (cb75ad5db 2021-02-10)
OS: macOS Bug Sur (11.2.3)
Xcode & Command line tools: 12.4
Your Cargo.toml is wrong.
If you look into the guide you linked in your question, you can see, that the crate-type has to be below the [lib] tag like so:
[package]
name = "greetings"
version = "0.1.1"
authors = ["fluffyemily <fluffyemily#mozilla.com>"]
description = "Example static library project built for iOS"
publish = false
[lib]
name = "greetings"
crate-type = ["staticlib", "cdylib"]
Also your code has to be in cargo/src/lib.rs by default as stated in the document (and not in rustylib.rs).
You can run cargo new rustylib --lib from the command line to create all the boilerplate, so that you only have to add the dependencies and the crate-type in the [lib] section of your Cargo.toml.
Edit
I think there is another problem:
You have entered C code in your rustylib.rs file, which can not work. I think what you intended to do, was to create the C bridge, which is called cargo/src/greetings.h in the guide you linked.

build_iphone.sh: line 52: /Users/.../pocketsphinx-master/configure: No such file or directory

I'm on macOS Mojave in terminal, and I'm getting an error that says no such file or directory for the directory ".../pocketsphinx-master/configure" when I run build_iphone.sh, which I got from this repository: cmusphinx/pocketsphinx-ios-demo.
The instructions for pocketsphinx found at this repository -- cmusphinx/pocketsphinx gives these instructions to use pocketsphinx with Xcode. Here's part of what it says, which I don't understand:
Pocketsphinx uses the standard unix autogen system, you can build pocketsphinx with automake given you already built sphinxbase You just need to pass correct configure arguments, set compiler path, set sysroot and other options. After you build the code you need to import dylib file into your project and you also need to configure includes for your project to find sphinxbase headers.
Here is what my terminal on my Mac mini looks like:
Daniels-Mac-mini:pocketsphinx-master shinehah$ sh build_iphone.sh
building arm64...
build_iphone.sh: line 52: /Users/shinehah/cmusphinx/pocketsphinx-master/configure: No such file or directory
I created that directory, but I still get the same error message. What do I need to put in that directory?
In build_iphone.sh, line 52, it says:
--host="${HOST_TYPE}" \
Here is the code segment it is from:
$CWD/configure
--host="${HOST_TYPE}" // line 52
--prefix="$DEST/$ARCH"
--without-lapack
--without-python
--with-sphinxbase="$SPHINXBASE_DIR"
|| exit 1

Substrate VM: Unable to launch the native image generator

I wanted to check out the mx image generator:
./mx image -cp $PWD/svmbuild -H:Class=HelloWorld -H:Name=helloworld
mx: unknown command 'image'
It seems that the "image" command is not available (anymore?)
Any replacement available?
Thanks
There's an mx native-image command.
The README file in the GraalVM project repository lists the following quick start snippet:
cd substratevm
mx build
echo "public class HelloWorld { public static void main(String[] args) {
System.out.println(\"Hello World\"); } }" > HelloWorld.java
$JAVA_HOME/bin/javac HelloWorld.java
mx native-image HelloWorld
./helloworld
Allegedly, one needs a JDK 8 with the JVMCI for this to work, here's a relevant quote from the README:
Install mx and point JAVA_HOME to a labsjdk.
For compilation native-image depends on the local toolchain, so make
sure: glibc-devel, zlib-devel (header files for the C library and
zlib) and gcc are available on your system.

gtk/gtk.h: No such file or directory

In opencv compilation, we need gtk. I have gtk-2.0 and gtk-3.0 installed.
This command gave me
dpkg -l libgtk2.0-0 libgtk-3-0
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-============-============-=================================
ii libgtk-3-0:amd 3.10.8-0ubun amd64 GTK+ graphical user interface lib
ii libgtk2.0-0:am 2.24.23-0ubu amd64 GTK+ graphical user interface lib
ii libgtk2.0-0:i3 2.24.23-0ubu i386 GTK+ graphical user interface lib
I have gtk-2.0 and gtk-3.0 folder inside /usr/include/.
They exist as /usr/include/gtk-2.0 and /usr/include/gtk-3.0
But my compilation for opencv gave me error as
src/window_gtk.cpp:48:21: fatal error: gtk/gtk.h: No such file or directory
#include "gtk/gtk.h"
^
compilation terminated.
I have gtk/gtk.h inside both gtk-2.0 and gtk-3.0 folders.
What could be wrong?
First, use brackets instead of double quotes searches in your include if that's not a file that belongs to your project, but a third-party one.
We also need to know which version of opencv you're trying to compile. OpenCV 2.x support GTK+ 2 only, whereas OpenCV 3.x support GTK+ 3.
We also need how you call cmake when you configure the OpenCV project, so please add the command line and the logs of that call too.
This will help determine the arguments given to the compiler, to check it uses the right include locations, and also check that it's trying to use the GTK+ backend and not the Qt one for example.

How to integrate LuaJIT with LuaRocks on Windows?

I downloaded the source of LuaJIT and compiled it with msvc120.dll (VS 2013 x64). When I run it from the command line I have no problems executing some basic lua. Now the LuaJIT installation guide mentions moving luajit.exe and lua51.dll into their own folder. From there it says to create a lua folder and under that a jit folder with the contents of src/jit moved underneath the newly created jit folder.
From my understanding my folder should look like and contain:
luajit.exe
lua51.dll
/lua
/jit
bc.lua
[rest of jit files]
vmdef.lua
Is this correct or am I missing files?
Now after I built my luajit I tried to wire it up into my luarocks to act as my interpreter using
install.bat /LUA C:\LuaJIT\2.0.3\[folder with above content]
However this cannot find the header files. I then copied over what are the header files into the folder above and that wires it up, but I can never actually get anything to compile when pointed over to LuaJIT. Edit: The error I get is the following,
C:\LuaJIT\2.0.3\bin\lua51.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x2D0
Error: Failed installing dependency: https://rocks.moonscript.org/luafilesystem-1.6.2-2.src.rock - Build error: Failed compiling module lfs.dll
Is the correct way to handle this to simply point to my lua binaries and from there leverage LuaJIT to run my files or am I doing something wrong with wiring up LuaJIT and luarocks? The former seems to work for the most part, since I only ran into one library compilation issue, lua-cjson.
I've run on exactly the same problem, but they've found a solution right here:
https://github.com/keplerproject/luafilesystem/issues/22
I knew that for "linking DLLs statically" there is a so-called "export" .lib file, which is passed to the linker (and not the DLL itself).
So, for example, when compiling, LuaRocks was doing this:
cl /nologo /MD /O2 -c -Fosrc/mime.obj -ID:/LuaJIT-2.0.4/include/ src/mime.c -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DNDEBUG -DLUASOCKET_API=__declspec(dllexport) -DMIME_API=__declspec(dllexport) mime.c
link -dll -def:core.def -out:mime/core.dll D:/LuaJIT-2.0.4/bin/lua51.dll src/mime.obj
My LuaJIT was compiled from source in D:\LuaJIT-2.0.4\src, but I made two folders myself: D:\LuaJIT-2.0.4\include with all *.h files copied from src and D:\LuaJIT-2.0.4\bin with luajit.exe, lua51.dll, and then later lua51.exp and lua51.lib. Still same error, but this was the right track.
Fix
Now, check where your LuaRocks configs are:
luarocks.bat help
Scroll down to a section like:
CONFIGURATION
Lua version: 5.1
Configuration files:
System: D:/luarocks/config-5.1.lua (ok)
User : (... snip ...)
Edit the System configuration file, specifically see the part:
variables = {
MSVCRT = 'VCRUNTIME140',
LUALIB = 'lua51.dll'
}
Here! LUALIB should be the .lib file. If your export lib is alongside the DLL, you just need to change to:
variables = {
MSVCRT = 'VCRUNTIME140',
LUALIB = 'lua51.lib' -- here!
}
Verification
And now:
luarocks.bat install luasocket
(...)
link -dll -def:core.def -out:socket/core.dll D:/LuaJIT-2.0.4/bin/lua51.lib src/luasocket.obj (...)
(...)
luasocket 3.0rc1-2 is now built and installed in D:\luarocks\systree (license: MIT)
Note the first argument passed to the linker.

Resources