凌云实验室IGKBoard开发板BSP开发相关文件
guowenxue
2023-07-26 9c9d93f07e278d1598118a05224944ab45aaf1b8
Add pinctrl in image

Signed-off-by: guowenxue <guowenxue@gmail.com>
1 files modified
3 files added
230 ■■■■■ changed files
images/build.sh 8 ●●●● patch | view | raw | blame | history
images/files/expand_rootfs 37 ●●●●● patch | view | raw | blame | history
images/files/pinctrl 143 ●●●●● patch | view | raw | blame | history
images/files/pinloop 42 ●●●●● patch | view | raw | blame | history
images/build.sh
@@ -199,7 +199,13 @@
    pr_info "start install root filesystem"
    mount -t ext4 /dev/mapper/${LOOP_DEV}p2 ${MNT_POINT}
    cp -af $ROOTFS/* ${MNT_POINT}
    cp -af $ROOTFS/*                    ${MNT_POINT}
    cp -rf files/pinctrl                ${MNT_POINT}/usr/bin/
    cp -rf files/pinloop                ${MNT_POINT}/usr/bin/
    cp -rf files/expand_rootfs          ${MNT_POINT}/usr/bin/
    chmod +x ${MNT_POINT}/usr/bin/pinctrl
    chmod +x ${MNT_POINT}/usr/bin/pinloop
    chmod +x ${MNT_POINT}/usr/bin/expand_rootfs
    sync && umount ${MNT_POINT}
    pr_warn "Build $DISTRO-$DISVER system image down"
images/files/expand_rootfs
New file
@@ -0,0 +1,37 @@
#!/bin/sh
#
# Copyright (C) 2022 LingYun IoT System Studio
# Author: Guo Wenxue<guowenxue@gmail.com>
#
# This shell script used to expand rootfs partition size to whole TF card space
#
set -e
set -u
# find the root partition information
ROOT_PART="$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')"
ROOT_DEV="/dev/$(lsblk -no pkname /dev/${ROOT_PART})"
PART_DEV="$(lsblk ${ROOT_DEV} | grep -w "\/" | grep mmcblk | awk '{print $1}' | cut -d- -f2)"
PART_NUM="$(echo ${PART_DEV} | cut -dp -f2)"
# Get the starting offset of the root partition
PART_START=$(fdisk -l $ROOT_DEV | grep $PART_DEV | awk '{print $2}')
[ "$PART_START" ] || return 1 ;
fdisk "$ROOT_DEV" > /dev/null 2>&1 <<EOF
p
d
$PART_NUM
n
p
$PART_NUM
$PART_START
p
w
EOF
resize2fs /dev/$ROOT_PART > /dev/null 2>&1
echo "Expand rootfs size successfully, it will be enlarged upon the next reboot."
images/files/pinctrl
New file
@@ -0,0 +1,143 @@
# This shell script used to control GPIO port on IGKBoard
direction=out
sysdir=/sys/class/gpio/
pinbase=0
groupin=32
pinnum=
pindir=
action=
set -u
# RedLed: GPIO01_IO11  GreenLed: GPIO01_IO10 BlueLed: GPIO05_IO09
function usage()
{
   echo "Show pinmap Usage: $0 [-v]"
   echo "Output set  Usage: $0 GPIO01_IO11 [1/0]"
   echo "Input read  Usage: $0 [-i] GPIO01_IO11"
   echo "Unexport    Usage: $0 [-u] GPIO01_IO11"
   exit;
}
function show_pinmap()
{
   echo "
+-------------+-------------+---IGKBoard---+-------------+-------------+
|    GPIO     |     Name    |   Physical  |     Name    |    GPIO     |
+-------------+-------------+-----++------+-------------+-------------+
|     3.3v    |     3.3v    |   1 ||  2   |     5v      |     5v      |
|  GPIO1_IO03 |   I2C1_SDA  |   3 ||  4   |     5v      |     5v      |
|  GPIO1_IO02 |   I2C1_SCL  |   5 ||  6   |     GND     |     GND     |
|  GPIO1_IO18 |      W1     |   7 ||  8   |  UART2_TX   |  GPIO1_IO20 |
|     GND     |     GND     |   9 ||  10  |  UART2_RX   |  GPIO1_IO21 |
|  GPIO1_IO24 |   UART3_TX  |  11 ||  12  |  UART3_RX   |  GPIO1_IO25 |
|  GPIO1_IO28 |   UART4_TX  |  13 ||  14  |     GND     |     GND     |
|  GPIO1_IO29 |   UART4_RX  |  15 ||  16  |  UART7_TX   |  GPIO3_IO21 |
|     3.3v    |     3.3v    |  17 ||  18  |  UART7_RX   |  GPIO3_IO22 |
|  GPIO3_IO27 |   SPI1_MOSI |  19 ||  20  |     GND     |     GND     |
|  GPIO3_IO28 |   SPI1_MISO |  21 ||  22  |     GPIO    |  GPIO3_IO23 |
|  GPIO3_IO25 |   SPI1_SCLK |  23 ||  24  |  SPI1_SS0   |  GPIO3_IO26 |
|     GND     |     GND     |  25 ||  26  |     GPIO    |  GPIO3_IO24 |
|  GPIO1_IO26 |   CAN1_TX   |  27 ||  28  |     PWM8    |  GPIO1_IO15 |
|  GPIO1_IO27 |   CAN1_RX   |  29 ||  30  |     GND     |     GND     |
|  GPIO1_IO22 |   CAN2_TX   |  31 ||  32  |     PWM7    |  GPIO1_IO14 |
|  GPIO1_IO23 |   CAN2_RX   |  33 ||  34  |     GND     |     GND     |
|  GPIO5_IO01 |     GPIO    |  35 ||  36  |     GPIO    |  GPIO1_IO11 |
|  GPIO5_IO08 |     GPIO    |  37 ||  38  |     GPIO    |  GPIO1_IO10 |
|     GND     |     GND     |  39 ||  40  |     GPIO    |  GPIO5_IO09 |
+-------------+-------------+---IGKBoard--+-------------+-------------+
|    GPIO     |     Name    |   Physical  |     Name    |    GPIO     |
+-------------+-------------+-----++------+-------------+-------------+
"
   exit 0;
}
function calc_pinum()
{
   pinstr=$1
   group=`echo $pinstr | cut -d_ -f1 | tr -cd "[0-9]"`
   pin=`echo $pinstr | cut -d_ -f2 | tr -cd "[0-9]"`
   group=`expr $group \- 1`
   pinum=`expr $group \* $groupin + $pin + $pinbase`
   pindir=$sysdir/gpio$pinum
   #echo "INFO: GPIO $pinstr map to pinum[$pinum]"
}
function export_gpio()
{
    if [ -e $pindir ] ; then
       return ;
    fi
    echo $pinum > $sysdir/export
}
function unexport_gpio()
{
    if [ ! -e $pindir ] ; then
       return ;
    fi
    echo $pinum > $sysdir/unexport
}
function set_gpio()
{
    echo out > $pindir/direction
    echo $1 > $pindir/value
}
function read_gpio()
{
    echo in > $pindir/direction
    cat $pindir/value
}
if [[ $# -lt 1 ]] ; then
   usage;
fi
while getopts "iuvh" OPTNAME
do
    case "${OPTNAME}" in
        "i")
           direction=in
           shift
           ;;
        "u")
           action=unexport;
           shift
           ;;
        "v")
           show_pinmap;
           shift
           ;;
        "h")
           usage;
           ;;
    esac
done
calc_pinum $1
if [[ $action == unexport ]] ; then
   unexport_gpio
   exit;
fi
export_gpio
if [[ $direction == in ]] ; then
   read_gpio
else
   set_gpio $2
fi
images/files/pinloop
New file
@@ -0,0 +1,42 @@
#!/bin/sh
# 40 Pin Header GPIO loop test script, it based on pinctrl shell script
function loop_test()
{
   if [[ $# != 3 ]] ; then
      echo "ERROR: Invalid input arguments"
      return 1;
   fi
   level=$3
   pinctrl $1 $level
   res=`pinctrl -i $2`
   printf "$1 out [$level] --> $2 in [$res] : "
   if [[ $level == $res ]]  ; then
      printf " [  OK  ]\n"
   else
      printf " [ FAIL ]\n"
      exit 1;
   fi
}
if [[ $# != 2 ]] ; then
   echo ""
   echo "Usage  : $0 Pin1 Pin2"
   echo "Example: $0 GPIO1_IO10 GPIO1_IO11"
   echo ""
   echo "You can check pinmap by 'pinctrl -v' "
   echo ""
   exit;
fi
loop_test $1 $2 1
loop_test $1 $2 0
loop_test $2 $1 1
loop_test $2 $1 0
exit 0;