此範例我們新增一個tester使用者,並讓他有admin權限能使用sudo
1. 首先我們必須要先有一個admin權限的使用者先登入(例如:root)
2. 接著使用下面指令,新增一個使用者,過程中會要求你輸入密碼:
#adduser tester
3. 接著我們使用指令"usermod" 來把tester 加入到 sudo 群組
#usermod -a -G sudo tester
接下來你就可以使用 sudo 來作一些需要權限的事情了~
2018年4月2日 星期一
2018年3月27日 星期二
【Linux Tool】i2c-tools 的使用方法, i2cdetect 、 i2cdump、i2cset
i2c-tools是一套OpenSource,透過這個tools我們可以透過i2c 介面與 IC 去作溝通
我們可以到下面的網站去抓整包的SourceCode,然後再透過你的toolchain去編譯出你板子上可以使用的工具,而編譯的方式我這邊就不贅述,我們這篇著重在tool如何使用
Download Path:
https://i2c.wiki.kernel.org/index.php/I2C_Tools
====================================================================
編譯完成後你應該會有i2cdetect、i2cdump、i2cset 這幾個執行檔
i2cdetect ===> 會列出 i2c的 Bus上所有的Device
i2cdump ===> 會列出 Device上所有的 Register值
i2cset ===> 可寫入到某個 Bus上的某個 Device上的 Register值
以下是實際操作的範例:
#./i2cdetect -l ===> 列出總共有幾個 i2c Bus
從上圖我們可以知道,這台設備上總共有 0 ~ 8 個 I2C Bus
另外我們也可以使用 i2cdetect 來確認 Bus上有哪些 Device
#./i2cdetect -r -y 1 ===> 列出 Bus 1上的所有Device
從上圖我們可以知道,這台設備的 I2C Bus1上,有4個Device,位置分別在 0x37, 0x4a, 0x4b, 0x50
接著我們來使用i2cdump來把某個 Register的值列出來吧!
#./i2cdump -f -y 1 0x50 ===> 列出 Bus1 的 Device 0x50的 Register值
最後我們使用 i2cset來更改Register的值吧!
#./i2cset -y 1 0x50 0x36 0x05 ===> 寫入 Bus1 的 Device 0x50的 0x36 Register值 寫入 0x05
註: i2cset的用法:
#./i2cset -y <bus> <device> <register> <value>
我們可以到下面的網站去抓整包的SourceCode,然後再透過你的toolchain去編譯出你板子上可以使用的工具,而編譯的方式我這邊就不贅述,我們這篇著重在tool如何使用
Download Path:
https://i2c.wiki.kernel.org/index.php/I2C_Tools
====================================================================
編譯完成後你應該會有i2cdetect、i2cdump、i2cset 這幾個執行檔
i2cdetect ===> 會列出 i2c的 Bus上所有的Device
i2cdump ===> 會列出 Device上所有的 Register值
i2cset ===> 可寫入到某個 Bus上的某個 Device上的 Register值
以下是實際操作的範例:
#./i2cdetect -l ===> 列出總共有幾個 i2c Bus
從上圖我們可以知道,這台設備上總共有 0 ~ 8 個 I2C Bus
另外我們也可以使用 i2cdetect 來確認 Bus上有哪些 Device
#./i2cdetect -r -y 1 ===> 列出 Bus 1上的所有Device
從上圖我們可以知道,這台設備的 I2C Bus1上,有4個Device,位置分別在 0x37, 0x4a, 0x4b, 0x50
接著我們來使用i2cdump來把某個 Register的值列出來吧!
#./i2cdump -f -y 1 0x50 ===> 列出 Bus1 的 Device 0x50的 Register值
最後我們使用 i2cset來更改Register的值吧!
#./i2cset -y 1 0x50 0x36 0x05 ===> 寫入 Bus1 的 Device 0x50的 0x36 Register值 寫入 0x05
註: i2cset的用法:
#./i2cset -y <bus> <device> <register> <value>
2018年3月14日 星期三
讓 Ubuntu 可以透過網路 ssh登入
只需要安裝ssh server,安裝指令如下:
#apt-get install openssh-server
之後Ubuntu開機會自己啟動 ssh server ~
安裝完成之後也可以透過netstat 指令來確認 sshd有在port 22啟動
#netstat -tulpn | grep 22
#apt-get install openssh-server
之後Ubuntu開機會自己啟動 ssh server ~
安裝完成之後也可以透過netstat 指令來確認 sshd有在port 22啟動
#netstat -tulpn | grep 22
如何讓Ubuntu 16.04 啟動時,直接進入文字模式,不進入X11
很簡單,只需要下面一行指令,他會幫你把link到 lightmd 的link檔案刪除,因此開機就直接進入文字介面
1. sudo systemctl disable display-manager
如果想要恢復,一開機就進入X11 GUI介面:
1. sudo ln -s -f /lib/systemd/system/lightdm.service /etc/systemd/system/display-manager.service
如果在文字模式下,想要暫時回到X11模式,可以先輸入:
1. /usr/sbin/lightmd
1. sudo systemctl disable display-manager
如果想要恢復,一開機就進入X11 GUI介面:
1. sudo ln -s -f /lib/systemd/system/lightdm.service /etc/systemd/system/display-manager.service
如果在文字模式下,想要暫時回到X11模式,可以先輸入:
1. /usr/sbin/lightmd
2018年2月1日 星期四
【shell script】shell script的 "字串比較","數字相加","數字判斷","數字累加","取字串長度",的用法
shell script 的字串比較:
yn="GG"
if [ "${yn}" == "GG" ]; then
echo "is the same !!"
fi
shell script 的數字相加:
a="10"
b="20"
c=`expr $a + $b`
shell script 的數字判斷:
declare -i num="60"
if [ $num -gt 50 ]; then
echo "correct !!!"
fi
shell script 的數字累加:
count="1"
count=$(($count+1))
echo "$count"
yn="GG"
if [ "${yn}" == "GG" ]; then
echo "is the same !!"
fi
shell script 的字串比較方法2 (如果上面判斷行不通):
yn="GG"
yn="GG"
um="GG"
if [ ${yn} == ${um} ]; then
echo "is the same !!"
fi
if [ ${yn} == ${um} ]; then
echo "is the same !!"
fi
shell script 的數字相加:
a="10"
b="20"
c=`expr $a + $b`
shell script 的數字判斷:
declare -i num="60"
if [ $num -gt 50 ]; then
echo "correct !!!"
fi
shell script 的數字累加:
count="1"
count=$(($count+1))
echo "$count"
shell script 的取字串長度:
STR="12345678"
STR="12345678"
LEN=`echo ${#STR}`
echo "STR length is $LEN" => 印出 "STR length is 8"
2018年1月19日 星期五
【Linux cmd】查找Linux某個指令的source code,以mke2fs為例
今天在找mke2fs 是哪包Source Code 所編譯出來的
查詢的方式很簡單,使用以下指令即可:
首先先找出mke2fs的路徑,我們知道他位於 /sbin/mke2fs
於是我們使用dpkg -S 來作查詢
#dpkg -S /sbin/mke2fs
所以我們可以知道,mke2fs 是由 e2fsprogs 所產出的執行檔
不過這招只適用於查找 apt-get install 之後所產出的指令,如果是自己進行編譯所產出的,使用dpkg 是找不到的~
查詢的方式很簡單,使用以下指令即可:
首先先找出mke2fs的路徑,我們知道他位於 /sbin/mke2fs
於是我們使用dpkg -S 來作查詢
#dpkg -S /sbin/mke2fs
所以我們可以知道,mke2fs 是由 e2fsprogs 所產出的執行檔
不過這招只適用於查找 apt-get install 之後所產出的指令,如果是自己進行編譯所產出的,使用dpkg 是找不到的~
2018年1月12日 星期五
error: dereferencing pointer to incomplete type ‘struct task_struct’
今天在編譯iqvlinux的時候,之前在kernel 4.10.17編譯時,都不會有什麼error產生
而今天改成在kernel 4.14.12編譯時出現了以下的錯誤訊息:
make: Entering directory '/home/danny/platform/project-4.14.12/linux-4.14.12'
CC [M] /home/danny/platform/project-4.14.12/sysapps/gmac/iqvlinux/src/linux/driver/linuxnaldriver.o
In file included from /home/danny/platform/project-4.14.12/sysapps/gmac/iqvlinux/src/linux/driver/linuxnaldriver.c:42:0:
./arch/x86/include/asm/uaccess.h: In function ‘set_fs’:
./arch/x86/include/asm/uaccess.h:33:9: error: dereferencing pointer to incomplete type ‘struct task_struct’
current->thread.addr_limit = fs;
^
而今天改成在kernel 4.14.12編譯時出現了以下的錯誤訊息:
make: Entering directory '/home/danny/platform/project-4.14.12/linux-4.14.12'
CC [M] /home/danny/platform/project-4.14.12/sysapps/gmac/iqvlinux/src/linux/driver/linuxnaldriver.o
In file included from /home/danny/platform/project-4.14.12/sysapps/gmac/iqvlinux/src/linux/driver/linuxnaldriver.c:42:0:
./arch/x86/include/asm/uaccess.h: In function ‘set_fs’:
./arch/x86/include/asm/uaccess.h:33:9: error: dereferencing pointer to incomplete type ‘struct task_struct’
current->thread.addr_limit = fs;
^
發生錯誤的流程如下說明:
編譯到linuxnaldriver.c的42行,這邊第42行是去include <asm/uaccess.h>,接著錯誤訊息就說明錯誤發生在 set_fs(),然後最後的錯誤是在 uaccess.h 的第33行,錯誤訊息就是如上面的error那行
查了一下google,很多人都說只要include header就可以解決,於是我先找了一下‘struct task_struct’的結構宣告在哪個檔案,google之後發現在<linux/sched.h>
於是我在 linuxnaldriver.c 42行前面加了 #include <linux/sched.h>
再進行編譯,於是就編譯成功了
訂閱:
文章 (Atom)



