syscon: get the git hash and dirty flag in build time

Signed-off-by: Dan Horák <dan@danny.cz>
pull/243/head
Dan Horák 4 years ago
parent 538a8629f4
commit d177ee32f9

1
.gitignore vendored

@ -14,3 +14,4 @@ tests/*/*.elf
TAGS
litedram/build/*
obj_dir/*
git.vhdl

@ -50,6 +50,9 @@ core_files = decode_types.vhdl common.vhdl wishbone_types.vhdl fetch1.vhdl \
loadstore1.vhdl mmu.vhdl dcache.vhdl writeback.vhdl core_debug.vhdl \
core.vhdl

git.vhdl: git.vhdl.in
./make_version.sh $@

soc_files = $(core_files) wishbone_arbiter.vhdl wishbone_bram_wrapper.vhdl sync_fifo.vhdl \
wishbone_debug_master.vhdl xics.vhdl syscon.vhdl soc.vhdl \
spi_rxtx.vhdl spi_flash_ctrl.vhdl git.vhdl
@ -272,5 +275,5 @@ distclean: _clean
make -f scripts/mw_debug/Makefile distclean
make -f hello_world/Makefile distclean

.PHONY: all prog check check_light clean distclean
.PHONY: all prog check check_light clean distclean git.vhdl
.PRECIOUS: microwatt.json microwatt_out.config microwatt.bit

@ -1,9 +0,0 @@
library ieee;
use ieee.std_logic_1164.all;

library work;

package git is
constant GIT_HASH : std_ulogic_vector(27 downto 0) := x"1234567";
constant GIT_DIRTY : std_ulogic := '0';
end git;

@ -0,0 +1,9 @@
library ieee;
use ieee.std_logic_1164.all;

library work;

package git is
constant GIT_HASH : std_ulogic_vector(27 downto 0) := x"@hash@";
constant GIT_DIRTY : std_ulogic := '@dirty@';
end git;

@ -0,0 +1,40 @@
#!/bin/bash

dirty="0"

usage() {
echo "$0 <file>"
echo -e "\tSubstitute @hash@ and @dirty@ in <file> with gathered values."
}

if [ "$1" = "-h" -o "$1" = "--help" ] ;
then
usage
exit 1;
fi
if [ -z $1 ] ;
then
usage
exit 1;
fi

src=$1

if test -e .git || git rev-parse --is-inside-work-tree > /dev/null 2>&1;
then
version=$(git describe --exact-match 2>/dev/null)
if [ -z "$version" ];
then
version=$(git describe 2>/dev/null)
fi
if [ -z "$version" ];
then
version=$(git rev-parse --verify --short HEAD 2>/dev/null)
fi
if git diff-index --name-only HEAD |grep -qv '.git';
then
dirty="1"
fi
echo "hash=$version dirty=$dirty"
sed -e "s/@hash@/$version/" -e "s/@dirty@/$dirty/" ${src}.in > ${src}
fi
Loading…
Cancel
Save