12/30/2014

GNU binutils 관련 정리

Linux 에서 App을 사용하다 보면 Debug이 필요할 때 있다.
이때 GCC에서 기본적으로 제공하는 Binutils 이다.

  • GNU Binutils
binutil 은 Cross Compiler를 직접 만들어 보신분들은 다 알거라고 생각든다. 
보통 Cross Compiler를 직접 GCC 기반으로 빌드해서 만드다고 하면, 가장먼저해야 할게 Binutil 빌드 작업이다.  
예전에는 GCC에 포함이 안되어진 것인데, 요즘은 직접 Cross Compiler를 빌드해서 만들어 본적이 없으니, 확인을 못하겠다. 
아래링크를 보니, 요즘 gprof도 같이 들어가는 것 같다. 
  https://en.wikipedia.org/wiki/GNU_Binutils


나의 경우는 주로 사용되는 것은 debug 확인용을 위해서 주로 사용되는 것이 readelf 인 것 같다.
  1. 사용되어지는 동적 Library 사용여부 확인 
  2. 심볼Table 확인  
  3. 이외 

  • readelf 기본 활용
아래와 같이 일반 symbol table을 분석하는 것이 편하며, dynmic symbol은 동적으로 연결되어 동작한다.
$ readelf -s ./bin/ti816x/bin/dvr_rdk_demo_mcfw_api.out   //쉽게 검색

$ readelf -s ./bin/ti816x/bin/dvr_rdk_demo_mcfw_api.out | grep  FILE

$ readelf -Ws ./bin/ti816x/bin/dvr_rdk_demo_mcfw_api.out | grep  FUNC   //Type 별로 검색 (길이제한해제)

$ readelf -Ws ./bin/ti816x/bin/dvr_rdk_demo_mcfw_api.out | grep  OBJECT //Type 별로 검색

$ readelf -S /usr/bin/ls   //각 Section 확인 (.got/.data/.text/...) 

$ readelf -l /usr/bin/ls   //각 Section 과 Segment Mapping 된것 확인(MMU에서 사용하기위해) 

$ readelf -x /usr/bin/ls   //각 Section Binary Dump  

  • ldd 기본활용 및 Linker 확장 
$ readelf -d /usr/bin/ls   | grep xxx  // ELF에서 LinkingLoader가 연결할 Shared Library 확인 

$ ldd ./bin/ls   | grep xxx  // ELF 동적연결된 so 파일 확인 및 PATH 확인 

/* 
결론적으로 readelf로 확인하는게 편하지만, ldd로 왜 더 나오는지는 완벽히는 이해가 되지 않지만, 
readelf -d 는 app이 필요한 것을 보여준다고 한다.
ldd 의 경우는 linkingloader가 필요한 것을 보여준다고 한다. 
문제가 생기면, LD_LIBRARY_PATH export로 확장하자 
*/

$ echo $LD_LIBRARY_PATH  // 만약 문제있다면, export로 확장

ldd 와 readelf 관련사항 
나와 같은 삽질을 해서 여기다 링크로 추가 
  

GCC Color 출력 (GCC 4.9이후 버전)
  https://xaizek.github.io/2015-10-25/enable-colorization-of-gcc-output/

  • readelf -h 기본정보확인 
http://forum.falinux.com/zbxe/index.php?document_srl=781536&mid=lecture_tip
$ readelf
Usage: readelf  elf-file(s)
 Display information about the contents of ELF format files
 Options are:
  -a --all               Equivalent to: -h -l -S -s -r -d -V -A -I    //모르면, -a 전체확인 
  -h --file-header       Display the ELF file header
  -l --program-headers   Display the program headers
     --segments          An alias for --program-headers
  -S --section-headers   Display the sections' header
     --sections          An alias for --section-headers
  -g --section-groups    Display the section groups
  -t --section-details   Display the section details
  -e --headers           Equivalent to: -h -l -S
  -s --syms              Display the symbol table      //symbols 전체확인 
     --symbols           An alias for --syms
  --dyn-syms             Display the dynamic symbol table   //다른 so 파일에 있음  
  -n --notes             Display the core notes (if present)
  -r --relocs            Display the relocations (if present)
  -u --unwind            Display the unwind info (if present)
  -d --dynamic           Display the dynamic section (if present)
  -V --version-info      Display the version sections (if present)
  -A --arch-specific     Display architecture specific information (if any)
  -c --archive-index     Display the symbol/file index in an archive
  -D --use-dynamic       Use the dynamic section info when displaying symbols
  -x --hex-dump=
                         Dump the contents of section name as bytes
  -p --string-dump=
                         Dump the contents of section name as strings
  -R --relocated-dump=
                         Dump the contents of section name as relocated bytes
  -z --decompress        Decompress section before dumping it
  -w[lLiaprmfFsoRtUuTgAckK] or
  --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames, //Debug 정보인, DWARF 확인가능 
               =frames-interp,=str,=loc,=Ranges,=pubtypes,
               =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,
               =addr,=cu_index,=links,=follow-links]
                         Display the contents of DWARF debug sections
  --dwarf-depth=N        Do not display DIEs at depth N or greater
  --dwarf-start=N        Display DIEs starting with N, at the same depth
                         or deeper
  --ctf=                 Display CTF info from section 
  --ctf-parent=
                         Use section  as the CTF parent

  --ctf-symbols=
                         Use section  as the CTF external symtab

  --ctf-strings=
                         Use section  as the CTF external strtab

  -I --histogram         Display histogram of bucket list lengths
  -W --wide              Allow output width to exceed 80 characters     //symbols 길이 
  @file                Read options from file
  -H --help              Display this information
  -v --version           Display the version number of readelf


  • readelf 기본메뉴얼 
