cartesi / machine-emulator-tools

Set of tools to help the development
Apache License 2.0
13 stars 20 forks source link

fix: add stty -onlcr to cartesi-init #36

Closed diegonehab closed 8 months ago

diegonehab commented 8 months ago

The expected behavior of the emulator is to pass through new-line control-characters directly from the inside to the outside. On the outside, if the output of the emulator is connected to a file, there should be no addition of a carriage-return. If, however, the output is connected to a terminal, the terminal itself will have been configured to add the carriage-return on its own.

In other words, we expect the following command to have the output shown

cartesi-machine.lua --no-init-splash --quiet -- echo | xxd
00000000: 0a                                       .

Instead, what we see before this PR (but when using a yet-to-be-released kernel linked to opensbi-1.3.1-ctsi-2) is

cartesi-machine.lua --no-init-splash --quiet -- echo | xxd
00000000: 0d0a                                     ..

This is because the terminal inside the emulator is configured with onlcr, so it is adding the carriage-return whenever it sees a new-line.

The PR configures the terminal with -onlcr so this doesn't happen.

Interestingly, prior to opensbi-1.3.1-ctsi-2, opensbi itself was adding yet another carriage-return on its own, whenever it saw a new-line sent to the legacy putchar we use with HTIF console. So the output was

cartesi-machine.lua --no-init-splash --quiet -- echo | xxd
00000000: 0d0d 0a                                  ...