Skip to content

Commit

Permalink
firmware: Rework version stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
mithro committed Jan 26, 2016
1 parent 6172f2c commit 74aa0db
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -5,7 +5,7 @@ firmware/lm32/boot.bin
firmware/lm32/firmware.bin
firmware/lm32/firmware.elf
firmware/lm32/fx2_fw_hdmi2usb.c
firmware/lm32/version.h
firmware/lm32/version_data.h
test/dump.png
build
*.pyc
Expand Down
11 changes: 7 additions & 4 deletions firmware/lm32/Makefile
Expand Up @@ -21,6 +21,7 @@ OBJECTS=isr.o \
main.o \
opsis_eeprom.o \
tofe_eeprom.o \
version.o \

all: firmware.bin

Expand Down Expand Up @@ -48,9 +49,11 @@ firmware.elf: $(OBJECTS) libs
main.o: main.c
$(compile-dep)

%.o: %.c version.h
%.o: %.c
$(compile-dep)

version.o: version.h version_data.h

%.o: %.S
$(assemble)

Expand All @@ -62,7 +65,7 @@ clean:
$(RM) $(OBJECTS) $(OBJECTS:.o=.d) firmware.elf firmware.bin
$(RM) .*~ *~

version.h: version.sh
bash version.sh
version_data.h: version_data.sh
bash version_data.sh

.PHONY: all main.o clean libs load version.h
.PHONY: all main.o clean libs load version_data.h
49 changes: 1 addition & 48 deletions firmware/lm32/ci.c
Expand Up @@ -24,15 +24,6 @@

int status_enabled;

void print_board_dna(void) {
int i;
printf("Board's DNA: ");
for(i=0; i<CSR_DNA_ID_SIZE; i++) {
printf("%02x", MMPTR(CSR_DNA_ID_ADDR+4*i));
}
printf("\r\n");
}

static void help_video_matrix(void)
{
puts("video_matrix commands (alias: 'x')");
Expand Down Expand Up @@ -139,44 +130,6 @@ static void help(void)
help_debug();
}

static void dump_csr(unsigned long long int v) {
int i = 0;
unsigned char* c = (unsigned char*)(&v);
for(i = 0; i < sizeof(unsigned long long int); i++) {
if (*(c+i) == '\0')
break;
putchar(*(c+i));
}
}

static void version(void)
{
int i = 0;
printf("gateware version info\r\n");
printf("===============================================\r\n");
printf(" platform: ");
dump_csr(platform_info_platform_read());
printf("\r\n");
printf(" target: ");
dump_csr(platform_info_target_read());
printf("\r\n");
printf(" revision: ");
for(i = 0; i < CSR_GIT_INFO_COMMIT_SIZE; i += sizeof(unsigned int)) {
unsigned int r = MMPTR(CSR_GIT_INFO_COMMIT_ADDR+i);
printf("%x", r);
}
printf("\r\n\r\n");
printf("misoc revision: %08x\r\n", identifier_revision_read());
printf("-----------------------------------------------\r\n");
printf("firmware version info\r\n");
printf("===============================================\r\n");
printf(" git commit: %s\n", git_commit);
printf("git describe: %s\n", git_describe);
printf(" git status:\n%s\n", git_status);
printf(" built: "__DATE__" "__TIME__"\r\n");
printf("-----------------------------------------------\r\n");
}

