sobota 11. května 2019

Pokračování s GDB


C:\Users\Jenda\Documents\ARM_GCC_Tools\bin>arm-none-eabi-gdb.exe "C:\Users\Jenda\Documents\STM32\STM32L1\Debug test\Debug\Debug test.elf"
C:\Users\Jenda\Documents\ARM_GCC_Tools\bin\arm-none-eabi-gdb.exe: warning: Couldn't determine a path for the index cache directory.
GNU gdb (GNU Tools for Arm Embedded Processors 8-2018-q4-major) 8.2.50.20181213-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=i686-w64-mingw32 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from C:\Users\Jenda\Documents\STM32\STM32L1\Debug test\Debug\Debug test.elf...
 (gdb) target remote localhost:3333    # připojení k OpenOCD
Remote debugging using localhost:3333
0x00000000 in ?? ()
(gdb) load                              # nahrání proramu na MCU
Loading section .isr_vector, size 0x13c lma 0x8000000
Loading section .text, size 0x1474 lma 0x800013c
Loading section .rodata, size 0x1c lma 0x80015b0
Loading section .init_array, size 0x4 lma 0x80015cc
Loading section .fini_array, size 0x4 lma 0x80015d0
Loading section .data, size 0xc lma 0x80015d4
Start address 0x80014f4, load size 5600
Transfer rate: 5 KB/sec, 933 bytes/write.
(gdb) monitor reset halt               # zastavení MCU
Unable to match requested speed 300 kHz, using 240 kHz
Unable to match requested speed 300 kHz, using 240 kHz
adapter speed: 240 kHz
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x080014f4 msp: 0x20004000
(gdb) l                                # zobrazení zdrojového kódu
warning: Source file is more recent than executable.
62      /**
63        * @brief  The application entry point.
64        * @retval int
65        */
66      int main(void)
67      {
68        /* USER CODE BEGIN 1 */
69
70        /* USER CODE END 1 */
71
(gdb) l 95                             # zobrazení zdrojového kódu od řádky 85
90        MX_GPIO_Init();
91        /* USER CODE BEGIN 2 */
92        volatile char array[10];
93        array[0] = 'a';
94        array[1] = 'b';
95        //array[25] = 'x';
96        array[2] = 'c';
97        array[3] = 'd';
98
99        for (int i = 8; i<10; i++) array[i] = i;
(gdb) b 97                             # přidání breakpointu na řádek 97
Breakpoint 1 at 0x8001242: file ..\Src\main.c, line 97.
(gdb) c                                # pokračování běhu programu
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, main () at ..\Src\main.c:97    # běh se zastavil na bteakpointu
97        array[3] = 'd';
(gdb) c
Continuing.

Program received signal SIGINT, Interrupt.
HAL_GPIO_ReadPin (GPIOx=0x40020000, GPIO_Pin=1) at ..\Drivers\STM32L1xx_HAL_Driver\Src\stm32l1xx_hal_gpio.c:401
401     }
(gdb) c
Continuing.

Program received signal SIGINT, Interrupt.
0x0800076e in HAL_GPIO_ReadPin (GPIOx=0x40020000, GPIO_Pin=1) at ..\Drivers\STM32L1xx_HAL_Driver\Src\stm32l1xx_hal_gpio.c:392
392       if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)GPIO_PIN_RESET)
(gdb) c
Continuing.