http://linuxcommand.org/man_pages/readelf1.html


  • ELF format 구조 
일반적으로 a.out format 과 coff format 는 동적링킹이 안되어져서 거의 사용이 안되어진다.
Linux의 경우, ELF의 경우에만 가능하며, 더불어 Debuging 정보인 DWARF도 포함가능
다들 알거라고 생각해서 아래에 간단히 링크로 연결  
  https://ko.wikipedia.org/wiki/ELF_%ED%8C%8C%EC%9D%BC_%ED%98%95%EC%8B%9D
  https://en.wikipedia.org/wiki/Executable_and_Linkable_Format


  • 이외 objdump 이용 
$ objdump -d   filename   // --disassemble  되면서 각 쉽게 Entry Point 확인가능하며 Debug시 보통 같이 나오는 것을 확인가능           

$ objdump -s /bin/ls    // binary dump 로 실제 Data 확인

  https://m.blog.naver.com/PostView.nhn?blogId=s2kiess&logNo=220066239893&proxyReferer=https%3A%2F%2Fwww.google.com%2F
  https://talkingaboutme.tistory.com/791
  https://talkingaboutme.tistory.com/795?category=478749

12/16/2014

Linux sys file system Simple 예제 (커널테스트용으로 작성)

1. Kernel 내부의 sys filesystem 로 Debug  

Kernel에서 내가 원하는 부분정보를 얻고,  설정을 변경하기 위해서 테스트용 sys filesystem을 추가구현해보도록 한다.

  • Kernel 의 sys file system module 의 예제 
링크된 sys file system module의 예제를 참고하여 기본구현
sysfs_create_group를 unregister 하기 위해서 sysfs_remove_group 써야한다고 하는데 이부분은 미확인
  http://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/sysfs-class-registration-942098/


상위소스와 같이 각각의 show_xx 함수와 store_xx 함수를 정의하여 attribute를 구성하여 추가한다.

  • device_attribute 로 sys file system 확장 (SDCard)
/sys/block/sdx/device/scsi_disk/xxx/cache_type
/sys/block/sdx/device/scsi_disk/xxx/FUA

/*
 *  /sys/device  이외에도 다양하게 제공 bus_attribute
 *
 *  sys filesystem의 portstate 추가 
 *      read  function : xx_show_xx   이미 이함수들이 추가되어있음 
 *      write function : xx_store_xx  이미 이함수들이 추가되어있음 
 */

static struct device_attribute sd_disk_attrs[] = {
 __ATTR(cache_type, S_IRUGO|S_IWUSR, sd_show_cache_type, sd_store_cache_type),
 __ATTR(FUA, S_IRUGO, sd_show_fua, NULL),
 __ATTR(allow_restart, S_IRUGO|S_IWUSR, sd_show_allow_restart, sd_store_allow_restart),
 __ATTR(manage_start_stop, S_IRUGO|S_IWUSR, sd_show_manage_start_stop, sd_store_manage_start_stop),
 __ATTR(protection_type, S_IRUGO, sd_show_protection_type, NULL),
 __ATTR(protection_mode, S_IRUGO, sd_show_protection_mode, NULL),
 __ATTR(app_tag_own, S_IRUGO, sd_show_app_tag_own, NULL),
 __ATTR(thin_provisioning, S_IRUGO, sd_show_thin_provisioning, NULL),
 __ATTR_NULL,

};

/*
 *  상위구현 된 부분에 본인이 추가할 부분 추가  
 *  sd_show_cache_type  sd_store_cache_type
 *   
 */
.........
.........

static struct class sd_disk_class = {
 .name  = "scsi_disk",
 .owner  = THIS_MODULE,
 .dev_release = scsi_disk_release,
 .dev_attrs = sd_disk_attrs,
};


MMC_DEV_ATTR 와  DEVICE_ATTR 로 변경되어 사용됨
  https://elixir.bootlin.com/linux/v4.10.17/source/drivers/mmc
  https://elixir.bootlin.com/linux/v4.10.17/source/drivers/mmc/core/sd.c


  • class_attribute를 이용하여 sys filesytem 확장 
/sys/class/rtl8370m/portstate 추가

/*
 *  /sys/class/rtl8370m/portstate
 *
 *  sys filesystem의 portstate 추가 
 *      read  function : portstate_show
 *      write function : portstate_store
 */
static struct class_attribute class_attr[] = {
 __ATTR(portstate, S_IWUSR | S_IRUGO, portstate_show, portstate_store),
 __ATTR_NULL
 };

