Esempio n. 1
0
// array view
static void array_view(unsigned *point, unsigned len) {
    unsigned i;
    for (i = 0; i < (len / 4); i++) {
        if (i >= 4 &&i % (unsigned)4 == 0)
            put_string(" ");
        if (i >= 8 && i % (unsigned)8 == 0)
            util_printf("0x%x\n", (point + i));
        util_printf("%x ", point[i]);
    }
    put_string("\n");
}
Esempio n. 2
0
void util_scan(char const *fmt, char const *text)
{
    size_t value;
    sscanf(text, fmt, &value);

    util_printf("%u", value);    
}
Esempio n. 3
0
// run another code
static void run_kernel(void) {
    unsigned read_size;
    unsigned boot_args[AT45_PAGE_SIZE / 4];
    kernel_t kernel = (kernel_t) LINUX_BASE_ADDRESS;
    unsigned *tags = (unsigned *) LINUX_TAGS_ADDRESS;
    unsigned *sz, len;
    const char *cmdline = "mem=128M root=/dev/sda1 rootwait ro";

    /*if (!at45_read(BOOT_2_ARGS_OFFSET, boot_args, AT45_PAGE_SIZE)) {
        read_size = boot_args[0];
        util_printf("Read 0x%x bytes\n", read_size);
        if (read_size > 0 && read_size < (AT45DB642D_SIZE - 4)) {
            if (!at45_read(LINUX_OFFSET, (unsigned *)LINUX_BASE_ADDRESS, read_size)) {*/
    put_string("Read success\nConfiguring\n");
    /* atag_core */
    *tags++ = 5;
    *tags++ = 0x54410001;
    *tags++ = 1;
    *tags++ = 4096;
    *tags++ = 0;

    /* atag_mem */
    *tags++ = 4;
    *tags++ = 0x54410002;
    *tags++ = SDRAM_BASE_ADDRESS;
    *tags++ = SDRAM_SIZE;

    /* atag_cmdline */
    sz = tags++;
    *tags++ = 0x54410009;
    len = cmdcpy(tags, cmdline);
    *sz = 2 + len;
    tags += len;

    /* atag_none */
    *tags++ = 0;
    *tags++ = 0;

    util_printf("Jump to the kernel image\n\n");

    kernel(0, MACHINE_ID, (void*) LINUX_TAGS_ADDRESS);
    /*}
    }
    }*/
}
Esempio n. 4
0
/*
 * Get the when part of a connection.
 */