static void reboot(void)
{
asm("call r0");
Expand Down Expand Up @@ -568,7 +521,7 @@ void ci_service(void)
puts("");
}
else if(strcmp(token, "reboot") == 0) reboot();
else if(strcmp(token, "version") == 0) version();
else if(strcmp(token, "version") == 0) print_version();
else if((strcmp(token, "video_matrix") == 0) || (strcmp(token, "x") == 0)) {
token = get_token(&str);
if((strcmp(token, "list") == 0) || (strcmp(token, "l") == 0)) {
Expand Down
3 changes: 1 addition & 2 deletions firmware/lm32/ci.h
@@ -1,8 +1,7 @@
#ifndef __CI_H
#define __CI_H

void print_board_dna(void);
void ci_prompt(void);
void ci_service(void);

#endif
#endif
6 changes: 3 additions & 3 deletions firmware/lm32/main.c
Expand Up @@ -17,6 +17,7 @@
#include "hdmi_out0.h"
#include "hdmi_out1.h"
#include "fx2.h"
#include "version.h"

int main(void)
{
Expand All @@ -31,8 +32,7 @@ int main(void)
#endif

puts("\r\nHDMI2USB firmware http://timvideos.us/");
print_board_dna();
printf("Revision %08x built "__DATE__" "__TIME__"\r\n", MSC_GIT_ID);
print_version();

config_init();
time_init();
Expand All @@ -51,7 +51,7 @@ int main(void)

// Reboot the FX2 chip into HDMI2USB mode
#ifdef CSR_FX2_RESET_OUT_ADDR
//fx2_init();
fx2_init();
#endif

// Set Encoder to be pattern
Expand Down
65 changes: 65 additions & 0 deletions firmware/lm32/version.c
@@ -0,0 +1,65 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <console.h>
#include <string.h>
#include <generated/csr.h>
#include <generated/mem.h>

#include "version.h"
#include "version_data.h"

#define ALIGNMENT 4

static void print_csr_string(unsigned int addr, size_t size) {
size_t i;
void* ptr = (void*)addr;
for (i = 0; i < (size * ALIGNMENT); i += ALIGNMENT) {
unsigned char c = MMPTR(ptr+i);
if (c == '\0')
return;
putchar(c);
}
}

static void print_csr_hex(unsigned int addr, size_t size) {
size_t i = 0;
void* ptr = (void*)addr;
for (i = 0; i < (size * ALIGNMENT); i += ALIGNMENT) {
unsigned char v = MMPTR(ptr+i);
printf("%02x", v);
}
}

void print_board_dna(void) {
print_csr_hex(CSR_DNA_ID_ADDR, CSR_DNA_ID_SIZE);
}

void print_version(void) {
printf("hardware version info\r\n");
printf("===============================================\r\n");
printf(" DNA: ");
print_board_dna();
printf("\r\n");
printf("\r\n");
printf("gateware version info\r\n");
printf("===============================================\r\n");
printf(" platform: ");
print_csr_string(CSR_PLATFORM_INFO_PLATFORM_ADDR, CSR_PLATFORM_INFO_PLATFORM_SIZE);
printf("\r\n");
printf(" target: ");
print_csr_string(CSR_PLATFORM_INFO_TARGET_ADDR, CSR_PLATFORM_INFO_TARGET_SIZE);
printf("\r\n");
printf(" revision: ");
print_csr_hex(CSR_GIT_INFO_COMMIT_ADDR, CSR_GIT_INFO_COMMIT_SIZE);
printf("\r\n");
printf("misoc revision: %08x\r\n", identifier_revision_read());
printf("\r\n");
printf("firmware version info\r\n");
printf("===============================================\r\n");
printf(" git commit: %s\n", git_commit);
printf(" git describe: %s\n", git_describe);
printf(" git status:\n%s\n", git_status);
printf(" built: "__DATE__" "__TIME__"\r\n");
printf("-----------------------------------------------\r\n");
}
7 changes: 7 additions & 0 deletions firmware/lm32/version.h
@@ -0,0 +1,7 @@
#ifndef __VERSION_H
#define __VERSION_H

void print_board_dna(void);
void print_version(void);

#endif // __VERSION_H
6 changes: 1 addition & 5 deletions firmware/lm32/version.sh → firmware/lm32/version_data.sh
@@ -1,8 +1,5 @@
#!/bin/bash
cat > version.h <<EOF
#ifndef __VERSION_H
#define __VERSION_H
cat > version_data.h <<EOF
const char* git_commit = "$(git log --format="%H" -n 1)";
const char* git_describe = "$(git describe --dirty)";
Expand All @@ -11,5 +8,4 @@ const char* git_status =
$(git status --short | sed -e's-^- " -' -e's-$-\\n"-')
" --\n";
#endif // __VERSION_H
EOF

0 comments on commit 74aa0db

Please sign in to comment.