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

Improved raspi support #5

Open
wants to merge 9 commits into
base: lkl-musl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 4 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ workflows:
jobs:
- linux-linux
- linux-netbsd
- qemu-arm-linux
- qemu-arm-netbsd
# FIXME: Forked version of QEMU is needed
# - qemu-arm-linux
# TODO: Investigate netbsd support for qemu-arm
# - qemu-arm-netbsd
- freebsd-linux
- freebsd-netbsd
61 changes: 56 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,59 @@
language: c
language: nix

compiler:
- gcc
- clang
env:
global:
# XXX: Nix on Travis uses the master branch of the nixpkgs repo, meaning we
# need to pin nixpkgs to a specific version if we want to avoid frequent
# rebuilds of dependant packages.
#
# TODO: <nixpkgs> should ideally point to the latest stable release.
# However, we currently use the unstable release (@ 2019-03-03) since we
# depend on NixOS/nixpkgs#52146, which hasn't been merged into stable yet.
# It should be possible to use stable once 19.03 is out.
- NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/34aa254f9ebf5899636a9927ceefbc9df80230f4.tar.gz

matrix:
include:
- name: "gcc-netbsd"
env: BUILD_TARGET=frankenlibc-gcc
- name: "clang-netbsd"
env: BUILD_TARGET=frankenlibc-clang
- name: "lkl-musl"
env: BUILD_TARGET=frankenlibc-lkl
- name: "raspi2-linux"
env: BUILD_TARGET=frankenlibc-arm

git:
# XXX: Submodules have to be fetched manually since it frequently times out.
submodules: false

cache:
timeout: 1000
directories:
- $HOME/nix.store
# XXX: Beware. Desperate attempt to cache the lkl repository.
- $TRAVIS_BUILD_DIR/.git/modules

before_cache:
- mkdir -p $HOME/nix.store
- |
nix copy --to file://$HOME/nix.store -f default.nix \
"$BUILD_TARGET".buildInputs \
"$BUILD_TARGET".nativeBuildInputs \
"$BUILD_TARGET".depsBuildBuild

before_install:
# XXX: Shallow clone of submodules is possible with newer version of git, but
# is tricky (https://stackoverflow.com/questions/2144406/how-to-make-shallow-git-submodules)
- travis_wait 30 git submodule update --init --recursive
- mkdir -p $HOME/.config/nix
- |
# XXX: We write the configuration line-by-line, since Travis doesn't seem
# to recognize heredoc delimiters for some reason.
echo "substituters = file://$HOME/nix.store https://cache.nixos.org/" \
>> ~/.config/nix/nix.conf
echo "require-sigs = false" \
>> ~/.config/nix/nix.conf

script:
- ./build.sh
- nix-build -A "$BUILD_TARGET"
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ PHONY: clean distclean qemu-arm spike seccomp
clean:
rm -rf rumpobj
$(MAKE) clean -C musl
$(MAKE) clean -C platform/qemu-arm

distclean: clean
rm -rf rump
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ ${INSTALL-install} ${RUMP}/bin/rexec ${BINDIR}
rumpkernel_install_extra_libs

