리눅스/커널2013. 12. 11. 16:00

framebuffer 사이즈를 구하는 방법은 다음과 같다.


framebuffer size = x resolution * y resolution * color depth


즉 1080p + 4 color depth이면 1920 * 1080 * 4가 된다.

'리눅스 > 커널' 카테고리의 다른 글

early_param에 대해  (0) 2014.03.31
/dev/tty 와 /dev/console의 차이점  (0) 2014.02.05
[커널] FB 문서  (0) 2013.12.09
[안드로이드][커널]Unknown symbol _GLOBAL_OFFSET_TABLE_  (0) 2013.08.09
Kernel Oops의 Taint 종류  (0) 2013.07.25
Posted by code cat
리눅스/커널2013. 12. 9. 08:29
			The Frame Buffer Device
			-----------------------

Maintained by Geert Uytterhoeven <geert@linux-m68k.org>
Last revised: May 10, 2001


0. Introduction
---------------

The frame buffer device provides an abstraction for the graphics hardware. It
represents the frame buffer of some video hardware and allows application
software to access the graphics hardware through a well-defined interface, so
the software doesn't need to know anything about the low-level (hardware
register) stuff.

The device is accessed through special device nodes, usually located in the
/dev directory, i.e. /dev/fb*.


1. User's View of /dev/fb*
--------------------------

From the user's point of view, the frame buffer device looks just like any
other device in /dev. It's a character device using major 29; the minor
specifies the frame buffer number.

By convention, the following device nodes are used (numbers indicate the device
minor numbers):

      0 = /dev/fb0	First frame buffer
      1 = /dev/fb1	Second frame buffer
	  ...
     31 = /dev/fb31	32nd frame buffer

For backwards compatibility, you may want to create the following symbolic
links:

    /dev/fb0current -> fb0
    /dev/fb1current -> fb1

and so on...