Program received signal SIGINT, Interrupt.
0x08000764 in HAL_GPIO_ReadPin (GPIOx=0x40020000, GPIO_Pin=1) at ..\Drivers\STM32L1xx_HAL_Driver\Src\stm32l1xx_hal_gpio.c:386
386     {
(gdb) c
Continuing.

Program received signal SIGINT, Interrupt.
0x08000782 in HAL_GPIO_ReadPin (GPIOx=0x40020000, GPIO_Pin=1) at ..\Drivers\STM32L1xx_HAL_Driver\Src\stm32l1xx_hal_gpio.c:401
401     }
(gdb) disas main          # disassemblování funkce main
Dump of assembler code for function main:
   0x08001224 <+0>:     push    {r7, lr}
   0x08001226 <+2>:     sub     sp, #16
   0x08001228 <+4>:     add     r7, sp, #0
   0x0800122a <+6>:     bl      0x800017c <HAL_Init>
   0x0800122e <+10>:    bl      0x80012a0 <SystemClock_Config>
   0x08001232 <+14>:    bl      0x800132c <MX_GPIO_Init>
   0x08001236 <+18>:    movs    r3, #97 ; 0x61
   0x08001238 <+20>:    strb    r3, [r7, #0]
   0x0800123a <+22>:    movs    r3, #98 ; 0x62
   0x0800123c <+24>:    strb    r3, [r7, #1]
   0x0800123e <+26>:    movs    r3, #99 ; 0x63
   0x08001240 <+28>:    strb    r3, [r7, #2]
=> 0x08001242 <+30>:    movs    r3, #100        ; 0x64
   0x08001244 <+32>:    strb    r3, [r7, #3]
   0x08001246 <+34>:    movs    r3, #8
   0x08001248 <+36>:    str     r3, [r7, #12]
   0x0800124a <+38>:    b.n     0x8001260 <main+60>
   0x0800124c <+40>:    ldr     r3, [r7, #12]
   0x0800124e <+42>:    uxtb    r1, r3
   0x08001250 <+44>:    mov     r2, r7
   0x08001252 <+46>:    ldr     r3, [r7, #12]
   0x08001254 <+48>:    add     r3, r2
   0x08001256 <+50>:    mov     r2, r1
   0x08001258 <+52>:    strb    r2, [r3, #0]
   0x0800125a <+54>:    ldr     r3, [r7, #12]
   0x0800125c <+56>:    adds    r3, #1
   0x0800125e <+58>:    str     r3, [r7, #12]
   0x08001260 <+60>:    ldr     r3, [r7, #12]
   0x08001262 <+62>:    cmp     r3, #11
   0x08001264 <+64>:    ble.n   0x800124c <main+40>
   0x08001266 <+66>:    movs    r1, #1
   0x08001268 <+68>:    ldr     r0, [pc, #44]   ; (0x8001298 <main+116>)
   0x0800126a <+70>:    bl      0x800075c <HAL_GPIO_ReadPin>
   0x0800126e <+74>:    mov     r3, r0
   0x08001270 <+76>:    cmp     r3, #1
   0x08001272 <+78>:    bne.n   0x8001266 <main+66>
   0x08001274 <+80>:    movs    r2, #0
   0x08001276 <+82>:    movs    r1, #64 ; 0x40
   0x08001278 <+84>:    ldr     r0, [pc, #32]   ; (0x800129c <main+120>)
   0x0800127a <+86>:    bl      0x800078a <HAL_GPIO_WritePin>
   0x0800127e <+90>:    movs    r0, #200        ; 0xc8
   0x08001280 <+92>:    bl      0x8000258 <HAL_Delay>
   0x08001284 <+96>:    movs    r2, #1
   0x08001286 <+98>:    movs    r1, #64 ; 0x40
   0x08001288 <+100>:   ldr     r0, [pc, #16]   ; (0x800129c <main+120>)
   0x0800128a <+102>:   bl      0x800078a <HAL_GPIO_WritePin>
   0x0800128e <+106>:   movs    r0, #200        ; 0xc8
--Type <RET> for more, q to quit, c to continue without paging--
   0x08001290 <+108>:   bl      0x8000258 <HAL_Delay>
   0x08001294 <+112>:   b.n     0x8001266 <main+66>
   0x08001296 <+114>:   nop
   0x08001298 <+116>:   movs    r0, r0
   0x0800129a <+118>:   ands    r2, r0
   0x0800129c <+120>:   lsls    r0, r0, #16
   0x0800129e <+122>:   ands    r2, r0
End of assembler dump.
(gdb) i b                        # výpis aktivních breakpointů
Num     Type           Disp Enb Address    What
1       breakpoint     keep y   0x08001236 in main at ..\Src\main.c:93
        breakpoint already hit 1 time
2       breakpoint     keep y   0x08001242 in main at ..\Src\main.c:97
        breakpoint already hit 1 time

(gdb) c
Continuing.

Program received signal SIGINT, Interrupt.
0x08001270 in main () at ..\Src\main.c:110
110         /* USER CODE END WHILE */
(gdb) q
A debugging session is active.

        Inferior 1 [Remote target] will be detached.

Quit anyway? (y or n) y

neděle 24. března 2019

FAT32


Disk /dev/sdb: 7.5 GiB, 8053063680 bytes, 15728640 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xc1adcabf

Device     Boot Start   End Sectors Size Id Type
/dev/sdb1        2048  2175     128  64K  b W95 FAT32

root@turris:~# hexdump /tmp/FAT32.bin -C
00000000  eb 3c 90 6d 6b 66 73 2e  66 61 74 00 02 04 01 00  |.<.mkfs.fat.....|
00000010  02 00 02 80 00 f8 01 00  3e 00 f8 00 00 00 08 00  |........>.......|
00000020  00 00 00 00 80 00 29 6b  11 ea ef 4e 4f 20 4e 41  |......)k...NO NA|
00000030  4d 45 20 20 20 20 46 41  54 31 32 20 20 20 0e 1f  |ME    FAT12   ..|
00000040  be 5b 7c ac 22 c0 74 0b  56 b4 0e bb 07 00 cd 10  |.[|.".t.V.......|
00000050  5e eb f0 32 e4 cd 16 cd  19 eb fe 54 68 69 73 20  |^..2.......This |
00000060  69 73 20 6e 6f 74 20 61  20 62 6f 6f 74 61 62 6c  |is not a bootabl|
00000070  65 20 64 69 73 6b 2e 20  20 50 6c 65 61 73 65 20  |e disk.  Please |
00000080  69 6e 73 65 72 74 20 61  20 62 6f 6f 74 61 62 6c  |insert a bootabl|
00000090  65 20 66 6c 6f 70 70 79  20 61 6e 64 0d 0a 70 72  |e floppy and..pr|
000000a0  65 73 73 20 61 6e 79 20  6b 65 79 20 74 6f 20 74  |ess any key to t|
000000b0  72 79 20 61 67 61 69 6e  20 2e 2e 2e 20 0d 0a 00  |ry again ... ...|
000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200  f8 ff ff 00 f0 ff 00 00  00 00 00 00 00 00 00 00  |................|
00000210  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000400  f8 ff ff 00 f0 ff 00 00  00 00 00 00 00 00 00 00  |................|
00000410  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000600  41 74 00 65 00 73 00 74  00 2e 00 0f 00 8f 74 00  |At.e.s.t......t.|
00000610  78 00 74 00 00 00 ff ff  ff ff 00 00 ff ff ff ff  |x.t.............|
00000620  54 45 53 54 20 20 20 20  54 58 54 20 00 00 6b 6f  |TEST    TXT ..ko|
00000630  78 4e 78 4e 00 00 6b 6f  78 4e 03 00 10 00 00 00  |xNxN..koxN......|
00000640  e5 20 00 49 00 6e 00 66  00 6f 00 0f 00 72 72 00  |. .I.n.f.o...rr.|
00000650  6d 00 61 00 74 00 69 00  6f 00 00 00 6e 00 00 00  |m.a.t.i.o...n...|
00000660  e5 53 00 79 00 73 00 74  00 65 00 0f 00 72 6d 00  |.S.y.s.t.e...rm.|
00000670  20 00 56 00 6f 00 6c 00  75 00 00 00 6d 00 65 00  | .V.o.l.u...m.e.|
00000680  e5 59 53 54 45 4d 7e 31  20 20 20 16 00 b1 7d 6f  |.YSTEM~1   ...}o|
00000690  78 4e 78 4e 00 00 00 70  78 4e 02 00 00 00 00 00  |xNxN...pxN......|
000006a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00004600  2e 20 20 20 20 20 20 20  20 20 20 10 00 b1 7d 6f  |.          ...}o|
00004610  78 4e 78 4e 00 00 00 70  78 4e 02 00 00 00 00 00  |xNxN...pxN......|
00004620  2e 2e 20 20 20 20 20 20  20 20 20 10 00 b1 7d 6f  |..         ...}o|
00004630  78 4e 78 4e 00 00 00 70  78 4e 00 00 00 00 00 00  |xNxN...pxN......|
00004640  e5 47 00 75 00 69 00 64  00 00 00 0f 00 ff ff ff  |.G.u.i.d........|
00004650  ff ff ff ff ff ff ff ff  ff ff 00 00 ff ff ff ff  |................|
00004660  e5 49 00 6e 00 64 00 65  00 78 00 0f 00 ff 65 00  |.I.n.d.e.x....e.|
00004670  72 00 56 00 6f 00 6c 00  75 00 00 00 6d 00 65 00  |r.V.o.l.u...m.e.|
00004680  e5 4e 44 45 58 45 7e 31  20 20 20 20 00 b4 7d 6f  |.NDEXE~1    ..}o|
00004690  78 4e 78 4e 00 00 00 70  78 4e 04 00 4c 00 00 00  |xNxN...pxN..L...|
000046a0  e5 74 00 00 00 ff ff ff  ff ff ff 0f 00 ce ff ff  |.t..............|
000046b0  ff ff ff ff ff ff ff ff  ff ff 00 00 ff ff ff ff  |................|
000046c0  e5 57 00 50 00 53 00 65  00 74 00 0f 00 ce 74 00  |.W.P.S.e.t....t.|
000046d0  69 00 6e 00 67 00 73 00  2e 00 00 00 64 00 61 00  |i.n.g.s.....d.a.|
000046e0  e5 50 53 45 54 54 7e 31  44 41 54 20 00 13 00 70  |.PSETT~1DAT ...p|
000046f0  78 4e 78 4e 00 00 01 70  78 4e 05 00 0c 00 00 00  |xNxN...pxN......|
00004700  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00004e00  52 65 61 64 20 43 6f 75  6e 74 65 72 3a 20 30 0a  |Read Counter: 0.|
00004e10  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00005600  7b 00 32 00 45 00 35 00  33 00 46 00 43 00 36 00  |{.2.E.5.3.F.C.6.|
00005610  38 00 2d 00 31 00 33 00  33 00 33 00 2d 00 34 00  |8.-.1.3.3.3.-.4.|
00005620  32 00 35 00 33 00 2d 00  41 00 44 00 39 00 35 00  |2.5.3.-.A.D.9.5.|
00005630  2d 00 42 00 33 00 36 00  35 00 39 00 31 00 38 00  |-.B.3.6.5.9.1.8.|
00005640  41 00 42 00 38 00 33 00  34 00 7d 00 00 00 00 00  |A.B.8.3.4.}.....|
00005650  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00005e00  0c 00 00 00 45 99 55 82  3c 6d 10 5f 00 00 00 00  |....E.U.<m._....|
00005e10  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00010000

Vlastní soubor ke stažení.

sobota 12. ledna 2019

Raspberry Pi programování bez OS

Před nějakou dobou jsem se pokoušel přeložit jednoduchý program pro Raspberry Pi bez takových zbytečností jako je linuxové jádro. :-) A jak na to?

sobota 5. ledna 2019

FAT tabulka

U příležitosti obnovy dat z čínské SD karty 64 GB za podezřele nízkou cenu mě napadlo se podívat na to jak jsou data na ni uložena.