Search code examples
terminalraspberry-pigdbraspbianatmel

How do I make Linux terminal shell out of these instructions?


I have been trying to make a .sh script using the instructions to run on the Raspberry Pi for the Atmel ATSAMD51G19A:


  1. Launch openocd in a new terminal window:

sudo openocd -f openocdcfg.cfg

OpenOCD should stay running if it successfully connected to the device.

  1. In a second terminal window, run the following:

gdb-multiarch AtmelStart.elf

  1. Type these within gdb (say yes when prompted):
target remote :3333
lo 
file User.elf
lo
mon reset

The display device should now be running the ncdisplay code.


Now I have no issues flashing the firmware onto the Atmel MCU. I only have issues when creating part 3 of the .sh script. So far, here is what my script looks like for part 3

(gdb) -ex target remote :3333
(gdb) -ex lo
(gdb) -ex file User.elf
(gdb) -ex y
(gdb) -ex y
(gdb) -ex lo
(gdb) -ex mon reset
(gdb) -ex q

None of the commands listed above will execute within gdb in terminal. I'm also unsure how to include 'y' for 'yes' within gdb when making a script. The terminal just stays idle waiting for the user to type a command.

I am still learning a lot about Linux and Debian/Ubuntu. In addition, this is the first time I have ever worked with gdb. Thank you for any help.


Solution

  • GDB takes a -x command line argument that allows you to pass in a set of commands to run, see https://sourceware.org/gdb/current/onlinedocs/gdb/File-Options.html#File-Options for more details.

    So you can place your GDB commands into a separate file (lets call it cmd.gdb) and then do gdb-multiarch -x cmd.gdb AtmelStart.elf.

    If GDB is processing commands from a command file then it will assume yes in answer to the yes/no prompts, so GDB will not stop.

    If you do want to stick to using -ex then you can try adding this command to the start of your list -ex 'set confirm off' this should stop GDB asking you yes/no questions.