Linux API/linux2021. 4. 5. 16:44

이런 에러 처음 겪네 -_-

 

runtime DIV/0 에러에 가깝다고 해야하나..

(문제는 전부 char 형인데 뜬금없이 float point..)

[링크 : https://stackoverflow.com/questions/4236853/floating-point-exception-c-why-and-what-is-it]

[링크 : https://kldp.org/node/122753]

[링크 : https://www.acmicpc.net/board/view/21892]

 

혹시나 해서 gdb 물려서 실행해보니

Program received signal SIGFPE, Arithmetic exception.

 

이름은 Floating Point Exception 에서 유래하긴 했는데

"0으로 나누기와 오버플로우를 포함한 모든 산술에러"에서 발생한다고 한다.

Macro: int SIGFPE

The SIGFPE signal reports a fatal arithmetic error. Although the name is derived from “floating-point exception”, this signal actually covers all arithmetic errors, including division by zero and overflow. If a program stores integer data in a location which is then used in a floating-point operation, this often causes an “invalid operation” exception, because the processor cannot recognize the data as a floating-point number.

Actual floating-point exceptions are a complicated subject because there are many types of exceptions with subtly different meanings, and the SIGFPE signal doesn’t distinguish between them. The IEEE Standard for Binary Floating-Point Arithmetic (ANSI/IEEE Std 754-1985 and ANSI/IEEE Std 854-1987) defines various floating-point exceptions and requires conforming computer systems to report their occurrences. However, this standard does not specify how the exceptions are reported, or what kinds of handling and control the operating system can offer to the programmer.

[링크 : https://www.gnu.org/software/libc/manual/html_node/Program-Error-Signals.html]

'Linux API > linux' 카테고리의 다른 글

Stopped (tty input)  (0) 2021.05.21
linux gpio interrupt poll?  (0) 2021.05.04
실행파일 not fount, FATAL: kernel too old  (0) 2021.04.05
spi 통신 예제(linux)  (0) 2021.01.28
linux USB bulk 통신  (0) 2020.10.21
Posted by 구차니
Linux API/linux2021. 4. 5. 10:53

빌드해서 올리는데 파일이 있는데 없다고?!?!

혹시나 해서 보는데 target에 file도 없어 ㅠㅠㅠㅠ 아놔 -_-

아무튼 

파일이 없는건

zynq> ./test
-sh: ./test: not found

zynq> ls -al /lib/ld-
ld-2.13.so     ld-linux.so.3

zynq> ls -al /lib/ld-linux.so.3
lrwxrwxrwx    1 root     root            10 Nov 27  2012 /lib/ld-linux.so.3 -> ld-2.13.so

zynq> ./test
FATAL: kernel too old
Aborted

 

/lib/ld-linux-armhf.so.3 와 /lib/ld-linux.so 의 차이 -_-

아니 저정도면 실행시에 링크파일이 없다고 에러나와줘야지 ㅠㅠ

왜 자기 자신이 없다고 에러가 나는게야!!

$ file test
test: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 4.9.0, with debug_info, not stripped

 

아무튼 빡쳐서(!) static 링크해서 빌드하고 실행했더니

$ file test
test: ELF 32-bit LSB executable, ARM, EABI5 version 1 (GNU/Linux), statically linked, for GNU/Linux 4.9.0, with debug_info, not stripped

 

야이!!!

zynq> ./test
FATAL: kernel too old
Aborted

 

에라이 걍 컴파일러 바꿔 -_-

[링크 : https://ggpapa.tistory.com/36]

[링크 : https://blog.naver.com/calb30095/221005114736]

'Linux API > linux' 카테고리의 다른 글

linux gpio interrupt poll?  (0) 2021.05.04
Floating point exception  (0) 2021.04.05
spi 통신 예제(linux)  (0) 2021.01.28
linux USB bulk 통신  (0) 2020.10.21
linux open() 과 8진법  (0) 2020.09.28
Posted by 구차니
Linux API/linux2021. 1. 28. 13:59

쓸일이 곧 생길게야.... (동공지진)

 

[링크 : https://github.com/torvalds/linux/blob/master/tools/spi/spidev_test.c]

+ 2021.02.08

 

It's easy to be confused here, and the vendor documentation you'll
find isn't necessarily helpful.  The four modes combine two mode bits:

 - CPOL indicates the initial clock polarity.  CPOL=0 means the
   clock starts low, so the first (leading) edge is rising, and
   the second (trailing) edge is falling.  CPOL=1 means the clock
   starts high, so the first (leading) edge is falling.

 - CPHA indicates the clock phase used to sample data; CPHA=0 says
   sample on the leading edge, CPHA=1 means the trailing edge.

   Since the signal needs to stablize before it's sampled, CPHA=0
   implies that its data is written half a clock before the first
   clock edge.  The chipselect may have made it become available.

[링크 : https://www.kernel.org/doc/Documentation/spi/spi-summary]

Posted by 구차니
Linux API/linux2020. 10. 21. 11:50

 

 

[링크 : https://stackoverflow.com/questions/15308770/read-usb-bulk-message-on-linux]

Posted by 구차니
Linux API/linux2020. 9. 28. 17:54

많이 쓰지 않다 보니 잊고 있었는데

open() 시스템 콜 사용에서 퍼미션 설정시 0644라고 해야지 644로 하면 이상한 퍼미션으로 생성된다.

원인을 찾다보니.. 0644 라고 써야 할걸 귀찮아서(?!) 644라고 썼더니 오작동 한 것 같은데

16진수가 아니라 굳이 8진법을 쓰는 이유는

rwx로 조합되는 것이 2^3 = 8 이기 때문 이려나?

 

새삼 이런데서 8진법으로 표기한다는게 신기하네..

 

--w----r-T

아무튼 644로 표기하면 위의 희한한 퍼미션으로 생성된다.

T니까.. stikcy bit고.. 이거 1000(8) 일텐데

 

644(10) = 1204(8) = 284(16)

더럽게(!) 우연히 1000(8)이 들어가 버렸네?

 

 

[링크 : https://blog.naver.com/tipsware/221498204578]

'Linux API > linux' 카테고리의 다른 글

spi 통신 예제(linux)  (0) 2021.01.28
linux USB bulk 통신  (0) 2020.10.21
open with O_CREAT or O_TMPFILE in second argument needs 3 arguments  (0) 2020.09.28
open() read() write() close()를 이용한 cp 예제  (0) 2020.09.28
fopen64  (0) 2019.06.24
Posted by 구차니
Linux API/linux2020. 9. 28. 17:43

빌드하다 보니 이상한 에러 발생

 

error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT or O_TMPFILE in second argument needs 3 arguments

 

원인은 open() 의 인자가 2개에서 3개로 늘어서 그렇다는데

vscode 에서 따라가서 봐도 인자는 2개 이상이면 문제가 없어야 하는데... 머지?

__fortify_function int

open (const char *__path, int __oflag, ...)

{

if (__va_arg_pack_len () > 1 __open_too_many_args ();

 

if (__builtin_constant_p (__oflag))

{

        if (__OPEN_NEEDS_MODE (__oflag) && __va_arg_pack_len () < 1)

        {

                __open_missing_mode ();

                return __open_2 (__path, __oflag);

        }

        return __open_alias (__path, __oflag, __va_arg_pack ());

}

 

if (__va_arg_pack_len () < 1) return __open_2 (__path, __oflag);

 

return __open_alias (__path, __oflag, __va_arg_pack ());

}

 

일단은 추적을 해보니 O_CREAT가 0이 아니거나 O_TMP_FILE이 설정되어 있을 경우

/* Detect if open needs mode as a third argument (or for openat as a fourth

argument). */

#ifdef __O_TMPFILE

# define __OPEN_NEEDS_MODE(oflag) \

(((oflag) & O_CREAT) != 0 || ((oflag) & __O_TMPFILE) == __O_TMPFILE)

#else

# define __OPEN_NEEDS_MODE(oflag) (((oflag) & O_CREAT) != 0)

#endif

 

그리고 인자가 1보다 작을 경우(즉, 퍼미션 이 없으면)

/* GCC 4.3 and above allow passing all anonymous arguments of an

__extern_always_inline function to some other vararg function. */

#if __GNUC_PREREQ (4,3)

# define __va_arg_pack() __builtin_va_arg_pack ()

# define __va_arg_pack_len() __builtin_va_arg_pack_len ()

#endif

 

아래를 수행해야 하는데 __open_missing_mode()는 따라가지지 않고

원래대로라면 __open_2(__path, __oflag) 으로 연결되어야 하는데 왜 에러가 난 걸까?

                __open_missing_mode ();

                return __open_2 (__path, __oflag);

[링크 : https://damduc.tistory.com/316]

 

+

/usr/include$ grep -rni "__errordecl" ./
./x86_64-linux-gnu/sys/cdefs.h:125:# define __errordecl(name, msg) \

별거 아닌.. 에러문 출력하는 선언문 인듯 한데..

# define __errordecl(name, msg) \
  extern void name (void) __attribute__((__error__ (msg)))
#else
# define __warndecl(name, msg) extern void name (void)
# define __warnattr(msg)
# define __errordecl(name, msg) extern void name (void)
#endif

 

정리를 하자면 O_CREAT, O_TMPFILE이 존재할 경우

컴파일 단계에서 __open_missing_mode (); 에 도달시 에러를 내고

그 다음 return으로 도달하지 못한다. 그리고 해당 항목은 GCC 4.3 이후 버전에서

인자를 확인하도록 추가되면서 영향을 받았다. 라고 해석을 해야 할 듯?

 

4.3 이후에 추가된 버그라고 봐야 하나?

 

if (__builtin_constant_p (__oflag))

{

        if (__OPEN_NEEDS_MODE (__oflag) && __va_arg_pack_len () < 1)

        {

                __open_missing_mode ();

                return __open_2 (__path, __oflag);

        }

        return __open_alias (__path, __oflag, __va_arg_pack ());

}

'Linux API > linux' 카테고리의 다른 글

linux USB bulk 통신  (0) 2020.10.21
linux open() 과 8진법  (0) 2020.09.28
open() read() write() close()를 이용한 cp 예제  (0) 2020.09.28
fopen64  (0) 2019.06.24
ubuntu iio rotate key 찾기 또 실패  (0) 2019.05.27
Posted by 구차니
Linux API/linux2020. 9. 28. 16:23

예제 보고 대충 따라서 만들어 봄

stdio.h를 했더니 fopen이랑 추천해주고 있어서 부랴부랴 찾아보니 unistd.h를 쓰라네?

cp.c:18:9: warning: implicit declaration of function ‘read’; did you mean ‘fread’? [-Wimplicit-function-declaration]
   len = read(fd_src, buff, BUFF_LEN);
         ^~~~
         fread
cp.c:20:4: warning: implicit declaration of function ‘write’; did you mean ‘fwrite’? [-Wimplicit-function-declaration]
    write(fd_dst, buff, len);
    ^~~~~
    fwrite
cp.c:25:2: warning: implicit declaration of function ‘close’; did you mean ‘pclose’? [-Wimplicit-function-declaration]
  close(fd_src);
  ^~~~~
  pclose

 

예외처리 하나도 없이 인자만 받아서 복사하는 cp 명령의 마이너 버전 코드.

#include <unistd.h>
#include <fcntl.h>

#define BUFF_LEN 4096

int main(int argc, char** argv)
{
        int fd_src = 0;
        int fd_dst = 0;
        int len = 0;
        char buff[BUFF_LEN];

        fd_src = open(argv[1], O_RDONLY);
        fd_dst = open(argv[2], O_CREAT | O_TRUNC | O_RDWR);

        while(1)
        {
                len = read(fd_src, buff, BUFF_LEN);
                if(len > 0)
                        write(fd_dst, buff, len);
                else
                        break;
        }

        close(fd_src);
        close(fd_dst);

}

 

[링크 : https://reakwon.tistory.com/39]

[링크 : https://linux.die.net/man/3/open]

[링크 : https://linux.die.net/man/2/close]

 

 

fstat으로 파일 길이 알아내기

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>

#include <sys/types.h>
#include <sys/stat.h>

#define BUFF_LEN 4096

int main(int argc, char** argv)
{
	int fd_src = 0;
	int fd_dst = 0;
	int len = 0;
	char buff[BUFF_LEN];
	struct stat statbuf;

	fd_src = open(argv[1], O_RDONLY);
	fd_dst = open(argv[2], O_CREAT | O_TRUNC | O_RDWR);

	fstat(fd_src, &statbuf);
	printf("filename : [%s], length [%ld]\n", argv[1], statbuf.st_size);

	while(1)
	{
		len = read(fd_src, buff, BUFF_LEN);
		if(len > 0)
			write(fd_dst, buff, len);
		else
			break;
	}

	close(fd_src);
	close(fd_dst);

}

 

[링크 : https://man7.org/linux/man-pages/man2/stat.2.html]

'Linux API > linux' 카테고리의 다른 글

linux open() 과 8진법  (0) 2020.09.28
open with O_CREAT or O_TMPFILE in second argument needs 3 arguments  (0) 2020.09.28
fopen64  (0) 2019.06.24
ubuntu iio rotate key 찾기 또 실패  (0) 2019.05.27
전원버튼 IRQ 발생 관련  (0) 2018.04.23
Posted by 구차니
Linux API/linux2019. 6. 24. 13:55

이걸 써야 하는지 안써도 되는데

그게 아니라면 -D_LARGEFILE_SOURCE 만 켜주면 되는건가?

 

[링크 : https://resetme.tistory.com/43]

[링크 : https://kldp.org/node/479]

[링크 : https://www.mkssoftware.com/docs/man3/fopen.3.asp]

 

[링크 : https://stackoverflow.com/.../what-is-the-difference-between-largefile-source-and-file-offset-bits-64]

Posted by 구차니
Linux API/linux2019. 5. 27. 19:09

xrandr을 이용해서 하거나 iio 관련해서 찾아보는데

어떠한 데몬이 어떤 키값을 통해서 작동을 하는지 감이 안온다.

 

/lib/udev/hwdb.d/60-keyboard.hwdb

 

키값을 읽어오는 명령어인데 회전 키를 누르면 두개가 뜬다. 도대체 어떤 키지?

$ sudo showkey -s
kb mode was ?UNKNOWN?
[ if you are trying this under X, it might not work
since the X server is also reading /dev/console ]

press any key (program terminates 10s after last keypress)...

0x6b 0xeb 
0x6b 0xeb 
0x6b 0xeb 

[링크 : https://unix.stackexchange.com/questions/49650/how-to-get-keycodes-for-xmodmap]

'Linux API > linux' 카테고리의 다른 글

open() read() write() close()를 이용한 cp 예제  (0) 2020.09.28
fopen64  (0) 2019.06.24
전원버튼 IRQ 발생 관련  (0) 2018.04.23
linux kernel governor 관련 코드  (0) 2018.04.17
linux shared memory 관련  (0) 2016.12.22
Posted by 구차니
Linux API/linux2018. 4. 23. 13:46

잘은 모르겠지만.. PC에서 쓰이는 PWRBTN  같은 전원관련 스위치들은

PMIC를 통해 인터럽트를 발생시킨다고 하는데..

GPIO를 통한 인터럽트인지 I2C(혹은 SMBUS)를 통해 통보받은걸 인터럽트로 넘겨주는건진 모르겠다.


2.7.15 Power Control Signals

i.MX6 Qseven PMIC SOM supports two power control signals PWGIN and PWRBTN# on Qseven Edge connector.

PWGIN input from Qseven Edge connector is the active high signal which is used to enable the power of i.MX6

Qseven PMIC SOM. For more details on PWRGIN signal usage, refer section 3.1.2.

i.MX6 Qseven PMIC SOM supports PWRBTN# input from Qseven Edge connector which is the active low signal and

connected to i.MX6 CPU’s ONOFF pin. This pin can be used to On/Off the i.MX6 CPU by connecting push button in

the carrier board. When the board power is On, a button press between 750ms to 5s will send an interrupt to core to

request software to bring down the i.MX6 safely (if software supports). Otherwise, button press greater than 5s

results in a direct hardware power down which is applicable when software is unable to power Off the device. When

the i.MX6 CPU power supply is Off, a button press greater in duration than 750ms asserts an output signal to request

power from a power IC to power up the i.MX6 CPU. 

[링크 : http://www1.futureelectronics.com/doc/IWAVE%20SYSTEMS%20TECHNOLOGIES/G15MDataSheet.pdf]


 +static irqreturn_t pb_isr(int irq, void *dev_id)

+{

+ int ret;

+ int state;

+

+ ret = intel_soc_pmic_readb(DC_TI_SIRQ_REG);

+ if (ret < 0) {

+ pr_err("[%s] power button SIRQ REG read fail %d\n",

+ pb_input->name, ret);

+ return IRQ_NONE;

+ }

+

+ state = ret & SIRQ_PWRBTN_REL;

+

+ if (force_trigger && state) {

+ /* If we lost the press interrupt when short pressing

+ * power button to wake up board from S3, simulate one.

+ */

+ input_event(pb_input, EV_KEY, KEY_POWER, 1);

+ input_sync(pb_input);

+ input_event(pb_input, EV_KEY, KEY_POWER, 0);

+ input_sync(pb_input);

+ } else {

+ input_event(pb_input, EV_KEY, KEY_POWER, !state);

+ input_sync(pb_input);

+ pr_info("[%s] power button %s\n", pb_input->name,

+ state ? "released" : "pressed");

+ }

+

+ if (force_trigger)

+ force_trigger = 0;

+

+ return IRQ_HANDLED;

+}

+

+static int pb_probe(struct platform_device *pdev)

+{

+ int ret;

+

+ pwrbtn_irq = platform_get_irq(pdev, 0);

+ if (pwrbtn_irq < 0) {

+ dev_err(&pdev->dev,

+ "get irq fail: irq1:%d\n", pwrbtn_irq);

+ return -EINVAL;

+ }

+ pb_input = input_allocate_device();

+ if (!pb_input) {

+ dev_err(&pdev->dev, "failed to allocate input device\n");

+ return -ENOMEM;

+ }

+ pb_input->name = pdev->name;

+ pb_input->phys = "power-button/input0";

+ pb_input->id.bustype = BUS_HOST;

+ pb_input->dev.parent = &pdev->dev;

+ input_set_capability(pb_input, EV_KEY, KEY_POWER);

+ ret = input_register_device(pb_input);

+ if (ret) {

+ dev_err(&pdev->dev,

+ "failed to register input device:%d\n", ret);

+ input_free_device(pb_input);

+ return ret;

+ }

+

+ ret = request_threaded_irq(pwrbtn_irq, NULL, pb_isr,

+ IRQF_NO_SUSPEND, DRIVER_NAME, pdev);

+ if (ret) {

+ dev_err(&pdev->dev,

+ "[request irq fail0]irq:%d err:%d\n", pwrbtn_irq, ret);

+ input_unregister_device(pb_input);

+ return ret;

+ }

+

+ return 0;

+}

[링크 : https://github.com/.../uefi/cht-m1stable/patches/PWRBTN-add-driver-for-TI-PMIC.patch]


> +int intel_soc_pmic_set_pdata(const char *name, void *data, int len)

> +{

> + struct cell_dev_pdata *pdata;

> +

> + pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);

> + if (!pdata) {

> + pr_err("intel_pmic: can't set pdata!\n");

> + return -ENOMEM;

> + }

> +

> + pdata->name = name;

> + pdata->data = data;

> + pdata->len = len;

> +

> + list_add_tail(&pdata->list, &pdata_list);

> +

> + return 0;

> +}

> +EXPORT_SYMBOL(intel_soc_pmic_set_pdata); 

[링크 : https://patchwork.kernel.org/patch/4227571/]



+

근데... 정기적으로 읽긴 그런 애매한 녀석이고..

이걸 인터럽트로 어떻게 던지지?



[링크 : https://www.intel.com/.../datasheets/7-series-chipset-pch-datasheet.pdf]

'Linux API > linux' 카테고리의 다른 글

fopen64  (0) 2019.06.24
ubuntu iio rotate key 찾기 또 실패  (0) 2019.05.27
linux kernel governor 관련 코드  (0) 2018.04.17
linux shared memory 관련  (0) 2016.12.22
linux ipc  (0) 2016.12.20
Posted by 구차니