@@ -61,27 +61,27 @@ void restore_terminal(int fd, const struct termios* old_termios) {
6161 tcsetattr (fd , TCSANOW , old_termios );
6262}
6363
64- int htool_console_run (struct libhoth_device * dev ,
65- const struct libhoth_htool_console_opts * opts ) {
64+ libhoth_error htool_console_run (struct libhoth_device * dev ,
65+ const struct libhoth_htool_console_opts * opts ) {
6666 printf ("%sStarting Interactive Console\n" , kAnsiRed );
6767
6868 struct hoth_channel_uart_config uart_config = {};
69- int status = libhoth_get_uart_config (dev , opts , & uart_config );
70- if (status == LIBHOTH_OK ) {
69+ libhoth_error status = libhoth_get_uart_config (dev , opts , & uart_config );
70+ if (status == HOTH_SUCCESS ) {
7171 if (opts -> baud_rate != 0 ) {
7272 uart_config .baud_rate = opts -> baud_rate ;
7373 status = libhoth_set_uart_config (dev , opts , & uart_config );
74- if (status != LIBHOTH_OK ) {
75- fprintf (
76- stderr ,
77- "libhoth_set_uart_config() failed: %d; unable to set baud-rate\n" ,
78- status );
74+ if (status != HOTH_SUCCESS ) {
75+ fprintf (stderr ,
76+ "libhoth_set_uart_config() failed: 0x%016llx; unable to set "
77+ " baud-rate\n" ,
78+ ( unsigned long long ) status );
7979 return status ;
8080 }
8181 status = libhoth_get_uart_config (dev , opts , & uart_config );
8282 }
8383 }
84- if (status == LIBHOTH_OK ) {
84+ if (status == HOTH_SUCCESS ) {
8585 printf ("Using baud-rate %d\n" , uart_config .baud_rate );
8686 }
8787 printf ("[ Use Ctrl+T-Q to quit ]%s\n" , kAnsiReset );
@@ -90,8 +90,9 @@ int htool_console_run(struct libhoth_device* dev,
9090 // will be stored at this offset)
9191 uint32_t offset ;
9292 status = libhoth_get_channel_status (dev , opts , & offset );
93- if (status != LIBHOTH_OK ) {
94- fprintf (stderr , "libhoth_get_channel_status() failed: %d\n" , status );
93+ if (status != HOTH_SUCCESS ) {
94+ fprintf (stderr , "libhoth_get_channel_status() failed: 0x%016llx\n" ,
95+ (unsigned long long )status );
9596 return status ;
9697 }
9798
@@ -106,15 +107,15 @@ int htool_console_run(struct libhoth_device* dev,
106107
107108 while (!quit ) {
108109 // Any previous failure should reset all of the USB state before retrying
109- while (status != LIBHOTH_OK ) {
110+ while (status != HOTH_SUCCESS ) {
110111 // TODO: Read STDIN during this time and buffer it so we can capture
111112 // quit events even when the console is disconnected. We will also want
112113 // to tune the reconnect time to match.
113114 if (libhoth_device_reconnect (dev ) != HOTH_SUCCESS ) {
114115 // Make sure we don't end up in a tight retry loop
115116 usleep (100 * 1000 );
116117 } else {
117- status = LIBHOTH_OK ;
118+ status = HOTH_SUCCESS ;
118119 }
119120 }
120121 // Give an opportunity for other clients to use the interface.
@@ -123,20 +124,21 @@ int htool_console_run(struct libhoth_device* dev,
123124 if (libhoth_claim_device (dev , 1000 * 1000 * opts -> claim_timeout_secs ) !=
124125 HOTH_SUCCESS ) {
125126 // If USB is down we might fail claim, just go back and retry
126- status = LIBHOTH_ERR_FAIL ;
127+ status = LIBHOTH_ERR_CONSTRUCT (HOTH_CTX_CMD_EXEC , HOTH_HOST_SPACE_LIBHOTH ,
128+ LIBHOTH_ERR_FAIL );
127129 continue ;
128130 }
129131
130132 status = libhoth_read_console (dev , STDOUT_FILENO , false, opts -> channel_id ,
131133 & offset );
132- if (status != LIBHOTH_OK ) {
134+ if (status != HOTH_SUCCESS ) {
133135 // Device resets cause failures, just loop and allow reconnection
134136 continue ;
135137 }
136138
137139 status = libhoth_write_console (dev , opts -> channel_id , opts -> force_drive_tx ,
138140 & quit );
139- if (status != LIBHOTH_OK ) {
141+ if (status != HOTH_SUCCESS ) {
140142 // Device resets cause failures, just loop and allow reconnection
141143 continue ;
142144 }
@@ -147,12 +149,14 @@ int htool_console_run(struct libhoth_device* dev,
147149 return status ;
148150}
149151
150- int htool_console_snapshot_legacy (struct libhoth_device * dev ) {
152+ libhoth_error htool_console_snapshot_legacy (struct libhoth_device * dev ) {
151153 size_t response_bytes_written ;
152- int status = libhoth_hostcmd_exec (dev , HOTH_CMD_CONSOLE_REQUEST , 0 , NULL , 0 ,
153- NULL , 0 , & response_bytes_written );
154- if (status != LIBHOTH_OK ) {
155- fprintf (stderr , "HOTH_CMD_CONSOLE_REQUEST status: %d\n" , status );
154+ libhoth_error status =
155+ libhoth_hostcmd_exec_v2 (dev , HOTH_CMD_CONSOLE_REQUEST , 0 , NULL , 0 , NULL ,
156+ 0 , & response_bytes_written );
157+ if (status != HOTH_SUCCESS ) {
158+ fprintf (stderr , "HOTH_CMD_CONSOLE_REQUEST status: 0x%016llx\n" ,
159+ (unsigned long long )status );
156160 return status ;
157161 }
158162
@@ -162,11 +166,12 @@ int htool_console_snapshot_legacy(struct libhoth_device* dev) {
162166 MAILBOX_SIZE - sizeof (struct hoth_host_response );
163167 while (true) {
164168 char buf [MAILBOX_SIZE ];
165- status = libhoth_hostcmd_exec (dev , HOTH_CMD_CONSOLE_READ , 0 , & read_request ,
166- sizeof (read_request ), buf , max_bytes_per_read ,
167- & response_bytes_written );
168- if (status != LIBHOTH_OK ) {
169- fprintf (stderr , "HOTH_CMD_CONSOLE_READ status: %d\n" , status );
169+ status = libhoth_hostcmd_exec_v2 (
170+ dev , HOTH_CMD_CONSOLE_READ , 0 , & read_request , sizeof (read_request ), buf ,
171+ max_bytes_per_read , & response_bytes_written );
172+ if (status != HOTH_SUCCESS ) {
173+ fprintf (stderr , "HOTH_CMD_CONSOLE_READ status: 0x%016llx\n" ,
174+ (unsigned long long )status );
170175 return status ;
171176 }
172177 fwrite (buf , strnlen (buf , sizeof (buf )), 1 , stdout );
@@ -176,8 +181,8 @@ int htool_console_snapshot_legacy(struct libhoth_device* dev) {
176181 return status ;
177182}
178183
179- int htool_console_snapshot (struct libhoth_device * dev ,
180- const struct libhoth_htool_console_opts * opts ) {
184+ libhoth_error htool_console_snapshot (
185+ struct libhoth_device * dev , const struct libhoth_htool_console_opts * opts ) {
181186 // Legacy host commands for console snapshot.
182187 if (!opts -> channel_id ) {
183188 return htool_console_snapshot_legacy (dev );
@@ -186,17 +191,18 @@ int htool_console_snapshot(struct libhoth_device* dev,
186191 // Starting from current_offset - 0x80000000 so it's guaranteed to be outside
187192 // of the Hoth buffer. Repeat read until reaching current offset.
188193 uint32_t current_offset ;
189- int status = libhoth_get_channel_status (dev , opts , & current_offset );
190- if (status != LIBHOTH_OK ) {
191- fprintf (stderr , "libhoth_get_channel_status) failed: %d\n" , status );
194+ libhoth_error status = libhoth_get_channel_status (dev , opts , & current_offset );
195+ if (status != HOTH_SUCCESS ) {
196+ fprintf (stderr , "libhoth_get_channel_status failed: 0x%016llx\n" ,
197+ (unsigned long long )status );
192198 return status ;
193199 }
194200 uint32_t offset = current_offset - 0x80000000 ;
195201
196202 while (true) {
197203 status = libhoth_read_console (dev , STDOUT_FILENO , false, opts -> channel_id ,
198204 & offset );
199- if (status != LIBHOTH_OK ) {
205+ if (status != HOTH_SUCCESS ) {
200206 break ;
201207 }
202208 // Extra check in case UINT32_MAX wrap-around.
0 commit comments