Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README #1

Open
wants to merge 12 commits into
base: xellxell
Choose a base branch
from
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.o
*.elf
*.elf32
*.bin
version.h
.cdtproject
.cproject
.project
.settings/
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ CFLAGS = -Wall -O2 -I. -Ilwip/include \
-m64 -mno-toc -DBYTE_ORDER=BIG_ENDIAN -mno-altivec \
-I nocfe -D_CFE_=1 -DENDIAN_BIG=1

ifdef CYGNOS
CFLAGS += -DCYGNOS
endif

AFLAGS = -Iinclude -m64
LDFLAGS = -nostdlib -n

Expand Down
15 changes: 15 additions & 0 deletions httpd/httpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,20 @@ static void response_mem_finish(struct http_state *http)
mem_free(priv);
}

static int response_fuses_process_request(struct http_state *http, const char *method, const char *url)
{
if (strcmp(method, "GET"))
return 0;

if (strcmp(url, "/FUSE"))
return 0;

extern char FUSES[350]; /* this has to be static */
http->code = 200;
response_static_process_request(http, FUSES);
return 1;
}


/* ---------- err400 handler */

Expand Down Expand Up @@ -789,6 +803,7 @@ struct httpd_handler http_handler[]=
#ifndef UNIX
{response_mem_process_request, 0, 0, response_mem_do_header, response_mem_do_data, 0, response_mem_finish},
#endif
{response_fuses_process_request, 0, 0, 0, response_static_do_data, 0, response_static_finish},
{response_vfs_process_request, 0, 0, response_vfs_do_header, response_vfs_do_data, 0, response_vfs_finish},
{response_err400_process_request, 0, 0, 0, response_static_do_data, 0, response_static_finish},
{response_err404_process_request, 0, 0, 0, response_static_do_data, 0, response_static_finish}
Expand Down
196 changes: 109 additions & 87 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ int getchar(void)

int putchar(int c)
{
#ifndef CYGNOS
if (c == '\n')
putch('\r');
#endif
putch(c);
xenos_putch(c);
return 0;
Expand Down Expand Up @@ -183,6 +185,92 @@ extern char __start_other[], __exception[];
#define LOADER_RAW 0x8000000004000000ULL
#define LOADER_MAXSIZE 0x1000000

void update_xell_flash(void *xell_address, u32 file_size) {
int i;

printf(" * flashing @1MB...\n");

sfcx_writereg(0, sfcx_readreg(0) &~ (4|8|0x3c0));
if (sfcx_readreg(0) != 0x01198010)
{
printf(" * unknown flash config %08lx, refuse to flash.\n", sfcx_readreg(0));
goto fail;
}

unsigned char hdr[0x210];
readsector(hdr, 0, 0);
if (memcmp(hdr + 0x10, "zeropair image, version=00, ", 0x1c))
{
printf(" * unknown hackimage version.\n");
printf("%s\n", hdr + 0x20);
goto fail;
}

const unsigned char elfhdr[] = {0x7f, 'E', 'L', 'F'};
if (!memcmp(xell_address, elfhdr, 4))
{
printf(" * really, we don't need an elf.\n");
goto fail;
}

int eraseblock_size = 16384; // FIXME for largeblock

int addr;
#define OFFSET 1024*1024

for (addr = 0; addr < 0x40000; addr += eraseblock_size)
{
int flash_addr = addr + OFFSET;
unsigned char block[0x210];
printf("%08x\r", flash_addr);

readsector(block, flash_addr, 0);

u32 phys_pos = sfcx_readreg(6); /* physical addr */

if (!(phys_pos & 0x04000000)) /* shouldn't happen, unless the existing image is broken. just assume the sector is okay. */
{
printf(" * Uh, oh, don't know. Reading at %08x failed.\n", i);
phys_pos = flash_addr;
}
phys_pos &= 0x3fffe00;

if (phys_pos != flash_addr)
printf(" * relocating sector %08x to %08x...\n", flash_addr, phys_pos);

flash_erase(phys_pos);
int j;
for (j = 0; j < (eraseblock_size / 0x200); ++j)
{
memset(block, 0xff, 0x200);
if (file_size > addr + j * 0x200)
memcpy(block, xell_address + addr + j * 0x200, 0x200);
memset(block + 0x200, 0, 0x10);

*(int*)(block + 0x200) = bswap_32(phys_pos / eraseblock_size);
block[0x205] = 0xFF;
calcecc(block);
write_page(phys_pos + j * 0x200, block);

readsector(block, phys_pos + j * 0x200, 0);
}
}
printf(" * update done, please reboot now!\n");
fail:
while (1);
}

void try_boot_fat(char *filename) {
extern u32 fat_file_size;
if (!fat_open(filename)) {
printf(" * fat open okay, loading file...\n");
int r = fat_read(LOADER_RAW, LOADER_MAXSIZE);
printf(" * executing...\n");
execute_elf_at((void*)LOADER_RAW);
} else
printf("fat open of %s failed!\n", filename);
}

void syscall();
void fix_hrmor();

Expand All @@ -200,7 +288,16 @@ int start(int pir, unsigned long hrmor, unsigned long pvr, void *r31)
unsigned char *p = (unsigned char*)bss_start;
memset(p, 0, bss_end - bss_start);

printf("\nXeLL - Xenon linux loader " LONGVERSION "\n");
#ifdef CYGNOS
/* set UART to 38400, 8, N, 1 */
*(volatile uint32_t*)0x80000200ea00101c = 0xae010000;
#endif

printf("\nXeLL - Xenon linux loader " LONGVERSION
#ifdef CYGNOS
" (Cygnos360 v2)"
#endif
"\n");
printf(" * Attempting to catch all CPUs...\n");

#if 1
Expand Down Expand Up @@ -248,6 +345,8 @@ int start(int pir, unsigned long hrmor, unsigned long pvr, void *r31)
return main();
}

