Bash script 실행 할 때, 다양한 option에 대한 argument를 넣고, parsing 하는 방법

 

#!/bin/bash

while getopts "hvf:" shortopt
do
	case $shortopt in 
    	h)
        	echo "Usage: $0 [-h] [-v] [-f file_name]"
            	echo "    -h: help"
            	echo "    -v: verbose"
            	echo "    -f filename: input file"
            	exit
            	;;
    	v)
        	VERBOSE=1
            	;;
        f)
        	FILE=$OPTARG
            	;;
        *)
        	echo "default settings"
            	;;
    esac
done

shortopt 가 OPTARG를 가지는 경우 ":"(Colon) 을 포함하고, 그외의 경우의 알파벳을 열거하여 while 문을 구성하면 된다.

'Programming > Bash Script' 카테고리의 다른 글

Bash if statement with regex  (0) 2021.09.06
Bash script for statement  (0) 2018.05.21
Bash Script case statement  (0) 2018.02.06
Bash Script Variable Split by Space  (0) 2018.02.04
Bash Script Echo  (0) 2018.02.04

2019.11.19 기준 Rasbian 의 최신 버전은 Debian Buster 기반으로 되어있다. 따라서, Rasbian에 qbittorrent-nox 를 설치하고자 하는 경우 add-apt-repository 명령으로 repository를 추가하고자 하면 에러가 발생한다.

따라서 Debian 홈페이지로 부터 qbittorrent-nox deb 파일을 다운받아 설치하면 된다.

라즈베리파이3의 경우 armhf 아키텍쳐 용을 라즈베리파이4의 경우 arm64 아키텍쳐 용을 다운받아 설치 하면 될 것이다.

설치 명령어는 다음과 같다.

$ sudo dpkg -i <downloaded_deb_file>

 

설치 후 Service 등록 등은 Github 설명 참조.

 

'Programming > RaspberryPi' 카테고리의 다른 글

Install Nextcloud on RaspberryPi  (0) 2023.03.15
Install Owncloud on RaspberryPi  (0) 2023.03.15
SD card image backup  (0) 2018.10.12
SDcard Partition Resize  (0) 2018.08.21
RaspberryPi Remote Desktop Client  (0) 2018.06.01

FPGA 같은 하드웨어를 사용하다보면, 가끔 데이터가 꼬일 때, Endianness 문제일 까 싶을 때가 있다.

간단한 C 코드를 통해 System의 Endianness 를 확인 할 수 있다.

 

예 1) 전처리기 활용

#if __BYTE_ORDER == __LITTLE_ENDIAN
	printf("Little Endian\n");
#elif __BYTE_ORDER == __BIG_ENDIAN
	printf("Big Endian\n");

예 2) Pointer 활용

int x = 1;
char* cp = &x;

if(*cp == 1){
	printf("Little Endian\n");
}
else{
	printf("Big Endian\n");
}

 

'Programming > C Language' 카테고리의 다른 글

C progress printing  (0) 2018.08.07
static  (0) 2018.07.13
가변 인자(variable arguments) stdarg.h  (0) 2017.12.11
extern  (0) 2017.06.21
static  (0) 2017.06.20

Hierarchy of the DRAM Subsystem

Every channel has its own memory controller that means it has its own address, command, and data bus.

In a rank, the address and command bus are shared to all chips, but the data bus is dedicated to a chip. Therefore the rank can offer a wide interface.

In a chip, all of the address, command, and data bus are shared to banks. However, in each bank, the address, command, and data are latched, and each bank operates its own command.

A column can be accessed when a row is open(activated).

 

DRAM Operation

DRAM Operation starts with row activation. Activating a row means select and open a row of DRAM cells in a specific bank and then the data could be accessed through row buffer(which is also called sense amplifier) in size of a column. When accessing a row is finished then, the row should be precharged(closed) for activating another row. 

The most critical timing parameters of DRAM are tRCD, tCL, tRP. tRCD stands for RAS to CAS delay time which means activating a row is finished and the row is ready to read or write, after tRCD from the ACT(Activation) command. Once RD(Read) or WR(Write) command, data could be transferred after tCL. And when accessing a row is finished, the PRE(Precharge) command should be followed. Precharging a row takes tRP. 

