From d963772c6633a0610898aaba2ae90d461e8f2de8 Mon Sep 17 00:00:00 2001 From: nishi Date: Fri, 7 Jul 2023 23:40:27 +0000 Subject: should be working, should be git-svn-id: https://svn.vegaa.systems/svn/vega-Vega/trunk@7 a8a8aea2-181d-ee11-89e8-15fd0e089fc4 --- tools/cross.sh | 148 +++++++++++++++++++++++++++++++++++++++++++++++++ tools/ksyms | 10 ++++ tools/meta-rip | 42 ++++++++++++++ tools/update-copyright | 12 ++++ 4 files changed, 212 insertions(+) create mode 100644 tools/cross.sh create mode 100755 tools/ksyms create mode 100755 tools/meta-rip create mode 100755 tools/update-copyright (limited to 'tools') diff --git a/tools/cross.sh b/tools/cross.sh new file mode 100644 index 0000000..77e47de --- /dev/null +++ b/tools/cross.sh @@ -0,0 +1,148 @@ +#!/bin/bash + +# +# Copyright (c) 2023 Ian Marco Moffett and the VegaOS team. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of VegaOS nor the names of its contributors may be used +# to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +################################################################ +# Configuration +################################################################ + +# Exit if there is an error +set -e + +# Target to use +TARGET=$1-elf + +# Versions to build +# Always use the latest working version (test before updating) +BUT_VER=2.40 +GCC_VER=13.1.0 + +# Tar file extension to use +# Always use the one with the smallest file size (check when updating version) +BUT_EXT=xz +GCC_EXT=xz + +# Multicore builds + +if [ "$(uname)" = "FreeBSD" ]; then + CORES=$(($(sysctl -n hw.ncpu) + 1)) + LOAD=$(sysctl -n hw.ncpu) +else + CORES=$(($(nproc) + 1)) + LOAD=$(nproc) +fi + +PREFIX="$(pwd)/cross" +export PATH="$PREFIX/bin:$PATH" + +echo "Building $TARGET Binutils $BUT_VER and GCC $GCC_VER..." +echo "Cores: $CORES, load: $LOAD" + +################################################################ +# Source Tarballs +################################################################ + +BUT_TARBALL=binutils-$BUT_VER.tar.$BUT_EXT +GCC_TARBALL=gcc-$GCC_VER.tar.$GCC_EXT + +mkdir -p buildcc +cd buildcc + +# Download tarballs +echo "Downloading Binutils tarball..." +if [ ! -f $BUT_TARBALL ]; then + wget https://ftp.gnu.org/gnu/binutils/$BUT_TARBALL +fi + +echo "Downloading GCC tarball..." +if [ ! -f $GCC_TARBALL ]; then + wget https://ftp.gnu.org/gnu/gcc/gcc-$GCC_VER/$GCC_TARBALL +fi + +# Unzip tarballs +printf "%s" "Unzipping Binutils tarball" +tar -xf $BUT_TARBALL +echo "" # Newline :~) +printf "%s" "Unzipping GCC tarball" +tar -xf $GCC_TARBALL + +################################################################ +# Building +################################################################ + +echo "Removing old build directories..." +rm -rf buildcc-gcc build-binutils + +# Build binutils +mkdir buildcc-binutils +cd buildcc-binutils +echo "Configuring Binutils..." +../binutils-$BUT_VER/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror +echo "Building Binutils..." +make -j$CORES -l$LOAD +echo "Installing Binutils..." +make install -j$CORES -l$LOAD +cd .. + +# Build gcc +cd gcc-$GCC_VER +echo "Downloading prerequisites for GCC..." +contrib/download_prerequisites +cd .. +mkdir buildcc-gcc +cd buildcc-gcc +echo "Configuring GCC..." +../gcc-$GCC_VER/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c --without-headers +echo "Building all-gcc..." +make all-gcc -j$CORES -l$LOAD +echo "Building all-target-libgcc..." +make all-target-libgcc -j$CORES -l$LOAD +echo "Installing GCC..." +make install-gcc -j$CORES -l$LOAD +echo "Installing target-libgcc..." +make install-target-libgcc -j$CORES -l$LOAD +cd ../.. + +echo "Removing build directory..." +rm -rf buildcc + +echo "Build complete, binaries are in $PREFIX/bin" + +################################################################ +# Basic Testing (just prints info for now) +################################################################ + +echo "Testing GCC..." +$TARGET-gcc -v + +echo "Testing LD..." +$TARGET-ld -v + +echo "Done!" diff --git a/tools/ksyms b/tools/ksyms new file mode 100755 index 0000000..f09203f --- /dev/null +++ b/tools/ksyms @@ -0,0 +1,10 @@ +#!/bin/bash +# $Id$ + +rm -f $1 +printf "#include \n\nstruct kernel_symbol" > $1 +printf " {\n\tuint64_t addr;\n\tchar* name;\n};\n\n" >> $1 +printf "const struct kernel_symbol g_ksym_table[] = {\n" >> $1 +nm $2 | grep " [tT] " | awk '{ print " { .addr = 0x"$1", .name = \""$3"\" }," }' | sort >> $1 +printf " { .addr = (size_t)-1, .name = \"\" }\n};\n\n" >> $1 +printf "const int ksym_elem_count = sizeof(g_ksym_table) / sizeof(*g_ksym_table);\n" >> $1 diff --git a/tools/meta-rip b/tools/meta-rip new file mode 100755 index 0000000..873a003 --- /dev/null +++ b/tools/meta-rip @@ -0,0 +1,42 @@ +#!/bin/bash +# $Id$ + +if [[ ! -f $1 ]] +then + echo "File not found: $1" + exit +fi + +readelf -S $1 | grep -q "\.meta\.note" > /dev/null +if [ $? -ne 0 ] +then + echo "No metadata in ELF; '.meta.note' non-existent" + exit +fi + +meta=$(objcopy $1 /dev/null --dump-section .meta.note=/dev/stdout | cat | tr -d '\0') + +# Remove the leading and trailing '$' characters +meta=${meta#'$'} +meta=${meta%'$'} + +# Use regular expression to extract the cookie, filename, author, and description +if [[ $meta =~ ^([^:]+):\s*([^,]+),\s*([^,]+),\s*(.*)$ ]]; then + cookie=${BASH_REMATCH[1]} + filename=${BASH_REMATCH[2]} + author=${BASH_REMATCH[3]} + description=${BASH_REMATCH[4]} + cookie=${cookie%?} # Remove the last character +fi + +if [[ $cookie != "Vega" ]] +then + echo "Invalid cookie found!" + exit +fi + +echo "Cookie: $cookie" +echo "Filename: $filename" +echo "Author: $author" +echo "Description: $description" + diff --git a/tools/update-copyright b/tools/update-copyright new file mode 100755 index 0000000..934803e --- /dev/null +++ b/tools/update-copyright @@ -0,0 +1,12 @@ +#!/bin/bash +# $Id$ + +# Set the current year as a variable +current_year=$(date +"%Y") + +# Find all files in the sys/ directory and its subdirectories +find . -type f -print0 | while read -d $'\0' file +do + # Replace the old copyright notice with the new one + sed -i "s/\(Copyright (c) \)[0-9]\{4\}\(.*\)/\1${current_year}\2/g" "${file}" +done -- cgit v1.2.3