The frame buffer devices are also `normal' memory devices, this means, you can
read and write their contents. You can, for example, make a screen snapshot by

  cp /dev/fb0 myfile

There also can be more than one frame buffer at a time, e.g. if you have a
graphics card in addition to the built-in hardware. The corresponding frame
buffer devices (/dev/fb0 and /dev/fb1 etc.) work independently.

Application software that uses the frame buffer device (e.g. the X server) will
use /dev/fb0 by default (older software uses /dev/fb0current). You can specify
an alternative frame buffer device by setting the environment variable
$FRAMEBUFFER to the path name of a frame buffer device, e.g. (for sh/bash
users):

    export FRAMEBUFFER=/dev/fb1

or (for csh users):

    setenv FRAMEBUFFER /dev/fb1

After this the X server will use the second frame buffer.


2. Programmer's View of /dev/fb*
--------------------------------

As you already know, a frame buffer device is a memory device like /dev/mem and
it has the same features. You can read it, write it, seek to some location in
it and mmap() it (the main usage). The difference is just that the memory that
appears in the special file is not the whole memory, but the frame buffer of
some video hardware.

/dev/fb* also allows several ioctls on it, by which lots of information about
the hardware can be queried and set. The color map handling works via ioctls,
too. Look into <linux/fb.h> for more information on what ioctls exist and on
which data structures they work. Here's just a brief overview:

  - You can request unchangeable information about the hardware, like name,
    organization of the screen memory (planes, packed pixels, ...) and address
    and length of the screen memory.

  - You can request and change variable information about the hardware, like
    visible and virtual geometry, depth, color map format, timing, and so on.
    If you try to change that information, the driver maybe will round up some
    values to meet the hardware's capabilities (or return EINVAL if that isn't
    possible).

  - You can get and set parts of the color map. Communication is done with 16
    bits per color part (red, green, blue, transparency) to support all 
    existing hardware. The driver does all the computations needed to apply 
    it to the hardware (round it down to less bits, maybe throw away 
    transparency).

All this hardware abstraction makes the implementation of application programs
easier and more portable. E.g. the X server works completely on /dev/fb* and
thus doesn't need to know, for example, how the color registers of the concrete
hardware are organized. XF68_FBDev is a general X server for bitmapped,
unaccelerated video hardware. The only thing that has to be built into
application programs is the screen organization (bitplanes or chunky pixels
etc.), because it works on the frame buffer image data directly.

For the future it is planned that frame buffer drivers for graphics cards and
the like can be implemented as kernel modules that are loaded at runtime. Such
a driver just has to call register_framebuffer() and supply some functions.
Writing and distributing such drivers independently from the kernel will save
much trouble...


3. Frame Buffer Resolution Maintenance
--------------------------------------

Frame buffer resolutions are maintained using the utility `fbset'. It can
change the video mode properties of a frame buffer device. Its main usage is
to change the current video mode, e.g. during boot up in one of your /etc/rc.*
or /etc/init.d/* files.

Fbset uses a video mode database stored in a configuration file, so you can
easily add your own modes and refer to them with a simple identifier.


4. The X Server
---------------

The X server (XF68_FBDev) is the most notable application program for the frame
buffer device. Starting with XFree86 release 3.2, the X server is part of
XFree86 and has 2 modes:

  - If the `Display' subsection for the `fbdev' driver in the /etc/XF86Config
    file contains a

	Modes "default"

    line, the X server will use the scheme discussed above, i.e. it will start
    up in the resolution determined by /dev/fb0 (or $FRAMEBUFFER, if set). You
    still have to specify the color depth (using the Depth keyword) and virtual
    resolution (using the Virtual keyword) though. This is the default for the
    configuration file supplied with XFree86. It's the most simple
    configuration, but it has some limitations.

  - Therefore it's also possible to specify resolutions in the /etc/XF86Config
    file. This allows for on-the-fly resolution switching while retaining the
    same virtual desktop size. The frame buffer device that's used is still
    /dev/fb0current (or $FRAMEBUFFER), but the available resolutions are
    defined by /etc/XF86Config now. The disadvantage is that you have to
    specify the timings in a different format (but `fbset -x' may help).

To tune a video mode, you can use fbset or xvidtune. Note that xvidtune doesn't
work 100% with XF68_FBDev: the reported clock values are always incorrect.


5. Video Mode Timings
---------------------

A monitor draws an image on the screen by using an electron beam (3 electron
beams for color models, 1 electron beam for monochrome monitors). The front of
the screen is covered by a pattern of colored phosphors (pixels). If a phosphor
is hit by an electron, it emits a photon and thus becomes visible.

The electron beam draws horizontal lines (scanlines) from left to right, and
from the top to the bottom of the screen. By modifying the intensity of the
electron beam, pixels with various colors and intensities can be shown.

After each scanline the electron beam has to move back to the left side of the
screen and to the next line: this is called the horizontal retrace. After the
whole screen (frame) was painted, the beam moves back to the upper left corner:
this is called the vertical retrace. During both the horizontal and vertical
retrace, the electron beam is turned off (blanked).

The speed at which the electron beam paints the pixels is determined by the
dotclock in the graphics board. For a dotclock of e.g. 28.37516 MHz (millions
of cycles per second), each pixel is 35242 ps (picoseconds) long:

    1/(28.37516E6 Hz) = 35.242E-9 s

If the screen resolution is 640x480, it will take

    640*35.242E-9 s = 22.555E-6 s

to paint the 640 (xres) pixels on one scanline. But the horizontal retrace
also takes time (e.g. 272 `pixels'), so a full scanline takes

    (640+272)*35.242E-9 s = 32.141E-6 s

We'll say that the horizontal scanrate is about 31 kHz:

    1/(32.141E-6 s) = 31.113E3 Hz

A full screen counts 480 (yres) lines, but we have to consider the vertical
retrace too (e.g. 49 `lines'). So a full screen will take

    (480+49)*32.141E-6 s = 17.002E-3 s

The vertical scanrate is about 59 Hz:

    1/(17.002E-3 s) = 58.815 Hz

This means the screen data is refreshed about 59 times per second. To have a
stable picture without visible flicker, VESA recommends a vertical scanrate of
at least 72 Hz. But the perceived flicker is very human dependent: some people
can use 50 Hz without any trouble, while I'll notice if it's less than 80 Hz.

Since the monitor doesn't know when a new scanline starts, the graphics board
will supply a synchronization pulse (horizontal sync or hsync) for each
scanline.  Similarly it supplies a synchronization pulse (vertical sync or
vsync) for each new frame. The position of the image on the screen is
influenced by the moments at which the synchronization pulses occur.

The following picture summarizes all timings. The horizontal retrace time is
the sum of the left margin, the right margin and the hsync length, while the
vertical retrace time is the sum of the upper margin, the lower margin and the
vsync length.

  +----------+---------------------------------------------+----------+-------+
  |          |                ↑                            |          |       |
  |          |                |upper_margin                |          |       |
  |          |                ↓                            |          |       |
  +----------###############################################----------+-------+
  |          #                ↑                            #          |       |
  |          #                |                            #          |       |
  |          #                |                            #          |       |
  |          #                |                            #          |       |
  |   left   #                |                            #  right   | hsync |
  |  margin  #                |       xres                 #  margin  |  len  |
  |<-------->#<---------------+--------------------------->#<-------->|<----->|
  |          #                |                            #          |       |
  |          #                |                            #          |       |
  |          #                |                            #          |       |
  |          #                |yres                        #          |       |
  |          #                |                            #          |       |
  |          #                |                            #          |       |
  |          #                |                            #          |       |
  |          #                |                            #          |       |
  |          #                |                            #          |       |
  |          #                |                            #          |       |
  |          #                |                            #          |       |
  |          #                |                            #          |       |
  |          #                ↓                            #          |       |
  +----------###############################################----------+-------+
  |          |                ↑                            |          |       |
  |          |                |lower_margin                |          |       |
  |          |                ↓                            |          |       |
  +----------+---------------------------------------------+----------+-------+
  |          |                ↑                            |          |       |
  |          |                |vsync_len                   |          |       |
  |          |                ↓                            |          |       |
  +----------+---------------------------------------------+----------+-------+

The frame buffer device expects all horizontal timings in number of dotclocks
(in picoseconds, 1E-12 s), and vertical timings in number of scanlines.


6. Converting XFree86 timing values info frame buffer device timings
--------------------------------------------------------------------

An XFree86 mode line consists of the following fields:
 "800x600"     50      800  856  976 1040    600  637  643  666
 < name >     DCF       HR  SH1  SH2  HFL     VR  SV1  SV2  VFL

The frame buffer device uses the following fields:

  - pixclock: pixel clock in ps (pico seconds)
  - left_margin: time from sync to picture
  - right_margin: time from picture to sync
  - upper_margin: time from sync to picture
  - lower_margin: time from picture to sync
  - hsync_len: length of horizontal sync
  - vsync_len: length of vertical sync

1) Pixelclock:
   xfree: in MHz
   fb: in picoseconds (ps)

   pixclock = 1000000 / DCF

2) horizontal timings:
   left_margin = HFL - SH2
   right_margin = SH1 - HR
   hsync_len = SH2 - SH1

3) vertical timings:
   upper_margin = VFL - SV2
   lower_margin = SV1 - VR
   vsync_len = SV2 - SV1

Good examples for VESA timings can be found in the XFree86 source tree,
under "xc/programs/Xserver/hw/xfree86/doc/modeDB.txt".


7. References
-------------

For more specific information about the frame buffer device and its
applications, please refer to the Linux-fbdev website:

    http://linux-fbdev.sourceforge.net/

and to the following documentation:

  - The manual pages for fbset: fbset(8), fb.modes(5)
  - The manual pages for XFree86: XF68_FBDev(1), XF86Config(4/5)
  - The mighty kernel sources:
      o linux/drivers/video/
      o linux/include/linux/fb.h
      o linux/include/video/



8. Mailing list
---------------

There is a frame buffer device related mailing list at kernel.org:
linux-fbdev@vger.kernel.org.

Point your web browser to http://sourceforge.net/projects/linux-fbdev/ for
subscription information and archive browsing.


9. Downloading
--------------

All necessary files can be found at

    ftp://ftp.uni-erlangen.de/pub/Linux/LOCAL/680x0/

and on its mirrors.

The latest version of fbset can be found at

    http://www.linux-fbdev.org/ 

  
10. Credits                                                       
----------                                                       
                
This readme was written by Geert Uytterhoeven, partly based on the original
`X-framebuffer.README' by Roman Hodek and Martin Schaller. Section 6 was
provided by Frank Neumann.

The frame buffer device abstraction was designed by Martin Schaller.


Posted by code cat

Encryption은

openssl aes-256-cbc -in input.txt -out output.enc



Decryption은

openssl aes-256-cbc -d -in output.enc -out input.txt

 

 

'리눅스 > 스크립트/유틸' 카테고리의 다른 글

[screen] detached된 세션 죽이기  (0) 2014.02.17
[Makefile] 다른 makefile 포함  (0) 2013.12.30
GDB  (0) 2013.09.24
[Makefile] overriding target 관련 warning 메세지  (0) 2013.09.02
[byobu] vertical line 없애기  (0) 2013.09.01
Posted by code cat
리눅스2013. 11. 25. 08:17

ext4 파일 시스템에 대한 커널 documentation에는 noauto_da_alloc에 대해서 다음과 같이 기술하고 있다.


auto_da_alloc(*)	Many broken applications don't use fsync() when 
noauto_da_alloc		replacing existing files via patterns such as
			fd = open("foo.new")/write(fd,..)/close(fd)/
			rename("foo.new", "foo"), or worse yet,
			fd = open("foo", O_TRUNC)/write(fd,..)/close(fd).
			If auto_da_alloc is enabled, ext4 will detect
			the replace-via-rename and replace-via-truncate
			patterns and force that any delayed allocation
			blocks are allocated such that at the next
			journal commit, in the default data=ordered
			mode, the data blocks of the new file are forced
			to disk before the rename() operation is
			committed.  This provides roughly the same level
			of guarantees as ext3, and avoids the
			"zero-length" problem that can happen when a
			system crashes before the delayed allocation
			blocks are forced to disk.


쉽게 풀어 얘기하자면, rename혹은 truncate같은 operation을 fsync()없이 행했을 경우, auto_da_alloc이 켜져 있으면 data=ordered 모드일 때, 다음 journal commit 시에 강제로 delayed 된 allocation 블럭들을 allocate 한다는 얘기다. (말이 쉽게 풀어 얘기지, 그냥 번역이네..)


따라서 ext3에 있던 "zero-length" 문제(delayed alloction 블럭이 disk에 쓰여지기 전에 시스템이 crash되는 문제)를 해결 할 수 있다.


noauto_da_alloc은 위와 같은 옵션을 꺼버리는 것이다.  이는 퍼포먼스 향상을 가져오지만 위에서 서술한 이점에 대해서는 포기하게 되는 것이다.

Posted by code cat
리눅스2013. 11. 24. 16:51


출처:http://docs.fedoraproject.org/en-US/Fedora/14/html/Storage_Administration_Guide/writebarr.html

Chapter 16. Write Barriers

write barrier is a kernel mechanism used to ensure that file system metadata is correctly written and ordered on persistent storage, even when storage devices with volatile write caches lose power. File systems with write barriers enabled also ensure that data transmitted via fsync() is persistent throughout a power loss.
Enabling write barriers incurs a substantial performance penalty for some applications. Specifically, applications that use fsync() heavily or create and delete many small files will likely run much slower.

16.1. Importance of Write Barriers

File systems take great care to safely update metadata, ensuring consistency. Journalled file systems bundle metadata updates into transactions and send them to persistent storage in the following manner:
  1. First, the file system sends the body of the transaction to the storage device.
  2. Then, the file system sends a commit block.
  3. If the transaction and its corresponding commit block are written to disk, the file system assumes that the transaction will survive any power failure.
However, file system integrity during power failure becomes more complex for storage devices with extra caches. Storage target devices like local S-ATA or SAS drives may have write caches ranging from 32MB to 64MB in size (with modern drives). Hardware RAID controllers often contain internal write caches. Further, high end arrays, like those from NetApp, IBM, Hitachi and EMC (among others), also have large caches.
Storage devices with write caches report I/O as "complete" when the data is in cache; if the cache loses power, it loses its data as well. Worse, as the cache de-stages to persistent storage, it may change the original metadata ordering. When this occurs, the commit block may be present on disk without having the complete, associated transaction in place. As a result, the journal may replay these uninitialized transaction blocks into the file system during post-power-loss recovery; this will cause data inconsistency and corruption.

How Write Barriers Work

Write barriers are implemented in the Linux kernel via storage write cache flushes before and after the I/O, which isorder-critical. After the transaction is written, the storage cache is flushed, the commit block is written, and the cache is flushed again. This ensures that:
  • The disk contains all the data.
  • No re-ordering has occurred.
With barriers enabled, an fsync() call will also issue a storage cache flush. This guarantees that file data is persistent on disk even if power loss occurs shortly after fsync() returns.


'리눅스' 카테고리의 다른 글

sysroot  (0) 2014.03.14
[EXT4] noauto_da_alloc 옵션에 대해서  (0) 2013.11.25
[Mint Linux] gnome shell emulation  (0) 2012.09.08
우분투 remote 로 접속해서 X 서버 돌리기  (0) 2012.04.17
ext4분석  (0) 2012.04.10
Posted by code cat

GDB

원래는 GDB 서버랑 클라이언트로 나누어서 보통 보드에다가 서버 돌리고, 호스트에서 접속해서 제어하는 방식을 쓰는데 뭐 접속이 안되서 그냥 클라이언트로 돌렸다. (당연히 해당보드에 맞게 컴파일해야 한다.)

 

gdb는 간단하게 다음과 같이,

gdb ./program_name arg1, ...

으로 실행하면 된다.

 

break 방법으로

(gdb) b main                    //함수로 break

(gdb) b crc.c:32               //소스파일 내 라인으로 break

 

break 정보를 볼라면,

info break

 

하면 되고, 다음의 명령어로 비활성/활성/삭제가 가능하다. (#은 break 에 해당하는 넘버)

disable break #

enable break #

delete break #

 

레지스터 내용을 볼라면,

info reg

 

특정 변수 값을 볼라면,

print var_name (변수 값 출력)

 

현재까지 호출된 fuction 을 backtrace할라면,(괄호는 간단한 명령어)

backtrace(bt)

 

스레드 관련 명령어는 다음과 같다.

info threads

위 명령으로 thread 별 lwp pid를 확인할 수 있다.(LWP:LightWeight Process)

 

스레드 인덱스 별로 backtrace 할려면,

t 13    // 13은 스레드 인덱스

와 같이 하면 된다.

 

Posted by code cat

영문은

warning: overriding commands for target '...'


한글번역된 메세지는

경고: 타켓 '...'에 대한 명령어보다 다른 것이 우선합니다.


우선해서 어쩌라고..????????


이래서 overriding이 되는 줄 몰랐다.  왜 저렇게 번역했는지는 모르겠지만, 영문 메세지로 확인하니 overriding이 되는걸 확인 할 수 있었다.

'리눅스 > 스크립트/유틸' 카테고리의 다른 글

openssl 을 이용한 암호화 방법  (0) 2013.11.25
GDB  (0) 2013.09.24
[byobu] vertical line 없애기  (0) 2013.09.01
ubuntu에 설치된 패키지 리스트 보기  (0) 2013.07.25
[screen/byobu] 윈도우 숫자 바꾸기  (0) 2013.06.29
Posted by code cat

byobu를 쓰는 이유 중 하나가 바로 vertical line split 기능일 것이다. (나만 그럴 수도..)

물론 screen에도 vertical line patch가 있지만... byobu가 더 이쁘니까..


어쨌든, vertical line을 만들고 나서 없애는 방법에 대해서 몰라 그냥 죽이는 방법을 썼었는데, 오늘 찾아보니 다음과 같이 하면 vertical line을 없앨 수 있다.


ctrl + a :remove {enter}


역시 찾아보면 다 나온다...

Posted by code cat
리눅스/커널2013. 8. 9. 17:06

출처: http://dtbaker.net/random-bits/android-unknown-symbol-_global_offset_table_/

 

커널 올리는 중에 에러가 나길래 찾아본 결과, 아래와 같은 글이 있었다.  결론적으로 이 방법이 솔루션이 되지는 못했지만, 참고 사항으로 올린다.

 

 

Android: Unknown symbol _GLOBAL_OFFSET_TABLE_

[ 1525.047424] bcm4329: Unknown symbol _GLOBAL_OFFSET_TABLE_ (err 0)

I received this error after compiling a custom Android kernel and modules using the arm-linux-androideabi-4.4.3 prebuilt toolchain.

I used arm-linux-androideabi-4.4.3 instead of arm-eabi-4.4.0 because arm-eabi-4.4.0 did not work for me on 64bit ubuntu ( * shrug * )

To fix this and to get my kernel modules loading I opened the Makefile within my kernel source folder and changed this:

MODFLAGS        = -DMODULE -march=armv7-a -mfpu=vfpv3 -ftree-vectorize

to this:

MODFLAGS        = -DMODULE -march=armv7-a -mfpu=vfpv3 -ftree-vectorize -fno-pic

Then re-built the kernel modules:

make clean
make modules

and copied my new module back over to android, away she goes!

————————-

if you cannot find MODFLAGS in the Makefile then look for:

CFLAGS_MODULE   =

and change it to

CFLAGS_MODULE   = -fno-pic

 

 

아 그리고  -fno-pic이 도대체 뭔 옵션인지 궁금해서 찾아보았다.

정말 더럽게 안 나온다.

gcc 메뉴얼을 찾아보니, -fpic에 대해 다음과 같이 설명하고 있다.

 

"타겟 머신에서 지원하는 경우, 공유 라이브러리를 위한 position-independent 코드 (PIC)을 생성한다.  이러한 코드는 global offset table(GOT)를 통해 모든 상수 주소에 대한 접근을 시도한다.  dynamic loader는 프로그램 실행의 시작시에 GOT 엔트리들을 처리한다.(참고로 dynamic loader는 GCC의 일부가 아니며 operating system의 일부이다).  ...

Position-indenpendent code 는 특정 머신의 지원이 필요하다...

이 플래그가 설정 된 경우, "__pic__""__PIC__" 는 1로 정의된다."

 

따라서 -fno-pic의 경우 position-independent 코드를 생성하지 말라는 것으로 보인다.

'리눅스 > 커널' 카테고리의 다른 글

FrameBuffer size 구하기  (0) 2013.12.11
[커널] FB 문서  (0) 2013.12.09
Kernel Oops의 Taint 종류  (0) 2013.07.25
[OS] priority inversion 해결방법  (0) 2013.01.13
monolithic vs microkernel  (0) 2013.01.13
Posted by code cat

다음의 명령어를 사용하면 된다.

 

dpkg --get-selections


Posted by code cat