${INSTALL-install} ${RUMP}/lib/*.o ${OUTDIR}/lib
[ -f ${RUMP}/lib/link.ld ] && ${INSTALL-install} ${RUMP}/lib/link.ld ${OUTDIR}/lib
[ -f ${RUMP}/lib/libg.a ] && ${INSTALL-install} ${RUMP}/lib/libg.a ${OUTDIR}/lib
${INSTALL-install} ${RUMPOBJ}/explode/libc.a ${OUTDIR}/lib

Expand Down Expand Up @@ -634,6 +635,7 @@ CC="${BINDIR}/${COMPILER}" \
RUMPDIR="${OUTDIR}" \
RUMPOBJ="${RUMPOBJ}" \
BINDIR="${BINDIR}" \
OS="${OS}" \
${MAKE} ${STDJ} -C tests

# test for executable stack
Expand Down
39 changes: 39 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{ pkgs ? import <nixpkgs> {} }:

with pkgs;

let
callPackage = lib.callPackageWith (pkgs // self);

keepDebugInfo = stdenv: stdenv // {
mkDerivation = args: stdenv.mkDerivation (args // {
dontStrip = true;
});
};

self = {
frankenlibc-gcc = callPackage ./nix/frankenlibc.nix {
stdenv = overrideCC stdenv gcc6;
};

frankenlibc-clang = callPackage ./nix/frankenlibc.nix {
inherit (llvmPackages_38) stdenv;
};

frankenlibc-lkl = callPackage ./nix/frankenlibc.nix {
rumpKernel = "linux";
};

frankenlibc-arm = callPackage ./nix/frankenlibc.nix {
stdenv = pkgsCross.arm-embedded.buildPackages.stdenv;
rumpKernel = "linux";
};

qemu-circle = callPackage ./nix/qemu-circle.nix { };

# XXX: We can't use enableDebugging from nixpkgs, since the linux kernel
# refuses to compile with -O0 flags.
enableDebugging = pkg: pkg.override { stdenv = keepDebugInfo pkg.stdenv; };
};

in self
23 changes: 23 additions & 0 deletions franken/init/fdinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@ franken_lkl_load_json_config(int fd)

}

static void
franken_lkl_load_env_config(void)
{
int ret;

json_cfg = (struct lkl_config *)malloc(sizeof(struct lkl_config));
if (!json_cfg) {
printf("malloc error\n");
return;
}
memset(json_cfg, 0, sizeof(struct lkl_config));

ret = lkl_load_config_env(json_cfg);
if (ret < 0)
printf("load_config_env error \n\n%s\n");
}

struct lkl_config *
franken_lkl_get_json_config(void)
{
Expand Down Expand Up @@ -165,6 +182,12 @@ __franken_fdinit()
break;
}
}

#ifdef MUSL_LIBC
/* No valid file descriptors exist */
if (fd == 0)
franken_lkl_load_env_config();
#endif
}

