2009. 3. 7. 13:36

ARM에서의 Veneer, Veneer code

Veneer 사전적인 의미는 합판 이라는 의미입니다.
(어릴때 가끔씩 베니어 합판이라는 용어를 들은 적도 있는 것 같습니다.)

처음 ARM에서 veneer 란 용어를 접했을때 제일 먼저 찾아본것이 사전인데
ARM에서 의도하는 바와는 좀 다르더군요.

사실 veneer에 대해서 몰라도 동작자체가 잘 안되고 하는 것은 아니지만,
아마도 ARM을 공부하는 사람이라면 기본적으로 알아야 겠지요. 더구나 디버깅을 잘하려면 말이죠.
인터넷에서는 위에서 말한 합판이라는 용어가 같은 단어라 참 찾기도 애매합니다.
그래서 ARM Manual을 뒤져서 정리했습니다.


Veneer에 대해서 ADS(Arm Development Suite) 에서는 다음과 같이 설명하고 있습니다.

Veneer
A small block of code used with subroutine calls when there is a requirement to change processor state or branch to an address that cannot be reached in the current processor state.

Veneer generation
armlink must generate veneers when:
  ● branch involves change of state between ARM state and Thumb state
  ● branch involves a destination beyond the branching range of the current state.
A veneer can extend the range of branch and change processor state. armlink combines long branch capability into the state change capability. All interworking veneers are also long branch veneers.
The following veneer types handle different branching requirements. The linker generates position-independent versions of the veneers if required:

ARM to ARM
    Long branch capability.
ARM to Thumb
    Long branch capability and interworking capability.
Thumb to ARM
    Long branch capability and interworking capability.
Thumb to Thumb
    Long branch capability.

armlink creates one input section called Veneer$$Code for each veneer. A veneer is generated only if no other existing veneer can satisfy the requirements. If two input sections contain a long branch to the same destination, only one veneer is generated if the veneer can be reached by both sections.
All veneers cannot be collected into one input section because the resulting veneer input section might not to be within range of other input sections. If the sections are not within addressing range, long branching is not possible.


결국 가장 veneer code를 사용하는 목적은 두가지로 정리됩니다.
  1. branch 시에 ARM mode와 Thumb mode 간의 상태변환이 필요할때.
  2. branch 시에 branch 하는 대상 address가 access 가능한 range를 벗어나 확장이 필요할때(if long branch is needed)
** 참고로 이 두가지에 모두 해당하는 상황도 있습니다.

이제 위의 두가지 경우에 대해서 좀더 자세히 살펴보면

1. ARM Thumb state transition
ARM instruction은 32bit 이고 Thumb instruction은 16bit입니다. 그래서 ARM instruction으로 작성된 함수에서 Thumb instruction으로 작성된 함수를 호출할 경우에는 반드시 상태 변환이 필요합니다.
다음에 좋은 예가 있습니다.
아래를 보면, $Ven$AT$$ThumbFunc 를 호출하는 부분이 있습니다. 이것을 쫓아가 보면
0x0A001028 에 있는 값을 r12에 저장하고, bx 를 사용하여 r12에 저장된 주소를 분기하고 있습니다.
bx 는 branch 후 state를 바꾸게 되는데, address가 홀수이면 ARM->Thumb으로 짝수이면, Thumb->ARM으로 변경합니다.
결국 아래 부분은 0x0A00101D가 홀수 address이므로 branch 후 ARM->Thumb으로 state를 바꾸게 됩니다.

여담으로 linker가 생성하는 심볼인 $Ven$AT$$ThumbFunc 는 AT가 ARM->Thumb으로 변환함을 의미합니다.
그밖에 AA,TA,TT 가 있습니다. 지금 아래 예제에는 없지만, long branch 를 나타내는 부분도 있습니다.
참고로 ARM에서의 veneer 관련 symbol naming및 의미입니다.
    ${Ven|other}${AA|AT|TA|TT}${I|L|S}[$PI]$$symbol_name
    AA : ARM to ARM
    AT : ARM to Thumb
    TA : Thumb to ARM
    TT : Thumb to Thumb
     I : Inline
    L : Long branch
    S : Short reach
    PI : Position Independent

	   ARMFunc
0x0A001000:	mov	r0,#1
0x0A001004:	bl	$Ven$AT$$ThumbFunc
0x0A001008:	mov	r2,#3
0x0A00100C:	mov	r0,#0x18
0x0A001010:	ldr	r1,0x0A001018 ; =#0x0A020013
0x0A001014:	mov	r0,#0
0x0A001018:	dcd	0x0A020013
	   ThumbFunc
