Monthly Archives: January 2014
Multicast IP/MAC-Address Mapping
Ethernet Internals
MAC Address
What range of MAC addresses can I safely use for my virtual machines?
MAC Address: Universally or Locally Administered Bit and Individual/Group Bit
Frame Check Sequence (FCS) = Cyclic Redundancy Check (CRC)
Cyclic Redundancy Check (CRC), Frame Check Sequence (FCS)
UDP Checksum
Short UDP Checksum Calculation HowTo
Following is a description by Ed Beroset of the calculation of the UDP checksum for this packet. Many thanks to Ed for figuring out the details and writing it up.
First, the checksum calculation is defined in RFC 768 but hints as to how to calculate it efficiently are in RFC 1071. Both are worth reading and contain a much more in-depth description that I’m going to write here.
The basic idea is that the UDP checksum is a the complement of a 16-bit one’s complement sum calculated over an IP “pseudo-header” and the actual UDP data. The IP pseudo-header is the source address, destination address, protocol (padded with a zero byte) and UDP length. So to take the example of this short packet, the source IP address is 152.1.51.27, and the destination IP address is 152.14.94.75. Divided into 16-bit quantities, these are 0x9801, 0x331b and 0x980e, 0x5e4b. If you add those together using two’s complement (e.g. with Windows calculator), you get 0x1c175. Note that this overflows a 16-bit quantity, but we’ll take care of that later. Next is to add in the protocol and UDP length. For this packet, the protocol is UDP so the protocol type byte is 17or 0x11. We pad that with zero to get 0x0011 and then add the UDP length which is 0x000a (10 bytes). So 0x1c175 + 0x0011 + 0x0! 00a = 0x1c190.
Now we add the entire UDP datagram, treating it all as 16-bit quantities and skipping the checksum (until we finish calculating it!). For this datagram, that’s 0xa08f, 0x2694, 0x000a, 0x6262, so if we add all that to our running sum, we get 0x1c190 + 0xa08f + 0x2694 + 0x000a + 0x6262 = 0x2eb1f.
Now to convert to a ones complement 16-bit sum we just treat our current sum (0x2eb1f) as a 32-bit quantity and add the high half to the low half. 0x0002 + 0xeb1f = 0xeb21. (If that still had an overflow, we’d add the high and low halves again until there was no longer an overflow.) Now we complement that quantity (i.e. flip all the bits, or do a NOT operation) and we get a value of 0x14de which is exactly what the reported checksum shows in the packet.
Short UDP Checksum Calculation HowTo
How to Calculate IP/TCP/UDP Checksum–Part 1 Theory
/* * Our algorithm is simple, using a 32 bit accumulator (sum), we add * sequential 16 bit words to it, and at the end, fold back all the * carry bits from the top 16 bits into the lower 16 bits. */ uint16_t raw_packet_calc_checksum(uint16_t *buffer, uint16_t len) { const uint16_t words = len / 2; uint32_t sum; uint16_t i; sum = 0; for (i = 0; i < words; i++) { sum = sum + *(buffer + i); } /* add carry */ sum = (sum >> 16) + sum; /* truncate to 16 bits */ return ~sum; }
AES Stick Figure
tcpdump Packet Capture / Sniffer / Analyzer
$ tcpdump -i em0 -s 65535 -w packet.pcap $ xz -z packet.pcap
TCPDUMP Quick Reference (PDF)
Tcpdump Commands – A Network Sniffer Tool
A tcpdump Tutorial and Primer
How to gather DNS A record requests?
Monitoring DNS Queries with tcpdump
Packet Analyzer: 15 TCPDUMP Command Examples
tcpdump: Capturing with tcpdump for viewing with Wireshark
Manual pages
Wikipedia
tcpdump (de)
tcpdump (en)
pcap (de)
Change PCAP files
Bit-Twist: Libpcap-based Ethernet packet generator
Strip off GTP Headers
Bittwiste: pcap Capture File Editor (by Joke Snelders)
Strip radiotap headers from capture files?
Bash scripting
Keyboard shortcuts
Command Line Editing
Commands For Moving
Mastering The Linux Shell – Bash Shortcuts Explained (Now With Cheat Sheets)
Bash Keyboard Shortcuts
[CTRL + P] Print previous command (Up arrow) [CTRL + N] Print next command (Down arrow) [CTRL + R] History search [ALT + R] Cancel changes, put back like in the history [! + !] Repeat last command [! + <cmd>] Run last command starting with <cmd> [! + *] Run all argument of previous command [! + $] Run last argument of previous command [ALT + .] Print last argument of previous command [^<p1> + ^<p2>] Run last command, replace <p1> with <p2>
[CTRL + F] Move forward one character (Right arrow) [CTRL + B] Move backward one character (Left arrow) [ALT + F] Move forward one word [ALT + B] Move backward one word [CTRL + A] Move to the start of the line [CTRL + E] Move to the end of the line [CTRL + X + X] Toggle between start of word and cursor
[CTRL + H] Delete previous character from the cursor (= Rubout, like Backspace) [CTRL + D] Delete current character from the cursor (Delete)
[CTRL + K] Cut from the cursor to the end of the line [CTRL + U] Cut from the cursor to the start of the line (like [CTRL + X + BACKSPACE] [ALT + D] Cut from the cursor to the end of the current word [CTRL + W] Cut from the cursor to the previous whitespace [CTRL + Y] Paste
[ALT + T] Swap current word with previous (or [ESC + T]) [CTRL + T] Swap the last two characters before the cursor (typo) [ALT + U] Upper-case word and move to the end of the word [ALT + L] Lower-case word and move to the end of the word [ALT + C] Capitalize word and move to the end of the word
Job ID / Percent sign (%)
Percent sign (%) in front of shell command
$ tail -f /var/log/messages [CTRL + Z] [1]+ Stopped tail -f /var/log/messages $ tail -f /var/log/maillog [CTRL + Z] [2]+ Stopped tail -f /var/log/maillog $ jobs [1]- Stopped tail -f /var/log/messages [2]+ Stopped tail -f /var/log/maillog $ fg %2 tail -f /var/log/maillog [CTRL + Z] [2]+ Stopped tail -f /var/log/maillog $ fg %1 tail -f /var/log/messages [CTRL + Z] [1]+ Stopped tail -f /var/log/messages $ kill %1 %2 [1]- Terminated tail -f /var/log/messages [2]+ Terminated tail -f /var/log/maillog
Simple commands vs Compound commands
What is the essential difference between compound command and normal command in bash?
four types of compound commands:
Funktion | Erklärung |
Group: {...;} |
can be used to group simple commands together to form a compound command. |
Subshell: (...) |
is similar to a group except that the commands are run in subshell environment. |
Arithmetic Expression: ((..)) |
a series of comma-separated arithmetic calculations may be performed. |
Test Command: [[...]] |
advanced form of the test command. |
Bash Brackets Quick Reference
Bash Brackets Quick Reference
How to use double or single brackets, parentheses, curly braces
When do we need curly braces around shell variables?
Differences Between Single and Double Brackets in Bash
( Single Parentheses ) (( Double Parentheses )) <( Angle Parentheses ) $( Dollar Single Parentheses ) $( Dollar Single Parentheses Dollar Q )$? $(( Dollar Double Parentheses )) [ Single Square Brackets ] [[ Double Square Brackets ]] { Single Curly Braces } ${Dollar Braces} <<Double Angle Heredocs
if [ ]
File based
Primary | Meaning |
---|---|
[ -a FILE ] | True if FILE exists. |
[ -b FILE ] | True if FILE exists and is a block-special file. |
[ -c FILE ] | True if FILE exists and is a character-special file. |
[ -d FILE ] | True if FILE exists and is a directory. |
[ -e FILE ] | True if FILE exists. |
[ -f FILE ] | True if FILE exists and is a regular file. |
[ -g FILE ] | True if FILE exists and its SGID bit is set. |
[ -h FILE ] | True if FILE exists and is a symbolic link. |
[ -k FILE ] | True if FILE exists and its sticky bit is set. |
[ -p FILE ] | True if FILE exists and is a named pipe (FIFO). |
[ -r FILE ] | True if FILE exists and is readable. |
[ -s FILE ] | True if FILE exists and has a size greater than zero. |
[ -t FD ] | True if file descriptor FD is open and refers to a terminal. |
[ -u FILE ] | True if FILE exists and its SUID (set user ID) bit is set. |
[ -w FILE ] | True if FILE exists and is writable. |
[ -x FILE ] | True if FILE exists and is executable. |
[ -O FILE ] | True if FILE exists and is owned by the effective user ID. |
[ -G FILE ] | True if FILE exists and is owned by the effective group ID. |
[ -L FILE ] | True if FILE exists and is a symbolic link. |
[ -N FILE ] | True if FILE exists and has been modified since it was last read. |
[ -S FILE ] | True if FILE exists and is a socket. |
[ FILE1 -nt FILE2 ] | True if FILE1 has been changed more recently than FILE2, or if FILE1 exists and FILE2 does not. |
[ FILE1 -ot FILE2 ] | True if FILE1 is older than FILE2, or is FILE2 exists and FILE1 does not. |
[ FILE1 -ef FILE2 ] | True if FILE1 and FILE2 refer to the same device and inode numbers. |
String based
Primary | Meaning |
---|---|
[ -o OPTIONNAME ] | True if shell option “OPTIONNAME” is enabled. |
[ -z STRING ] | True of the length if “STRING” is zero. |
[ -n STRING ] or [ STRING ] | True if the length of “STRING” is non-zero. |
[ STRING1 == STRING2 ] | True if the strings are equal. “=” may be used instead of “==” for strict POSIX compliance. |
[ STRING1 != STRING2 ] | True if the strings are not equal. |
[ STRING1 < STRING2 ] | True if “STRING1” sorts before “STRING2” lexicographically in the current locale. |
[ STRING1 > STRING2 ] | True if “STRING1” sorts after “STRING2” lexicographically in the current locale. |
[ ARG1 OP ARG2 ] | “OP” is one of -eq, -ne, -lt, -le, -gt or -ge. These arithmetic binary operators return true if “ARG1” is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to “ARG2”, respectively. “ARG1” and “ARG2” are integers. |
Process List (ps)
$ ps auxf
$ ps auxd
#!/usr/bin/env
Howto Make Script More Portable With #!/usr/bin/env As a Shebang
#!/usr/bin/env bash rather than #!/bin/bash
Bash Conditional Expressions
The Set Builtin
Glob and Wildcard
What if a Wildcard Doesn’t Match?
Why does using double brackets “[[” to check if wildcard matched files exists fail, while single brackets “[” work?
Test if there are files matching a pattern in order to execute a script
Test whether a glob has any matches in Bash
Think You Understand Wildcards? Think Again.
how to handle bash * matching when there are no matches?
shopt -s nullglob set -- *.txt if [ "$#" -gt 0 ]; then ./script "$@" # call script with that list of files. fi # Or with bash arrays so you can keep the arguments: files=( *.txt ) # apply C-style boolean on member count (( ${#files[@]} )) && ./script "${files[@]}" # Or with Bash built-in function compgen -G "<glob-pattern>" if compgen -G "/tmp/someFiles*" > /dev/null; then echo "Some files exist." fi
Arrays
6.7 Arrays
You don’t know Bash: An introduction to Bash arrays
- Any element of an array may be referenced using
${name[subscript]}
. - The braces are required to avoid conflicts with the shell’s filename expansion operators.
- If the subscript is
‘@’
or‘*’
, the word expands to all members of the array name
Funktion | Erklärung |
arr=() |
Create an empty array |
arr=(1 2 3) |
Initialize array |
${arr[2]} |
Retrieve third element |
${arr[@]} |
Retrieve all elements |
${!arr[@]} |
Retrieve array indices |
${#arr[@]} |
Calculate array size |
arr[0]=3 |
Overwrite 1st element |
arr+=(4) |
Append value(s) |
arr=( $(ls) ) |
Save ls output as an array of files |
${arr[@]:s:n} |
Retrieve n elements starting at index s |
Control Structures
if
Bash if elif else Statement: A Comprehensive Tutorial
Syntax | What it is | When to use |
Subshell executed in a subprocess | When the commands affect the current shell or environment. The changes do not remain when the subshell completes. | |
Bash extension | Use for arithmetic operations and C-style variable manipulation. | |
POSIX builtin | Comparing numbers and testing whether a file exists. | |
Bash extension | String matching a wildcard pattern. |
while
while [ ]; do command done while [[ ]]; do command done while (( )); do command done
until
until [condition] do block of code done
for
Parameter
Parameter | Purpose |
$0, $1, $2, etc. |
Positional parameters, passed from command line to script, passed to a function, or set to a variable. |
$# |
Number of command-line arguments or positional parameters |
$* |
All of the positional parameters, seen as a single word. |
$@ |
Same as $*, but each parameter is a quoted string, that is, the parameters are passed on intact, without interpretation or expansion. This means, among other things, that each parameter in the argument list is seen as a separate word. |
Parameter | Purpose |
$0, $1, $2, ... |
The positional parameters starting from parameter 0. Parameter 0 refers to the name of the program that started bash, or the name of the shell script if the function is running within a shell script. See the bash man pages for information on other possibilities, such as when bash is started with the -c parameter. A string enclosed in single or double quotes will be passed as a single parameter, and the quotes will be stripped. In the case of double quotes, any shell variables such as $HOME will be expanded before the function is called. You will need to use single or double quotes to pass parameters that contain embedded blanks or other characters that might have special meaning to the shell. |
$* |
The positional parameters starting from parameter 1. If the expansion is done within double quotes, then the expansion is a single word with the first character of the IFS special variable separating the parameters, or no intervening space if IFS is null. The default IFS value is a blank, tab, and newline. If IFS is unset, then the separator used is a blank, just as for the default IFS. |
$@ |
The positional parameters starting from parameter 1. If the expansion is done within double quotes, then each parameter becomes a single word, so that “$@” is equivalent to “$1” “$2” … If your parameters are likely to contain embedded blanks, you will want to use this form. |
$# |
The number of parameters, not including parameter 0. |
Internal Variables
Advanced Bash-Scripting Guide: 9.1. Internal Variables
Variable | Purpose |
$BASHPID |
Process ID of the current instance of Bash. This is not the same as the $$ variable, but it often gives the same result. |
$PS1 |
This is the main prompt, seen at the command-line. |
$PS2 |
The secondary prompt, seen when additional input is expected. It displays as “>”. |
$PS3 |
The tertiary prompt, displayed in a select loop. |
$PS4 |
The quartenary prompt, shown at the beginning of each line of output when invoking a script with the -x [verbose trace] option. |
$PWD |
Working directory (directory you are in at the time). |
$OLDPWD |
Old working directory. |
$HOME |
PHome directory of the user. |
$- |
Flags passed to script. |
$! |
PID (process ID) of last job run in background. |
$_ |
Special variable set to final argument of previous command executed. |
$? |
Exit status of a command, function, or the script itself. |
$$ |
Process ID (PID) of the script itself. The $$ variable often finds use in scripts to construct “unique” temp file names. |
$ ( echo $$; echo $BASHPID ) 11436 8408
Default values
Expansion | Purpose |
${PARAMETER:-WORD} |
If PARAMETER is unset or null, the shell expands WORD and substitutes the result.The value of PARAMETER is not changed. |
${PARAMETER:=WORD} |
If PARAMETER is unset or null, the shell expands WORD and assigns the result to PARAMETER. This value is then substituted. You cannot assign values to positional parameters or special parameters this way. |
${PARAMETER:?WORD} |
If PARAMETER is unset or null, the shell expands WORD and writes the result to standard error. If WORD is not present a message is written instead. If the shell is not interactive, it exits. |
${PARAMETER:+WORD} |
If PARAMETER is unset or null, nothing is substituted. Otherwise the shell expands WORD and substitutes the result. |
APP_NAME=${APP_NAME:-"default_name"} $ export FOO=first $ echo "The ${FOO:-second} choice" The first choice $ unset FOO $ echo "The ${FOO:-second} choice" The second choice $ export FOO= $ echo "The ${FOO:-second} choice" The second choice
Default values
bash assign default value
Field splitting / Word splitting / String splitting
What is word splitting? Why is it important in shell programming?
- Early shells had only a single data type: strings.
- To store a list of file names in a variable, you would put spaces between them./li>
- At the time, spaces in file names were either forbidden or widely considered Not Done.
list="a b c" for entry in list; do echo $entry done
- These days, spaces in file names are something you need to cope with
- Always use double quotes, i.e. write “$foo”, unless you understand why you need word splitting
- The term word splitting also called field splitting, because what constitutes a word (also called field) can be configured by setting the
IFS
variable - By default,
IFS
contains basic whitespace characters (ASCII space, tab and newline)
How to Split a String Into an Array in Bash
- A for loop construct in
Bash
can split a string value and iterate over the tokens. - The for loop performs string splitting based on the characters defined in the IFS shell variable.
- Splitting a string into an array is a common task.
- The sentence was split into words and the words were added to the words array correctly
sentence='Hello World of Linux' words=() for i in $sentence; do words+=($i) ; done for word in ${words[@]}; do echo $word ; done # Result: Hello World of Linux
- The for loop uses the characters in the
IFS
shell variable to split strings. IFS
stands for Internal Field Separator andBash
uses it to recognize fields.- Its value defaults to
" \t\n"
, meaning that the shell uses the space, the tab, or the newline characters to split a string value into fields or words.
IFS=$IFS# printf "%q" "$IFS" # Result ' \t\n#' sentence='Hello#World#of#Linux' words=() for i in $sentence; do words+=($i) ; done for word in ${words[@]}; do echo $word ; done # Result: Hello World of Linux
- Finally, we can reset IFS to its initial value by removing the # character:
- We extract a three-character length substring of
IFS
, starting from position 0, and assigned it back to theIFS
variable
IFS="${IFS:0:3}" $ printf '%q' "${IFS}" # Result: ' \t\n'
Single (‘) and Double (“) Quotes
Difference between single and double quotes in Bash
Parameter Expansion
Parameter expansion
Parameter Expansion
- Simple usage
- Indirection
- Case modification
- Variable name expansion
- Substring removal
- Search and replace
- String length
- Substring expansion
- Use a default value
- Assign a default value
- Use an alternate value
- Display error if null or unset
Manipulating Strings
Bash : removing part of a string (= Parameter Expansion)
Substring Removal (Abschneiden von Mustern)
Eine gewöhnungsbedürftige, aber doch sehr nette Funktion ist das Herausschneiden bestimmter Muster aus der Zeichenkette einer Variablen.
Funktion | Erklärung |
${variable%muster} |
Entfernt rechts das kleinste passende Stück. |
${variable%%muster} |
Entfernt rechts das größte passende Stück. |
${variable#muster} |
Entfernt links das kleinste passende Stück. |
${variable##muster} |
Entfernt links das größte passende Stück. |
From the beginning: path1="/usr/local/bin/bash" ${PARAMETER#PATTERN} => shortest matching: ${path1#/*} => usr/local/bin/bash ${PARAMETER##PATTERN} => longest matching: ${path1##*/} => bash From the end: path2="x/usr/local/bin/bash" ${PARAMETER%PATTERN} => shortest matching: ${path2%/*} => x/usr/local/bin ${PARAMETER%%PATTERN} => longest matching: ${path2%%/*} => x var="Memory Used: 19.54M" var=${var#*: } # Remove everything up to a colon and space var=${var%M} # Remove the M at the end
Substring Replacement
Funktion | Erklärung |
${string/substring/replacement} |
Replace first match of $substring with $replacement. |
${string//substring/replacement} |
Replace all matches of $substring with $replacement. |
${string/#substring/replacement} |
If $substring matches front end of $string, substitute $replacement for $substring. |
${string/%substring/replacement} |
If $substring matches back end of $string, substitute $replacement for $substring. |
stringZ=abcABC123ABCabc echo ${stringZ/#abc/XYZ} # XYZABC123ABCabc # Replaces front-end match of 'abc' with 'XYZ'. echo ${stringZ/%abc/XYZ} # abcABC123ABCXYZ # Replaces back-end match of 'abc' with 'XYZ'.
Lists of Commands, Command Sequences
Lists of Commands
Writing Better Shell Scripts – Part 2
Meaning of colon in Bash after a double pipe
Bourne Shell Builtins
Is there a difference between how two ampersands and a semi-colon operate in bash?
- Two logical short-circuits are the double ampersand (&&) and double pipe (||) operators.
- The && only allows the command that comes after it in the series to be executed if the previous command exited with a status of 0.
- The || operator does the opposite by only allowing the next command to be executed if the previous one returned a non-zero exit status.
- The ; just separates one command from another.
- The : is a null statement, so it does nothing.
- The . executes a script in the current shell, not starting a new shell
$ true; echo $? 0 $ false; echo $? 1 === && === $ true && echo "hello" hello $ false && echo "hello" <no output> === || === $ true || echo "hello" <no output> $ false || echo "hello" hello === ; === $ true; echo "hallo" hallo $ false; echo "hallo" hallo ======================= [ -n STRING ] => True if the length of "STRING" is non-zero. === return value === $ [ -n "hallo" ]; echo $? 0 $ [ -n "" ]; echo $? 1 === if then === $ if [ -n "hallo" ]; then echo "welt"; fi welt $ if [ -n "" ]; then echo "welt"; fi <no output> === && === $ [ -n "hallo" ] && echo "welt" welt $ [ -n "" ] && echo "welt" <no output> === || === $ [ -n "hallo" ] || echo "welt" <no output> $ [ -n "" ] || echo "welt" welt
testfunc() { return $1 } { echo "success" testfunc 0 echo "success" testfunc 0 echo "failure" testfunc 4 } && { echo "good 1" } || { echo "exception 1" } # Result: exception 1 { echo "success" testfunc 0 echo "success" testfunc 0 echo "failure" testfunc 4 echo "success" testfunc 0 } && { echo "good 2" } || { echo "exception 2" } # Result good 2 # Just test the last function!
Bang dollar-sign
$ ./app a b c d e f $ !* a b c d e f -bash: a: command not found $ !$ f -bash: f: command not found
Brace Expansion
$ cp filename filename-old $ cp filename-old filename
$ cp filename{,-old} $ cp filename{-old,} $ cp filename{-v1,-v2}
Arithmetic Expansion
Bash Math Operations (Bash Arithmetic) Explained
- No
$
in Arithmetic Expansion… - … except that you want to assign/output/store it in the script
- Compound notation
(())
which evaluates the expression - The variable operator
$
to store the result
$((expression)) echo $((2+3)) # Result 5 echo $((x=2, y=3, x+y)) # Result 5 ((x=2, y=3, a=x+y, b=x*y, c=x**y)); echo $a, $b, $c # Result 5, 6, 7
number=1 echo $((++number)) echo $number # Result 2 2 number=1 echo $((number++)) echo $number # Result 1 2 number=1 ((number=number+2)) echo $number # Result 3
number=1 if ((number > 0)); then echo "hurra!" fi idx=0 count=3 while ((idx < count)); do echo $idx ((idx++)) done
Process Substitution
- pipe. Passes the output (stdout) of a previous command to the input (
stdin
) of the next one, or to the shell. This is a method of chaining commands together. - redirection.
scriptname >filename
redirects the output ofscriptname
to filefilename
- process substitution.
Chapter 23. Process Substitution
A Comprehensive Guide to Process Substitution in Bash
Exit code
Exit and Exit Status
Exit Codes With Special Meanings
Understanding Exit Codes and how to use them in bash scripts
$ bla -bash: bla: command not found $ echo $? 127
Exit Code Number | Meaning | Example | Comments |
---|---|---|---|
1 | Catchall for general errors | let “var1 = 1/0” | Miscellaneous errors, such as “divide by zero” and other impermissible operations |
2 | Misuse of shell builtins (according to Bash documentation) | empty_function() {} | Missing keyword or command, or permission problem (and diff return code on a failed binary file comparison). |
126 | Command invoked cannot execute | /dev/null | Permission problem or command is not an executable |
127 | “command not found” | illegal_command | Possible problem with $PATH or a typo |
128 | Invalid argument to exit | exit 3.14159 | exit takes only integer args in the range 0 – 255 (see first footnote) |
128+n | Fatal error signal “n” | kill -9 $PPID of script | $? returns 137 (128 + 9) |
130 | Script terminated by Control-C | Ctl-C | Control-C is fatal error signal 2, (130 = 128 + 2, see above) |
255* | Exit status out of range | exit -1 | exit takes only integer args in the range 0 – 255 |
Quartus FAQ
Links
Altera Qsys Erfahrungen
em4fun Altera DE0-Nano
FAQ
Question
Error (176310): Can't place multiple pins assigned to pin location Pin_D1 (IOPAD_X0_Y37_N7) Info (176311): Pin epcs_config_asd0_o is assigned to pin location Pin_D1 (IOPAD_X0_Y37_N7) Info (176311): Pin ~ALTERA_ASDO_DATA1~ is assigned to pin location Pin_D1 (IOPAD_X0_Y37_N7)
Answer
Use SOPC or Qsys and add “EPCS Serial Flash Controller”
error: can’t place multiple pins assigned to pin location
Question
Qsys: Warning: No matching role found
Answer
You may safely ignore these messages for Altera components because the signals are not required for design operation.
Qsys: Warning: No matching role found
Question
Info (209060): Started Programmer operation at Fri Jan 24 15:27:32 2014 Info (209016): Configuring device index 1 Info (209017): Device 1 contains JTAG ID code 0x020F40DD Error (209014): CONF_DONE pin failed to go high in device 1 Error (209012): Operation failed Info (209061): Ended Programmer operation at Fri Jan 24 15:27:38 2014
Answer
Reset Hardware or
Error (209014): CONF_DONE pin failed to go high in device
Why do I receive the error ‘CONF_DONE pin failed to go high in device X’ when I try to JTAG configure my Altera FPGA using the Quartus II software and a download cable?
Question
Remove VHDL commentar from component declartion
Answer
RegEx Code
[ -]*[ .][a-z0-9_.]*$ or [ -]*\w[a-z0-9_]*$
Question
Warning- "Properties (isMemoryDevice) have been set on interface uas - in composed mode these are ignored"
Answer
This warning means that the NIOS® II software tools may not see the isMemoryDevice assignment which will make it harder in the GUI to choose memory addresses at this range as being valid to store boot data
Warning- “Properties (isMemoryDevice) have been set on interface uas – in composed mode these are ignored”
Question
component nios is port ( [...] bridge_cfi_flash_read_n : out std_logic_vector(0 downto 0); [...] );
Error (10476): VHDL error at dionysos_top.vhd(238): type of identifier "flash_oe_n_o" does not agree with its usage as "std_logic_vector" type Error (10558): VHDL error at dionysos_top.vhd(238): cannot associate formal port "bridge_cfi_flash_read_n" of mode "out" with an expression
Answer
Generate as Verilog, edit componen from std_logic_vector to std_logic!
Tri-state conduits and VHDL component
Qsys and tristate bridge
Wrong Answer
Re-create Qsys tree. Updating from earlyer versions (ex. 12.1) to current version (13.1) is NOT safe!
Question
/opt/altera13.1/nios2eds/bin/sof2flash: 6: /opt/altera13.1/nios2eds/bin/sh_jar.sh: Bad substitution
Answer
Question
Why does sof2flash, elf2flash,elf2hex and bin2flash fail from Quartus II 13.1 when run on a Windows PC?
Answer
$ export QUARTUS_BINDIR=${QUARTUS_ROOTDIR}/bin
Installation of Quartus 13.1
Question
# ./setup.sh bash: ./setup.sh: /bin/env: bad interpreter: No such file or directory
Answer
# ln -s /usr/bin/env env
Question
# ./setup.sh You must have the 32-bit compatibility libraries installed for the Quartus II installer and software to operate properly.
Answer
Ubuntu apt-get install ia32 for 32-bit on 64-bit
Installing 32-bit libs on a 64-bit Linux system
$ sudo dpkg --add-architecture i386 $ sudo apt-get install lib32z1 $ sudo apt-get install gcc-4.9-base:i386 libc6:i386 libgcc1:i386 libx11-6:i386 libxau6:i386 libxcb1:i386 libxdmcp6:i386 libxext6:i386 $ sudo apt-get install fontconfig:i386 libexpat1:i386 libfontconfig1:i386 libfreetype6:i386 libpng12-0:i386 zlib1g:i386
Question
How to synthesis the whole project or just some VHDL files in the command-line?
Answer
Using Quartus from command line
Quartus-II Handbook Version 13.0, page 2-10 (or search ASSIGNMENT_FILES) ==> produces one example Makefile $ quartus_map --help=makefiles or $ PATH=$PATH:/opt/altera/13.0/quartus/bin $ quartus_map binary_ops_00000000 --source=binary_ops_00000000.v --family="Cyclone III" $ quartus_fit binary_ops_00000000 $ quartus_eda binary_ops_00000000 --formal_verification --tool=conformal $ cp -v fv/conformal/binary_ops_00000000.vo output.v
Generating a System for Synthesis or Simulation – Generating a Qsys system using the command-line
Knowledge Base: Can I open the Qsys tool from the Command line?
Qsys Scripts
Qsys on 64-bit Linux error
Quartus II Tcl Example: Automatic Script Execution
$ <Quartus II installation directory>\quartus\sopc_builder\bin\ip-generate --help $ <Quartus II installation directory>\quartus\sopc_builder\bin\ip-make-simscript --help $ <ACDS install directory>\quartus\sopc_builder\bin\qsys-edit $ qsys-script $ qsys-generate <QSYS-file> --family=""
Question
How to use SVN revision and current time in VHDL.
Answer
Use TCL-script
Quartus II Tcl Example: Get Subversion Revision Number
$ quartus_sh.exe -t svn_version.tcl [...] Info: Command: quartus_sh -t svn_version.tcl Info: Revision for ../.. is 658 Info: Build time 1425395821 Info (23030): Evaluation of Tcl script svn_version.tcl was successful [...]
# this .tcl script is from http://www.altera.com/support/examples/tcl/tcl-svn-revision.html proc get_subversion_revision { file_name } { global done # The maximum number of seconds to wait for the svn info # command to complete set timeout_seconds 30 # The svn info command with filename that is run (the ./trunk/hdl directory) set cmd "svn info ../.." # Attempt to get the version information. # If the command can't be run, return an error. # Otherwise set up a file event to process the command output. if { [catch {open "|$cmd"} input] } { return -code error $input } else { fileevent $input readable [list get_revision_info $input ] # Set up a timeout so that the process can't hang if the # repository is down. set timeout [after [ expr { $timeout_seconds * 1000 } ] \ [list set done -1] ] # Don't continue until the revision number is found, # or the operation times out. Cancel the timeout anyway. vwait done after cancel $timeout } } proc get_build_time { } { global build_time global tcl_platform set timeout_seconds 30 set OS [lindex $tcl_platform(os) 0] if { $OS == "Windows" } { post_message "Build on Windows: use batch file" set cmd "build_date_win32.bat" } else { post_message "Build on Linux: use date" set cmd "date +%s" } if { [catch {open "|$cmd"} input] } { return -code error $input } gets $input build_time } proc get_revision_info { inp } { global done revision_number if { [eof $inp] } { catch {close $inp} set done 1 } elseif { $done } { gets $inp line } else { gets $inp line # Use a regular expression to match the line with the # revision number. if { [regexp {^Revision:\s+(\d+)\s*$} $line match revision_number] } { set done 1 } } } set path $::env(PATH) post_message "PATH = $path" set done 0 set revision_number "" set build_time "" # The file name is usually your project file .qpf set file_name "../.." #set file_name [lindex $quartus(args) 1] if { [catch { get_subversion_revision $file_name } msg] } { post_message -type critical_warning "Couldn't run command to get revision number. $msg" } else { if { -1 == $done } { post_message -type critical_warning "Timeout getting revision number." set revision_number "0" } elseif { [string equal "" $revision_number] } { post_message -type critical_warning "Couldn't find revision number in output of svn info $file_name." set revision_number "0" } post_message "Revision for $file_name is $revision_number" if { [catch { get_build_time } msg] } { post_message -type critical_warning "Couldn't run command to get build time: $msg" } post_message "Build time $build_time" #create file, overwite if already existing set output [open "../../common_source/core/pm_revision_number.vhd" w] puts $output "LIBRARY IEEE;" puts $output "USE IEEE.STD_LOGIC_1164.ALL;" puts $output "USE IEEE.NUMERIC_STD.ALL;" puts $output "PACKAGE pm_revision_number IS" puts $output "" puts $output "CONSTANT ci_rev_num : integer := $revision_number;" puts $output "CONSTANT ci_build_time : integer := $build_time;" puts $output "" puts $output "END PACKAGE;" puts $output "" close $output }
Info: Command: quartus_sh -t svn_version.tcl compile TCC_PTP_v2 TCC_PTP_v2_top Info: Quartus(args): compile TCC_PTP_v2 TCC_PTP_v2_top Info: PATH = c:\altera\14.1\quartus\bin64\;c:\altera\14.1\quartus\bin64\;C:\Windows\... Info: Revision for ../.. is 658 Critical Warning: Couldn't run command to get build time: couldn't execute "date": no such file or directory Info: Build time Info (23030): Evaluation of Tcl script svn_version.tcl was successful
No PATH to C:/altera/14.1/quartus/bin64/cygwin/bin !!! ==> no date
Scripting and Options for quartus_sh
Run common TCL script on Windows and Linux
what is the windows equivalent of the command “date+%s”
:UnixTime [ReturnVar] [TimeStamp] :: :: Computes the Unix time from the current local time as reported by the :: operating system. The Unix time is the number of seconds that have elapsed :: since midnight Coordinated Universal Time (UTC), January 1, 1970, not :: counting leap seconds. :: :: The result is returned in variable ReturnVar, :: or the result is echoed if ReturnVar is not specified :: :: If the TimeStamp is provided in the 2nd parameter, then the Unix time for :: the TimeStamp is computed, rather then for the current time. :: :: The TimeStamp must have the same format as used by WMIC: :: :: YYYYMMDDhhmmss.ffffffSzzz :: :: where: :: :: YYYY = gregorian year :: MM = month :: DD = day :: hh = hour in 24 hour format :: mm = minute :: ss = seconds :: ffffff = fractional seconds (microseconds) :: S = timezone sign: + or - :: zzz = timezone: minutes difference from GMT :: :: Each component must be zero prefixed as needed to maintain the proper width. :: :: The ReturnVar parameter must be provided in order to use the TimeStamp. :: A ReturnVar of "" will function the same as no ReturnVar. This enables the :: specification of a TimeStamp without an actual ReturnVar. :: @echo off setlocal set "ts=%~2" if not defined ts for /f "skip=1 delims=" %%A in ('wmic os get localdatetime') do if not defined ts set "ts=%%A" set /a "yy=10000%ts:~0,4% %% 10000, mm=100%ts:~4,2% %% 100, dd=100%ts:~6,2% %% 100" set /a "dd=dd-2472663+1461*(yy+4800+(mm-14)/12)/4+367*(mm-2-(mm-14)/12*12)/12-3*((yy+4900+(mm-14)/12)/100)/4" set /a ss=(((1%ts:~8,2%*60)+1%ts:~10,2%)*60)+1%ts:~12,2%-366100-%ts:~21,1%((1%ts:~22,3%*60)-60000) set /a ss+=dd*86400 endlocal & if "%~1" neq "" (set %~1=%ss%) else echo %ss% exit /b
Question
Comparator
Identitäts-Komparatoren (engl. Identity Comparator)
Größen-Komparatoren (engl. Magnitude Comparator)
Komparator (Digitaltechnik)
SN74LS682 – 8-Bit Identity/Magnitude Comparators
How to use dedicate carry in and cascade chain in Altera FPGA?
n-bit generic magnitude comparator
Magnitude Comparator (arithmetical) Generator
Altera: Advanced Synthesis Cookbook
Altera: Logic Elements and Logic Array Blocks in Cyclone IV Device
Altera-Provided Logic & Symbol Libraries
Altera VHDL & Verilog HDL alt_mf Logic Function Library
Lesson 36 – VHDL Example 20: 4-Bit Comparator – Procedures
Parallelized magnitude comparator
N-bit comparator
Answer
Linux BIOS Information
$ sudo dmidecode -t bios Handle 0x0000, DMI type 0, 24 bytes BIOS Information Vendor: Dell Inc. Version: 2.3.1 Release Date: 05/21/2007 Address: 0xF0000 Runtime Size: 64 kB ROM Size: 1024 kB Characteristics: PCI is supported PNP is supported APM is supported BIOS is upgradeable BIOS shadowing is allowed Boot from CD is supported Selectable boot is supported EDD is supported Japanese floppy for Toshiba 1.2 MB is supported (int 13h) Print screen service is supported (int 5h) 8042 keyboard services are supported (int 9h) Serial services are supported (int 14h) Printer services are supported (int 17h) ACPI is supported USB legacy is supported LS-120 boot is supported BIOS boot specification is supported Function key-initiated network boot is supported Targeted content distribution is supported BIOS Revision: 2.3 $ sudo dmidecode [...] Handle 0x0100, DMI type 1, 27 bytes System Information Manufacturer: Dell Inc. Product Name: OptiPlex 745 Version: Not Specified Serial Number: 4Y2563J UUID: 44454C4C-5900-1032-8035-B4C04F36334A Wake-up Type: Power Switch SKU Number: Not Specified Family: Not Specified [...] Handle 0x0400, DMI type 4, 40 bytes Processor Information Socket Designation: Microprocessor Type: Central Processor Family: Core 2 Manufacturer: Intel [...] Handle 0x080D, DMI type 8, 9 bytes Port Connector Information Internal Reference Designator: ENET Internal Connector Type: None External Reference Designator: Not Specified External Connector Type: RJ-45 Port Type: Network Port [...] Handle 0x1000, DMI type 16, 15 bytes Physical Memory Array Location: System Board Or Motherboard Use: System Memory Error Correction Type: Single-bit ECC Maximum Capacity: 8 GB Error Information Handle: Not Provided Number Of Devices: 4 [...] Handle 0x1100, DMI type 17, 27 bytes Memory Device Array Handle: 0x1000 Error Information Handle: Not Provided Total Width: 64 bits Data Width: 64 bits Size: 1024 MB Form Factor: DIMM Set: None Locator: DIMM_1 Bank Locator: Not Specified Type: DDR Type Detail: Synchronous Speed: 667 MHz [...]
Advanced Encryption Standard (AES)
Upgrade Ubuntu
Preferred method
sudo apt-get install update-manager-core sudo do-release-upgrade or sudo apt-get update sudo apt-get upgrade sudo apt-get -f install (not "install -f"!) sudo apt-get -y install apt sudo do-release-upgrade
Use the update-manager
sudo apt-get install update-manager sudo update-manager -d
Can also been used
sudo apt-get update sudo apt-get upgrade sudo apt-get dist-upgrade
Ubuntu Saucy – Upgrading from older versions
FAQ
How to Upgrade From Ubuntu 12.04 LTS to Ubuntu 13.04
How To Upgrade From Ubuntu 13.04 Raring To Ubuntu 13.10 Saucy Salamander – See more at: http://www.unixmen.com/upgrade-ubuntu-13-04-raring-ubuntu-13-10-saucy-salamander/#sthash.00K4bvFQ.dpuf
Can I skip over releases when upgrading?
Upgrade from 12.04 to 13.04?
How do I fix a “Could not get lock /var/lib/dpkg/lock” problem?
/var/cache/debconf/config.dat is locked by another process
debconf: DbDriver “config”: /var/cache/debconf/config.dat is locked by another process
Unable to install due to debconf problem
What do I select for “GRUB install devices” after an update?
Question
$ sudo apt-get install -f E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable) E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
Answer
$ sudo rm /var/lib/dpkg/lock $ sudo rm /var/cache/apt/archives/lock $ sudo rm /var/lib/apt/lists/lock
Question
$ sudo apt-get install -f E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.
Answer
$ sudo dpkg --configure -a [...] debconf: DbDriver "config": /var/cache/debconf/config.dat is locked by another process: Resource temporarily unavailable dpkg: error processing samba-common (--configure): subprocess installed post-installation script returned error exit status 1 [...] dpkg: dependency problems prevent configuration of smbclient: smbclient depends on samba-common (= 2:3.6.6-3ubuntu5.3); however: Package samba-common is not configured yet. dpkg: error processing smbclient (--configure): dependency problems - leaving unconfigured [...] Errors were encountered while processing: samba-common smbclient samba-common-bin rsyslog isc-dhcp-client samba network-manager
Question
debconf: DbDriver "config": /var/cache/debconf/config.dat is locked by another process: Resource temporarily unavailable dpkg: error processing samba-common (--configure)
Answer
$ fuser -v /var/cache/debconf/config.dat # No process uses this file # cp -R /var/cache/debconf /var/cache/debconf.backup # rm /var/cache/debconf/*.dat # dpkg --configure -a Setting up samba-common (2:3.6.6-3ubuntu5.3) ... Replacing config file /etc/samba/smb.conf with new version Setting up smbclient (2:3.6.6-3ubuntu5.3) ... Setting up samba-common-bin (2:3.6.6-3ubuntu5.3) ... Setting up rsyslog (5.8.6-1ubuntu9.3) ... Skipping profile in /etc/apparmor.d/disable: usr.sbin.rsyslogd rsyslog stop/waiting rsyslog start/running, process 3290 Setting up isc-dhcp-client (4.2.4-1ubuntu10.4) ... Setting up samba (2:3.6.6-3ubuntu5.3) ... smbd start/running, process 3348 nmbd start/running, process 3382 Setting up network-manager (0.9.6.0-0ubuntu7.1) ...
Question
Trigger für ureadahead (0.100.0-19) werden verarbeitet ... Trigger für dbus (1.10.6-1ubuntu3) werden verarbeitet ... Trigger für systemd (229-4ubuntu6) werden verarbeitet ... Trigger für initramfs-tools (0.122ubuntu8.1) werden verarbeitet ... update-initramfs: Generating /boot/initrd.img-4.4.0-28-generic Fehler traten auf beim Bearbeiten von: apt apt-utils apt-offline E: Sub-process /usr/bin/dpkg returned an error code (1) ############## apt (1.2.12~ubuntu16.04.1) wird eingerichtet ... useradd: existing lock file /etc/gshadow.lock without a PID useradd: /etc/gshadow konnte nicht gesperrt werden; versuchen Sie es später noch einmal. adduser: »/usr/sbin/useradd -d /nonexistent -g nogroup -s /bin/false -u 122 _apt« gab den Fehlercode 10 zurück. Programmende. usermod: Benutzer »_apt« ist nicht vorhanden. dpkg: Fehler beim Bearbeiten des Paketes apt (--configure): Unterprozess installiertes post-installation-Skript gab den Fehlerwert 6 zurück dpkg: Abhängigkeitsprobleme verhindern Konfiguration von apt-utils: apt-utils hängt ab von apt (= 1.2.12~ubuntu16.04.1); aber: Paket apt ist noch nicht konfiguriert. dpkg: Fehler beim Bearbeiten des Paketes apt-utils (--configure): Abhängigkeitsprobleme - verbleibt unkonfiguriert dpkg: Abhängigkeitsprobleme verhindern Konfiguration von apt-offline: apt-offline hängt ab von apt; aber: Paket apt ist noch nicht konfiguriert. dpkg: Fehler beim Bearbeiten des Paketes apt-offline (--configure): Abhängigkeitsprobleme - verbleibt unkonfiguriert Trigger für libc-bin (2.23-0ubuntu3) werden verarbeitet ... Es wurde kein Apport-Bericht verfasst, da die Fehlermeldung darauf hindeutet, dass dies lediglich ein Folgefehler eines vorherigen Problems ist. Es wurde kein Apport-Bericht verfasst, da die Fehlermeldung darauf hindeutet, dass dies lediglich ein Folgefehler eines vorherigen Problems ist. /sbin/ldconfig.real: /usr/lib/libbrscandec2.so.1 is not a symbolic link /sbin/ldconfig.real: /usr/lib/libbrcolm2.so.1 is not a symbolic link Fehler traten auf beim Bearbeiten von: apt apt-utils apt-offline W: No sandbox user '_apt' on the system, can not drop privileges E: Sub-process /usr/bin/dpkg returned an error code (1)
Answer
$ sudo mv /etc/sub /etc/gshadow.lock_old $ sudo mv /etc/subgid.lock /etc/subgid.lock_old $ sudo mv /etc/subuid.lock /etc/subuid.lock_old $ sudo /usr/sbin/useradd -d /nonexistent -g nogroup -s /bin/false -u 122 _apt