Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
AUTOMAKE_OPTIONS = foreign
SUBDIRS = src
SUBDIRS = src scripts
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ AC_CHECK_FUNCS([bzero getpagesize memset munmap select strstr strtoul strtoull])
AC_CONFIG_FILES([
Makefile
src/Makefile
scripts/Makefile
])
AC_OUTPUT
1 change: 1 addition & 0 deletions scripts/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin_SCRIPTS = splash-convert
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ GITCOMMIT:= $(shell git describe --abbrev=12 --dirty --always)

CFLAGS=-Wall -fno-tree-cselim

tshwctl_SOURCES = tshwctl.c fpga.c eval_cmdline.c helpers.c
tshwctl_SOURCES = tshwctl.c fpga.c helpers.c
tshwctl_CPPFLAGS = -DGITCOMMIT="\"${GITCOMMIT}\""

lcdmesg_SOURCES = lcdmesg.c helpers.c fpga.c
Expand Down
89 changes: 0 additions & 89 deletions src/eval_cmdline.c

This file was deleted.

10 changes: 0 additions & 10 deletions src/eval_cmdline.h

This file was deleted.

24 changes: 24 additions & 0 deletions src/helpers.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <endian.h>
#include <string.h>
#include <errno.h>

int get_model(void)
{
Expand Down Expand Up @@ -29,3 +31,25 @@ int get_model(void)

return ret;
}

int chosen_read_u32(const char *name, uint32_t *value)
{
char path[256];
FILE *fp;
uint32_t be_val;
size_t n;

snprintf(path, sizeof(path), "/sys/firmware/devicetree/base/chosen/%s", name);

fp = fopen(path, "rb");
if (!fp)
return errno;
Comment on lines +45 to +46
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, if we just return -1 here, errno would get passed just the same.

n = fread(&be_val, 1, sizeof(be_val), fp);
fclose(fp);

if (n != sizeof(be_val))
return EIO;
Comment on lines +50 to +51
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something to keep in mind in the future, when returning an error code we probably want to follow along with how errno handles it. e.g. return -1 and then set errno appropriately for consistency. Either that, or, as the kernel does it, return a negative code e.g. -EIO


*value = be32toh(be_val);
return 0;
}
Comment on lines +35 to +55
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all uses 4 space indenting, should be tabs

1 change: 1 addition & 0 deletions src/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
#define __HELPERS_H__

int get_model(void);
int chosen_read_u32(const char *name, uint32_t *value);

#endif //__HELPERS_H__
36 changes: 27 additions & 9 deletions src/tshwctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "eval_cmdline.h"
#include "fpga.h"
#include "helpers.h"

Expand All @@ -24,17 +23,36 @@ int model = 0;

void do_info(void)
{
fpga_init(0x50004000);
eval_cmd_init();
int ret;

fpga_init(0x50004000);
printf("MODEL=%X\n", model);

if(model == 0x7100) {
printf("FPGA_REV=0x%X\n", fpeek32(0x0) >> 16);
printf("CPU_OPTS=0x%X\n", eval_cmd("cpu_opts"));
printf("IO_OPTS=0x%X\n", eval_cmd("io_opts"));
printf("IO_MODEL=0x%X\n", eval_cmd("io_model"));
} else if(model == 0x7250) {
if (model == 0x7100) {
uint32_t cpu_options, io_options, io_model;

ret = chosen_read_u32("cpu-options", &cpu_options);
if (ret) {
fprintf(stderr, "cpu-options missing from device-tree chosen.\n"
"This may be an outdated u-boot\n");
Comment on lines +36 to +37
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fprintf(stderr, "cpu-options missing from device-tree chosen.\n"
"This may be an outdated u-boot\n");
fprintf(stderr, "cpu-options missing from loaded devicetree.\n"
"This may be an outdated U-Boot build.\n");

return;
}

ret = chosen_read_u32("io-options", &io_options);
if (ret) {
return;
}

ret = chosen_read_u32("io-model", &io_model);
if (ret) {
return;
}
Comment on lines +35 to +49
Copy link
Collaborator

@ts-kris ts-kris May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest of codebase looks like it does not add braces for single line following an if, suggest these change to

if (ret)
	return;

for consistency.

EDIT: This would only apply to lines 41-49 above, I accidentally highlighted too far back.


printf("FPGA_REV=%d\n", fpeek32(0x0));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to understand why this line changed from fpeek32(0x0) >> 16 to this. Was it always a bug or did this change happen at some point in the FPGA history and could break on older FPGA revisions?

printf("CPU_OPTS=0x%X\n", cpu_options);
printf("IO_OPTS=0x%X\n", io_options);
printf("IO_MODEL=0x%X\n", io_model);
} else if (model == 0x7250) {
uint32_t fpga_rev = fpeek32(0x0);
uint32_t fpga_hash = fpeek32(0x4);
uint32_t opts = fpeek32(0x8);
Expand Down