0x0A00101C:	mov	r0,#1
0x0A00101E:	bx	r14	
	   $Ven$AT$$ThumbFunc
0x0A001020:	ldr	r12,0x0A001028 ; = #0x0A00101D
0x0A001024:	bx	r12
0x0A001028:	dcd	0x0A00101D
0x0A00102C:	dcd	0x0A00331F
0x0A001030:	dcd	0x007F2E00
0x0A001034:	dcd	0xA703031F
0x0A001038:	dcd	0xA703032E



2.Long branch out of range
다음을 보면 range를 벗어나 확장이 필요한 경우(out of range)에 대한 적절한 설명이 있습니다. 역시 ARM manual입니다.

Machine-level B and BL instructions have a range of ± 32Mb from the address of the current instruction. However, you can use these instructions even if label is out of range. Often you do not know where label is placed by the linker. When necessary, the ARM linker adds code to allow longer branches (see The ARM linker chapter in Linker and Utilities Guide). The added code is called a veneer.

address range가 32Mb 정도이고 이것을 벗어나는 address일경우에는 veneer를 쓴다는 이야기입니다.
(이것은 register의 크기가 4byte, 즉 32bit 이기 때문입니다.)
하지만 이것도 ARM mode에서의 이야기이고, Thumb mode에서는 16bit입니다.
간단한 내용으로 따로 예제는 들지 않지만, 위와 비슷합니다.

출처 : 직접 작성
References
  http://www.arm.com
  ADS Manual
  Elf for ARM architecture

2009. 2. 1. 14:06
I2C Bus Interface
  - 1. Introduction

-------------------------------------------------------------------------------------
1. I2C, I2C(IIC) Bus Interface

  간단히 말해 통신방식의 하나로서, 주로 주변장치(Peripheral)와 통신/제어 용으로 많이 사용합니다.
  SCLK, SDATA 두개의 line을 사용하는 동기식 직렬통신(Synchoronous Serial Communication)의 하나입니다.
  비슷한 방식 통신 방식에는 UART, SPI 등이 있습니다.

  사실 별 신경쓰지 않고 있는 IIC, I2C 이 이름은 Inter-IC의 약자이다. IC는 Intergrated Circuit의 약자이다.
  어느 사이트에서 이 이름의 발음을 나름 쉽고 재미있게 표현했다.
  "eye-squared-see" 물론 이것은 발음상의 이야기이다

  통신 방식의 하나이지만, 앞서 말한 Inter-IC에서 보듯이, 주 목적이 제어입니다.
  
  여담으로 말하자면, 처음 고안한 회사가 Philips(현 NXP) 입니다.
  실제 이 회사 사이트에 가면 i2c specification을 얻을 수 있습니다.
  다음 링크를 참조하세요
  http://www.nxp.com/acrobat_download/literature/9398/39340011.pdf

2. 기본적인 구성 및 통신 방식 
   * 기본적인 구성
     - SCL : Serial Clock
     - SDA : Serial Data
     - 이 두 SCL, SDA로 Send, Recieve를 모두 수행합니다.

   *  Transferring bit/bytes

   * 기본적인 특징 및 통신 방식
     - Master Slave Relationship
       모든 I2C 장치들은 Master와 Slave간의 통신입니다.
       사실 이둘을 어떻게 구분하느냐는 것은 간단히 Clock generation을 누가 하느냐라고 보면 됩니다.

     - Single Master, Multiple Slave
       하나의 Master에 여러개의 Slave가 연결될 수 있습니다.
       이런 특징과 더불어 Slave device는 device고유의 Slave address를 가지고 이를 통해 각각의 Slave와 통신합니다.

     - Communication Protocol
       ▷ Slave Address를 지정
       ▷ I2C의 구성에서 보듯이 Read/Write에 대한 전용 line이 없고 통신 프로토콜 상에서 Read/Write를 결정.
       ▷ ACK(Acknowledgement), NACK(Non-Acknowledgement)
         [Slave Address][R/W][NACK/ACK]  [DATA][NACK/ACK]



--------------------------------------------------------------------------------------------------------
출처 : 직접 작성
2009. 1. 21. 10:00

이 에러는 얼마전 내가 겪었던 나름대로 당혹스러웠던 에러였다.

다른데서 잘 동작하는 게 갑자기 링크에러를 내다니...

결국은 내가 무지한 탓이었지만...


