Stlink: ๊ฐœ๋ฐœ ๋ถ„๊ธฐ์—์„œ ๋นŒ๋“œ ์˜ค๋ฅ˜, cpuid ๋ฌธ์ œ

์— ๋งŒ๋“  2020๋…„ 04์›” 20์ผ  ยท  7์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: stlink-org/stlink

๋นŒ๋“œ ์ปค๋ฐ‹ c7874f805c63c60285f2b190f6589da8ae5e47fa๋ฅผ ์‹œ๋„ํ•ฉ๋‹ˆ๋‹ค.
๊ทธ๋ฆฌ๊ณ  ๋‹ค์Œ ์˜ค๋ฅ˜๋กœ ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.

/builddir/build/BUILD/stlink-org-stlink-c7874f8/tests/usb.c: In function 'main':
/builddir/build/BUILD/stlink-org-stlink-c7874f8/tests/usb.c:34:9: error: 'cpuid.revision' may be used uninitialized in this func
tion [-Werror=maybe-uninitialized]
   34 |         printf("cpuid:part = %#x, rev = %#x\n", cpuid.part, cpuid.revision);
      |         ^
/builddir/build/BUILD/stlink-org-stlink-c7874f8/tests/usb.c:31:27: note: 'cpuid.revision' was declared here
   31 |         cortex_m3_cpuid_t cpuid;
      |                           ^
/builddir/build/BUILD/stlink-org-stlink-c7874f8/tests/usb.c:34:9: error: 'cpuid.part' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   34 |         printf("cpuid:part = %#x, rev = %#x\n", cpuid.part, cpuid.revision);
      |         ^
/builddir/build/BUILD/stlink-org-stlink-c7874f8/tests/usb.c:31:27: note: 'cpuid.part' was declared here
   31 |         cortex_m3_cpuid_t cpuid;
      |                           ^
/builddir/build/BUILD/stlink-org-stlink-c7874f8/tests/usb.c:33:9: error: 'cpuid.variant' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   33 |         printf("cpuid:impl_id = %0#x, variant = %#x\n", cpuid.implementer_id, cpuid.variant);
      |         ^
/builddir/build/BUILD/stlink-org-stlink-c7874f8/tests/usb.c:31:27: note: 'cpuid.variant' was declared here
   31 |         cortex_m3_cpuid_t cpuid;
      |                           ^
/builddir/build/BUILD/stlink-org-stlink-c7874f8/tests/usb.c:33:9: error: 'cpuid.implementer_id' may be used uninitialized in this function [-Werror=maybe-uninitialized]
   33 |         printf("cpuid:impl_id = %0#x, variant = %#x\n", cpuid.implementer_id, cpuid.variant);
      |         ^
/builddir/build/BUILD/stlink-org-stlink-c7874f8/tests/usb.c:31:27: note: 'cpuid.implementer_id' was declared here
   31 |         cortex_m3_cpuid_t cpuid;
      |                           ^
lto1: all warnings being treated as errors

์–ด๋–ป๊ฒŒ ๊ณ ์น  ์ˆ˜ ์žˆ์Šต๋‹ˆ๊นŒ?

bucompilation bufixed errocompilation olinux staturesolved

๋ชจ๋“  7 ๋Œ“๊ธ€

macOS์—์„œ๋Š” ์ฝ”๋“œ๊ฐ€ ์ž˜ ๋นŒ๋“œ๋ฉ๋‹ˆ๋‹ค.

src/common.c

int stlink_cpu_id(stlink_t *sl, cortex_m3_cpuid_t *cpuid) {
    uint32_t raw;

    if (stlink_read_debug32(sl, STLINK_REG_CM3_CPUID, &raw))
        return -1;

    cpuid->implementer_id = (raw >> 24) & 0x7f;
    cpuid->variant = (raw >> 20) & 0xf;
    cpuid->part = (raw >> 4) & 0xfff;
    cpuid->revision = raw & 0xf;
    return 0;
}

cpuid.part ๋ฐ cpuid.revision์ด ์‹ค์ œ๋กœ ์—ฌ๊ธฐ์—์„œ ์ดˆ๊ธฐํ™”๋œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ ์˜ค์ž‘๋™ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๊นŒ?

    if (stlink_read_debug32(sl, STLINK_REG_CM3_CPUID, &raw))
        return -1;

์ด ๊ฒฝ์šฐ cpuid.*๋Š” ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์€ ์ƒํƒœ๋กœ ์œ ์ง€๋ฉ๋‹ˆ๋‹ค.

Ubuntu์—์„œ๋„ ์„ฑ๊ณต์ ์œผ๋กœ ์ปดํŒŒ์ผ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๋ ˆ์ง€์Šคํ„ฐ ์ฝ๊ธฐ ์˜ค๋ฅ˜์˜ ๊ฒฝ์šฐ ๋ณ€์ˆ˜ cpuid๋Š” uninited๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

--- a/tests/usb.c
+++ b/tests/usb.c
@@ -29,7 +29,11 @@ int main(int ac, char** av) {
printf("-- core_id: %#x\n", sl->core_id);

     cortex_m3_cpuid_t cpuid;

- stlink_cpu_id(sl, &cpuid);
+ if (stlink_cpu_id(sl, &cpuid))
+ {
+ printf("์•Œ ์ˆ˜ ์—†๋Š” ์นฉ\n");
+ memset(&cpuid, 0, sizeof(cortex_m3_cpuid_t))
+ }
printf("cpuid:impl_id = %0#x, ๋ณ€ํ˜• = %#x\n", cpuid.implementer_id, cpuid.variant);
printf("cpuid:part = %#x, rev = %#x\n", cpuid.part, cpuid.revision);

stlink_cpu_id์— ๋ฐ˜ํ™˜ ๊ฐ’ ๊ฒ€์‚ฌ๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  ํ•ด๋‹น ๊ฐ’์„ 0์œผ๋กœ ์ดˆ๊ธฐํ™”ํ•˜๋ฉด ๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ๋  ์ˆ˜ ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ๋‚˜๋Š” ๊ทธ๊ฒƒ์„ ์‹œ๋„ ํ•  ๊ฒƒ์ด๋‹ค.

๊ตฌ์„ฑํ•˜๋Š” ๋™์•ˆ -Werror=maybe-uninitialized ์žˆ์Šต๋‹ˆ๋‹ค.

-- Performing Test C_SUPPORTS_WMAYBE_UNINITIALIZED
-- Performing Test C_SUPPORTS_WMAYBE_UNINITIALIZED - Success

@Vascom ๋‚ด ์ง€์ ์„ ํ…Œ์ŠคํŠธ https://github.com/chenguokai/stlink/tree/issue937 ?
๊ทธ๊ฒƒ์ด ํšจ๊ณผ๊ฐ€ ์žˆ๋‹ค๋ฉด, ๋‚˜๋Š” PR์„ ์˜ฌ๋ฆด ๊ฒƒ์ž…๋‹ˆ๋‹ค.

@Vascom ๋‚ด ์ง€์ ์„ ํ…Œ์ŠคํŠธ https://github.com/chenguokai/stlink/tree/issue937 ?
๊ทธ๊ฒƒ์ด ํšจ๊ณผ๊ฐ€ ์žˆ๋‹ค๋ฉด, ๋‚˜๋Š” PR์„ ์˜ฌ๋ฆด ๊ฒƒ์ž…๋‹ˆ๋‹ค.

์˜ˆ, ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