/*
 * 별도로 본인이 보고 싶고 설정하고 싶은 두 함수를 설정
 *
 */

static ssize_t portstate_show(struct class *cls, char *buf)
{
   char *x[] = {"Enabled", "Disabled"}; 
   printk("portstate_show\n");
   return sprintf(buf, "%s\n", x[0]);
}

static ssize_t portstate_store(struct class *cls, const char *buf, size_t count)
{
   printk("portstate_store \n");
   return 1;
}

.......

/*  /sys/class/rtl8370m    */

static struct class rtl8370m_drv = {
 .name = "rtl8370m",    
 .owner = THIS_MODULE,
 .class_attrs =(struct class_attribute *) &class_attr,
};



 
  • sys file 을 이용한 GPIO 
  https://www.kernel.org/doc/Documentation/gpio/sysfs.txt
  http://infoarts.tistory.com/21
  https://www.kernel.org/doc/Documentation/i2c/dev-interface


  • 기본 CHARTER DRIVER 예제들
  http://parkjunehyun.tistory.com/m/post/248
  http://www.opensourceforu.com/2011/08/io-control-in-linux/


  • Udev Rule 관련설정
  https://kernel.googlesource.com/pub/scm/linux/hotplug/udev/+/1ed38f41749dde482e164e692255b60c38b5d876/etc/udev/rules.d/60-persistent-storage.rules
  http://www.troot.co.kr/tc/1958


12/04/2014

VLAN 관련내용

1. VLAN이란

VLAN( Virtual LAN )이란?
네트웍 노드들의 물리적인 위치와는 상관없이 다수의 노드들을 브로드케스트 도메인으로 세그먼트하는 방법으로 그룹을 구성하는 것을 의미한다.

(브로드케스트 도메인을 VLAN 도메인으로 그룹핑하여, 원하는 VLAN에게만 브로드케스트 가능)
이로서 네트웍상의 자원과 사용자들을 여러 작업그룹으로 분리하여, 세그먼트간의 트래픽을 현저하게 줄일수 있다.
VLAN은 네트웍 자원사용을 오직 인증된 사용자만이 이용할수 있도록 함으로써 네트웍 보안사항을 향상시킨다.

결국. VLAN은 네트웍 자원 엑세스를 제한함으로써 보안을 향상시키고, 브로트캐스트 도메인의 크기를 줄여서 브로드캐스트 트래픽량을 줄이는 효과가 발생하고
결과적으로는 전체 네트웍 성능을 보다 향상시키게되는 것이다.


1.1 VLAN 구성

VLAN을 구성하는 방법은 여러가지가 있다. 스위치의 포트를 기준, 디바이스들의 MAC주소 기준 또는 사용자가 정의한 IP주소 그외 프로토콜, 응용프로그램별로 VLAN을 구성할 수 있다


ref.
http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=108&docId=65196845&qb=dmxhbg==&enc=utf8&section=kin&rank=1&search_sort=0&spq=0&pid=S4qrGsoRR1GssaUrkv0sssssssV-125897&sid=VIqr4AoUU14AAFXrRN0



1.2  VLAN의 기본개념 및 Trunk, VTP.

http://4network.tistory.com/entry/vlan
http://itstudent.tistory.com/11
http://onecellboy.tistory.com/278


1.3  STP 필요성

Switch가 두개가 연결이 될 경우, Broadcast가 발생할 경우, Looping이 이 발생하고, 이를 Broadcast Storm이라고 부릅니다.

이 Looping문제를 해결하기위해서 Connection 구조를  Loop가 되지 않도록 Tree 구조로
변경을 합니다. ( Tree 는 확장트리 )

http://ko.wikipedia.org/wiki/%EC%8B%A0%EC%9E%A5_%ED%8A%B8%EB%A6%AC_%ED%94%84%EB%A1%9C%ED%86%A0%EC%BD%9C 
http://4network.tistory.com/entry/Spanning-Tree-Protocol%EC%9D%80-%EC%99%9C-%ED%95%84%EC%9A%94%ED%95%9C%EA%B0%80
http://4network.tistory.com/entry/STP%EB%8A%94-%EA%B8%B0%EC%A4%80%EC%A0%90%EC%9D%B4-%EC%9E%88%EC%96%B4%EC%95%BC-%ED%95%9C%EB%8B%A4



기본용어설명 VLAN

https://www.urz.uni-heidelberg.de/Netzdienste/docext/3com/superstack/3_0/3500/3i3afmTOC.html



VID와 trunk 개념 Image

trunk는 switch간에 연결을 위해서 필요.

http://imagesearch.naver.com/search.naver?sm=ext&viewloc=0&where=idetail&rev=31&query=vlan&ie=utf8&aq=0&spq=0&nx_search_query=vlan&nx_and_query=&nx_sub_query=&nx_search_hlquery=&nx_search_fasquery=&datetype=0&startdate=0&enddate=0&start=1&img_id=blog32465698%7C75%7C40108727490_8



- EFID, Enhanced FID,  Priority
- VINX VSEL



RTL8370M and DM8167

pnx8493
https://code.google.com/p/rt-n56u/source/browse/uboot/rt-n56u/drivers/rtl8367.c