Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 13 commits
  • 10 files changed
  • 0 commit comments
  • 2 contributors
View
12 libxenon/drivers/console/console.c
@@ -182,8 +182,10 @@ void console_init(void) {
}
void console_set_colors(unsigned int background, unsigned int foreground){
- console_color[0]=background;
- console_color[1]=foreground;
+ if (background > -1)
+ console_color[0]=background;
+ if (foreground > -1)
+ console_color[1]=foreground;
}
void console_get_dimensions(unsigned int * width,unsigned int * height){
@@ -191,6 +193,12 @@ void console_get_dimensions(unsigned int * width,unsigned int * height){
if (height) *height=max_y;
}
+unsigned int console_get_color(int num){
+ if (num < 0 || num > 1)
+ return 0;
+ return console_color[num];
+}
+
void console_close(void)
{
stdout_hook = 0;
View
27 libxenon/drivers/console/console.h
@@ -5,6 +5,33 @@
extern "C" {
#endif
+unsigned int old_console_color[2];
+
+#define CONSOLE_COLOR_RED 0x0000FF00
+#define CONSOLE_COLOR_BLUE 0xD8444E00
+#define CONSOLE_COLOR_GREEN 0x00800000
+#define CONSOLE_COLOR_BLACK 0x00000000
+#define CONSOLE_COLOR_WHITE 0xFFFFFF00
+#define CONSOLE_COLOR_GREY 0xC0C0C000
+#define CONSOLE_COLOR_BROWN 0x00339900
+#define CONSOLE_COLOR_PURPLE 0xFF009900
+#define CONSOLE_COLOR_YELLOW 0x00FFFF00
+#define CONSOLE_COLOR_ORANGE 0x0066FF00
+#define CONSOLE_COLOR_PINK 0xFF66FF00
+
+#define CONSOLE_WARN CONSOLE_COLOR_YELLOW
+#define CONSOLE_ERR CONSOLE_COLOR_ORANGE
+
+#define PRINT_COL(bg, fg, s, ...) \
+ old_console_color[0] = console_get_color(0); old_console_color[1] = console_get_color(1); \
+ console_set_colors(bg,fg); \
+ printf(s, ##__VA_ARGS__); \
+ console_set_colors(old_console_color[0],old_console_color[1]);
+
+#define PRINT_WARN(s, ...) PRINT_COL(-1,CONSOLE_WARN,s, ##__VA_ARGS__)
+#define PRINT_ERR(s, ...) PRINT_COL(-1,CONSOLE_ERR,s, ##__VA_ARGS__)
+
+unsigned int console_get_color(int num);
void console_set_colors(unsigned int background, unsigned int foreground); // can be called before init
void console_get_dimensions(unsigned int * width,unsigned int * height);
void console_putch(const char c);
View
46 libxenon/drivers/elf/elf.c
@@ -1,3 +1,11 @@
+/* devtree preparation & initrd handling
+
+Copyright (C) 2010-2011 Hector Martin "marcan" <hector@marcansoft.com>
+
+This code is licensed to you under the terms of the GNU GPL, version 2;
+see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
+*/
+
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
@@ -10,6 +18,7 @@
#include <libfdt/libfdt.h>
#include <nocfe/addrspace.h>
+#include "elf.h"
#include "elf_abi.h"
#define INITRD_RELOC_START ((void*)0x85FE0000)
@@ -198,6 +207,7 @@ void elf_runFromMemory (void *addr, int size)
{
int i;
+ printf(" * Executing...\n");
shutdown_drivers();
// relocate code
@@ -270,7 +280,7 @@ void elf_runWithDeviceTree (void *elf_addr, int elf_size, void *dt_addr, int dt_
return;
}
- if (bootargs && bootargs[0])
+ if (bootargs[0])
{
res = fdt_setprop(ELF_DEVTREE_START, node, "bootargs", bootargs, strlen(bootargs)+1);
if (res < 0){
@@ -281,21 +291,17 @@ void elf_runWithDeviceTree (void *elf_addr, int elf_size, void *dt_addr, int dt_
if (initrd_start && initrd_size)
{
- printf(" * Relocating initrd...\n");
- memset(INITRD_RELOC_START,0,INITRD_MAX_SIZE);
- memcpy(INITRD_RELOC_START,initrd_start,initrd_size);
-
- initrd_start = INITRD_RELOC_START;
+ kernel_relocate_initrd(initrd_start,initrd_size);
u64 start, end;
- start = (u32)PHYSADDR((uint64_t)initrd_start);
+ start = (u32)PHYSADDR((u32)initrd_start);
res = fdt_setprop(ELF_DEVTREE_START, node, "linux,initrd-start", &start, sizeof(start));
if (res < 0){
printf("couldn't set chosen.linux,initrd-start property\n");
return;
}
- end = (u32)PHYSADDR((uint64_t)initrd_start + (uint64_t)initrd_size);
+ end = (u32)PHYSADDR(((u32)initrd_start + (u32)initrd_size));
res = fdt_setprop(ELF_DEVTREE_START, node, "linux,initrd-end", &end, sizeof(end));
if (res < 0) {
printf("couldn't set chosen.linux,initrd-end property\n");
@@ -332,26 +338,40 @@ void elf_runWithDeviceTree (void *elf_addr, int elf_size, void *dt_addr, int dt_
elf_runFromMemory(elf_addr,elf_size);
}
-void kernel_set_initrd(void *start, size_t size)
+void kernel_prepare_initrd(void *start, size_t size)
{
if (size > INITRD_MAX_SIZE){
printf(" ! Initrd bigger than 32 MB, Aborting!\n");
return;
}
- if (initrd_start != NULL) free(initrd_start);
-
+ if(initrd_start != NULL)
+ free(initrd_start);
initrd_start = (uint8_t*)malloc(size);
+
memcpy(initrd_start,start,size);
+ initrd_size = size;
+}
+
+void kernel_relocate_initrd(void *start, size_t size)
+{
+ printf(" * Relocating initrd...\n");
+
+ memset(INITRD_RELOC_START,0,INITRD_MAX_SIZE);
+ memcpy(INITRD_RELOC_START,start,size);
+ initrd_start = INITRD_RELOC_START;
initrd_size = size;
printf("Initrd at %p/0x%lx: %ld bytes (%ldKiB)\n", initrd_start, \
- (u32)PHYSADDR((uint64_t)initrd_start), initrd_size, initrd_size/1024);
+ (u32)PHYSADDR((u32)initrd_start), initrd_size, initrd_size/1024);
}
void kernel_reset_initrd(void)
{
+ if (initrd_start != NULL)
+ free(initrd_start);
+
initrd_start = NULL;
initrd_size = 0;
}
@@ -370,4 +390,4 @@ void kernel_build_cmdline(const char *parameters, const char *root)
strlcat(bootargs, parameters, MAX_CMDLINE_SIZE);
printf("Kernel command line: '%s'\n", bootargs);
-}
+}
View
3 libxenon/drivers/elf/elf.h
@@ -9,7 +9,8 @@ extern "C" {
void elf_runFromMemory (void *addr, int size);
int elf_runFromDisk (char *filename);
void elf_runWithDeviceTree (void *elf_addr, int elf_size, void *dt_addr, int dt_size);
-void kernel_set_initrd(void *start, size_t size);
+void kernel_prepare_initrd(void *start, size_t size);
+void kernel_relocate_initrd(void *start, size_t size);
void kernel_reset_initrd(void);
void kernel_build_cmdline(const char *parameters, const char *root);
View
12 libxenon/drivers/lwip/xenon/netif/enet.c
@@ -182,7 +182,8 @@ err_t enet_init(struct netif *netif)
static int enet_open(struct netif *netif)
{
- enet_context *context = (enet_context *) netif->state;
+ int tries=10;
+ struct enet_context *context = (struct enet_context *) netif->state;
//printf("NIC reset\n");
write32n(0xea001424, 0); // disable interrupts
@@ -234,7 +235,12 @@ static int enet_open(struct netif *netif)
xenon_gpio_control(4,0,0x10);
phy_write(0, 0x9000);
- while (phy_read(0) & 0x8000);
+
+ while (phy_read(0) & 0x8000){
+ mdelay(500);
+ tries--;
+ if (tries<=0) break;
+ };
// phy_write(0x10, 0x8058);
// phy_write(4, 0x5e1);
@@ -243,7 +249,7 @@ static int enet_open(struct netif *netif)
int linkstate = phy_read(1);
if (!(linkstate & 4))
{
- int tries=10;
+ tries=10;
printf("Waiting for link...");
while (!(phy_read(1) & 4)){
View
3 libxenon/drivers/newlib/newlib.c
@@ -413,6 +413,9 @@ void _exit(int status)
try_return_to_xell(0xc8070000,0x1c000000); // xell-gggggg (ggboot)
try_return_to_xell(0xc8095060,0x1c040000); // xell-2f (freeboot)
try_return_to_xell(0xc8100000,0x1c000000); // xell-1f, xell-ggggggg
+ try_return_to_xell(0xc80C0000,0x1c000000);
+ try_return_to_xell(0xc80E0000,0x1c000000);
+ try_return_to_xell(0xc8B80000,0x1c000000);
}
for(;;);
View
14 libxenon/drivers/usb/usbctrl.c
@@ -315,10 +315,10 @@ static int usbctrl_ireq_callback(usbreq_t *ur)
//FIXME: A polled, disconnected controller may cause uneeded spam of the controller status message
if(uhid->index == -1)
{
- printf("Wireless controller %i has connected\n", uhid->wireless_index);
+ //printf("Wireless controller %i has connected\n", uhid->wireless_index);
int i;
for (i = 0; controller_mask & (1<<i); ++i);
- printf("attached controller %d\n", i);
+ //printf("attached controller %d\n", i);
uhid->index = i;
setcontroller(uhid, uhid->index);
controller_mask |= 1<<i;
@@ -329,8 +329,8 @@ static int usbctrl_ireq_callback(usbreq_t *ur)
if (b[0] == 0x8 && b[1] == 0x0)
{
- printf("Wireless controller %i has disconnected\n", uhid->wireless_index);
- printf("detatched controller %d\n", uhid->index);
+ //printf("Wireless controller %i has disconnected\n", uhid->wireless_index);
+ //printf("detatched controller %d\n", uhid->index);
setcontroller(NULL, uhid->index);
controller_mask &= ~(1<<uhid->index);
@@ -457,7 +457,9 @@ static int usbctrl_attach(usbdev_t *dev,usb_driver_t *drv)
usb_endpoint_descr_t *epdscr;
usb_interface_descr_t *ifdscr;
- int wireless = (GETUSBFIELD(&dev->ud_devdescr, idProduct) == 0x291) || (GETUSBFIELD(&dev->ud_devdescr, idProduct) == 0x2aa) || (GETUSBFIELD(&dev->ud_devdescr, idProduct) == 0x2a9);
+ int wireless = (GETUSBFIELD(&dev->ud_devdescr, idProduct) == 0x291) ||
+ (GETUSBFIELD(&dev->ud_devdescr, idProduct) == 0x2aa) ||
+ (GETUSBFIELD(&dev->ud_devdescr, idProduct) == 0x2a9);
if(wireless)
{
@@ -480,7 +482,7 @@ static int usbctrl_attach(usbdev_t *dev,usb_driver_t *drv)
}
- printf("Initializing wireless controller %d\n", i);
+ //printf("Initializing wireless controller %d\n", i+1); // Be quiet
softc->index = -1;
softc->wireless_index = i;
//controller_mask |= 1<<i; //Dont set this right now, let wired controllers use the slots
View
8 libxenon/drivers/usb/usbdevs.c
@@ -91,10 +91,10 @@ usb_drvlist_t usb_drivers[] = {
*/
{USB_DEVICE_CLASS_HUMAN_INTERFACE, VENDOR_ANY,PRODUCT_ANY, &usbhid_driver},
- {CLASS_ANY, 0x045e,0x28e, &usbctrl_driver},
- {CLASS_ANY, 0x045e,0x291, &usbctrl_driver},
- {CLASS_ANY, 0x045e,0x2aa, &usbctrl_driver},
- {CLASS_ANY, 0x045e,0x2a9, &usbctrl_driver},
+ {CLASS_ANY, 0x045e,0x291, &usbctrl_driver}, // RF unit
+ {CLASS_ANY, 0x045e,0x28e, &usbctrl_driver}, // wired controller
+ {CLASS_ANY, 0x045e,0x2aa, &usbctrl_driver}, // wireless controller
+ {CLASS_ANY, 0x045e,0x2a9, &usbctrl_driver}, // wireless controller
/*
* Mass storage devices
*/
View
87 libxenon/drivers/xenon_nand/xenon_sfcx.c
@@ -1,8 +1,12 @@
#include <xetypes.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
#include "xenon_sfcx.h"
struct sfc sfc = {0};
+unsigned char* blockbuf;
//static unsigned char sfcx_page[MAX_PAGE_SZ]; //Max known hardware physical page size
//static unsigned char sfcx_block[MAX_BLOCK_SZ]; //Max known hardware physical block size
@@ -380,6 +384,89 @@ int sfcx_rawaddress_to_block(int address)
return address / sfc.block_sz_phys;
}
+int rawflash_writeImage(int len, int f)
+{
+ int i=0;
+ int secondPgOffset = sfc.page_sz_phys;
+ int addr, addrphy, status, r;
+ int readsz = sfc.pages_in_block*sfc.page_sz_phys;
+ int numblocks = (len/sfc.block_sz_phys);
+ blockbuf = malloc(readsz);
+ if(blockbuf == NULL)
+ {
+ printf("ERROR: unable to allocate 0x%x bytes for a buffer!\n", readsz);
+ return 0;
+ }
+ if(sfc.meta_type == META_TYPE_2)
+ secondPgOffset = 0x1080; // 0x210*8
+ while(i < numblocks)
+ {
+ printf("processing block 0x%04x of 0x%04x \r", i+1, numblocks);
+ addr = i*sfc.block_sz;
+ // check first two pages of each block to find out if it's a good block
+ status = sfcx_read_block(blockbuf, addr, 1);
+ if((sfcx_is_pagevalid(blockbuf) == 0) || (sfcx_is_pagevalid(&blockbuf[secondPgOffset]) == 0))
+ status = status | STATUS_BB_ER;
+ r = read(f, blockbuf, readsz);
+ if (r < 0)
+ {
+ printf("ERROR: failed to read %d bytes from file\n\n",readsz);
+ return 0;
+ }
+ if((status & (STATUS_BB_ER|STATUS_ECC_ER)) == 0)
+ {
+ addr = i*sfc.block_sz_phys;
+ addrphy = i*sfc.block_sz;
+ sfcx_erase_block(addrphy);
+ sfcx_write_block(blockbuf, addrphy);
+ }
+ else
+ printf("block 0x%x seems bad, status 0x%08x\n", i, status);
+ i++;
+ }
+ printf("\n\n");
+ return 1;
+}
+
+void try_rawflash(char *filename)
+{
+ struct stat s;
+ int size;
+ int f = open(filename, O_RDONLY);
+ if (f < 0)
+ {
+ return;
+ }
+ printf(" * rawflash v4 started (by cOz)\n");
+
+ fstat(f, &s);
+ size = s.st_size;
+ if((size == (RAW_NAND_64*4)) || (size == (RAW_NAND_64*8))) // 256 or 512M NAND image, only flash 64M
+ {
+ size = RAW_NAND_64;
+ }
+ else if((size != 0x1080000)&& (size != RAW_NAND_64)) // 16 M size
+ {
+ printf("error: %s - size %d is not valid image size!\n", filename, size);
+ close(f);
+ return;
+ }
+ printf("\n * found '%s'. press power NOW if you don't want to flash the NAND.\n",filename);
+ delay(15);
+
+ printf("%s opened OK, attempting to write 0x%x bytes to flash...\n",filename, size);
+ if(rawflash_writeImage(size, f) == 1)
+ printf("image written, shut down now!\n");
+ else
+ printf("failed to write image :(\n");
+
+ close(f);
+ if(blockbuf != NULL)
+ free(blockbuf);
+
+ for(;;); // loop
+}
+
/*
int sfcx_read_metadata_type(void)
{
View
2 libxenon/drivers/xenon_nand/xenon_sfcx.h
@@ -129,6 +129,8 @@ int sfcx_block_to_address(int block);
int sfcx_address_to_block(int address);
int sfcx_block_to_rawaddress(int block);
int sfcx_rawaddress_to_block(int address);
+int rawflash_writeImage(int len, int f);
+void try_rawflash(char *filename);
int sfcx_read_metadata_type(void);

No commit comments for this range

Something went wrong with that request. Please try again.