-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GPIO SIM #46
Open
Trenton-Ruf
wants to merge
5
commits into
master
Choose a base branch
from
gpio-sim
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
GPIO SIM #46
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7f7faae
Adding GPIO-SIM support for Debian development machines
Trenton-Ruf bb64b31
Update README.md
Trenton-Ruf 7283815
Update README.md
Trenton-Ruf fb4aa56
updated instructions with sudo commands
Trenton-Ruf 43fb2a9
Moved apt-get commands out of kernel_build_debian.sh script and into …
Trenton-Ruf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# GPIO-SIM | ||
For working with Simulated GPIOs | ||
|
||
## Setup | ||
|
||
### Build and install the linux Kernel from source | ||
Adds the GPIO-SIM kernel module and its dependencies | ||
- Debian | ||
```bash | ||
# Install prerequisites | ||
sudo apt-get update | ||
sudo apt-get -y install dpkg-dev | ||
sudo apt-get -y install build-essential fakeroot | ||
sudo apt-get -y build-dep linux | ||
|
||
# Get linux source | ||
sudo apt-get -y install linux-source | ||
|
||
# Build and install kernel | ||
./kernel_build_debian.sh | ||
``` | ||
### Add udev rules giving user permissions for GPIO | ||
```bash | ||
./gpio_rules.sh | ||
``` | ||
## USE | ||
|
||
### Add simulated GPIO chips and lanes to configfs | ||
- Parses from the device-tree | ||
- Must be run on each boot, consider adding to ~/.bashrc | ||
```bash | ||
sudo ./setup_sims.sh | ||
``` | ||
### remove simulated GPIO chips | ||
```bash | ||
sudo ./clean_sims.sh | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
# SPDX-FileCopyrightText: 2023 Kent Gibson <[email protected]> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
# A helper to remove any orphaned gpio-sims from the system. | ||
# This should only be necessary if a test was killed abnormally | ||
# preventing it from cleaning up the sims it created, or if you | ||
# created a sim using basic_sim.sh. | ||
|
||
SIMDIR="/sys/kernel/config/gpio-sim" | ||
find $SIMDIR -type d -name hog -exec rmdir '{}' '+' | ||
find $SIMDIR -type d -name "line*" -exec rmdir '{}' '+' | ||
find $SIMDIR -type d -name "bank*" -exec rmdir '{}' '+' | ||
rmdir $SIMDIR/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
sudo groupadd gpiod | ||
sudo usermod -aG gpiod $USER | ||
|
||
# This gives user permissions for all gpio. | ||
# Might want to change it to specific pins? | ||
|
||
echo '# udev rules for gpio port access through libgpiod | ||
SUBSYSTEM=="gpio", KERNEL=="gpiochip[0-4]", GROUP="gpiod", MODE="0660"' | sudo tee /etc/udev/rules.d/60-gpiod.rules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
|
||
# For Debian | ||
# Build and install GPIO-SIM kernel module | ||
# Main reference https://www.debian.org/doc/manuals/debian-kernel-handbook/ch-common-tasks.html | ||
|
||
# Get the directory of the sourced script | ||
SCRIPT_DIR=$(dirname "$(realpath "$0")") | ||
|
||
# Make the build directory | ||
BUILD_DIR=$SCRIPT_DIR/Kernel_Build | ||
mkdir -p $BUILD_DIR | ||
|
||
cd /usr/src | ||
# Find the latest version of the downloaded source | ||
SOURCE=$(ls | grep linux-source | sort -V | tail -n 1) | ||
|
||
# Extract the source | ||
tar xaf /usr/src/$SOURCE -C $BUILD_DIR | ||
|
||
# Get the version number (X.Y) from the source name | ||
VERSION=${SOURCE#linux-source-} | ||
VERSION=${VERSION%.tar.bz2} | ||
VERSION=${VERSION%.tar.xz} | ||
|
||
# Move into the source directory in the build directory | ||
cd $BUILD_DIR/linux-source-$VERSION | ||
|
||
# Build the Kernel | ||
MAKEFLAGS="-j$(nproc) LOCALVERSION=-gpio-sim CONFIG_GPIO_SIM=y" | ||
make clean | ||
make oldconfig # Combine this Kernel's configuration with the current running Kernel | ||
make deb-pkg $MAKEFLAGS | ||
|
||
# Move to the parent directory where the .deb files are located | ||
cd .. | ||
|
||
# Confirm before installing the kernel packages | ||
read -p "Are you sure you want to install the kernel packages? (y/n) " -n 1 -r | ||
echo # (optional) move to a new line | ||
if [[ $REPLY =~ ^[Yy]$ ]] | ||
then | ||
sudo dpkg -i linux-image*.deb linux-headers*.deb | ||
echo "Restart your machine to have the new build-in modules load on boot" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/bin/bash | ||
|
||
# Creates GPIO-SIM entries that match the device-tree configuration | ||
# described in FILE | ||
|
||
# Get the directory of the sourced script | ||
script_dir=$(dirname "${BASH_SOURCE[0]}") | ||
|
||
# The device tree file to parse | ||
FILE=$script_dir/../device_trees/oresat-c3-0601.dts | ||
|
||
mountpoint /sys/kernel/config > /dev/null || mount -t configfs configfs /sys/kernel/config | ||
|
||
# Initialize banks | ||
# 4 banks 32 gpio each | ||
dir=/sys/kernel/config/gpio-sim/basic | ||
for i in {0..3} | ||
do | ||
mkdir -p $dir/bank$i | ||
echo 32 > $dir/bank$i/num_lines | ||
done | ||
|
||
# Read the device tree file line by line | ||
while IFS= read -r line | ||
do | ||
# Check if the line contains "gpio-name" | ||
if [[ $line == *"gpio-name"* ]]; then | ||
# Extract the gpio-name | ||
gpio_name=$(echo $line | cut -d'"' -f 2) | ||
echo "GPIO Name: $gpio_name" | ||
|
||
read -r line | ||
# Extract the gpiochip number and lane number | ||
gpiochip_number=$(echo $line | cut -d' ' -f 3 | tr -dc '0-9') | ||
lane_number=$(echo $line | cut -d' ' -f 4) | ||
echo "GPIOCHIP Number: $gpiochip_number" | ||
echo "Lane Number: $lane_number" | ||
|
||
mkdir -p $dir/bank$gpiochip_number/line$lane_number | ||
echo "$gpio_name" > $dir/bank$gpiochip_number/line$lane_number/name | ||
|
||
# not setting direction becauase gpio-sim does not allow setting an initial direction | ||
# Only when "hogging" the lane by the kernel it can set as input, output-high, and output-low | ||
|
||
# read -r line | ||
## Extract the direction | ||
# direction=$(echo $line | tr -d '[:space:]' | sed 's/;$//') | ||
# echo "Direction: $direction" | ||
|
||
#mkdir -p dir/bank$gpiochip_number/line$lane_number/hog/ | ||
#echo "hog-name-example" > $dir/bank$gpiochip_number/line$lane_number/hog/name | ||
#echo "$direction" > $dir/bank$gpiochip_number/line$lane_number/hog/direction | ||
# | ||
fi | ||
|
||
done < "$FILE" | ||
|
||
echo 1 > $dir/live |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is running on an OreSat card, you can read from
/boot/dtbs/<kernel_verion>/am335x-pocketbeagle.dtbo
(it is symbolically linked to correct device tree) rather than hard-coding thisThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this will be running on a development machine rather than the C3 it needs to grab the dts file.