/* XXX would be much nicer to build these functions against NetBSD libc headers, but at present
Expand Down
2 changes: 1 addition & 1 deletion linux
Submodule linux updated from 50adb1 to 7830d2
58 changes: 58 additions & 0 deletions nix/frankenlibc.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{ stdenv, lib, buildPackages, bc, e2fsprogs, nettools, python, which, zlib
, gcc-arm-embedded, qemu-circle
, rumpKernel ? "netbsd"
, doCheck ? true }:

assert rumpKernel == "netbsd" || rumpKernel == "linux";

let
inherit (stdenv) buildPlatform hostPlatform targetPlatform;

rumpCC =
# XXX: We can't build with pkgsCross.arm-embedded.cc because newlib-nano
# is required instead of newlib. See NixOS/nixpkgs#51907 for details.
if targetPlatform.isAarch32 then gcc-arm-embedded
else assert hostPlatform == targetPlatform; stdenv.cc;

in
stdenv.mkDerivation {
name = "frankenlibc";

src = lib.cleanSource ../.;

depsBuildBuild = [ zlib ]
++ lib.optional (buildPlatform != targetPlatform) buildPackages.stdenv.cc;
depsBuildTarget = [ rumpCC ];
nativeBuildInputs = [ bc e2fsprogs nettools python which ];
buildInputs = [ rumpCC ]
++ lib.optional targetPlatform.isAarch32 qemu-circle;

preConfigure = lib.optionalString targetPlatform.isAarch32 ''
export CC="${gcc-arm-embedded}/bin/arm-none-eabi-gcc"
export NM="${gcc-arm-embedded}/bin/arm-none-eabi-nm"
export AR="${gcc-arm-embedded}/bin/arm-none-eabi-ar"
export OBJCOPY="${gcc-arm-embedded}/bin/arm-none-eabi-objcopy"
'';

buildFlags = [
"-q" # XXX: Travis terminates builds with excessive log ouput
"-k " rumpKernel
] ++ lib.optional targetPlatform.isAarch32 "qemu-arm"
# XXX: We perform the check phase here because it is tricky to setup outside
# build.sh.
++ lib.optional (!(doCheck && buildPlatform == hostPlatform)) "notest";

buildPhase = ''
mkdir -p $out
./build.sh -d $out $buildFlags
'';

installPhase = ''
mkdir -p $out/libexec/tools
mv rumpobj/tests $out/libexec
mv $out/bin/rump.* $out/libexec/tools || true
'';

enableParallelBuilding = true;
inherit doCheck;
}
41 changes: 41 additions & 0 deletions nix/qemu-circle.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{ stdenv, fetchurl, fetchFromGitHub, overrideCC, qemu, gcc6, SDL }:

let
qemu-circle = qemu.override {
hostCpuTargets = [ "arm-softmmu" ];
pulseSupport = false;
sdlSupport = false; SDL2 = SDL;
gtkSupport = false;
vncSupport = false;
smartcardSupport = false;
spiceSupport = false;
xenSupport = false;
cephSupport = false;
openGLSupport = false;
virglSupport = false;
smbdSupport = false;
};

diffForCommit = commit: "https://github.com/qemu/qemu/commit/${commit}.diff";
in
qemu-circle.overrideAttrs (old: rec {
name = "qemu-circle-${version}";
version = "2.4.1";
sha256 = "19936r6x7wal09zh0f1s5y32v4k4z5nmnfb2jf0padmff3808jl9";
src = fetchFromGitHub {
owner = "rsta2";
repo = "qemu";
rev = "7a24a5a051ea83529b057fd18c76ca40eb717392";
fetchSubmodules = true;
inherit sha256;
};

patches = builtins.tail old.patches ++ [
(fetchurl {
url = diffForCommit "75e5b70e6b5dcc4f2219992d7cffa462aa406af0";
sha256 = "0a9a09xy4iy6gnmhlbgj28pvzxwp7h165s3rvpc9n6b7lbm0dibj";
})
];

stdenv = overrideCC stdenv gcc6;
})
56 changes: 48 additions & 8 deletions platform/qemu-arm/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
COMPILE.c?=$(CC) -c $(CPPFLAGS) $(CFLAGS)
COMPILE.S?=$(CC) -c $(CPPFLAGS) $(ASFLAGS)
INSTALL?=install
RUMPOBJ?=../../rumpobj
OBJDIR=$(RUMPOBJ)/platform
RUMP?=$(RUMPOBJ)/rump
Expand All @@ -8,6 +9,7 @@ CRTFILES=$(CRTDIR)/startup.o $(CRTDIR)/crt0.o
CRTFILES+=$(CRTDIR)/crti.o $(CRTDIR)/crtn.o
CRTFILES+=$(CRTDIR)/crtbegin.o $(CRTDIR)/crtbeginT.o
CRTFILES+=$(CRTDIR)/crtend.o
CRTFILES+=$(CRTDIR)/link.ld
OBJ=$(CRTFILES)
LIBG=$(CRTDIR)/libg.a
OBJ+=$(LIBG)
Expand All @@ -24,7 +26,6 @@ OBJ+=$(OBJDIR)/kill.o
OBJ+=$(OBJDIR)/lseek.o
OBJ+=$(OBJDIR)/mmap.o
OBJ+=$(OBJDIR)/mprotect.o
OBJ+=$(OBJDIR)/__libc_start_main.o
OBJ+=$(OBJDIR)/poll.o
OBJ+=$(OBJDIR)/pread.o
OBJ+=$(OBJDIR)/pwrite.o
Expand All @@ -34,7 +35,11 @@ OBJ+=$(OBJDIR)/read.o
OBJ+=$(OBJDIR)/readv.o
OBJ+=$(OBJDIR)/write.o
OBJ+=$(OBJDIR)/writev.o
HEADERS=$(CRTDIR) $(OBJDIR)
OBJ+=$(OBJDIR)/libcircle.o
OBJ+=$(OBJDIR)/libcircleusb.o
OBJ+=$(OBJDIR)/libcircleinput.o
OBJ+=$(OBJDIR)/libcirclefs.o
HEADERS=$(CRTDIR) $(OBJDIR) circle
INCLUDES=-I../include -I../../franken/include -I.
CPPFLAGS+=-nostdinc $(INCLUDES)
CFLAGS+=-fno-stack-protector
Expand All @@ -48,8 +53,8 @@ $(OBJDIR):
$(CRTDIR):
mkdir -p $(CRTDIR)

$(CRTDIR)/startup.o: startup.s $(HEADERS)
$(COMPILE.S) -o $@ startup.s
$(CRTDIR)/startup.o: circle/lib/startup.o $(HEADERS)
$(INSTALL) $< $@

$(CRTDIR)/crt0.o: $(CRTDIR)
printf "\n" | $(COMPILE.c) -o $@ -x c -
Expand All @@ -69,6 +74,9 @@ $(CRTDIR)/crtbeginT.o: $(CRTDIR)
$(CRTDIR)/crtend.o: $(CRTDIR)
printf "\n" | $(COMPILE.c) -o $@ -x c -

$(CRTDIR)/link.ld: link.ld $(CRTDIR)
$(INSTALL) -m644 $< $@

$(LIBG): $(CRTDIR)
printf "\n" | $(COMPILE.c) -o $(OBJDIR)/g.o -x c -
$(AR) cr $@ $(OBJDIR)/g.o
Expand Down Expand Up @@ -105,9 +113,6 @@ $(OBJDIR)/getrandom.o: getrandom.c $(HEADERS)
$(OBJDIR)/kill.o: kill.c $(HEADERS)
$(COMPILE.c) -o $@ kill.c

$(OBJDIR)/__libc_start_main.o: __libc_start_main.c $(HEADERS)
$(COMPILE.c) -o $@ __libc_start_main.c

$(OBJDIR)/lseek.o: lseek.c $(HEADERS)
$(COMPILE.c) -o $@ lseek.c

Expand Down Expand Up @@ -144,6 +149,41 @@ $(OBJDIR)/write.o: write.c $(HEADERS)
$(OBJDIR)/writev.o: writev.c $(HEADERS)
$(COMPILE.c) -o $@ writev.c

.PHONY: clean
$(OBJDIR)/libcircle.o: circle/lib/libcircle.o $(HEADERS)
$(INSTALL) $< $@

$(OBJDIR)/libcircleusb.o: circle/lib/usb/libcircleusb.o $(HEADERS)
$(INSTALL) $< $@

$(OBJDIR)/libcircleinput.o: circle/lib/input/libcircleinput.o $(HEADERS)
$(INSTALL) $< $@

$(OBJDIR)/libcirclefs.o: circle/lib/fs/libcirclefs.o $(HEADERS)
$(INSTALL) $< $@

circle: circle/lib/startup.o circle/lib/libcircle.o
circle: circle/lib/usb/libcircleusb.o circle/lib/input/libcircleinput.o
circle: circle/lib/fs/libcirclefs.o

circle/lib/startup.o:
$(MAKE) -C circle/lib $(notdir $@) $(CIRCLE_FLAGS)

circle/lib/libcircle.o:
$(MAKE) -C circle/lib $(notdir $@) $(CIRCLE_FLAGS)

circle/lib/usb/libcircleusb.o:
$(MAKE) -C circle/lib/usb $(notdir $@) $(CIRCLE_FLAGS)

circle/lib/input/libcircleinput.o:
$(MAKE) -C circle/lib/input $(notdir $@) $(CIRCLE_FLAGS)

circle/lib/fs/libcirclefs.o:
$(MAKE) -C circle/lib/fs $(notdir $@) $(CIRCLE_FLAGS)

.PHONY: clean circle
clean:
rm -f $(OBJ)
$(MAKE) -C circle/lib clean
$(MAKE) -C circle/lib/usb clean
$(MAKE) -C circle/lib/input clean
$(MAKE) -C circle/lib/fs clean
Loading