Because the row address is transferred with ACT command and the column address is transferred with RD/WR, which means that row and column address are not used simultaneously, address pins could be shared. 

 

DRAM Bank Structure

DRAM Bank is a set of rows and columns, which operates a command. A DRAM chip consists of multiple banks, and each bank could operate its own command. However, the command, address, data pins are shared to all of the banks, and all of DRAM commands are synchronized, DRAM operations could be pipelined. With pipelining, bank structure is good for hiding long latency of DRAM(tRCD, tCL, tRP, etc).

This is a logical structure of a DRAM Bank. All of the pin counts are referenced from Micron DDR4 8Gb X8 DRAM Chip. In this case, a DRAM bank consists of 64K rows and 1K columns. This chip has 8 bit of data pin, generally, 8 of chips are combined into a DIMM. With 8 chips, each of 8 data pins, and 8 burst length, 64Byte of data could be read or write at single DRAM command. Row buffer size is 8Kb for each chip. 

This is a functional block diagram from Micron DDR4 8Gb X8 DRAM chip. Note that it is a chip. Because DDR4 uses 8 burst length, it seems that 64 bit of data in the row buffer could be transferred to FIFO, in a operation. The LSB 3 bits of column address are discarded, and 8 columns, each of 8 bits are accessed at once.

'Programming > Computer Architecture' 카테고리의 다른 글

Cache write policies  (0) 2022.10.31

일반적인 Linux 배포판을 쓰지 않고, Kernel source와 Root file system 으로 부터 Linux system 을 구성한 경우,

Linux runtime 에 kernel module을 compile 하여 insmod/rmmod 를 할 수 있다.


Kernel module을 컴파일 하기 위해서는 현재 Linux system 에서 사용되고 있는 kernel source를 필요로 한다.

일반적인 방법과 유사하게 사용하기 위해

kernel source 를 /usr/src 디렉토리에 위치시키고,

/lib/modules/<kernel_version>/build 와 symbolic link 시킨다.

# cd /lib/modules/<kernel_version>

# ln -s /usr/src/<kernel_source_dir> build

커널 모듈을 컴파일 하기 위한 준비 작업은 아래 와 같다.

# cd /usr/src/<kernel_source_dir>

# make <defconfig>

# make prepare

# make scripts

※ 참조: http://www.fun25.co.kr/blog/linux-ubuntu-14-04-kernel-module-compile


kernel module을 컴파일 할 Makefile은 아래와 같이 구성한다.

obj-m := test_module.o


all:

make -C /lib/modules/<kernel_version>/build M=$(PWD) modules

clean:

make -C /lib/modules/<kernel_version>/build M=$(PWD) clean

아래는 테스트를 위한 기본적인 kernel module source code.

#include <linux/module.h>

#include <linux/kernel.h>


int init_module(void){

printk(KERN_ALERT"Hello"\n);

return 0;

}


void cleanup_module(void){

printk(KERN_ALERT"Bye"\n);

}


kernel module을 컴파일 하고, insmod/rmmod 를 통해 test 한다.

# make

# insmod <kernel_module>.ko

# rmmod <kernel_module>.ko

※ 이 때, 현재 Linux system 에서 사용되는 kernel 과 다른 source로 부터 kernel module을 컴파일 하게 되면 version 차이로 오류가 나타난다.

'Programming > Linux Kernel' 카테고리의 다른 글

cross kernel debugging  (0) 2020.06.19
Kernel module programming  (0) 2018.05.23
Kernel Version Check  (0) 2018.05.23
Kernel 프로그래밍 - printk  (0) 2017.06.20

Ubuntu 에서 Headless browser 인 PhantomJS를 설치하는 방법을 소개한다.


PhantomJS는 기본적으로 Multi platform 을 지원하여, Windows, Linux, FreeBSD 등 다양한 OS 상에서 구동 될 수 있다.

Architecture / OS 에 따라 기본적으로 제공되는 파일을 사용하여 설치 할 수 없는 경우

Github 로 부터 source code를 다운 받아 설치 할 수 있다.


PhantomJS에서 필요한 패키지(Qt, WebKit 등)를 자동으로 설치 하기 떄문에 Dependency가 없다고 하지만,