static int
get_when(FILE * inFile, ABObj obj, ABObj action)
{
    int                 return_value = 0;
    ISTRING             string = NULL;
    AB_WHEN             when = AB_WHEN_UNDEF;
    int			numWhens = 0;

    if (!abio_get_list_begin(inFile))
        return (abil_print_load_err(ERR_WANT_LIST), -1);

    while (!abio_get_list_end(inFile))
    {
        if (!abio_gil_get_name(inFile, &string))
            return (abil_print_load_err(ERR_WANT_NAME), -1);

        when = gilP_string_to_when(istr_string(string));
	if (when == AB_WHEN_UNDEF)
	{
	    if (util_be_verbose())
	    {
	        util_printf("WARNING: ignoring unsupported when: %s\n",
		    istr_string(string));
	    }
	}
	else
	{
	    obj_set_when(action, when);
            istr_destroy(string);
	    ++numWhens;
	    if (numWhens > 1)
	    {
	        util_printf_err(
		    "WARNING: multiple :when values not supported. "
		    "Using first value\n");
	    }
	}
    }
    return return_value;
}
Esempio n. 5
0
// main function
extern void main(void) {
    unsigned char flag, numb_pages;
    unsigned i, write_size, read_size, temp_six_vector, six_vector, errors;
    // calculate temp six vector
    numb_pages = 0;
    i = AT45_PAGE_NUMB;
    while(i >>= 1)
        numb_pages++;
    temp_six_vector = (numb_pages << 13)  + (AT45_PAGE_SIZE << 17);
    
    // setup SYS interrupt
    aic_configure_irq(AT91C_ID_SYS, AT91C_AIC_PRIOR_LOWEST,
                      AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE, aic_asm_sys_handler);
    // enable SYS interrupt
    aic_enable_irq(AT91C_ID_SYS);
    // setup rtt - 1Hz clock
    AT91C_BASE_ST->ST_RTMR = 0x4000;
    
    upoint_r = pt_mem_area, upoint_w = (pt_mem_area + AT45DB642D_SIZE);
    put_string("Init AT45DB642D and get device information\n");
    
    if (!at45_init())
        put_string("Device inited and ready\n");
    else
        put_string("Error!\n");

    while (flag != 'q') {
        put_string("\nload(l), write(w), quit(q), erase(e): ");
        flag = get_char();
        switch(flag) {
            // loading data to sdram
            case 'l':
                put_string("Please trasfer the boot file:\n");
                transfer_size = 0;
                // setup rtt interrupt flag
                AT91C_BASE_ST->ST_IER = AT91C_ST_RTTINC;
                // enable RXRDY interrupt in DBGU
                AT91C_BASE_DBGU->DBGU_IER |= AT91C_US_RXRDY;
                while(!transfer_size);
                delay(100000);
                if (transfer_size > 0) {
                    put_string("Transfer complete\n");
                    util_printf("Byte's sended: %x\n", transfer_size);
                }
            break;
            // writing bytes from data flash 
            case 'w':
                if (transfer_size == 0) {
                    put_string("Please transfer begin, write end\n");
                    break;
                }
                else if (transfer_size > (AT45DB642D_SIZE)) {
                    put_string("Trasfer is larger than flash size\n");
                    break;
                }
                else {
                    if ((unsigned)transfer_size % AT45_PAGE_SIZE)
                        write_size = ((unsigned)transfer_size / AT45_PAGE_SIZE + 1) * AT45_PAGE_SIZE;
                    else
                        write_size = transfer_size;
                    put_string("\nModification of Arm Interrupt Vector #6\n");
                    six_vector = (write_size / 512) + 1 + temp_six_vector;
                    util_printf("Six vector is 0x%x\n", six_vector);
                    upoint_w[5] = six_vector;
                    util_printf("Write 0x%x bytes\n", write_size);
                    
                    array_view(upoint_w, write_size);
                    
                    if (!at45_write(0x0, upoint_w, write_size))
                        put_string("Write success\n");
                    else
                        put_string("Error!\n");
                    if (!at45_read(0x0, upoint_r, write_size)) {
                        put_string("Read success\nStart verification\n");
                        six_vector = upoint_r[5];
                        if ((six_vector & 0xfffff000) - temp_six_vector) {
                            util_printf("Six vector is damage, current 0x%x, original 0x%x\n",
                                        six_vector, temp_six_vector);
                            break;
                        }
                        else {
                            put_string("Six vector is correct\nStart code verification\n");
                        }
                        for (i = 0; i < write_size / 4; i++) {
                            if (upoint_r[i] != upoint_w[i]) {
                                errors++;
                                util_printf("Addr - %x, write - %x, read - %x\n", i, upoint_w[i], upoint_r[i]);
                            }
                        }
                        put_string("Stop code verification\n");
                        if (errors)
                            put_string("Verification failed!\n");
                        else
                            put_string("Verification success!\n");
                    }
                }
            break;
            // erase first page
            case 'e':
                if (!at45_read(0x0, upoint_r, 0x20)) {
                    six_vector = upoint_r[5];
                    read_size = (six_vector & 0xff) * 512;
                    for (i = 0; i <= read_size; i += AT45_PAGE_SIZE) {
                        if (!at45_page_erase(i))
                            put_string("Erase success\n");
                        else
                            put_string("Error!\n");
                    }
                }
            break;
            // exit of loop
            case 'q':
                put_string("\nQuit & Reset\n");
                AT91C_BASE_ST->ST_WDMR = 256 | AT91C_ST_RSTEN;
                AT91C_BASE_ST->ST_CR = AT91C_ST_WDRST;
            break;
            // undef
            default:
                put_string("\nUndefined command\n");
            break;
        }
    }
    // Infinity loop
    while (1) {
        // Disable pck for idle cpu mode
        AT91C_BASE_PMC->PMC_SCDR = AT91C_PMC_PCK;
    }
}
Esempio n. 6
0
int main(int, char ** argv) {
		const long double clock1 = clock();
		
		SysLog_t _log(argv[ 0 ]);
		log = &_log;

		try {
				wiki_storage = new WikiStorage_t( WIKI_STORAGE_LOCATION );

		} catch( std::bad_alloc ex ) {
				log->alert("%s", "Memory allocation faild.");
				cgi_responde::send_extra(cgi_responde::status_500_internal_server_error);
				return -1;

		} catch( std::io_error ex ) {
				log->alert("%s: %s", "InOut error occured", ex.what());
				cgi_responde::send_extra(cgi_responde::status_500_internal_server_error);
				return -1;				

		} catch( std::invalid_argument ex ) {
				log->alert("%s: %s", "Wrong storage configuration", ex.what());
				cgi_responde::send_extra(cgi_responde::status_500_internal_server_error);
				return -1;

		} catch( ... ) {
				log->emergency("%s", "main(): unknown exception.");
				cgi_responde::send_extra(cgi_responde::status_500_internal_server_error);
				return -1;
		}

		try {
				cgi_request::construct( 0 );
				cgi_responde::construct();

				if( strncmp("HTTP", cgi_request::get_server_protocol(), 4) )
						throw std::invalid_argument("There is not supported server protocol.");

				script_name.append(cgi_request::get_script_name());
				server_url.append("http://");
				server_url.append(cgi_request::get_server_name());
				
				if( 80 != atoi(cgi_request::get_server_port()) )
						server_url.append(':').append(cgi_request::get_server_port());

		} catch( std::bad_alloc ex ) {
				log->alert("%s", "Memory allocation faild.");
				cgi_responde::send_extra(cgi_responde::status_500_internal_server_error);
				return -1;

		} catch( std::invalid_argument ex ) {
				log->emergency("%s: %s", "Wrong script running", ex.what());
				cgi_responde::send_extra(cgi_responde::status_500_internal_server_error);
				return -1;

		} catch( std::io_error ex ) {
				log->alert("%s: %s", "InOut error occured", ex.what());
				cgi_responde::send_extra(cgi_responde::status_500_internal_server_error);
				return -1;				

		} catch( std::length_error ex ) {
				log->notice("%s: %s", "Too lagre request", ex.what());
				cgi_responde::send_extra(cgi_responde::status_413_request_entity_too_large);
				return -1;

		} catch( std::logic_error ex ) {
				log->emergency("%s", ex.what());
				cgi_responde::send_extra(cgi_responde::status_500_internal_server_error);
				return -1;

		} catch( ... ) {
				log->emergency("%s", "main(): unknown exception.");
				cgi_responde::send_extra(cgi_responde::status_500_internal_server_error);
				return -1;
		}

		try {
#ifndef NDEBUG
				{
						const char * gateway_interface = cgi_request::get_gateway_interface();
						const char * script_name = cgi_request::get_script_name();
						const char * path_info = cgi_request::get_path_info();
						const char * request_method = cgi_request::get_request_method();

						log->debug("%s", util_ctime());
						log->debug("### connection ###");
						log->debug("# cgi input");
						log->debug("  gateway interface: %s", gateway_interface);
						log->debug("  script_name: %s", script_name);
						log->debug("  path_info: %s", path_info ? path_info : "");
						log->debug("  request_method: %s", request_method);
						log->flush();
				}
#endif
				build();
				
#ifndef NDEBUG
				{
						const char * status = cgi_responde::get_status();
						const char * location = cgi_responde::get_location();
						const char * content_type = cgi_responde::get_content_type();

						log->debug("# cgi output");
						log->debug("  status: %s", status ? status : "");
						log->debug("  location: %s", location ? location : "");
						log->debug("  content-type: %s", content_type ? content_type : "");
						log->flush();
				}
#endif

				cgi_responde::send();

		} catch( std::bad_alloc ex ) {
				log->alert("%s", "Memory allocation faild.");
				cgi_responde::send_extra(cgi_responde::status_500_internal_server_error);
				return -1;

		} catch( std::io_error ex ) {
				log->alert("%s: %s", "InOut error occured", ex.what());
				cgi_responde::send_extra(cgi_responde::status_500_internal_server_error);
				return -1;

		} catch( const std::invalid_argument ex ) {
				log->warning("%s: %s", "Wrong request", ex.what());
				cgi_responde::send_extra(cgi_responde::status_400_bad_request);
				return -1;

		} catch( const std::out_of_range ex ) {
				log->emergency("%s: %s", "Internal overful", ex.what());
				cgi_responde::send_extra(cgi_responde::status_500_internal_server_error);
				return -1;

		} catch( std::logic_error ex ) {
				log->emergency("%s: %s", "Incorrect arhitechure", ex.what());
				cgi_responde::send_extra(cgi_responde::status_500_internal_server_error);
				return -1;

		} catch( ... ) {
				log->emergency("%s", "main(): unknown exception.");
				cgi_responde::send_extra(cgi_responde::status_500_internal_server_error);
				return -1;
		}

		cgi_request::destruct();
		cgi_responde::destruct();
		
		delete wiki_storage;

		const long double clock2 = clock();

		util_printf("\r\n<!-- clock: %.3Lf -->", (clock2 - clock1) / CLOCKS_PER_SEC);

		return 0;
}
Esempio n. 7
0
// at45x writing data
Esempio n. 8
0
// at45x initing