char FUSES[350]; /* this string stores the ascii dump of the fuses */

int main() {
int i;

Expand All @@ -272,8 +371,10 @@ int main() {

#if 1
printf(" * FUSES - write them down and keep them safe:\n");
char *fusestr = FUSES;
for (i=0; i<12; ++i)
printf("fuseset %02d: %016lx\n", i, *(unsigned long*)(0x8000020000020000 + (i * 0x200)));
fusestr += sprintf(fusestr, "fuseset %02d: %016lx\n", i, *(unsigned long*)(0x8000020000020000 + (i * 0x200)));
printf(FUSES);
#endif

if (get_online_processors() != 0x3f)
Expand All @@ -295,102 +396,23 @@ int main() {
mftb(&e);
} while (tb_diff_sec(&e, &s) < 5);

if (f)
if (f && 0 == fat_init(f))
{
extern u32 fat_file_size;

if (fat_init(f))
printf(" * FAT init failed\n");
else if (fat_open("/xenon.elf"))
printf("fat open of /xenon.elf failed\n");
else
{
printf(" * fat open okay, loading file...\n");
int r = fat_read(LOADER_RAW, LOADER_MAXSIZE);
printf(" * executing...\n");
execute_elf_at((void*)LOADER_RAW);
}

try_boot_fat("xenon.elf");

#if 1
if (!fat_open("/updxell.bin"))
{
printf(" * found XeLL update. press power NOW if you don't want to update.\n");
delay(15);
fat_read(LOADER_RAW, LOADER_MAXSIZE);
printf(" * flashing @1MB...\n");

sfcx_writereg(0, sfcx_readreg(0) &~ (4|8|0x3c0));
if (sfcx_readreg(0) != 0x01198010)
{
printf(" * unknown flash config %08x, refuse to flash.\n", sfcx_readreg(0));
goto fail;
}

unsigned char hdr[0x210];
readsector(hdr, 0, 0);
if (memcmp(hdr + 0x10, "zeropair image, version=00, ", 0x1c))
{
printf(" * unknown hackimage version.\n");
printf("%s\n", hdr + 0x20);
goto fail;
}

const unsigned char elfhdr[] = {0x7f, 'E', 'L', 'F'};
if (!memcmp((void*)LOADER_RAW, elfhdr, 4))
{
printf(" * really, we don't need an elf.\n");
goto fail;
}

int eraseblock_size = 16384; // FIXME for largeblock

int addr;
#define OFFSET 1024*1024

for (addr = 0; addr < 0x40000; addr += eraseblock_size)
{
int flash_addr = addr + OFFSET;
unsigned char block[0x210];
printf("%08x\r", flash_addr);

readsector(block, flash_addr, 0);

u32 phys_pos = sfcx_readreg(6); /* physical addr */

if (!(phys_pos & 0x04000000)) /* shouldn't happen, unless the existing image is broken. just assume the sector is okay. */
{
printf(" * Uh, oh, don't know. Reading at %08x failed.\n", i);
phys_pos = flash_addr;
}
phys_pos &= 0x3fffe00;

if (phys_pos != flash_addr)
printf(" * relocating sector %08x to %08x...\n", flash_addr, phys_pos);

flash_erase(phys_pos);
int j;
for (j = 0; j < (eraseblock_size / 0x200); ++j)
{
memset(block, 0xff, 0x200);
if (fat_file_size > addr + j * 0x200)
memcpy(block, (void*)LOADER_RAW + addr + j * 0x200, 0x200);
memset(block + 0x200, 0, 0x10);

*(int*)(block + 0x200) = bswap_32(phys_pos / eraseblock_size);
block[0x205] = 0xFF;
calcecc(block);
write_page(phys_pos + j * 0x200, block);

readsector(block, phys_pos + j * 0x200, 0);
}
}
printf(" * update done\n");

fail:
while (1);
update_xell_flash(LOADER_RAW, fat_file_size);
}
#endif
}
} else
printf(" * USB/FAT init failed.\n");

printf(" * try booting tftp\n");
boot_tftp(network_boot_server_name(), network_boot_file_name());
Expand Down
5 changes: 3 additions & 2 deletions network.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "netif/etharp.h"

struct netif netif;
struct ip_addr ipaddr, netmask, gw;
static tb_t now, last_tcp, last_dhcp;

extern void enet_poll(struct netif *netif);
Expand All @@ -27,6 +26,8 @@ void network_poll();

void network_init()
{
struct ip_addr ipaddr, netmask, gw;

printf("trying to initialize network...\n");

#ifdef STATS
Expand Down Expand Up @@ -97,7 +98,7 @@ void print_network_config()
{
#define NTOA(ip) (int)((ip.addr>>24)&0xff), (int)((ip.addr>>16)&0xff), (int)((ip.addr>>8)&0xff), (int)(ip.addr&0xff)
printf(" * XeLL network config: %d.%d.%d.%d / %d.%d.%d.%d\n",
NTOA(ipaddr), NTOA(netmask));
NTOA(netif.ip_addr), NTOA(netif.netmask));
}

void network_poll()
Expand Down
Loading