9. Headers
There exists a handful of files that have been created and/or edited that contain no header block whatsoever. These poor unloved souls should become part of the family and have a nice shiny header block just like the rest of their brethren.
Two options exist :-
- Go through the files in the repository and fumble together the missing headers.
- Write a script to do the majority of the donkey work.
Who can pass up the opportunity to write some new code? 😉
Destination unknown! Summary of what is required...
- (done) Obtain a full list of files held in the repository.
- (done) Use the above list to create an ignore list (not our files, binaries, etc.).
- Iterate through the full list using the ignore list to pick out the files of interest.
- Determine the file type from the file contents and/or filename.
- Determine the start line from where the header block should begin.
- Select a suitable comment style based on the file type.
- Examine the file to check for a pre-existing header block, if found ignore the file.
- Create some sensible default fields to go inside the new header block.
- Insert the new header block into the unloved file at the correct position.
- Write the code in a modular fashion so new features can easily be added.
Note: By using a
full list and
ignore list combo instead of just an
include list prevents any new file additions from easily being missed. Much the same as with the
.gitignore philosophy.
Lets consider the
comment style to be used for the various source files in the repository. Many different styles & types exist in the world of source code. So far four distinct styles & types have been used, which we will stick with for now.
Hash (script) example (header starts from line 3 not 1)
#!/bin/bash
#
# File .......... xilinx.sh
# Author ........ Steve Haywood
# Version ....... 1.0
# Date .......... 8 February 2021
# Description ...
# Determine and list which Xilinx tools are available and let the user select
# the require ones to use. Does not reverse any previously selected tools upon
# selecting news ones so to is cleaner to use in a new Terminal session.
#
Hash (non-script) example
#
# File .......... create_vivado_project.tcl
# Author ........ Steve Haywood
# Version ....... 1.0
# Date .......... 23 December 2021
# Description ...
# Simple Tcl script to create a new Vivado project, import external
# sources and (optionally) generate the bitstream & export the hardware.
#
Slash example
//
// File .......... hello_world.c
// Author ........ Steve Haywood
// Version ....... 1.0
// Date .......... 27 December 2021
// Description ...
// The classic hello world C application.
//
Star example (kind of a missing extra empty comment line at end, for correct balance)
/*
* File .......... style.css
* Author ........ Steve Haywood
* Website ....... http://www.spacewire.co.uk
* Project ....... SpaceWire UK Tutorial
* Version ....... 1.1
* Conception .... 17 January 2022
* Standard ...... CSS 3
* Description ...
* Global Cascading Style Sheet for use in all webpages.
*/
PHP example (kind of an extra empty comment line at start & end, but looks balanced)
<?php
//
// File .......... index.php
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... SpaceWire UK Tutorial
// Version ....... 1.0
// Conception .... 27 February 2024
// Standard ...... PHP 7
// Description ...
// Webpage for Home.
//
?>
A script to achieve the above requirements.
- Download the script & make it executable.
steve@Desktop:/tmp/scratch$ wget https://spacewire.co.uk/tutorial/shared/repos/0027/common/other/src/script/swuk_repos_gen_fix_headers
steve@Desktop:/tmp/scratch$ chmod +x swuk_repos_gen_fix_headers
#!/bin/bash
#
# File .......... swuk_repos_gen_fix_headers
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Common (SpaceWire UK Tutorial)
# Date .......... 30 Jan 2025
# Version ....... 1.0
# Description ...
# Iterate through a collection of project directories and create/correct any
# of the missing/erroneous headers. All functions are controlled by command line
# switches.
#
# Fields in the header :-
#
# File .......... Set to the filename of the source in question.
# Author ........ Set to a constant in this script.
# Website ....... Set to a constant in this script.
# Project ....... Set to the project name plus a constant in this script.
# Date .......... If not provided set to a default value, otherwise corrected to
# have a consistent format.
# Version ....... Major part set to be the number of changes provided from
# 'git log' for the source in question. Minor part is optionally
# set to 0.
# Description ... If not provided set to a default value.
#
# Strict
set -euo pipefail
# General constants
declare -r c_newline=$'\n'
# Verbosity levels # Summary - Err - Warn - Note - Files(Inc) - Files(Exc)
declare -ri c_verb_summary=0 # Yes - No - No - No - No - No
declare -ri c_verb_errors=1 # Yes - Yes - No - No - No - No
declare -ri c_verb_warnings=2 # Yes - Yes - Yes - No - No - No
declare -ri c_verb_notes=3 # Yes - Yes - Yes - Yes - No - No
declare -ri c_verb_include=4 # Yes - Yes - Yes - Yes - Yes - No
declare -ri c_verb_exclude=5 # Yes - Yes - Yes - Yes - Yes - Yes
# Message types
declare -ri c_error=${c_verb_errors}
declare -ri c_warning=${c_verb_warnings}
declare -ri c_note=${c_verb_notes}
declare -ri c_action=${c_verb_include}
# User constants
declare -r c_author="Steve Haywood"
declare -r c_website="http://www.spacewire.co.uk"
declare -r c_project="SpaceWire UK Tutorial"
declare -r c_date="Sage date!"
declare -r c_description="Sage words!"
# Known filenames (very in-extensive!)
declare -ra c_name_hash=(Makefile)
# Known extensions (by no means extensive or 100% correct!)
declare -ra c_ext_hash=(bb bbappend cgi conf sh tcl xdc)
declare -ra c_ext_slash=(c h js sv v vh)
declare -ra c_ext_star=(css dtsi)
declare -ra c_ext_php=(php)
declare -ra c_ext_html=(htm html)
# Comment types (by no means extensive!)
declare -ri c_type_unknown=0
declare -ri c_type_hash=1
declare -ri c_type_slash=2
declare -ri c_type_star=3
declare -ri c_type_php=4
declare -ri c_type_html=5
# Opening comments
declare -rA c_hdr_open=(
[${c_type_unknown}]="?"
[${c_type_hash}]="#"
[${c_type_slash}]="//"
[${c_type_star}]="/*"
[${c_type_php}]="<?php"
[${c_type_html}]="<!--"
)
# Empty comments
declare -rA c_hdr_empty=(
[${c_type_unknown}]="?"
[${c_type_hash}]="#"
[${c_type_slash}]="//"
[${c_type_star}]=" *"
[${c_type_php}]="//"
[${c_type_html}]="//"
)
# Body comments
declare -rA c_hdr_body=(
[${c_type_unknown}]="? "
[${c_type_hash}]="# "
[${c_type_slash}]="// "
[${c_type_star}]=" * "
[${c_type_php}]="// "
[${c_type_html}]="// "
)
# Closing comments
declare -rA c_hdr_close=(
[${c_type_unknown}]="?"
[${c_type_hash}]="#"
[${c_type_slash}]="//"
[${c_type_star}]=" */"
[${c_type_php}]="?>"
[${c_type_html}]="-->"
)
################################################################################
# Display formatted message for comments, warnings, errors & notes.
# Arguments ...... $1 = Level (2 = Error 3 = Warning, 4 = Note)
# $2 = Line number (1..) (0 = Do not display line number)
# $3 = Message text
# Return ......... None
# Shared (In) .... errors*, file, filenamedisp*, verbosity, warnings*
# Shared (Out) ... errors*, filenamedisp*, warnings*
msg() {
local -ri level=$1 # Int: Error level
local -ri lineno=$2 # Int: Line number
local -r message=$3 # Str: Error message
local -rA lookup=(
[${c_error}]="\e[31mError\e[0m ....."
[${c_warning}]="\e[36mWarning\e[0m ..."
[${c_note}]="\e[32mNote\e[0m ......"
[${c_action}]="\e[93mAction\e[0m ...."
)
if [[ ${verbosity} -ge ${level} ]]; then
if [[ ${filenamedisp} -eq 0 ]]; then
>&2 echo ${file}
filenamedisp=1
fi
>&2 echo -ne " ${lookup[${level}]}"
[[ ${lineno} -gt 0 ]] && >&2 printf " %02d :" ${lineno} || >&2 echo -n "... :"
>&2 echo " ${message}"
fi
if [[ ${level} -eq ${c_warning} ]]; then
warnings=$((warnings+1))
fi
if [[ ${level} -eq ${c_error} ]]; then
errors=$((errors+1))
fi
}
################################################################################
# Get the file type based on name and/or extension.
# Arguments ...... None
# Return ......... File type
# Shared (In) .... file
# Shared (Out) ... None
getcomtype()
{
# Default to unknown type
local -i type=${c_type_unknown} # Int: File type
# Standard path/filename split # $file ..... path/to/dir/filename.extension
local fname=$(basename "${file}") # Str: $fname .... filename.extension
local fbase="${fname%.*}" # Str: $fbase .... filename
local fext="${fname##*.}" # Str: $fext ..... extension
# Get comment type (name is primary, extension is secondary)
if [[ " ${c_name_hash[*]} " =~ " ${fname} " ]]; then
type=${c_type_hash}
elif [[ " ${c_ext_hash[*]} " =~ " ${fext} " ]]; then
type=${c_type_hash}
elif [[ " ${c_ext_slash[*]} " =~ " ${fext} " ]]; then
type=${c_type_slash}
elif [[ " ${c_ext_star[*]} " =~ " ${fext} " ]]; then
type=${c_type_star}
elif [[ " ${c_ext_php[*]} " =~ " ${fext} " ]]; then
type=${c_type_php}
elif [[ " ${c_ext_html[*]} " =~ " ${fext} " ]]; then
type=${c_type_html}
fi
echo ${type}
}
################################################################################
# Read the comment header block from a source file.
# Arguments ...... None
# Return ......... None
# Shared (In) .... com*, end*, file, header*, lines*, start*, type*, valid*
# Shared (Out) ... com*, end*, header*, lines*, start*, type*, valid*
#
# Note: The single line read used below is the stock way of doing this, where :-
# 1. IFS= (or IFS='') prevents leading/trailing whitespace from being trimmed.
# 2. -r prevents backslash escapes from being interpreted.
# 3. [[ -n ${line} ]] prevents the last line from being ignored if it doesn't end with a \n.
#
read_header()
{
# Declare local variables
local line="" # Str: Line string
local -i pos=1 # Int: Line position
local -i stage=0 # Int: Operation stage (0=Pre-header, 1=Header)
# Initialise shared variables
type=0 # Int: File type (0=Unknown, 1=Script)
com="" # Str: Comment style
valid=0 # Int: Found a valid header (0:No, 1:Yes)
start=0 # Int: Start position of header
end=0 # Int: End position of header
header="" # Str: Captured header block (string)
lines=() # Arr: Captured header block (array)
# Iterate through lines of file
while IFS= read -r line || [[ -n "${line}" ]] && [[ ${pos} -lt 100 ]]; do
if [[ (${pos} -eq 1) && (${line:0:2} == "#!") ]]; then
type=1
elif [[ "${line}" =~ ^[[:space:]]*$ ]]; then
[[ ${stage} -eq 1 ]] && break # End of header
else
[[ ${stage} -eq 0 ]] &&
start=${pos}
end=${pos}
stage=1
if [[ "${line}" =~ ^.*[Ff][Ii][Ll][Ee]\ \.{3,}\ .+$ ]]; then
valid=1
com=$(echo "${line}" | sed -n 's/^\(.*\)[Ff][Ii][Ll][Ee] \.\{3,\} .\+/\1/p')
fi
header+="${line}${c_newline}"
lines+=("${line}")
fi
pos=$((pos+1))
done < "${file}"
# Clean up positions
if [[ ${valid} -eq 0 ]]; then
end=0
if [[ ${type} -eq 0 ]]; then
start=0
else
start=2
fi
fi
}
################################################################################
# Parse header block into an associative array.
# Arguments ...... None
# Return ......... None
# Shared (In) .... default*, keys*, lines, type
# Shared (Out) ... default*, keys*
parse_header()
{
# Declare local variables
local textblock="" # Str: Block of text (description, history)
local -ir linecnt=${#lines[@]} # Int: Header line count
local -i linenum # Int: Header line number
local line # Str: Header line string
local -i sling # Int: Sling trailing description line (0=keep, 1=sling)
local parts # Str: Field parts string (2 or 3 parts, | separated)
IFS=''
for (( linenum=0; linenum<${linecnt}; linenum++ )); do
line=${lines[linenum]}
line="${line%"${line##*[![:space:]]}"}" # Trim trailing whitespace
local -a fields=() # Header fields array
if [[ ${textblock} != "" ]]; then
sling=0
case ${linenum} in
$((linecnt-3)))
if [[ ${type} == ${c_type_php} && ${line} == " *" ]]; then
sling=1 # Sling pre-pre-closing ' *' for PHP headers
fi
;;
$((linecnt-2)))
if [[ (${type} == ${c_type_php}) && (${line} == "//" || ${line} == "*/" || ${line} == " */") ]]; then
sling=1 # Sling pre-closing '//', '*/' & ' */' for PHP headers
fi
;;
$((linecnt-1)))
if [[ ${type} == ${c_type_star} || ${type} == ${c_type_php} || ${type} == ${c_type_html} ]]; then
sling=1 # Sling closing ' */', '?>' & '-->' for CSS, PHP & HTML headers
fi
;;
esac
if [[ ${sling} -eq 0 ]]; then
default[${fid}]+="${line}|"
fi
fi
# Obtain the 3 part variant of the field (name dots value) in the header block
parts=$(echo "${line}" | sed -n 's/^.*\([A-Z][a-z]\{3,11\}\) \(\.\{3,11\}\) \(.*\)/\1|\2|\3/p')
# Split the field parts into an array
IFS='|' read -ra fields <<< "${parts}"
if [[ ${#fields[@]} -eq 3 ]]; then
# Extra check
local tmp="${fields[0]}${fields[1]}"
if [[ ${#tmp} -eq 14 ]]; then
local fid=${fields[0],,} # Lower case fid
#local fdots=${fields[1]}
local fvalue=${fields[2]}
default[${fid}]=${fvalue}
keys+=("${fid}") # Add discovered field (name) to the keys list
[[ ${textblock} != "" ]] && textblock=""
fi
fi
# Obtain the 2 part variant of the field (name dots) in the header block
parts=$(echo "${line}" | sed -n 's/^.*\([A-Z][a-z]\{3,11\}\) \(\.\{3,11\}\)$/\1|\2/p')
# Split the field parts into an array
IFS='|' read -ra fields <<< "${parts}"
# Determine if field is known
if [[ ${#fields[@]} -eq 2 ]]; then
# Extra check
local tmp="${fields[0]}${fields[1]}"
if [[ ${#tmp} -eq 14 ]]; then
local fid=${fields[0],,} # Lower case fid
#local fdots=${fields[1]}
default[${fid}]=""
keys+=("${fid}") # Add discovered field (name) to the keys list
[[ ${textblock} != "" ]] && textblock="" || textblock=${fid}
fi
fi
done
unset IFS
}
################################################################################
# Write the 'ed' commands required to strip out the source file headers and
# replace them with new ones.
# Arguments ...... None
# Return ......... None
# Shared (In) .... addheader, addminor, addproject, addwebsite, com, end, file,
# fixfilename, formatdate, gitversion, hdr_body, hdr_close,
# hdr_empty, hdr_open, lines, projdir, remstandard,
# renconception, reorganise, rewrite, start, type, valid
# Shared (Out) ... default*, keys*, lines, type
rewrite_write()
{
# Declare local variables
[[ ${type} == ${c_type_html} || ${type} == ${c_type_php} ]] &&
local post_open="${c_newline}${hdr_empty}" || local post_open=""
[[ ${type} == ${c_type_html} || ${type} == ${c_type_php} ]] &&
local pre_close="${hdr_empty}${c_newline}" || local pre_close=""
# Declare shared variables
local -a keys=() # Arr : List of fields discovered in header
local -A default=( # ARR: Default header
[file]=""
[author]=""
[website]=""
[project]=""
[conception]=""
[date]=""
[version]=""
[history]=""
[description]=""
)
# Obtain filename from full path
local -r filename=$(basename "${file}")
# Obtain major version based on log entry count
local -ir major=$(git log --oneline ${file} | wc -l)
# Add minor version (fixed at .0)
local minor=""
[[ ${addminor} -eq 1 ]] && local minor=".0"
local -Ar projects=( # ARR: Project names
["common"]="Common"
["zedboard_hello_world"]="Zedboard Hello World"
["zedboard_leds_buttons"]="Zedboard LEDs & Buttons"
["zedboard_leds_switches"]="Zedboard LEDs & Switches"
["zedboard_linux"]="Zedboard Linux"
)
# Obtain project
local proj=$(echo ${file} | cut -d'/' -f1)
if [[ ${valid} -eq 1 ]]; then # Header detected, process it
# Parse header block into associated array & keys list
parse_header
# Iterate though all the fields in the default header & apply the options requested
for key in ${!default[@]}
do
local fieldvalue=${default[${key}]}
case ${key} in
"file") ## 'mandatory'
# Check for difference between field value vs. expected field value
if [[ (${fixfilename} -eq 1) && (${filename} != ${fieldvalue}) ]]; then
# Throw a warning to signal file modification
msg c_warning 0 "Changing value of '${key^}' field from '${default[${key}]}' to '${filename}'."
# Override 'File' field value
default[${key}]=${filename}
fi
;;
"date")
# Check for a field value
if [[ ${default[${key}]} != "" ]]; then
# Evaluate 'Date' value using the date command
local date=$(date -d "${fieldvalue}" +'%d %b %Y' 2>/dev/null)
# Check for field viability
if [[ ${date} != "" ]]; then
# Check for difference between field value vs. expected field value
if [[ (${formatdate} -eq 1) && (${date} != ${fieldvalue}) ]]; then
# Throw a warning to signal file modification
msg c_warning 0 "'${key^}' field is incorrectly formatted, found '${default[${key}]}', changing to '${date}'."
# Override 'Date' field value
default[${key}]=${date}
else
# No big deal, throw note
msg c_note 0 "'${key^}' field is correctly formatted, found '${default[${key}]}'."
fi
else
# Unrecognizable date, throw error
msg c_error 0 "'${key^}' field is invalid, expecting a valid date, found '${default[${key}]}'."
fi
fi
;;
"conception")
# Check for a field value
if [[ (${renconception} -eq 1) && (${default[${key}]} != "") ]]; then
# Evaluate 'Date' value using the date command
local date=$(date -d "${fieldvalue}" +'%d %b %Y' 2>/dev/null)
# Check for field viability
if [[ ${date} != "" ]]; then
# Check for difference between field value vs. expected field value
if [[ (${formatdate} -eq 1) && (${date} != ${fieldvalue}) ]]; then
# Throw a warning to signal file modification
msg c_warning 0 "'${key^}' field detected, renaming it to 'Date', field is incorrectly formatted, found '${default[${key}]}', changing to '${date}'."
# Override 'Date' value with 'Conception' value
default[date]=${date}
else
# Throw a warning to signal file modification
msg c_warning 0 "'${key^}' field detected, renaming to 'Date', field is correctly formatted, found '${default[${key}]}'."
default[date]=${date}
fi
else
# Unrecognizable date, throw error
msg c_error 0 "'${key^}' field detected, renaming to 'Date', field is invalid, expecting a valid date, found '${default[${key}]}'."
default[date]=${default[${key}]}
fi
# Override field value with default
default[${key}]=""
fi
;;
"version")
# Obtain major version based on log entry count
local versexp="${major}"
# Check for difference between field value vs. expected field value
if [[ (${gitversion} -eq 1) && (${versexp} != ${fieldvalue}) ]]; then
# Throw a warning to signal file modification
msg c_warning 0 "'${key^}' field incorrect, found '${default[${key}]}', changing to '${versexp}'."
# Override field value with expected
default[${key}]="${versexp}${minor}"
else
# No big deal, throw note
msg c_note 0 "'${key^}' field is correct, found '${default[${key}]}'."
fi
;;
"standard")
# Check for a field value
if [[ (${remstandard} -eq 1) && (${default[${key}]} != "") ]]; then
# Throw a warning to signal modification
msg c_warning 0 "'${key^}' field detected, removing '${c_website}'."
# Override field value with default
default[${key}]=""
fi
;;
"website")
# Check for a field value
if [[ (${addwebsite} -eq 1) && (${default[${key}]} == "") ]]; then
# Throw a warning to signal modification
msg c_warning 0 "'${key^}' field missing, inserting '${c_website}'."
# Override field value with default
default[${key}]=${c_website}
fi
;;
"project")
# Check for a field value
if [[ (${addproject} -eq 1) && (${default[${key}]} == "") ]]; then
# Throw a warning to signal modification
msg c_warning 0 "'${key^}' field missing, inserting '${c_project}'."
# Override field value with default
default[${key}]="${projects[${proj}]} (${c_project})"
elif [[ (${addproject} -eq 1) && (${default[${key}]} == "${c_project}") ]]; then
# Throw a warning to signal modification
msg c_warning 0 "'${key^}' field incomplete, adding '${projects[${proj}]}'."
# Override field value with default
default[${key}]="${projects[${proj}]} (${c_project})"
fi
;;
"author"|"history"|"version"|"description")
: # Ignore known!
;;
*)
msg c_error 0 "'${key^}' field is unknown, its value is '${default[${key}]}', ignoring."
;;
esac
done
#################################
# Output the final header block #
#################################
echo -e "\ned ${projdir}/${file} <<END" >> ../${rewrite}
echo "${start},${end}d" >> ../${rewrite}
echo "." >> ../${rewrite}
echo "$((start-1))a" >> ../${rewrite}
local text="" # Str: Text from texts array
local key # Str: Key from keys array
# Put the 'mandatory' fields in the 'correct' display order
[[ ${reorganise} -eq 1 ]] &&
keys=(file author website project date version history description)
# Opening comment
echo "${hdr_open}${post_open}" >> ../${rewrite}
# Iterate though all the 'mandatory' fields
for key in ${keys[@]}; do
local dots=$(printf '.%.0s' {1..28} | head -c $((14-${#key})))
case ${key} in
"description")
echo "${hdr_body}${key^} ${dots}" >> ../${rewrite}
# Split the 'whole string' text block back into separate 'lines'
IFS='|' read -ra texts <<< "${default[${key}]}"
# Get the comment marker of the very first line
local -l lcom=${#com}
# Display separate lines with their comment markers exchanged
for text in "${texts[@]}"; do
local ttmp="${text:lcom}"
if [[ ${#ttmp} -eq 0 ]]; then
echo "${hdr_empty}" >> ../${rewrite}
else
echo "${hdr_empty} ${text:lcom}" >> ../${rewrite}
fi
done
;;
*)
if [[ -n ${default[${key}]} ]]; then
echo "${hdr_body}${key^} ${dots} ${default[${key}]}" >> ../${rewrite}
fi
;;
esac
done
# Closing comment (adjust according to last comment marker of description)
if [[ "${text}" != "${pre_close}${hdr_close}" ]]; then
echo "${pre_close}${hdr_close}" >> ../${rewrite}
fi
echo "." >> ../${rewrite}
echo "wq" >> ../${rewrite}
echo "END" >> ../${rewrite}
else # No header detected, add a new one
if [[ ${addheader} -eq 1 ]]; then # '--add' option, output 'ed' commands to add a new header
# Throw as a warning due to file modification
msg c_warning 0 "No identifiable header comment block found, inserting a new header @ line $((start+1))."
cat << EOF >> ../${rewrite}
ed ${projdir}/${file} <<END
${start}a
${hdr_open}${post_open}
${hdr_body}File .......... ${filename}
${hdr_body}Author ........ ${c_author}
${hdr_body}Website ....... ${c_website}
${hdr_body}Project ....... ${projects[${proj}]} (${c_project})
${hdr_body}Date .......... ${c_date}
${hdr_body}Version ....... ${major}${minor}
${hdr_body}Description ...
${hdr_body} ${c_description}
${pre_close}${hdr_close}
.
wq
END
EOF
else # No '--add' option, output commented out 'ed' commands to add a new header
cat << EOF >> ../${rewrite}
#ed ${projdir}/${file} <<END
#${start}a
#Sage header!
#.
#wq
#END
EOF
fi
fi
}
################################################################################
# Write the 'ed' commands required to strip out the source file headers and
# replace them with new ones (in this case the existing ones).
# Arguments ...... None
# Return ......... None
# Shared (In) .... end, file, lines, projdir, start, template, valid
# Shared (Out) ... None
template_write()
{
# Take appropriate action depending on header presence
if [[ ${valid} -eq 1 ]]; then
# Write commands to replace original header with itself
echo -e "\ned ${projdir}/${file} <<END" >> ../${template}
echo "${start},${end}d" >> ../${template}
echo "." >> ../${template}
echo "$((start-1))a" >> ../${template}
printf '%s\n' "${lines[@]}" >> ../${template}
echo -e "." >> ../${template}
echo "wq" >> ../${template}
echo "END" >> ../${template}
else
# Write commented out insert header stub
cat << EOF >> ../${template}
#ed ${projdir}/${file} <<END
#${start}a
#Sage header!
#.
#wq
#END
EOF
fi
}
################################################################################
# Process single project directory & produce 'ed' scripts.
# Arguments ...... None
# Return ......... None
# Shared (In) .... addheader, addminor, addproject, addwebsite, argv,
# considered*, examined*, exclude, fixfilename, formatdate,
# gitversion, optwhitespace, projdir, remstandard,
# renconception, reorganise, rewrite, template, verbosity
# Shared (Out) ... addheader, addminor, addproject, addwebsite, argv, com*,
# considered*, end*, examined*, file, fixfilename, formatdate,
# gitversion, hdr_body, hdr_close, hdr_empty, hdr_open,
# header*, lines*, projdir, remstandard, renconception,
# reorganise, rewrite, start*, template, type*, valid*
process_project()
{
# Declare local variables
local -a files=() # Arr: List of repository files (array)
local file # Str: File name
local -i filenamedisp=0 # Int: Filename displayed flag (0=no, 1=yes)
# Declare local (shared) variables
local -i type=0 # Int: File type (0=Unknown, 1=Script)
local com="" # Str: Comment style
local -i valid=0 # Int: Found a valid header (0:No, 1:Yes)
local -i start=0 # Int: Start position of header
local -i end=0 # Int: End position of header
local header="" # Str: Captured header block (string)
local lines=() # Arr: Captured header block (array)
# Write template
echo -e "\n#### ${projdir} ######################################################################" >> ../${template}
echo -e "\n#### ${projdir} ######################################################################" >> ../${rewrite}
# Get repository file list
readarray -t files < <(git ls-files)
# Iterate though all the repository files
for file in "${files[@]}"; do
# Set header for changes (filename) to not yet displayed
filenamedisp=0
# Exclude files that are not created or edited source
if [[ ! " ${exclude[*]} " =~ " ${file} " ]]; then
# Remove trailing whitespace (in place)
if [[ ! -L ${file} ]]; then
if (($(option_set ${optwhitespace}))); then
dos2unix ${file}
sed -i 's/[[:blank:]]*$//' ${file}
fi
fi
# Display action for inclusive file
if [[ ${verbosity} -ge ${c_verb_include} ]]; then
msg c_action 0 "Processing"
fi
# Read comment header block into an array
read_header
# Determine file type from filename
[[ ${type} -eq ${c_type_unknown} ]] &&
type=$(getcomtype)
# Check for known file type
if [[ ${type} -ne ${c_type_unknown} ]]; then
# Check the source file exists
if [[ -L ${file} ]]; then
msg c_note 0 "Source file is a link, skipping."
elif [[ -f ${file} ]]; then
# Obtain comment construction parts
local hdr_open=${c_hdr_open[${type}]}
local hdr_empty=${c_hdr_empty[${type}]}
local hdr_body=${c_hdr_body[${type}]}
local hdr_close=${c_hdr_close[${type}]}
template_write
rewrite_write
else
msg c_error 0 "Source file not found, skipping."
fi
else
msg c_error 0 "Source file type is unknown, skipping."
fi
# Increase examined files count
examined=$((examined+1))
else
# Display action for exclusive file
[[ ${verbosity} -ge ${c_verb_exclude} ]] &&
msg c_action 0 "Skipping"
fi
# Increase considered files count
considered=$((considered+1))
done
}
################################################################################
# Process project directories & produce 'ed' scripts.
# Arguments ...... None
# Return ......... None
# Shared (In) .... addheader, addminor, addproject, addwebsite, argv,
# considered*, examined*, exclude, fixfilename, formatdate,
# gitversion, optwhitespace, projdirs, remstandard,
# renconception, reorganise, rewrite, template, verbosity
# Shared (Out) ... addheader, addminor, addproject, addwebsite, argv,
# considered*, examined*, exclude, fixfilename, formatdate,
# gitversion, optwhitespace, projdir, remstandard,
# renconception, reorganise, rewrite, template, verbosity
process_projects()
{
local projdir # Str: Current subdirectory name
# Iterate through subdirectories
for projdir in ${projdirs[@]}
do
# Move into subdirectory
cd ${projdir}
echo -e "\nProcessing ... ${projdir}\n"
# Process subdirectory
process_project
# Move out of subdirectory
cd ..
done
}
################################################################################
# Check if an argument option is set.
# Arguments ...... $1 ... Str: Option
# Return ......... Set (0=unset, 1=set)
# Shared (In) .... argv
# Shared (Out) ... None
option_set()
{
[[ " ${argv[*]} " =~ " ${1} " ]] && echo 1 || echo 0
}
################################################################################
# Main function
# Arguments ...... None
# Return ......... None
# Exit code ...... Status (0=success, 1=failure)
# Shared (In) .... argv
# Shared (Out) ... addheader, addminor, addproject, addwebsite, argv,
# considered*, examined*, exclude, fixfilename, formatdate,
# gitversion, optwhitespace, projdirs, remstandard,
# renconception, reorganise, rewrite, template, verbosity
main()
{
# Declare local constants
local -r optadd="--add" # Str: Add option name
local -r optfilename="--filename" # Str: Filename option name
local -r optwebsite="--website" # Str: Website option name
local -r optproject="--project" # Str: Project option name
local -r optfmtdate="--fmtdate" # Str: Format Date option name
local -r optconception="--conception" # Str: Conception option name
local -r optversion="--version" # Str: Version option name
local -r optminor="--minor" # Str: Minor option name
local -r optstandard="--standard" # Str: Standard option name
local -r optreorg="--reorg" # Str: Reorganise option name
local -r optall="--all" # Str: All option name
local -r optwhitespace="--whitespace" # Str: Whitespace option name
local -r opthelp="--help" # Str: Help option name
local -Ar options=( # ARR: Options & associated help information
[${optadd}]="Add missing header block and populated it with default fields."
[${optfilename}]="Correct 'File' field if incorrect."
[${optwebsite}]="Add 'Website' field if missing."
[${optproject}]="Add 'Project' field if missing."
[${optfmtdate}]="Reformat 'Date' field to DD Mmm YYYY."
[${optconception}]="Rename 'Conception' field to 'Date' & reformat it to DD Mmm YYYY."
[${optversion}]="Update the 'Version' field to pair with the GIT commit count."
[${optminor}]="Add minor part (x.0) to the version string."
[${optstandard}]="Remove 'Standard' field if present."
[${optreorg}]="Reorganise header into desired field order."
[${optall}]="Action all above options, except ${optminor}."
[${optwhitespace}]="Remove all trailing whitespace in file (done directly not via the 'ed' scripts)."
[${opthelp}]="Display this help and exit."
)
local -ar optorder=( # Arr: Help options display order
${optadd}
${optfilename}
${optwebsite}
${optproject}
${optfmtdate}
${optconception}
${optversion}
${optminor}
${optstandard}
${optreorg}
${optall}
${optwhitespace}
${opthelp}
)
# Declare local variables
local arg # Str: Current argument from argv array
local project="" # Str: Project directory [arg] (mandatory)
local exfile="" # Str: Exclude file [arg] (mandatory)
local -i verbosity=10 # Int: Verbosity level [arg] (optional)
local -i addheader=0
local -i fixfilename=0
local -i addwebsite=0
local -i addproject=0
local -i formatdate=0
local -i renconception=0
local -i gitversion=0
local -i addminor=0
local -i remstandard=0
local -i reorganise=0
local option # Str: Current option from optorder array
# Display help information
if (($(option_set ${opthelp}))); then
echo "Usage: $(basename $0) PROJECT-DIRECTORY... EXCLUDE-FILE... [VERBOSITY]... [OPTION]..."
echo "Generate 'ed' scripts for adding & correcting source file headers in the PROJECT-DIRECTORY."
echo
echo "Mandatory arguments to long options are mandatory for short options too."
for option in ${optorder[@]}
do
echo " ${option} $(printf ' %.0s' {1..12} | head -c $((12-${#option}))) ${options[${option}]}"
done
echo
echo "The VERBOSITY argument:"
echo " 0 Summary"
echo " 1 Summary + Errors"
echo " 2 Summary + Errors + Warnings"
echo " 3 Summary + Errors + Warnings + Notes"
echo " 4 Summary + Errors + Warnings + Notes + Include"
echo " 5 Summary + Errors + Warnings + Notes + Include + Exclude"
exit 0
fi
# Get & check the arguments
for arg in ${argv[@]}; do
if [[ ${arg:0:2} == "--" ]]; then # Option
[[ ! -v options[${arg}] ]] && echo "Option (${arg}) is not recognised!" && exit 1
case ${arg} in
"--add") addheader=1 ;;
"--filename") fixfilename=1 ;;
"--website") addwebsite=1 ;;
"--project") addproject=1 ;;
"--fmtdate") formatdate=1 ;;
"--conception") renconception=1 ;;
"--version") gitversion=1 ;;
"--minor") addminor=1 ;;
"--standard") remstandard=1 ;;
"--reorg") reorganise=1 ;;
"--all")
addheader=1
fixfilename=1
addwebsite=1
addproject=1
formatdate=1
renconception=1
gitversion=1
#addminor=1
remstandard=1
reorganise=1
;;
esac
elif [[ -z ${project} ]]; then # Project directory
project=${arg}
[[ ! -d ${project} ]] && echo "Project directory (${arg}) does not exist!" && exit 1
elif [[ -z ${exfile} ]]; then # Exclude file
exfile=${arg}
[[ ! -f ${exfile} ]] && echo "Exclude file (${arg}) does not exist!" && exit 1
elif [[ ${verbosity} -eq 10 ]]; then # Verbosity level
verbosity=${arg}
else
echo "Unexpected argument (${arg}) found!" && exit 1
fi
done
# Further check the arguments
[[ -z ${project} ]] && echo "No project directory specified!" && exit 1
[[ -z ${exfile} ]] && echo "No exclude file specified!" && exit 1
local template="do_proof"
local rewrite="do_fixes"
# Get all subdirectories into an ordered array
local -a projdirs=() # List of project subdirectories (array, alphanumeric order)
readarray -t projdirs < <(find ${project} -mindepth 1 -maxdepth 1 -type d | sort | cut -d'/' -f2-)
[[ ${#projdirs[@]} -eq 0 ]] && echo "Project Directory specified (${argv[0]}) does not contain any subdirectories!" && exit 1
# Get excluded file list
local -a exclude=() # List of excluded files (array)
readarray -t exclude < ${argv[1]}
# Variables
local -i considered=0 # Number of files considered
local -i examined=0 # Number of files examined
local -i errors=0 # Number of errors encountered
local -i warnings=0 # Number of warnings encountered
# Move into project directory
cd ${project}
# Kick off template & rewrite scripts
echo "#!/bin/bash" > ${template}
echo "#!/bin/bash" > ${rewrite}
chmod +x ${template} ${rewrite}
# Perform the operations
process_projects
# Move out of project directory
cd ..
[[ ${verbosity} -ge ${c_verb_summary} ]] &&
echo -e "\nConsidered ${considered} files, skipped $((considered-examined)), examined ${examined}, detected ${errors} errors and ${warnings} warnings."
}
################################################################################
# Opening gambit.
# Arguments ...... None
# Return ......... None
# Exit code ...... Status (0=success, 1=failure)
# Shared (In) .... $#, $@
# Shared (Out) ... argc, argv
declare -ri argc=${#} # Int: Get argument count
declare -ra argv=(${@}) # Arr: Get argument values (space-separated) into array
main
exit 0
- Examine what options are available with the script.
steve@Desktop:/tmp/scratch$ swuk_repos_gen_fix_headers --help
Usage: swuk_repos_gen_fix_headers PROJECT-DIRECTORY... EXCLUDE-FILE... [VERBOSITY]... [OPTION]...
Generate 'ed' scripts for adding & correcting source file headers in the PROJECT-DIRECTORY.
--add Add missing header block and populated it with default fields.
--filename Correct 'File' field if incorrect.
--website Add 'Website' field if missing.
--project Add 'Project' field if missing.
--fmtdate Reformat 'Date' field to DD Mmm YYYY.
--conception Rename 'Conception' field to 'Date' & reformat it to DD Mmm YYYY.
--version Update the 'Version' field to pair with the GIT commit count.
--minor Add minor part (x.0) to the version string.
--standard Remove 'Standard' field if present.
--reorg Reorganise header into desired field order.
--all Action all above options, except --minor.
--whitespace Remove all trailing whitespace in file (done directly not via the 'ed' scripts)
--help Display this help and exit.
The VERBOSITY argument:
0 Summary
1 Summary + Errors
2 Summary + Errors + Warnings
3 Summary + Errors + Warnings + Notes
4 Summary + Errors + Warnings + Notes + Include
5 Summary + Errors + Warnings + Notes + Include + Exclude
Create a split project in
/tmp that includes the
.git directory in each of the commit subdirectories.
steve@Desktop:/tmp/scratch$ swuk_repos_split git@192.168.2.20:tmp_repo local_split_git --keepgit
Replace all the duplicate files in the split project subdirectories with symbolic links.
steve@Desktop:/tmp/scratch$ swuk_repos_history local_split_git --link
Execute the
generate fix headers script using the pre-existing
ignore file & set the
verbosity level to 1 (errors).
steve@Desktop:/tmp/scratch$ swuk_repos_gen_fix_headers local_split_git ${swuk_user}/general/v14_fileset_ignore.txt 1
The result (parts of interest from the last subdirectory scan)...
zedboard_leds_switches/.gitignore
Error ........ : Error Source file type is unknown, skipping.
zedboard_leds_switches/fw/project.txt
Error ........ : Source file type is unknown, skipping.
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/project.txt
Error ........ : Source file type is unknown, skipping.
zedboard_linux/os/src/other/zedboard_leds_switches.txt
Error ........ : Source file type is unknown, skipping.
There are a couple of extra files that a are best ignored at this stage. Create a specific
header ignore file based on the previous
ignore file to include the .gitignore, project identification and Zedboard configuration files.
steve@Desktop:/tmp/scratch$ cp ${swuk_user}/general/v14_fileset_ignore.txt ${swuk_user}/general/v14_fileset_ignore_hdr.txt
Edit the file :-
steve@Desktop:/tmp/scratch$ subl ${swuk_user}/general/v14_fileset_ignore_hdr.txt
common/fw/src/constraint/zedboard_master_XDC_RevC_D_v3.xdc
zedboard_hello_world/fw/src/diagram/system/system.bd
zedboard_hello_world/fw/system_wrapper.xsa
zedboard_leds_buttons/fw/src/diagram/system/system.bd
zedboard_leds_buttons/fw/system_wrapper.xsa
zedboard_leds_switches/fw/project.txt
zedboard_leds_switches/fw/src/diagram/system/system.bd
zedboard_leds_switches/fw/src/ip_repo/register_bank_1.0/bd/bd.tcl
zedboard_leds_switches/fw/src/ip_repo/register_bank_1.0/component.xml
zedboard_leds_switches/fw/src/ip_repo/register_bank_1.0/drivers/register_bank_v1_0/data/register_bank.mdd
zedboard_leds_switches/fw/src/ip_repo/register_bank_1.0/drivers/register_bank_v1_0/data/register_bank.tcl
zedboard_leds_switches/fw/src/ip_repo/register_bank_1.0/drivers/register_bank_v1_0/src/Makefile
zedboard_leds_switches/fw/src/ip_repo/register_bank_1.0/drivers/register_bank_v1_0/src/register_bank.c
zedboard_leds_switches/fw/src/ip_repo/register_bank_1.0/drivers/register_bank_v1_0/src/register_bank.h
zedboard_leds_switches/fw/src/ip_repo/register_bank_1.0/drivers/register_bank_v1_0/src/register_bank_selftest.c
zedboard_leds_switches/fw/src/ip_repo/register_bank_1.0/example_designs/bfm_design/design.tcl
zedboard_leds_switches/fw/src/ip_repo/register_bank_1.0/example_designs/bfm_design/register_bank_v1_0_tb.sv
zedboard_leds_switches/fw/src/ip_repo/register_bank_1.0/example_designs/debug_hw_design/design.tcl
zedboard_leds_switches/fw/src/ip_repo/register_bank_1.0/example_designs/debug_hw_design/register_bank_v1_0_hw_test.tcl
zedboard_leds_switches/fw/src/ip_repo/register_bank_1.0/hdl/register_bank_v1_0_S00_AXI.v
zedboard_leds_switches/fw/src/ip_repo/register_bank_1.0/hdl/register_bank_v1_0.v
zedboard_leds_switches/fw/src/ip_repo/register_bank_1.0/xgui/register_bank_v1_0.tcl
zedboard_leds_switches/fw/system_wrapper.xsa
zedboard_leds_switches/.gitignore
zedboard_linux/os/petalinux/config.project
zedboard_linux/os/petalinux/.gitignore
zedboard_linux/os/petalinux/.petalinux/metadata
zedboard_linux/os/petalinux/project-spec/attributes
zedboard_linux/os/petalinux/project-spec/configs/busybox/inetd.conf
zedboard_linux/os/petalinux/project-spec/configs/config
zedboard_linux/os/petalinux/project-spec/configs/init-ifupdown/interfaces
zedboard_linux/os/petalinux/project-spec/configs/rootfs_config
zedboard_linux/os/petalinux/project-spec/hw-description/drivers/register_bank_v1_0/data/register_bank.mdd
zedboard_linux/os/petalinux/project-spec/hw-description/drivers/register_bank_v1_0/data/register_bank.tcl
zedboard_linux/os/petalinux/project-spec/hw-description/drivers/register_bank_v1_0/src/Makefile
zedboard_linux/os/petalinux/project-spec/hw-description/drivers/register_bank_v1_0/src/register_bank.c
zedboard_linux/os/petalinux/project-spec/hw-description/drivers/register_bank_v1_0/src/register_bank.h
zedboard_linux/os/petalinux/project-spec/hw-description/drivers/register_bank_v1_0/src/register_bank_selftest.c
zedboard_linux/os/petalinux/project-spec/hw-description/metadata
zedboard_linux/os/petalinux/project-spec/hw-description/ps7_init.c
zedboard_linux/os/petalinux/project-spec/hw-description/ps7_init_gpl.c
zedboard_linux/os/petalinux/project-spec/hw-description/ps7_init_gpl.h
zedboard_linux/os/petalinux/project-spec/hw-description/ps7_init.h
zedboard_linux/os/petalinux/project-spec/hw-description/ps7_init.html
zedboard_linux/os/petalinux/project-spec/hw-description/ps7_init.tcl
zedboard_linux/os/petalinux/project-spec/hw-description/system_wrapper.bit
zedboard_linux/os/petalinux/project-spec/hw-description/system.xsa
zedboard_linux/os/petalinux/project-spec/meta-user/conf/layer.conf
zedboard_linux/os/petalinux/project-spec/meta-user/conf/user-rootfsconfig
zedboard_linux/os/petalinux/project-spec/meta-user/COPYING.MIT
zedboard_linux/os/petalinux/project-spec/meta-user/README
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/axi-gpio-zed-test/axi-gpio-zed-test.bb
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/axi-gpio-zed-test/files/Makefile
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/axi-gpio-zed-test/.gdbinit
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/axi-gpio-zed-test/README
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/gpio-demo/files/gpio-demo.c
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/gpio-demo/files/Makefile
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/gpio-demo/gpio-demo.bb
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/led-runner/.gdbinit
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/led-runner/README
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/.gdbinit
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/README
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpoke/files/Makefile
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpoke/files/peek.c
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpoke/files/poke.c
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpoke/peekpoke.bb
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/amber.gif
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/phpliteadmin.php
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/green.gif
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/project.txt
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/red.gif
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/share/amber.gif
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/share/green.gif
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/share/red.gif
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/zedboard/btn_none.png
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/zedboard/btn_off.png
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/zedboard/btn_on.png
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/zedboard/led_off.png
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/zedboard/led_on.png
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/zedboard.png
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/zedboard/sw_none.png
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/zedboard/sw_off.png
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/zedboard/sw_on.png
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/zedboard/zedboard.png
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/.gdbinit
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/README
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-bsp/device-tree/device-tree.bbappend
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-bsp/device-tree/files/pl-custom.dtsi
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-bsp/uboot-device-tree/files/system-user.dtsi
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-bsp/uboot-device-tree/uboot-device-tree.bbappend
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-bsp/u-boot/files/bsp.cfg
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-bsp/u-boot/files/platform-top.h
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-bsp/u-boot/u-boot-xlnx_%.bbappend
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-kernel/linux/linux-xlnx_%.bbappend
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-kernel/linux/linux-xlnx/bsp.cfg
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-kernel/linux/linux-xlnx/user_2023-08-08-08-28-00.cfg
zedboard_linux/os/src/other/axi_gpio_zed.txt
zedboard_linux/os/src/other/zedboard_leds_switches.txt
Direct download available here :-
steve@Desktop:/tmp/scratch$ wget https://spacewire.co.uk/tutorial/shared/documents/swuk_tutorial/general/v14_fileset_ignore_hdr.txt -O ${swuk_user}/general/v14_fileset_ignore_hdr.txt
Execute the
generate fix headers script again using the new
header ignore file.
steve@Desktop:/tmp/scratch$ swuk_repos_gen_fix_headers local_split_git ${swuk_user}/general/v14_fileset_ignore_hdr.txt 1
The result, bad date spelling. Example below :-
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/files/peek.c
Error ........ : 'Date' field is invalid, expecting a valid date, found '26 Novemebr 2021'.
zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/files/poke.c
Error ........ : 'Date' field is invalid, expecting a valid date, found '26 Novemebr 2021'.
The two generated scripts inside the project directory (
do_proof &
do_fixes) can be used to remove all the source file headers in all the project subdirectories and replace them with new ones.
- do_proof - replaces the original headers with themselves (proof run script).
- do_fixes - replaces the original headers with new ones based on the switches provided to generate fix headers.
Execute the
do_proof script to confirm it does what it should. Strips off the original header and replaces it (in this case) with the original header.
steve@Desktop:/tmp/scratch$ cp -r local_split_git local_split_git_copy
steve@Desktop:/tmp/scratch$ cd local_split_git
steve@Desktop:/tmp/scratch/local_split_git$ ./do_proof
steve@Desktop:/tmp/scratch/local_split_git$ cd ..
steve@Desktop:/tmp/scratch$ diff -r local_split_git local_split_git_copy
Looks good! No differences detected!
With confidence that
do_proof does not break anything it makes for a nice template to compare alongside
do_fixes.
Execute
Beyond Compare & keep it open going forward to see the differences. Select the
Diffs option on the ribbon of
Behond Compare to see just the differences.
steve@Desktop:/tmp/scratch$ bcompare local_split_git/{do_fixes,do_proof} &
Looks good! Some trailing whitespace has shown up (unexpected) and four of the PHP files have had their header style made consistent (expected).
There
should not be any trailing whitespace at all, an editor malfunction, lets see how bad it is.
steve@Desktop:/tmp/scratch$ swuk_repos_gen_fix_headers local_split_git ${swuk_user}/general/v14_fileset_ignore_hdr.txt 0 --whitespace
steve@Desktop:/tmp/scratch$ cp local_split_git/{do_proof,do_fixes} local_split_git_copy
steve@Desktop:/tmp/scratch$ diff -r local_split_git local_split_git_copy | grep "^>" | wc -l
13
Awful result! This should be 0. Sublime isn't clearing the trailing whitespace for some reason even though it is set to do so! Looking at the
Behond Compare window should now show only the PHP style changes.
With the difference tool kept open the various switches of the
generate fix headers script can be applied.
Run the
fix_headers script with the
--add switch thrown to
add any missing headers.
steve@Desktop:/tmp/scratch$ swuk_repos_gen_fix_headers local_split_git ${swuk_user}/general/v14_fileset_ignore_hdr.txt 0 --add --minor
Considered 2104 files, skipped 1379, examined 725, detected 2 errors and 54 warnings.
Lots of missing headers and lots of red in
Behond Compare as expected.
Run the
fix_headers script with the
--filename switch thrown to fix any
File field errors.
steve@Desktop:/tmp/scratch$ swuk_repos_gen_fix_headers local_split_git ${swuk_user}/general/v14_fileset_ignore_hdr.txt 0 --filename
Considered 2104 files, skipped 1379, examined 725, detected 2 errors and 1 warnings.
1
File field to be spelt correctly.
Run the
fix_headers script with the
--fmtdate switch thrown to make the
Date field consistent.
steve@Desktop:/tmp/scratch$ swuk_repos_gen_fix_headers local_split_git ${swuk_user}/general/v14_fileset_ignore_hdr.txt 0 --fmtdate
Considered 2104 files, skipped 1379, examined 725, detected 2 errors and 26 warnings.
26
Date fields to be reformatted.
Run the
fix_headers script with the
--version switch thrown to change the
Version field to that of the GIT change count.
steve@Desktop:/tmp/scratch$ swuk_repos_gen_fix_headers local_split_git ${swuk_user}/general/v14_fileset_ignore_hdr.txt 0 --version --minor
Considered 2104 files, skipped 1379, examined 725, detected 2 errors and 48 warnings.
15
Version fields that need to tally with the change count in GIT.
Run the
fix_headers script with the
--standard switch thrown to remove the
Standard field.
steve@Desktop:/tmp/scratch$ swuk_repos_gen_fix_headers local_split_git ${swuk_user}/general/v14_fileset_ignore_hdr.txt 0 --standard
Considered 2104 files, skipped 1379, examined 725, detected 2 errors and 25 warnings.
25
Standard fields to be removed.
Run the script with the
--website &
--reorg switches thrown to add the
Website field.
steve@Desktop:/tmp/scratch$ swuk_repos_gen_fix_headers local_split_git ${swuk_user}/general/v14_fileset_ignore_hdr.txt 0 --website --reorg
Considered 2104 files, skipped 1379, examined 725, detected 2 errors and 31 warnings.
31
Website fields to be added.
Run the script with the
--project &
--reorg switches thrown to add the
Project field.
steve@Desktop:/tmp/scratch$ swuk_repos_gen_fix_headers local_split_git ${swuk_user}/general/v14_fileset_ignore_hdr.txt 0 --project --reorg
Considered 2104 files, skipped 1379, examined 725, detected 2 errors and 48 warnings.
31
Project fields to be added.
Run the script with the
--conception &
--reorg switches thrown to change the field name
Conception to be
Date and reformat the date.
steve@Desktop:/tmp/scratch$ swuk_repos_gen_fix_headers local_split_git ${swuk_user}/general/v14_fileset_ignore_hdr.txt 0 --conception --reorg
Considered 2104 files, skipped 1379, examined 725, detected 2 errors and 17 warnings.
17
Conception to
Date field renames required.
Run the
fix_headers script with the
--all switch thrown to apply ALL changes.
steve@Desktop:/tmp/scratch$ swuk_repos_gen_fix_headers local_split_git ${swuk_user}/general/v14_fileset_ignore_hdr.txt 0 --all --minor
Considered 2104 files, skipped 1379, examined 725, detected 2 errors and 250 warnings.
Take a look at how much missing information there is.
steve@Desktop:/tmp/scratch$ grep 'Sage' local_split_git/do_fixes | wc -l
108
54 new headers need to have
Date &
Description fields added. My bad!
This is for me to do: Take the generated do_fixes script, hand edit it to achieve the desired results and wrap it with the standard bash command pleasantries.
- Download the script & make it executable.
steve@Desktop:/tmp/scratch$ wget https://spacewire.co.uk/tutorial/shared/repos/0027/common/other/src/script/swuk_repos_fix_headers
steve@Desktop:/tmp/scratch$ chmod +x swuk_repos_fix_headers
#!/bin/bash
#
# File .......... swuk_repos_fix_headers
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Common (SpaceWire UK Tutorial)
# Date .......... 25 Mar 2025
# Version ....... 1.0
# Description ...
# Edit the headers in a split repository using the 'ed' command. Core function
# is basically the output from swuk_repos_gen_fix_headers, edited by hand to add
# the missing information.
#
# Strict
set -euo pipefail
################################################################################
# Edit the headers.
# Arguments ...... None
# Return ......... None
# Shared (In) .... None
# Shared (Out) ... None
edit_headers()
{
#### 0001 - Part 1 #############################################################
ed 0001/common/fw/src/script/create_vivado_project.sh <<END
3,15d
.
2a
#
# File .......... create_vivado_project.sh
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Common (SpaceWire UK Tutorial)
# Date .......... 03 May 2021
# Version ....... 1.0
# Description ...
# Very simple script to launch Vivado and run the TCL script. Should be run
# in the project host directory that contains the fw & sw subdirectories, for
# example :-
#
# user@host:~/projects/project$ create_vivado_project.sh
# user@host:~/projects/project$ create_vivado_project.sh build
#
.
wq
END
ed 0001/common/fw/src/script/create_vivado_project.tcl <<END
1,9d
.
0a
#
# File .......... create_vivado_project.tcl
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Common (SpaceWire UK Tutorial)
# Date .......... 23 Dec 2021
# Version ....... 1.0
# Description ...
# Simple Tcl script to create a new Vivado project, import external
# sources and (optionally) generate the bitstream & export the hardware.
#
.
wq
END
ed 0001/common/other/src/script/create_project_structure.sh <<END
4,13d
.
3a
#
# File .......... create_project_structure.sh
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Common (SpaceWire UK Tutorial)
# Date .......... 29 Dec 2021
# Version ....... 1.0
# Description ...
# Simple script to create a possible project directory structure for combined
# firmware, hardware, operating system & software development. Very much work
# in progress and by all means not a golden solution to anything.
#
.
wq
END
ed 0001/common/other/src/script/xilinx.sh <<END
3,12d
.
2a
#
# File .......... xilinx.sh
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Common (SpaceWire UK Tutorial)
# Date .......... 08 Feb 2021
# Version ....... 1.0
# Description ...
# Determine and list which Xilinx tools are available and let the user select
# the require ones to use. Does not reverse any previously selected tools upon
# selecting news ones so to is cleaner to use in a new Terminal session.
#
.
wq
END
ed 0001/common/other/src/script/xilinx_2021_2.sh <<END
2a
#
# File .......... xilinx_2021_2.sh
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Common (SpaceWire UK Tutorial)
# Date .......... 08 Feb 2021
# Version ....... 1.0
# Description ...
# Setup for the 2021.2 Xilinx tools.
#
.
wq
END
ed 0001/common/sw/src/script/create_vitis_project.sh <<END
3,15d
.
2a
#
# File .......... create_vitis_project.sh
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Common (SpaceWire UK Tutorial)
# Date .......... 03 May 2021
# Version ....... 1.0
# Description ...
# Very simple script to launch the Xilinx software command-line tool,
# run the TCL script and launch Vitis. Should be run in the project host
# directory that contains the fw & sw subdirectories, for example :-
#
# user@host:~/projects/project$ create_vitis_project.sh
# user@host:~/projects/project$ create_vitis_project.sh build
#
.
wq
END
ed 0001/common/sw/src/script/create_vitis_project.tcl <<END
1,9d
.
0a
#
# File .......... create_vitis_project.tcl
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Common (SpaceWire UK Tutorial)
# Date .......... 21 Dec 2021
# Version ....... 1.0
# Description ...
# Simple Tcl script to create a new Vitis application, import external
# sources and (optionally) build the application.
#
.
wq
END
#### 0002 - Part 2 #############################################################
ed 0002/zedboard_hello_world/sw/src/c/hello_world.c <<END
1,8d
.
0a
//
// File .......... hello_world.c
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Hello World (SpaceWire UK Tutorial)
// Date .......... 27 Dec 2021
// Version ....... 1.0
// Description ...
// The classic hello world C application.
//
.
wq
END
#### 0003 - Part 3 #############################################################
ed 0003/common/fw/src/script/zedboard_presets.tcl <<END
0a
#
# File .......... zedboard_presets.tcl
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Common (SpaceWire UK Tutorial)
# Date .......... 22 Dec 2021
# Version ....... 1.0
# Description ...
# ZYNQ7 Processing System presets, as set by the Zedboard BSP.
#
.
wq
END
ed 0003/zedboard_leds_switches/fw/src/constraint/zedboard.xdc <<END
0a
#
# File .......... zedboard.xdc
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard LEDs & Switches (SpaceWire UK Tutorial)
# Date .......... 22 Dec 2021
# Version ....... 1.0
# Description ...
# Pin & timing constraints for the Zedboard LEDs & Switches design.
#
.
wq
END
ed 0003/zedboard_leds_switches/fw/src/testbench/testbench.sv <<END
1,10d
.
0a
//
// File .......... testbench.sv
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard LEDs & Switches (SpaceWire UK Tutorial)
// Date .......... 22 Dec 2021
// Version ....... 1.0
// Description ...
// Very simple testbench to check correct connectivity of the block diagram.
// Uses the Zynq Verification IP suite to read/write the GPIO LED register and
// read the GPIO switch register.
//
.
wq
END
ed 0003/zedboard_leds_switches/sw/src/c/zedboard_leds_switches.c <<END
1,8d
.
0a
//
// File .......... zedboard_leds_switches.c
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard LEDs & Switches (SpaceWire UK Tutorial)
// Date .......... 15 Jan 2022
// Version ....... 1.0
// Description ...
// Very simple LEDs & Switches example design.
//
.
wq
END
#### 0004 - Part 4 #############################################################
ed 0004/zedboard_leds_buttons/fw/src/constraint/zedboard.xdc <<END
0a
#
# File .......... zedboard.xdc
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard LEDs & Buttons (SpaceWire UK Tutorial)
# Date .......... 22 Dec 2021
# Version ....... 1.0
# Description ...
# Pin & timing constraints for the Zedboard LEDs & Buttons design.
#
.
wq
END
ed 0004/zedboard_leds_buttons/fw/src/testbench/testbench.sv <<END
1,10d
.
0a
//
// File .......... testbench.sv
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard LEDs & Buttons (SpaceWire UK Tutorial)
// Date .......... 22 Dec 2021
// Version ....... 1.0
// Description ...
// Very simple testbench to check correct connectivity of the block diagram.
// Uses the Zynq Verification IP suite to read/write the GPIO LED register and
// read the GPIO switch register.
//
.
wq
END
ed 0004/zedboard_leds_buttons/sw/src/c/zedboard_leds_buttons.c <<END
1,8d
.
0a
//
// File .......... zedboard_leds_buttons.c
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard LEDs & Buttons (SpaceWire UK Tutorial)
// Date .......... 15 Jan 2022
// Version ....... 1.0
// Description ...
// Very simple LEDs & Push Buttons interrupt example design.
//
.
wq
END
#### 0005 - Part 5 #############################################################
ed 0005/zedboard_linux/os/petalinux/project-spec/meta-user/conf/petalinuxbsp.conf <<END
0a
#
# File .......... petalinuxbsp.conf
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 17 Jan 2022
# Version ....... 1.0
# Description ...
# Updated to install the following :-
# -- ntp ....... Network Time Protocol
# -- ntpdate ... Set the date and time via NTP
# -- ntpq ...... Standard NTP query program
# -- sntp ...... Simple Network Time Protocol
#
.
wq
END
#ed 0005/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi <<END
#0a
#/*
# * File .......... system-user.dtsi
# * Author ........ Steve Haywood
# * Website ....... http://www.spacewire.co.uk
# * Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# * Date .......... Sage date!
# * Version ....... 1.0
# * Description ...
# * Sage words!
# */
#
#.
#wq
#END
#### 0006 - Part 6 #############################################################
#### 0007 - Part 7 #############################################################
ed 0007/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/led-runner/files/led-runner <<END
2a
#
# File .......... led-runner
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 18 Jan 2022
# Version ....... 1.0
# Description ...
# Expanding & contracting LED sequence using the GPIO located at 0x4120_0000.
#
.
wq
END
ed 0007/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/led-runner/led-runner.bb <<END
1,3d
.
0a
#
# File .......... led-runner.bb
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 18 Jan 2022
# Version ....... 1.0
# Description ...
# Recipe for an autostart application.
#
.
wq
END
#### 0008 - Part 8a ############################################################
ed 0008/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/index.html <<END
0a
<!--
// File .......... index.html
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 21 Jan 2022
// Version ....... 1.0
// Description ...
// Simple hello world in HTML that displays the Zedboard image.
-->
.
wq
END
ed 0008/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/website.bb <<END
1,4d
.
0a
#
# File .......... website.bb
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 21 Jan 2022
# Version ....... 1.0
# Description ...
# Application recipe for a basic website that consists of a webpage (html) & an
# image of the Zedboard (png).
#
.
wq
END
#### 0009 - Part 8b ############################################################
ed 0009/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.cgi <<END
2a
#
# File .......... index.cgi
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 21 Jan 2022
# Version ....... 1.0
# Description ...
# Dynamic (server side) webpage to display system information from PetaLinux
# running on the Zedboard.
#
.
wq
END
ed 0009/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/website.bb <<END
1,4d
.
0a
#
# File .......... website.bb
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 21 Jan 2022
# Version ....... 2.0
# Description ...
# Application recipe for a dynamic (server side) webpage that consists of a
# webpage (cgi) & an image of the Zedboard (png).
#
.
wq
END
#### 0010 - Part 8c ############################################################
ed 0010/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.cgi <<END
2a
#
# File .......... index.cgi
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 21 Jan 2022
# Version ....... 2.0
# Description ...
# Dynamic (server & client side) webpage to display system information from
# PetaLinux running on the Zedboard. Updated to add a widget that displays the
# uptime of PetaLinux.
#
.
wq
END
ed 0010/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/uptime.cgi <<END
2a
#
# File .......... uptime.cgi
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 21 Jan 2022
# Version ....... 1.0
# Description ...
# Simple CGI to provide the system uptime.
#
.
wq
END
ed 0010/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/uptime.js <<END
0a
//
// File .......... uptime.js
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 21 Jan 2022
// Version ....... 1.0
// Description ...
// Uptime support functions for the dynamic (client side) webpage.
//
.
wq
END
ed 0010/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/website.bb <<END
1,4d
.
0a
#
# File .......... website.bb
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 21 Jan 2022
# Version ....... 3.0
# Description ...
# Application recipe for a dynamic (server & client side) webpage that consists
# of a webpage (cgi), uptime script (cgi), support functions (js) & an image of
# the Zedboard (png).
#
.
wq
END
#### 0011 - Part 10 ############################################################
ed 0011/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/files/Makefile <<END
0a
#
# File .......... Makefile
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 05 Mar 2022
# Version ....... 1.0
# Description ...
# Makefile for the peek & poke CGI binaries.
#
.
wq
END
ed 0011/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/files/peek.c <<END
1,9d
.
0a
//
// File .......... peek.c
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 26 Nov 2021
// Version ....... 1.0
// Description ...
// Very simple CGI peek application for single 32-bit reads. Provides
// status & error reporting back to the client side application.
//
.
wq
END
ed 0011/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/files/poke.c <<END
1,9d
.
0a
//
// File .......... poke.c
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 26 Nov 2021
// Version ....... 1.0
// Description ...
// Very simple CGI poke application for single 32-bit writes. Provides
// status & error reporting back to the client side application.
//
.
wq
END
ed 0011/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/peekpokecgi.bb <<END
1,5d
.
0a
#
# File .......... peekpokecgi.bb
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 05 Mar 2022
# Version ....... 1.0
# Description ...
# Application recipe for the peek & poke CGI binaries.
#
.
wq
END
#### 0012 - Part 11 ############################################################
ed 0012/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.cgi <<END
2a
#
# File .......... index.cgi
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 06 Mar 2022
# Version ....... 3.0
# Description ...
# Dynamic (server & client side) webpage to display system information from
# PetaLinux running on the Zedboard. Already includes a widget that displays the
# uptime of PetaLinux. Updated to add extra widgets to read & write register
# functionality.
#
.
wq
END
ed 0012/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/uptime.js <<END
0a
//
// File .......... uptime.js
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 06 Mar 2022
// Version ....... 2.0
// Description ...
// Uptime support functions for the dynamic (client side) webpage. Updated to
// add read and write register requests that call the peek & poke CGI scripts
// and update the client side webpage accordingly.
//
.
wq
END
#### 0013 - Part 12 ############################################################
ed 0013/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.cgi <<END
2a
#
# File .......... index.cgi
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 07 Mar 2022
# Version ....... 4.0
# Description ...
# Dynamic (server & client side) webpage to display system information from
# PetaLinux running on the Zedboard. Already includes a widget that displays the
# uptime of PetaLinux and widgets to read & write register functionality.
# Updated to use a style sheet for a more improved look.
#
.
wq
END
ed 0013/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/styles.css <<END
0a
/*
* File .......... styles.css
* Author ........ Steve Haywood
* Website ....... http://www.spacewire.co.uk
* Project ....... Zedboard Linux (SpaceWire UK Tutorial)
* Date .......... 07 Mar 2022
* Version ....... 1.0
* Description ...
* Introduction of a style sheet to separate out the embedded styles from the
* webpage. Much more flexible and easier to maintain.
*/
.
wq
END
ed 0013/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/website.bb <<END
1,4d
.
0a
#
# File .......... website.bb
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 07 Mar 2022
# Version ....... 4.0
# Description ...
# Application recipe for a dynamic (server & client side) webpage that consists
# of a webpage (cgi), uptime script (cgi), support functions (js), styles (css) &
# an image of the Zedboard (png).
#
.
wq
END
#### 0014 - Part 13a ###########################################################
ed 0014/zedboard_leds_switches/fw/src/testbench/testbench.sv <<END
1,10d
.
0a
//
// File .......... testbench.sv
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard LEDs & Switches (SpaceWire UK Tutorial)
// Date .......... 17 Jun 2022
// Version ....... 2.0
// Description ...
// Very simple testbench to check correct connectivity of the block diagram.
// Uses the Zynq Verification IP suite to read/write the GPIO LED register and
// read the GPIO switch register.
//
.
wq
END
#### 0015 - Part 13b ###########################################################
ed 0015/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.cgi <<END
2a
#
# File .......... index.cgi
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 17 Jun 2022
# Version ....... 5.0
# Description ...
# Dynamic (server & client side) webpage to display system information from
# PetaLinux running on the Zedboard. Already includes a widget that displays the
# uptime of PetaLinux and widgets to read & write register functionality. Also
# uses a style sheet for a more improved look. Enhanced the peek & poke
# capabilities such that multiple registers can be accessed. Added in global
# controls for the multiple registers and also file access so the register
# configuration can be saved and re-loaded.
#
.
wq
END
ed 0015/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/uptime.js <<END
0a
//
// File .......... uptime.js
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 17 Jun 2022
// Version ....... 3.0
// Description ...
// Uptime support functions for the dynamic (client side) webpage. Updated to
// add read and write register requests that call the peek & poke CGI scripts
// and update the client side webpage accordingly. Enhanced functions to
// improve webpage look & feel, including the use of new status animation images
// for success/fail of register read/write calls and also a register
// configuration save & re-load facility.
//
.
wq
END
ed 0015/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/website.bb <<END
1,4d
.
0a
#
# File .......... website.bb
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 17 Jun 2022
# Version ....... 5.0
# Description ...
# Application recipe for a dynamic (server & client side) webpage that consists
# of a webpage (cgi), uptime script (cgi), support functions (js), styles (css),
# an image of the Zedboard (png) & 3 status animation images (gif).
#
.
wq
END
#### 0016 - Part 14a ###########################################################
ed 0016/zedboard_leds_switches/fw/src/design/axi_identification.v <<END
1,20d
.
0a
//
// File .......... axi_identification.v
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard LEDs & Switches (SpaceWire UK Tutorial)
// Date .......... 05 Dec 2021
// Version ....... 1.0
// Description ...
// AXI4-Lite controlled register bank written in basic Verilog. The register
// bank contains the following fixed length identification and timestamp
// strings.
//
// Product Description ........ 128 Characters - 32 Registers - 0x000 - 0x07F
// Company .................... 64 Characters - 16 Registers - 0x080 - 0x0BF
// Author ..................... 64 Characters - 16 Registers - 0x0C0 - 0x0FF
// Product Version ............ 16 Characters - 4 Registers - 0x100 - 0x10F
// Firmware Build Timestamp ... 32 Characters - 8 Registers - 0x110 - 0x12F
// Unused ..................... 208 Characters - 52 Registers - 0x130 - 0x1FF
// --- --- -------------
// 512 128 - 0x000 - 0x1FF
//
.
wq
END
ed 0016/zedboard_leds_switches/fw/src/diagram/system/hdl/system_wrapper.sv <<END
1,9d
.
0a
//
// File .......... system_wrapper.sv
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard LEDs & Switches (SpaceWire UK Tutorial)
// Date .......... 06 Dec 2021
// Version ....... 1.0
// Description ...
// Top level wrapper for the underlying block design.
//
.
wq
END
ed 0016/zedboard_leds_switches/fw/src/script/post_bit.tcl <<END
1,10d
.
0a
#
# File .......... post_bit.tcl
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard LEDs & Switches (SpaceWire UK Tutorial)
# Date .......... 24 Oct 2021
# Version ....... 1.0
# Description ...
# Script to replace 'project.txt' (Information about last version of firmware)
# with 'project_new.txt' (Information about new version of firmware). The file
# replace only occurs if the bitstream was generated successfully.
#
.
wq
END
ed 0016/zedboard_leds_switches/fw/src/script/pre_synth.tcl <<END
1,10d
.
0a
#
# File .......... pre_synth.tcl
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard LEDs & Switches (SpaceWire UK Tutorial)
# Date .......... 24 Oct 2021
# Version ....... 1.0
# Description ...
# Script to read product/project information from a text file, increase
# the version/revision, get current timestamp and set the generics/parameters
# on the top level module.
#
.
wq
END
ed 0016/zedboard_leds_switches/fw/src/testbench/testbench.sv <<END
1,10d
.
0a
//
// File .......... testbench.sv
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard LEDs & Switches (SpaceWire UK Tutorial)
// Date .......... 13 Sep 2022
// Version ....... 3.0
// Description ...
// Very simple testbench to check correct connectivity of the block diagram.
// Uses the Zynq Verification IP suite to read/write the GPIO LED register and
// read the GPIO switch register.
//
.
wq
END
#### 0017 - Part 14b ###########################################################
ed 0017/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/files/Makefile <<END
0a
#
# File .......... Makefile
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 13 Sep 2022
# Version ....... 2.0
# Description ...
# Makefile for the peek, poke & peekstring CGI binaries.
#
.
wq
END
ed 0017/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/files/peekstring.c <<END
1,14d
.
0a
//
// File .......... peekstring.c
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 29 Oct 2021
// Version ....... 1.0
// Description ...
// CGI type module to read a string from memory and return it.
// Usage ...
// http://<web address>/cgi-bin/peekstring?base&size&offset&maxchars
// base = Base address of memory region to be used
// size = Size of memory region to be used
// offset = Offset address of string within memory region
// maxchars = Maximum length of return string
//
.
wq
END
ed 0017/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/peekpokecgi.bb <<END
1,5d
.
0a
#
# File .......... peekpokecgi.bb
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 13 Sep 2022
# Version ....... 2.0
# Description ...
# Application recipe for the peek, poke & peekstring CGI binaries.
#
.
wq
END
ed 0017/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.cgi <<END
2a
#
# File .......... index.cgi
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 13 Sep 2022
# Version ....... 6.0
# Description ...
# Dynamic (server & client side) webpage to display system information from
# PetaLinux running on the Zedboard. Already includes a widget that displays the
# uptime of PetaLinux and widgets to read & write register functionality. Also
# uses a style sheet for a more improved look. Enhanced the peek & poke
# capabilities such that multiple registers can be accessed. Added in global
# controls for the multiple registers and also file access so the register
# configuration can be saved and re-loaded. Added a Product Information
# section for the Firmware.
#
.
wq
END
ed 0017/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/uptime.js <<END
0a
//
// File .......... uptime.js
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 13 Sep 2022
// Version ....... 4.0
// Description ...
// Uptime support functions for the dynamic (client side) webpage. Updated to
// add read and write register requests that call the peek & poke CGI scripts
// and update the client side webpage accordingly. Enhanced functions to improve
// webpage look & feel, including the use of new status animation images for
// success/fail of register read/write calls and also a register configuration
// save & re-load facility. Added the functions required to support reading
// strings from the PL address space and dynamically updating the the webpage
// accordingly.
//
.
wq
END
#### 0018 - Part 16a ###########################################################
ed 0018/zedboard_leds_switches/fw/src/design/axi_identification.v <<END
1,21d
.
0a
//
// File .......... axi_identification.v
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard LEDs & Switches (SpaceWire UK Tutorial)
// Date .......... 02 Oct 2022
// Version ....... 2.0
// Description ...
// AXI4-Lite controlled register bank written in basic Verilog. The register
// bank contains the following fixed length identification and timestamp
// strings.
//
// Description ................ 128 Characters - 32 Registers - 0x000 - 0x07F
// Company .................... 64 Characters - 16 Registers - 0x080 - 0x0BF
// Author ..................... 64 Characters - 16 Registers - 0x0C0 - 0x0FF
// Version .................... 32 Characters - 8 Registers - 0x100 - 0x11F
// Timestamp .................. 32 Characters - 8 Registers - 0x120 - 0x13F
// Hash ....................... 64 Characters - 16 Registers - 0x140 - 0x17F
// Unused ..................... 144 Characters - 36 Registers - 0x180 - 0x20F
// --- --- -------------
// 528 132 - 0x000 - 0x20F
//
.
wq
END
ed 0018/zedboard_leds_switches/fw/src/diagram/system/hdl/system_wrapper.sv <<END
1,9d
.
0a
//
// File .......... system_wrapper.sv
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard LEDs & Switches (SpaceWire UK Tutorial)
// Date .......... 02 Oct 2022
// Version ....... 2.0
// Description ...
// Top level wrapper for the underlying block design.
//
.
wq
END
ed 0018/zedboard_leds_switches/fw/src/script/pre_synth.tcl <<END
1,10d
.
0a
#
# File .......... pre_synth.tcl
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard LEDs & Switches (SpaceWire UK Tutorial)
# Date .......... 02 Oct 2022
# Version ....... 2.0
# Description ...
# Script to read product/project information from a text file, obtain GIT
# repository information and set the generics/parameters on the top level
# module.
#
.
wq
END
#### 0019 - Part 16b ###########################################################
ed 0019/common/other/src/script/petalinux-build-id.sh <<END
3,13d
.
2a
#
# File .......... petalinux-build-id.sh
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Common (SpaceWire UK Tutorial)
# Date .......... 02 Oct 2022
# Version ....... 1.0
# Description ...
# Script to read project information file, obtain GIT repository information,
# append project information file with GIT information, build PetaLinux project
# and then restore project information file.
#
.
wq
END
#### 0020 - Part 16c ###########################################################
ed 0020/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.cgi <<END
2a
#
# File .......... index.cgi
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 02 Oct 2022
# Version ....... 7.0
# Description ...
# Dynamic (server & client side) webpage to display system information from
# PetaLinux running on the Zedboard. Already includes a widget that displays the
# uptime of PetaLinux and widgets to read & write register functionality. Also
# uses a style sheet for a more improved look. Enhanced the peek & poke
# capabilities such that multiple registers can be accessed. Added in global
# controls for the multiple registers and also file access so the register
# configuration can be saved and re-loaded. Added a Product Information
# section for the Firmware & the Operating System.
#
.
wq
END
ed 0020/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/uptime.js <<END
0a
//
// File .......... uptime.js
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 02 Oct 2022
// Version ....... 5.0
// Description ...
// Uptime support functions for the dynamic (client side) webpage. Updated to
// add read and write register requests that call the peek & poke CGI scripts
// and update the client side webpage accordingly. Enhanced functions to improve
// webpage look & feel, including the use of new status animation images for
// success/fail of register read/write calls and also a register configuration
// save & re-load facility. Added the functions required to support reading
// strings from the PL address space and dynamically updating the the webpage
// accordingly. Now displays the GIT Hash in the Firmware Information section &
// supports the displaying of a whole new PetaLinux Information section.
//
.
wq
END
ed 0020/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/website.bb <<END
1,4d
.
0a
#
# File .......... website.bb
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 02 Oct 2022
# Version ....... 6.0
# Description ...
# Application recipe for a dynamic (server & client side) webpage that consists
# of a webpage (cgi), uptime script (cgi), support functions (js), styles (css),
# an image of the Zedboard (png), 3 status animation images (gif) & a project
# information file (txt).
#
.
wq
END
#### 0021 - Part 16d ###########################################################
#### 0022 - Part 17a ###########################################################
ed 0022/zedboard_leds_switches/fw/src/constraint/zedboard.xdc <<END
0a
#
# File .......... zedboard.xdc
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard LEDs & Switches (SpaceWire UK Tutorial)
# Date .......... 29 Oct 2022
# Version ....... 2.0
# Description ...
# Pin & timing constraints for the Zedboard LEDs & Switches design. Now includes
# constraints for the Buttons.
#
.
wq
END
ed 0022/zedboard_leds_switches/fw/src/design/axi_gpio_zed.v <<END
1,13d
.
0a
//
// File .......... axi_gpio_zed.v
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard LEDs & Switches (SpaceWire UK Tutorial)
// Date .......... 29 Oct 2022
// Version ....... 1.0
// Description ...
// AXI4-Lite controlled GPIO block written in basic Verilog. Primary purpose
// is to provide access to the LEDs, Switches & Push Buttons of the Zedboard.
// Design offers an Interrupt that can be thrown when any of the Push Buttons
// are pressed or released. Address map is compatible with the one used in the
// AXI GPIO IP from Xilinx, albeit a cut-down version.
//
.
wq
END
ed 0022/zedboard_leds_switches/fw/src/design/axi_register_bank.v <<END
1,25d
.
0a
//
// File .......... axi_register_bank.v
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard LEDs & Switches (SpaceWire UK Tutorial)
// Date .......... 29 Oct 2022
// Version ....... 1.0
// Description ...
// AXI4-Lite controlled general purpose register bank written in basic
// Verilog. This module is intended to be a building block for something more
// useful.
//
// With c_data_w = 32 the number of registers is as follows :-
//
// c_addr_w - c_registers
// ~~~~~~~~ - ~~~~~~~~~~~
// 2 - 1
// 3 - 2
// 4 - 4
// 5 - 8
// 6 - 16
// 7 - 32
// 8 - 64
// 9 - 128
// 10 - 256
//
.
wq
END
ed 0022/zedboard_leds_switches/fw/src/design/debounce.v <<END
1,9d
.
0a
//
// File .......... debounce.v
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard LEDs & Switches (SpaceWire UK Tutorial)
// Date .......... 29 Oct 2022
// Version ....... 1.0
// Description ...
// Simple switch debouncer.
//
.
wq
END
ed 0022/zedboard_leds_switches/fw/src/diagram/system/hdl/system_wrapper.sv <<END
1,9d
.
0a
//
// File .......... system_wrapper.sv
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard LEDs & Switches (SpaceWire UK Tutorial)
// Date .......... 29 Oct 2022
// Version ....... 3.0
// Description ...
// Top level wrapper for the underlying block design.
//
.
wq
END
#### 0023 - Part 17b ###########################################################
ed 0023/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/axi-gpio-zed-test/files/axi-gpio-zed-test.c <<END
1,9d
.
0a
//
// File .......... axi-gpio-zed-test.c
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 29 Oct 2022
// Version ....... 1.0
// Description ...
// Very simple program to access a GPIO device using the User Space I/O
// subsystem. Demonstrates a blocking wait on interrupt routine.
//
.
wq
END
ed 0023/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/led-runner/files/led-runner <<END
2a
#
# File .......... led-runner
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 29 Oct 2022
# Version ....... 2.0
# Description ...
# Expanding & contracting LED sequence using the GPIO located at 0x4001_0000.
#
.
wq
END
ed 0023/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi <<END
0a
/*
* File .......... system-user.dtsi
* Author ........ Steve Haywood
* Website ....... http://www.spacewire.co.uk
* Project ....... Zedboard Linux (SpaceWire UK Tutorial)
* Date .......... 29 Oct 2022
* Version ....... 2.0
* History .......
* 1.0 TEMPLATE
* Description ...
* Added User Space I/O (UIO) for the AXI GPIO Zed module.
*/
.
wq
END
#### 0024 - Part 18 ############################################################
ed 0024/zedboard_linux/os/petalinux/project-spec/meta-user/conf/petalinuxbsp.conf <<END
0a
#
# File .......... petalinuxbsp.conf
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 03 Aug 2023
# Version ....... 2.0
# Description ...
# Updated to install the following :-
# -- ntp ....... Network Time Protocol
# -- ntpdate ... Set the date and time via NTP
# -- ntpq ...... Standard NTP query program
# -- sntp ...... Simple Network Time Protocol
# -- nano ...... Text editor
# Updated to install a LAMP style stack :-
# -- Apache .... HTTP server
# -- SQLite .... SQL database engine
# -- PHP ....... Scripting language
#
.
wq
END
ed 0024/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/peekpokecgi.bb <<END
1,5d
.
0a
#
# File .......... peekpokecgi.bb
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 03 Aug 2023
# Version ....... 3.0
# Description ...
# Application recipe for the peek, poke & peekstring CGI binaries. Forced
# run-as-root privileges set.
#
.
wq
END
ed 0024/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/hello_world.php <<END
0a
<?php
//
// File .......... hello_world.php
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 03 Aug 2023
// Version ....... 1.0
// Description ...
// Simple hello world in PHP.
//
?>
.
wq
END
ed 0024/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.php <<END
0a
<?php
//
// File .......... index.php
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 03 Aug 2023
// Version ....... 8.0
// History .......
// 7.0 zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.cgi
// Description ...
// Dynamic (server & client side) webpage to display system information from
// PetaLinux running on the Zedboard. Already includes a widget that displays the
// uptime of PetaLinux and widgets to read & write register functionality. Also
// uses a style sheet for a more improved look. Enhanced the peek & poke
// capabilities such that multiple registers can be accessed. Added in global
// controls for the multiple registers and also file access so the register
// configuration can be saved and re-loaded. Added a Product Information
// section for the Firmware & the Operating System. This source is a direct
// conversion from the previous CGI (shell script).
//
?>
.
wq
END
ed 0024/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/phpliteadmin.config.php <<END
0a
<?php
//
// File .......... phpliteadmin.config.php
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 03 Aug 2023
// Version ....... 1.0
// History .......
// 0.0 TEMPLATE
// Description ...
// PHPLite configuration with the database location changed from . to db.
//
?>
.
wq
END
ed 0024/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/sqlite_test.php <<END
1,16d
.
0a
<?php
//
// File .......... sqlite_test.php
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 03 Aug 2023
// Version ....... 1.0
// Description ...
// Simple HTML, PHP & SQLite example code that checks the basic operation of
// SQLite. SQL queries used are :-
//
// 1. Create/open database
// 1. Create table
// 3. Insert row
// 4. Close database
//
?>
.
wq
END
ed 0024/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/test-cgi <<END
2a
#
# File .......... test-cgi
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 03 Aug 2023
# Version ....... 1.0
# Description ...
# Stock test script (now enabled to run).
#
.
wq
END
ed 0024/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/index.html <<END
0a
<!--
// File .......... index.html
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 03 Aug 2023
// Version ....... 2.0
// Description ...
// Simple index page for accessing all the other pages.
-->
.
wq
END
ed 0024/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/uptime.js <<END
0a
//
// File .......... uptime.js
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 03 Aug 2023
// Version ....... 6.0
// Description ...
// Uptime support functions for the dynamic (client side) webpage. Updated to
// add read and write register requests that call the peek & poke CGI scripts
// and update the client side webpage accordingly. Enhanced functions to improve
// webpage look & feel, including the use of new status animation images for
// success/fail of register read/write calls and also a register configuration
// save & re-load facility. Added the functions required to support reading
// strings from the PL address space and dynamically updating the the webpage
// accordingly. Now displays the GIT Hash in the Firmware Information section &
// supports the displaying of a whole new PetaLinux Information section. Added
// backslash to uptime CGI call.
//
.
wq
END
ed 0024/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/website.bb <<END
1,4d
.
0a
#
# File .......... website.bb
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 03 Aug 2023
# Version ....... 7.0
# Description ...
# Application recipe for a dynamic (server & client side) webpage that consists
# of a webpage (php), uptime script (cgi), support functions (js), styles (css),
# an image of the Zedboard (png), 3 status animation images (gif) & a project
# information file (txt). The move to a LAMP style stack introduces new PHP
# files (index, hello_world, sqlite_test & phpliteadmin).
#
.
wq
END
ed 0024/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-httpd/apache2/apache2_%.bbappend <<END
0a
#
# File .......... apache2_%.bbappend
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 03 Aug 2023
# Version ....... 1.0
# Description ...
# Modify Apache 2 recipe to suite PetaLinux.
#
.
wq
END
#### 0025 - Part 19 ############################################################
ed 0025/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/files/Makefile <<END
0a
#
# File .......... Makefile
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 09 Feb 2024
# Version ....... 3.0
# Description ...
# Makefile for the peek, poke, peekstring & loadfirmware CGI binaries.
#
.
wq
END
ed 0025/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/files/loadfirmware.c <<END
1,11d
.
0a
//
// File .......... loadfirmware.c
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 09 Feb 2024
// Version ....... 1.0
// Description ...
// Very simple CGI to load PL bitstream.
//
.
wq
END
ed 0025/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/peekpokecgi.bb <<END
1,5d
.
0a
#
# File .......... peekpokecgi.bb
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 09 Feb 2024
# Version ....... 4.0
# Description ...
# Application recipe for the peek, poke, peekstring & loadfirmware CGI binaries.
# Forced run-as-root privileges set.
#
.
wq
END
ed 0025/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.php <<END
1,11d
.
0a
<?php
//
// File .......... index.php
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 09 Feb 2024
// Version ....... 9.0
// History .......
// 7.0 zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.cgi
// Description ...
// Dynamic (server & client side) webpage to display system information from
// PetaLinux running on the Zedboard. Already includes a widget that displays the
// uptime of PetaLinux and widgets to read & write register functionality. Also
// uses a style sheet for a more improved look. Enhanced the peek & poke
// capabilities such that multiple registers can be accessed. Added in global
// controls for the multiple registers and also file access so the register
// configuration can be saved and re-loaded. Added a Product Information
// section for the Firmware & the Operating System. This source is a direct
// conversion from the previous CGI (shell script). Now includes a table that
// displays the loadable firmware images available on the SD Card.
//
?>
.
wq
END
ed 0025/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/uptime.js <<END
1,11d
.
0a
//
// File .......... uptime.js
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 09 Feb 2024
// Version ....... 7.0
// Description ...
// Uptime support functions for the dynamic (client side) webpage. Updated to
// add read and write register requests that call the peek & poke CGI scripts
// and update the client side webpage accordingly. Enhanced functions to improve
// webpage look & feel, including the use of new status animation images for
// success/fail of register read/write calls and also a register configuration
// save & re-load facility. Added the functions required to support reading
// strings from the PL address space and dynamically updating the the webpage
// accordingly. Now displays the GIT Hash in the Firmware Information section &
// supports the displaying of a whole new PetaLinux Information section. Added
// backslash to uptime CGI call. Now includes support for loadable firmware
// images.
//
.
wq
END
#### 0026 - Part 20 ############################################################
ed 0026/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/files/Makefile <<END
0a
#
# File .......... Makefile
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 27 Feb 2024
# Version ....... 4.0
# Description ...
# Makefile for the peek, poke, peekstring, loadfirmware & bitbash CGI binaries.
#
.
wq
END
ed 0026/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/files/bitbash.c <<END
1,17d
.
0a
//
// File .......... bitbash.c
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 28 Feb 2024
// Version ....... 2.0
// History .......
// 1.0 zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/files/peek.c
// +1.0 zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/files/poke.c
// Description ...
// Very simple CGI application for peeking, poking and general bit bashing
// of a single 32-bit address location. Provides read back value or an error
// message to the client side application.
//
// Examples :-
// http://192.168.2.87/cgi-bin/bitbash?peek&0x40010000 ......... Peek value @ 0x40010000
// http://192.168.2.87/cgi-bin/bitbash?poke&0x40010000&0xF ..... Poke 0xF @ 0x40010000
// http://192.168.2.87/cgi-bin/bitbash?set&0x40010000&0x81 ..... Set bits 0 & 7 @ 0x40010000
// http://192.168.2.87/cgi-bin/bitbash?clear&0x40010000&0x2 .... Clear bit 1 @ 0x40010000
// http://192.168.2.87/cgi-bin/bitbash?toggle&0x40010000&0xC ... Toggle bits 2 & 3 @ 0x40010000
//
.
wq
END
ed 0026/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/peekpokecgi/peekpokecgi.bb <<END
1,5d
.
0a
#
# File .......... peekpokecgi.bb
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 27 Feb 2024
# Version ....... 5.0
# Description ...
# Application recipe for the peek, poke, peekstring, loadfirmware & bitbash CGI
# binaries.
#
.
wq
END
ed 0026/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/phpliteadmin.config.php <<END
0a
<?php
//
// File .......... phpliteadmin.config.php
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 27 Feb 2024
// Version ....... 2.0
// History .......
// 0.0 TEMPLATE
// Description ...
// PHPLite configuration with the database location changed to be a directory on the
// Zedboard SD-Card.
//
?>
.
wq
END
ed 0026/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/sqlite_test.php <<END
1,23d
.
0a
<?php
//
// File .......... sqlite_test.php
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 27 Feb 2024
// Version ....... 2.0
// Description ...
// Simple HTML, PHP & SQLite example code that offers some degree of error
// checking on the form inputs. Reports SQL operations and success/failure
// status. Demonstrates some of the common SQL queries :-
//
// 1. Create/open database
// 2. Create table
// 3. Drop table
// 4. Insert row
// 5. Delete row
// 6. Update row
// 7. Close database
//
?>
.
wq
END
ed 0026/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/home/index.php <<END
1,13d
.
0a
<?php
//
// File .......... index.php
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 27 Feb 2024
// Version ....... 1.0
// Description ...
// Webpage for Home.
//
?>
.
wq
END
ed 0026/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/index.php <<END
1,13d
.
0a
<?php
//
// File .......... index.php
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 27 Feb 2024
// Version ....... 1.0
// Description ...
// Forwarder page for use in root www directory.
//
?>
.
wq
END
ed 0026/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/peekpoke/index.php <<END
1,13d
.
0a
<?php
//
// File .......... index.php
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 27 Feb 2024
// Version ....... 10.0
// History .......
// 9.0 zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.php
// 7.0 zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.cgi
// Description ...
// Webpage for Peek & Poke Addresses.
//
?>
.
wq
END
ed 0026/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/peekpoke/script.js <<END
1,11d
.
0a
//
// File .......... script.js
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 27 Feb 2024
// Version ....... 8.0
// History .......
// 7.0 zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/uptime.js
// Description ...
// Javascript for Peek & Poke Addresses.
//
.
wq
END
ed 0026/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/share/footer.php <<END
1,13d
.
0a
<?php
//
// File .......... footer.php
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 27 Feb 2024
// Version ....... 1.0
// Description ...
// Footer include for website pages.
//
?>
.
wq
END
ed 0026/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/share/header.php <<END
1,13d
.
0a
<?php
//
// File .......... header.php
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 27 Feb 2024
// Version ....... 1.0
// Description ...
// Header include for website pages.
//
?>
.
wq
END
ed 0026/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/share/script.js <<END
1,11d
.
0a
//
// File .......... script.js
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 28 Feb 2024
// Version ....... 1.0
// Description ...
// Global Javascript for use in all webpages.
//
.
wq
END
ed 0026/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/share/style.css <<END
1,11d
.
0a
/*
* File .......... style.css
* Author ........ Steve Haywood
* Website ....... http://www.spacewire.co.uk
* Project ....... Zedboard Linux (SpaceWire UK Tutorial)
* Date .......... 27 Feb 2024
* Version ....... 2.0
* History .......
* 1.0 zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/styles.css
* Description ...
* Global Cascading Style Sheet for use in all webpages.
*/
.
wq
END
ed 0026/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/system/index.php <<END
1,11d
.
0a
<?php
//
// File .......... index.php
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 27 Feb 2024
// Version ....... 10.0
// History .......
// 9.0 zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.php
// 7.0 zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/cgi-bin/index.cgi
// Description ...
// Webpage for System Information & Firmware Load.
//
?>
.
wq
END
ed 0026/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/system/script.js <<END
1,11d
.
0a
//
// File .......... script.js
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 27 Feb 2024
// Version ....... 8.0
// History .......
// 7.0 zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/uptime.js
// Description ...
// Javascript for System Information & Firmware Load.
//
.
wq
END
ed 0026/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/zedboard/index.php <<END
1,15d
.
0a
<?php
//
// File .......... index.php
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 26 Feb 2024
// Version ....... 1.0
// Description ...
// Webpage for Interactive Zedboard.
//
?>
.
wq
END
ed 0026/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/zedboard/script.js <<END
1,11d
.
0a
//
// File .......... script.js
// Author ........ Steve Haywood
// Website ....... http://www.spacewire.co.uk
// Project ....... Zedboard Linux (SpaceWire UK Tutorial)
// Date .......... 28 Feb 2024
// Version ....... 1.0
// Description ...
// Javascript for Interactive Zedboard.
//
.
wq
END
ed 0026/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/files/zedboard/style.css <<END
1,11d
.
0a
/*
* File .......... style.css
* Author ........ Steve Haywood
* Website ....... http://www.spacewire.co.uk
* Project ....... Zedboard Linux (SpaceWire UK Tutorial)
* Date .......... 28 Feb 2024
* Version ....... 1.0
* Description ...
* Cascading Style Sheet for Interactive Zedboard.
*/
.
wq
END
ed 0026/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-apps/website/website.bb <<END
1,4d
.
0a
#
# File .......... website.bb
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 27 Feb 2024
# Version ....... 8.0
# Description ...
# Application recipe for a dynamic (server & client side) website that is split
# into separate sections (directories). Each section contains an index page
# along with any associated files (sub-pages, scripts, styles, images, etc.).
# There are also two shared areas for common files.
#
.
wq
END
ed 0026/zedboard_linux/os/petalinux/project-spec/meta-user/recipes-httpd/apache2/apache2_%.bbappend <<END
0a
#
# File .......... apache2_%.bbappend
# Author ........ Steve Haywood
# Website ....... http://www.spacewire.co.uk
# Project ....... Zedboard Linux (SpaceWire UK Tutorial)
# Date .......... 27 Feb 2024
# Version ....... 2.0
# Description ...
# Modified Apache 2 recipe to suite PetaLinux. Updated to allow Apache to run as
# root instead of deamon.
#
.
wq
END
}
################################################################################
# Check if an argument option is set.
# Arguments ...... $1 ... Str: Option
# Return ......... Set (0=unset, 1=set)
# Shared (In) .... argv
# Shared (Out) ... None
option_set()
{
[[ " ${argv[*]} " =~ " ${1} " ]] && echo 1 || echo 0
}
################################################################################
# Main function.
# Arguments ...... None
# Return ......... None
# Shared (In) .... argv
# Shared (Out) ... argv
main()
{
# Declare local constants
local -r opthelp="--help" # Str: Help option name
local -Ar options=( # ARR: Options & associated help information
[${opthelp}]="Display this help and exit."
)
local -ar optorder=( # Arr: Help options display order
${opthelp}
)
# Declare local variables
local arg # Str: Current argument from argv array
local project="" # Str: Project directory [arg] (mandatory)
local option # Str: Current option from optorder array
# Display help information
if (($(option_set ${opthelp}))); then
echo "Usage: $(basename ${0}) PROJECT-DIRECTORY... [OPTION]..."
echo "Edit headers in the source files in PROJECT-DIRECTORY. Core function is the output from swuk_repos_gen_fix_headers."
echo
for option in ${optorder[@]}
do
echo " ${option} $(printf ' %.0s' {1..12} | head -c $((12-${#option}))) ${options[${option}]}"
done
echo
exit 0
fi
# Get & check the arguments
for arg in ${argv[@]}; do
if [[ ${arg:0:2} == "--" ]]; then # Option
[[ ! -v options[${arg}] ]] && echo "Option (${arg}) is not recognised!" && exit 1
elif [[ -z ${project} ]]; then # Project directory
project=${arg}
[[ ! -d ${project} ]] && echo "Project directory (${arg}) does not exist!" && exit 1
else
echo "Unexpected argument (${arg}) found!" && exit 1
exit 1
fi
done
# Further check the arguments
[[ -z ${project} ]] && echo "No project directory specified!" && exit 1
# Move into project directory
cd ${project}
# Edit the headers
edit_headers
# Move out of project directory
cd ..
}
################################################################################
# Opening gambit.
# Arguments ...... None
# Return ......... None
# Exit code ...... Status (0=success, 1=failure)
# Shared (In) .... $#, $@
# Shared (Out) ... argc, argv
declare -ri argc=${#} # Int: Get argument count
declare -ra argv=(${@}) # Arr: Get argument values (space-separated) into array
main
exit 0
- Examine what options are available with the script.
steve@Desktop:/tmp/scratch$ swuk_repos_fix_headers --help
Usage: swuk_repos_fix_headers PROJECT-DIRECTORY... [OPTION]...
Edit headers in the source files in PROJECT-DIRECTORY. Core function is the output from swuk_repos_gen_fix_headers.
--help Display this help and exit.