직관적으로 ARM 사이트(http://www.arm.com)에서 찾아보면 다음과 같이 나온다.
http://www.arm.com/support/faqdev/1240.html


그냥 봐선 저 내용 잘 이해가 안될 것이다.
저 내용만 보고 이해를 하려면, ARM link시에 사용하는 몇몇 옵션들에 대해서 이미 잘 알고 있다는 전제하에서 가능하다.

그럼 차근차근 저 내용을 풀어 보도록 하겠다.


  What does "Error: L6248E: cannot have address type relocation" mean?
  실제 에러는 이렇게 나오지는 않고, 이 의미를 포함해서 나온다.
  처음에 제일 당황스러운 부분이다. 왜 주소를 가질수 없다는 걸까? 
  분명히 코딩 상의 문제는 아니다.



 This linker error can occur when trying to build "Position Independent" code. Consider a small example like:
#include <stdio.h>
char *str = "test";
int main(void)
{
    printf ("%s",str);
}

 그냥 보면 이 코드는 전혀 문제가 없어 보인다. 정말 단순하기 짝이 없지만 크게 문제될 부분으로 보이지는 않는다.
실제로 gcc로 컴파일 해보자. 아무 에러 안나고 잘 실행될 것이다.
중요한 것은 링크 옵션에 있다.


when compiled and linked with:
armcc -c -apcs /ropi pi.c
armlink -ropi pi.othe linker will report a message of the form:


Error: L6248E: pi.o(.data) in ABSOLUTE region 'ER_RW' cannot have address/offset type relocation to .constdata in PI region 'ER_RO'.


For the code above, the compiler generates a global pointer "str" to the char string "test". The global pointer "str" will need to be initialized to the address of the char string "test" in the .constdata section.
However, absolute addresses cannot be used in a PI system, so the link step fails,
because of the ABS32 relocations to (position independent).constdata.

자 드디어 보여지는 링크 옵션. 강조해 놓은 저부분에 아무런 문제도 없어 보이는 코드에서 링크에러를 보여주는 원인 제공자이다. 
 눈에 띄는 옵션 들이 있다. -apcs /ropi
 Error 부분을 보면 낯선 구문이 보인다. PI region 'ER_RO' 이걸 이해하는데 키워드중 하나가 바로  PI region이다.

* PI region
  - Position Independent Region 의 약자이다.
     ARM Manual에는 간략하게 이런 설명이 있다.
     One or more of the position-independent regions is automatically moved to a different address.
     이 이야기는 load 시, 즉 프로그램이 실행되어 data 영역이 ram 에 로드될때 PI region에 속한 data 영역은 absolute하지 않고 relative 하다, 다른 말로 different address를 가진다는 이야기이다.

* Error 부문을 해석해 보면
  ABSOLUTE region ER_RW 에 있는 pi.o(.data)(-- 이것은 data영역 즉 변수에 대한 영역이다.--) 는 PI region ER_RO에 속한 .constdata 에 대한 address를 가질수 없다라는 뜻으로 해석된다. 
  좀더 쉽게 접근하자면,  absolute region에서 relative region의 address를 참조할 수 없다라고 이해하면 된다.
  (어떻게 보면 정말 당연한 이야기이기도 하다.)
  Position Independent region이라는 것이 absolute address를 가지는 것이 아니라 pc-relative address를 가진 다는 의미이다.

 * 그렇다면 갑자기 PI region이라는 것은 어디서 튀어나온 것일까?
   그렇다, 이것은 옵션에 지정되어 있다. 
      /ropi, -ropi

  이 두 옵션에 대해 ARM manual에서는 다음과 같이 설명하고 있다.
* -ropi
---------------------------------------------------------------------------------------------------------
This option generates (read-only) position-independent code. /pic is an alias for this option. If this option is selected the compiler:
 - addresses read-only code and data pc-relative
 - sets the Position Independent (PI) attribute on read-only output sections.
Note
The ARM tools cannot determine if the final output image will be Read-Only Position Independent (ROPI) until the linker finishes processing input sections. This means that the linker might emit ROPI error messages, even though you have selected this option.
---------------------------------------------------------------------------------------------------------

* 다시 Error 밑 쪽의 설명을 참조하여 풀어보면
  compiler는 global pointer 변수 str를 만들고, 코드에 이에 대한 초기값이 지정되어 있으므로 이 초기값으로 str 변수 값을 초기화한다. 이 때 "test" 이 값은 const data 형태로 생성하고, 이는 ro 영역, read only 영역에 속한다. 
그런데 컴파일과 링크 옵션에서 지정했다시피 ro 영역은 PI region으로 지정하였다. 이 이야기는 "test"에 대한 address가 load시마다 달라질 수 있다는 의미이다. str이라는 변수는 compile 시 초기값이 결정되어야만 하고, 이 초기값으로 사용되는 "test"에 대한 address는 load시에 결정된다. 결국 compiler는 global pointer 변수 str의 초기값으로 load시 마다 달라질 수 있는 address를 넣을 수 없기 때문에 이런 에러를 보여주는 것이다.

 

To resolve this, you must re-write the code to avoid the explicit pointer. Two possible ways are shown below:

1) Use a global array instead of a global pointer:

