Skip to content

Commit

Permalink
add scripts to build linux
Browse files Browse the repository at this point in the history
  • Loading branch information
sizhuo-zhang committed Feb 15, 2018
1 parent 2435903 commit fb8a9bf
Show file tree
Hide file tree
Showing 11 changed files with 2,527 additions and 1 deletion.
15 changes: 15 additions & 0 deletions riscv_custom/riscv_custom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#ifdef __riscv

#define riscv_roi_begin() asm volatile("csrwi 0x801, 1")
#define riscv_roi_end() asm volatile("csrwi 0x801, 0")
#define riscv_terminate() asm volatile("csrwi 0x800, 0")

#else

#define riscv_roi_begin()
#define riscv_roi_end()
#define riscv_terminate()

#endif
2 changes: 2 additions & 0 deletions riscv_custom/terminate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
terminate
terminate.dump
6 changes: 6 additions & 0 deletions riscv_custom/terminate/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PREFIX = riscv64-unknown-linux-gnu
TARGET = terminate

all:
$(PREFIX)-g++ -I.. -static main.cpp -o $(TARGET)
$(PREFIX)-objdump -d $(TARGET) > $(TARGET).dump
7 changes: 7 additions & 0 deletions riscv_custom/terminate/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "riscv_custom.h"

int main() {
riscv_terminate();
while(1);
return 0;
}
22 changes: 22 additions & 0 deletions tools/build-busybox.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -e

if [ $# -ne 0 ]; then
JOBS=$1
else
JOBS=1
fi

CURDIR=`pwd`

cd RV64G
rm -rf busybox*
wget https://busybox.net/downloads/busybox-1.21.1.tar.bz2
tar -xf busybox-1.21.1.tar.bz2
cd busybox-1.21.1
cp $CURDIR/configs/busybox_config .config
make -j$JOBS

cd $CURDIR
echo "busybox compiled successfully"
61 changes: 61 additions & 0 deletions tools/build-linux.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/python

import os
import stat
import shutil
import argparse
import subprocess

parser = argparse.ArgumentParser()
parser.add_argument('--testdir', dest = 'test_dir',
required = False, default = '')
parser.add_argument('--jobs', dest = 'jobs', required = False, default = 1)
args = parser.parse_args()

root = os.path.join(os.environ['RISCY_HOME'], 'tools')
linux_dir = os.path.join(root, 'riscv-linux')
config_dir = os.path.join(root, 'configs')
build_dir = os.environ['RISCY_TOOLS']
test_dir = '' if args.test_dir == '' else os.path.abspath(args.test_dir)

# copy initramfs.txt and .config
shutil.copy(os.path.join(config_dir, 'linux_config'),
os.path.join(linux_dir, '.config'))
shutil.copy(os.path.join(config_dir, 'initramfs.txt'), linux_dir)

# append to initramfs.txt with contents in test folder
if test_dir != '':
with open(os.path.join(linux_dir, 'initramfs.txt'), 'a') as fp:
def writeTree(ramfs_dir, src_dir):
for f in os.listdir(src_dir):
ramfs_path = os.path.join(ramfs_dir, f)
src_path = os.path.join(src_dir, f)
mode = os.stat(src_path).st_mode
perm = oct(stat.S_IMODE(mode))[-3:]
if stat.S_ISDIR(mode):
fp.write('dir {} {} 0 0\n'.format(ramfs_path, perm))
writeTree(ramfs_path, src_path)
elif stat.S_ISREG(mode):
fp.write('file {} {} {} 0 0\n'.format(ramfs_path,
src_path,
perm))
else:
raise Exception('unknown file type ' + src_path)
writeTree('/test', test_dir)

# compile vmlinux
cmd = 'cd {}; make ARCH=riscv -j{}'.format(linux_dir, args.jobs)
print 'Running: {}'.format(cmd)
subprocess.check_call(cmd, shell = True)

# compile bbl
cmd = ('cd {}; '.format(build_dir) +
'rm -rf build-pk; mkdir -p build-pk; cd build-pk; ' +
'../../riscv-pk/configure ' +
'--prefix={} '.format(build_dir) +
'--host=riscv64-unknown-linux-gnu ' +
'--with-payload={}; '.format(os.path.join(linux_dir, 'vmlinux')) +
'make -j{}; make install'.format(args.jobs))
print 'Running: {}'.format(cmd)
subprocess.check_call(cmd, shell = True)

Loading

0 comments on commit fb8a9bf

Please sign in to comment.