Ruby, gperf 등 일부 패키지를 설치 하지 않으면 install 도중 Error를 맞이하게 된다.


Prerequisites

1. Ruby Installation

Ruby install은 RVM(Ruby Version Manager)를 통해 할 수 있다. 따라서, Ruby install 을 위한 RVM install 이 필요하다. 

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

$ cd /tmp && \curl -sSL https://get.rvm.io -o rvm.sh

$ cat /tmp/rvm.sh | bash -s stable

*참조: https://www.rosehosting.com/blog/install-ruby-on-rails-on-ubuntu-16-04/

RVM이 설치 되면, Ruby를 설치 할 수 있다. 


RVM 실행

$ source /usr/local/rvm/scripts/rvm


RVM에서 설치 가능한 Ruby version 확인

$ rvm list known


Ruby 설치(stable 최신 버전 2.5.1, 2018.12.10 기준)

$ rvm install 2.5.1


2. Gperf Installation

$ sudo apt-get install gperf


Git source Fetch

$ git clone https://github.com/ariya/phantomjs


PhantomJS Installation from source

$ cd phantomjs

$ ./build.py 

(시간이 꽤 걸린다.)

'Programming > Linux' 카테고리의 다른 글

Piping ls to cp  (0) 2020.12.02
How to use GDB  (0) 2020.03.12
Linux screen  (0) 2018.09.27
Xshell + Xming  (0) 2018.09.10
Memtester  (0) 2018.07.15

누구나 말하기 전에 세 문을 거쳐야 한다. 그것이 참말인가, 그것이 필요한 말인가, 그것이 친절한 말인가

 - 「개인주의자 선언」 중에서


'Life > A sentense of the day' 카테고리의 다른 글

인생에서 절대 잊어버리지 말아야 할 사람  (0) 2020.03.01
인정  (0) 2020.02.06
  (0) 2018.11.22
불행한 이유  (0) 2018.11.06
기회주의자  (0) 2018.07.05

"타인에게 공감하지 못하는 무능력, 그것이 바로 악이다"

 - 알쓸신잡3 중에서

'Life > A sentense of the day' 카테고리의 다른 글

인정  (0) 2020.02.06
세 황금문  (0) 2018.12.03
불행한 이유  (0) 2018.11.06
기회주의자  (0) 2018.07.05
추억  (0) 2018.06.20

우리가 더 불행한 이유는 결국 우리 스스로 자승자박하고 있기 떄문 아닐까

 - 「개인주의자 선언」 중에서

'Life > A sentense of the day' 카테고리의 다른 글

세 황금문  (0) 2018.12.03
  (0) 2018.11.22
기회주의자  (0) 2018.07.05
추억  (0) 2018.06.20
뭐하고 있을까?  (0) 2018.06.19

라즈비안이 들어있는 SD 카드를 이미지로 백업하고 싶은 경우 

Win 32 Disk Imager 로 백업 이미지를 만들 수 있다.


방법은 간단하다.

1. Win 32 Disk Imager 설치

2. Backup 할 SD 카드를 꼽고

3. Win 32 Disk Imager 에서 Backup 할 Drive를 선택 + output Image 가 될 파일을 지정

※ 파티션이 여러개 여서, 여러 개의 Drive로 보이더라도, Linux File system 이라 윈도우에서 안보이는 경우여도 첫 번째 파티션을 선택하면 전체 백업 된다.

4. Read


백업된 이미지를 다시 SD 카드에 쓰기위해서는

1. Win 32 Disk Imager 에서 Backup 된 image를 선택 + Drive 지정

2. Write

※ 이때, Backup 된 이미지는 기존 SD 카드의 크기를 가지기 때문에, 복원을 위해서는 기존 SD 카드의 크기보다 크거나 같은 SD 카드가 필요하며, 기존 SD 카드보다 큰 SD 카드의 경우 복원 후 resize 가 필요하다.


'Programming > RaspberryPi' 카테고리의 다른 글

Install Owncloud on RaspberryPi  (0) 2023.03.15
Rasbian qbittorrent-nox installation  (0) 2019.11.19
SDcard Partition Resize  (0) 2018.08.21
RaspberryPi Remote Desktop Client  (0) 2018.06.01
Raspbian Korean(Hangul) Install  (0) 2018.05.18

+ Recent posts