#include <stdio.h>
const char str[] = "test";
int main(void)
{
printf ("%s",str);
}

2) Use a local pointer instead of a global pointer:

#include <stdio.h>
int main(void)
{
char *str = "test";
printf ("%s",str);
}

Please note that if you are using a list with multiple elements, such as:

char * list[] = {"zero", "one", "two"};

You will get a separate link error for each element in the array. In this case, the recommended solution is:

char list[3][5] = {"zero", "one", "two"};

with the print instruction being (for example):

printf("%s", list[1]);

Note that you will need to declare a two dimensional array for the list, with the first dimension as the number of elements in the array, and the second dimension as the maximum size for an element in the array.

 
 ARM 사이트에서 제시하는 이런 에러에 대한 해결 방안이다.
 결국 코드를 바꿔야 한다. 이런식의 코드를 Position Independent code라고 부른다.

 이 예제의 내용은 비교적 이해하기 어렵지 않다.
 1) 같은 const 영역 ro 영역에 두는 것이다. 물론 같은 ro 영역이니 상관없다.
 2) global로 쓰지 않고 local variable로 사용하는 것이다.

 마지막의 두 array에 대한 예제는 크기를 지정하지 않은 경우와 지정한 경우에 대해 차이가 있고, 이 차이에 의해 이 에러를 일으킬 수 있다는 점을 설명하고 있다.
  좀 더 다르게 이런식의 접근도 가능하다.
   char *list[]   ==> 배열 포인터, 즉 global pointer variable이다. 결론적으로 처음 설명한 것과 같은 논리이다.
   char list[3][5] ==> 사이즈와 값이 결정된 array이다. 
  이둘의 차이는 하나는 포인터를 가지는 변수고, 하나는 값을 가지는 변수라는 점이다.

 이 에러의 초점은 주소 참조 이다. 그러니 address를 참조하지 않는다면 아예 해당되지 않는 이야기인 것이다.


참조
http://www.arm.com
2009. 1. 11. 08:57
요즘은 serial port를 생략(?)하고 나오는 경우가 종종 있다.

그러다보니 나와같은 사람들한테는...ㅡㅡ 영 불편하다.

아니 불편한게 아니라 불만이다.

각종 확인 및 테스트 , 디버깅을 serial로 하는데 이게 안되면 어쩌란 소린가.


이럴 경우 유용한 어댑터이다. 찾기도 디따 힘들다.
serial 공인 속도 뿐만 아니라 비공인 최고 속도까지도 지원한다. 물론 써본거라 보장하고
다른 개발자들도 애용하는 어댑터이다.

US232R-10, US232R-100

제품 홈페이지 : http://www.ftdichip.com/Products/EvaluationKits/USB-Serial.htm
국내판매처 : http://www.ezdaq.com/main/index.php

2009. 1. 9. 00:14

* 한글 설정
  locale 파일을 찾아 default값을 변경해도 되고  /etc/default/locale 파일이다.
  다음과 같이 export 명령을 사용해서 locale을 변경해도 된다.
    > export LANG="ko_KR.EUC-KR"

* 커널 버젼 확인
    > uname -a
2008. 12. 25. 12:26

우분투를 vmware로 깔고 들어가서 당황스러웠던게..

root 패스워드를 설정한적이 없다는 거였다. 어떻게 들어가지.



아래와 같이 하면 된다.

터미널을 열고


1.sudo passwd root
2.패스워드를 물어보면 로그인 계정의 암호
3.root 패스워드 입력


2008. 12. 23. 16:42

SMDK2440

dEVELOPER's/ARM, Embedded 2008. 12. 23. 16:42
예전에 같이 임베디드 소프트웨어 경진대회에서 부상으로 같이 받았던걸

내가 희생(?) 하여 구한 보드이다.

문제는 회로도가 없다는 거다..ㅠ.ㅠ


일단은 경민이한테 얻은 링크다.

http://neri.cafe24.com/menu/bbs/view.php?id=kb&page=1&sn1=&divpage=1&sn=off&ss=on&sc=on&keyword=smdk&select_arrange=headnum&desc=asc&no=276

오 회로도가 있다. 일단 링크 걸고 얼른 첨부해 놓자.

일단 링크
http://cafe.naver.com/armpower.cafe?iframe_url=/ArticleRead.nhn%3Farticleid=4