Esempio n. 1
0
void ICACHE_FLASH_ATTR fetch_code_from_cloud()
{
	char buf0[512], buf1[512];

	if ( user_params_get(buf0, sizeof(buf0)) )
	{
		buf0[sizeof(buf0) - 1] = 0;
		char *p = (char*)os_strstr(buf0, ";");
		if (p != NULL && p != buf0)
		{
			p[0] = 0;
			char *q = (char*)os_strstr(p + 1, ";");
			if (q != NULL && q != p + 1)
			{
				q[0] = 0;
				_miid = (char*)os_malloc(os_strlen(buf0) + 1);
				_security = (char*)os_malloc(os_strlen(p + 1) + 1);
				os_strcpy(_miid, buf0);
				os_strcpy(_security, p + 1);

				__printf("Node:%s\n", _miid);

				os_sprintf(buf1, CLOUD_FETCH_URL, _miid, _security);
				os_sprintf(buf0, HTTP_QUERY, buf1);

				http_get(CLOUD_HOST, buf0, user_on_http_response, NULL);
				return;
			}
		}
	}

	__printf("Please set node ID!\n");
	luainit("");
}
int main()
{
	int n1,n2;
	Node *first,*second;
	Node *i;
	
	while(scanf_s("%d %d",&n1,&n2)!=EOF)
	{
		if(!n1&&!n2)
		{
			printf("NULL\n");
			return 0;
		}

		for(int k=0;k<n1;k++)
		{
			Node *newNode=new Node;
			scanf_s("%d",&newNode->value);
			newNode->next=NULL;
			if(k==0)
			{
				first=newNode;
				i=first;
			}
			else
			{

				i->next=newNode;
				i=i->next;
			}

		}
		for(int k=0;k<n2;k++)
		{
			Node *newNode=new Node;
			scanf_s("%d",&newNode->value);
			newNode->next=NULL;
			if(k==0)
			{
				second=newNode;
				i=second;
			}
			else{
				i->next=newNode;
				i=i->next;
			}
		}
		
		__printf(first);
		__printf(second);

		Node *result=merge(first,second);
		__printf(result);
		deletenode(result);  //bug 没有delete干净

	}
	
	return 0;
}
Esempio n. 3
0
void __attribute__((noreturn)) eeload_start() {
	void (*entry)();
	__puts("EELOAD start\n");

	__printf("about to SifInitRpc(0)\n");
	SifInitRpc(0);
    __printf("done rpc\n");

	entry = (void (*)())loadElfFile("INTRO");
	entry();

	entry = (void (*)())loadElfFile("LOADER");
	entry();

	for (;;);
}
Esempio n. 4
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR user_init(void)
{
	int i;

    // rom use 74880 baut_rate, here reinitialize
    uart_init(BIT_RATE_115200, BIT_RATE_115200);

	uart_tx_one_char('\r');
	__printf("NodeLua %s (With liblua %s) Copyright (C) 2014 NodeLua.org free mem=%d\n", NODELUA_RELEASE NODELUA_RELEASE_LOC, LUA_RELEASE, system_get_free_heap_size());

	// char *argv[] = {"lua", "-e", (char*)buf};
	// for(i = 0; 1; i ++)
	// {
	// 	uint16_t val = system_adc_read();
	// 	__printf("adc=%d\n", val);
	// 	luamain(sizeof(argv)/sizeof(char*), argv);
	// }

    struct station_config config;
    wifi_station_get_config(&config);
	if (wifi_get_opmode() == STATION_MODE && os_strlen(config.ssid) > 0)
	{
		os_timer_disarm(&check_sta_timer);
		os_timer_setfn(&check_sta_timer, (os_timer_func_t *)user_check_ip, 1);
		os_timer_arm(&check_sta_timer, 100, 0);
	}
	else
	{
		__printf("Please set wifi parameters to connect to an exist AP!\n");
		luainit("");
	}

	return;

// #if ESP_PLATFORM
//     user_esp_platform_init();
// #endif
//
//     user_devicefind_init();
// #ifdef SERVER_SSL_ENABLE
//     user_webserver_init(SERVER_SSL_PORT);
// #else
//     user_webserver_init(SERVER_PORT);
// #endif
}
Esempio n. 5
0
void cmd80000002_INIT_CMD(SifCmdCSData *packet, struct tag_cmd_common *common){
    __printf("cmd80000002_INIT_CMD\n");
	if (packet->hdr.opt==0){
		iSetEventFlag(common->systemStatusFlag, 0x100);
		SifSetEEIOPflags(0x20000);
		common->saddr=packet->newaddr;
	}else
		iSetEventFlag(common->systemStatusFlag, 0x800);
}
Esempio n. 6
0
void ICACHE_FLASH_ATTR user_params_set(char *valbuf, int buflen)
{
	spi_flash_erase_sector(0x10000 / (SPI_FLASH_SEC_SIZE) - 1);
	SpiFlashOpResult succ = spi_flash_write(0x10000-(SPI_FLASH_SEC_SIZE), (uint32 *)valbuf, buflen);
	if (succ == SPI_FLASH_RESULT_OK)
	{
		DEBUG_MSG("user_params_set: (len=%d) %s\n", buflen, valbuf);
		os_memset(valbuf, 0x00, buflen);
		user_params_get(valbuf, buflen);
	}
	else
	{
		__printf("failed to set user params! %d\n", succ);
	}
}
Esempio n. 7
0
int __libc_system(const char *command)
{
	int wait_val, pid;
	struct sigaction sa, save_quit, save_int;
	sigset_t save_mask;

	if (command == 0)
		return 1;

	memset(&sa, 0, sizeof(sa));
	sa.sa_handler = SIG_IGN;
	/* __sigemptyset(&sa.sa_mask); - done by memset() */
	/* sa.sa_flags = 0; - done by memset() */

	sigaction(SIGQUIT, &sa, &save_quit);
	sigaction(SIGINT, &sa, &save_int);
	__sigaddset(&sa.sa_mask, SIGCHLD);
	sigprocmask(SIG_BLOCK, &sa.sa_mask, &save_mask);

	if ((pid = vfork()) < 0) {
		wait_val = -1;
		goto out;
	}
	if (pid == 0) {
		sigaction(SIGQUIT, &save_quit, NULL);
		sigaction(SIGINT, &save_int, NULL);
		sigprocmask(SIG_SETMASK, &save_mask, NULL);

		execl("/bin/sh", "sh", "-c", command, (char *) 0);
		_exit(127);
	}

#if 0
	__printf("Waiting for child %d\n", pid);
#endif

	if (__wait4_nocancel(pid, &wait_val, 0, 0) == -1)
		wait_val = -1;

out:
	sigaction(SIGQUIT, &save_quit, NULL);
	sigaction(SIGINT, &save_int, NULL);
	sigprocmask(SIG_SETMASK, &save_mask, NULL);
	return wait_val;
}
Esempio n. 8
0
int __libc_system(const char *command)
{
	int wait_val, pid;
	__sighandler_t save_quit, save_int, save_chld;

	if (command == 0)
		return 1;

	save_quit = signal(SIGQUIT, SIG_IGN);
	save_int = signal(SIGINT, SIG_IGN);
	save_chld = signal(SIGCHLD, SIG_DFL);

	if ((pid = vfork()) < 0) {
		signal(SIGQUIT, save_quit);
		signal(SIGINT, save_int);
		signal(SIGCHLD, save_chld);
		return -1;
	}
	if (pid == 0) {
		signal(SIGQUIT, SIG_DFL);
		signal(SIGINT, SIG_DFL);
		signal(SIGCHLD, SIG_DFL);

		execl("/bin/sh", "sh", "-c", command, (char *) 0);
		_exit(127);
	}
	/* Signals are not absolutly guarenteed with vfork */
	signal(SIGQUIT, SIG_IGN);
	signal(SIGINT, SIG_IGN);

#if 0
	__printf("Waiting for child %d\n", pid);
#endif

	if (wait4(pid, &wait_val, 0, 0) == -1)
		wait_val = -1;

	signal(SIGQUIT, save_quit);
	signal(SIGINT, save_int);
	signal(SIGCHLD, save_chld);
	return wait_val;
}
Esempio n. 9
0
///////////////////////////////////////////////////////////////////////[04]
void SifInitCmd(){
    __printf("iopSifInitCmd\n");
	SifSetIOPEEflags(0x20000);
	WaitEventFlag(cmd_common.systemStatusFlag, 0x100, 0, 0);
}
Esempio n. 10
0
// this is the start point of execution at 0xBFC4A000
// 
// it loads the IOPBTCONF module list from rom0 and compiles a
// list of modules and their addresses.
// 
// this list is then passed to loadcore as it is executed in order
// to then load the rest of the modules
// 
// args:	total size of IOP ram in MegaBytes
//			bootinfo flags
//			string containing the reboot image filepath
//			? doesnt seem to be used
void _start(int ramMBSize, int bootInfo, char* udnlString, int unk)
{
	ROMFS ri;
	void *(*sysmem_entry)(u32 iopmemsize);
	void (*loadcore_entry)(BOOT_PARAMS *init);
	int i;
    ROMDIR_INFO romdir_info;
    ROMFILE_INFO romfile_info;
	char conf_filename[10];
    int ram_byte_size, num_lines;
    u32 module_load_addr;
    u32** modules_ptr;
    char* file_data_ptr, *file_data_end;
    void* psysmemstart;
    BOOT_PARAMS* boot_params;

    if( ramMBSize <= 2 )
        ram_byte_size = 2;
    else
        ram_byte_size = ramMBSize;
	ram_byte_size <<= 20;
    
    // compile module list to send to loadcore
    boot_params = (BOOT_PARAMS*)0x30000; // random address, has to be clear before loadcore call
	boot_params->ramMBSize	= ramMBSize;
	boot_params->bootInfo		= bootInfo;
	boot_params->udnlString	= NULL;
	boot_params->moduleAddrs	= (u32**)((u32)boot_params + sizeof(BOOT_PARAMS)); // right after

    // if a undl string is specified, get a copy of it and store a pointer to it
	if(udnlString)
	{
		boot_params->udnlString = (char*)boot_params->moduleAddrs;
		kstrcpy(boot_params->udnlString, udnlString);
		boot_params->moduleAddrs = (u32**)((u32)boot_params->udnlString + ROUND_UP(kstrlen(udnlString) + 8, 4));
	}

    // find the romdir table in the rom
    if( searchRomDir((u32*)0xBFC00000, (u32*)0xBFC10000, &romdir_info) == NULL )
	{
        __printf("IOPBOOT: failed to find start of rom!\n");
		// error - cant find romdir!
		while(1) *(u8*)0x80000000 = 0;
	}

    // find the bootconf file in the romdir table
    kstrcpy(conf_filename, "IOPBTCONF");
	conf_filename[8] = '0' + bootInfo;
	if( !searchFileInRom(&romdir_info, conf_filename, &romfile_info) )
	{
		kstrcpy(conf_filename, "IOPBTCONF");
		if( !searchFileInRom(&romdir_info, conf_filename, &romfile_info) )
		{
            __printf("IOPBTCONF file not found!\n");
			// error - cant find conf file!
			while(1) *(u8*)0x80000000 = 1;
		}
	}

    // count the number of lines in conf file
    file_data_ptr = (char*)romfile_info.fileData;
    file_data_end = (char*)romfile_info.fileData + romfile_info.entry->fileSize;    
    {
        num_lines = 0;
        while( file_data_ptr < file_data_end ) {
            // loop until a "newline" charcter is found
            while(file_data_ptr < file_data_end) {
                if(*file_data_ptr++ < ' ')
                    break;
            }
            
            // loop until a "non-newline" charcter is found
            while(file_data_ptr < file_data_end) {
                if(*file_data_ptr++ >= ' ')
                    break;
            }
            
            num_lines++;
        }
        num_lines++;
    }

    // get the addresses of each module
    {
        module_load_addr = 0;
        boot_params->numConfLines = num_lines-1;
        modules_ptr = boot_params->moduleAddrs;
        char* file_data_ptr = (char*)romfile_info.fileData;
        while( file_data_ptr < file_data_end ) {
            if(*file_data_ptr == '@') {
                file_data_ptr++;
                module_load_addr = getHexNumber(&file_data_ptr);
            }
            else if(*file_data_ptr == '!') {
                if( file_data_ptr[1] == 'a' &&
                    file_data_ptr[2] == 'd' &&
                    file_data_ptr[3] == 'd' &&
                    file_data_ptr[4] == 'r' &&
                    file_data_ptr[5] == ' ' ) {
                    file_data_ptr += 6;
                    *modules_ptr++ = (u32*)(getHexNumber(&file_data_ptr) * 4 + 1);
                    *modules_ptr++ = 0;
                }
            }
            else if(*file_data_ptr != '#') {
                // 'file_data_ptr' should be pointing to a filename
                // this finds the address of that file in the rom
                ROMFILE_INFO module_fileinfo;
                char strmodule[16];
                for(i = 0; i < 16; ++i) {
                    if( file_data_ptr[i] < ' ' )
                        break;
                    strmodule[i] = file_data_ptr[i];
                }
                strmodule[i] = 0;
                
                if( searchFileInRom(&romdir_info, strmodule, &module_fileinfo) == NULL ) {
                    __printf("IOPBOOT: failed to find %s module\n", strmodule);
                    return;
                }

                //__printf("mod: %s:%x\n", strmodule, module_fileinfo.fileData);
                                
                *modules_ptr++ = (u32*)module_fileinfo.fileData;
                *modules_ptr = 0; // don't increment
            }
            
            // loop until a "newline" charcter is found
            while(file_data_ptr < file_data_end) {
                if(*file_data_ptr++ < ' ')
                    break;
            }
            
            // loop until a "non-newline" charcter is found
            while(file_data_ptr < file_data_end) {
                if(*file_data_ptr >= ' ')
                    break;
                file_data_ptr++;
            }
        }
    }

    if( searchFileInRom(&romdir_info, "IOPBOOT", &romfile_info) == NULL ) {
        __printf("loadElfFile: failed to find IOPBOOT module\n");
        return;
    }

    // load sysmem module to memory and execute it
    if( searchFileInRom(&romdir_info, "SYSMEM", &romfile_info) == NULL ) {
        __printf("loadElfFile: failed to find SYSMEM module\n");
        return;
    }
    sysmem_entry = (void *(*)(u32))loadElfFile(&romfile_info, module_load_addr);
    if( sysmem_entry == 0 )
        return;

    psysmemstart = sysmem_entry(ram_byte_size);
    //FlushIcache();
    if( psysmemstart == 0 ) {
        __printf("IOPBOOT: sysmem failed\n");
        return;
    }

    __printf("SYSMEM success, start addr: %x, alloc start: %x\n", module_load_addr, psysmemstart);
    
    if( searchFileInRom(&romdir_info, "LOADCORE", &romfile_info) == NULL ) {
        __printf("loadElfFile: failed to find SYSMEM module\n");
        return;
    }
    loadcore_entry = (void (*)())loadElfFile(&romfile_info, (u32)psysmemstart);
    if( loadcore_entry == 0 )
        return;
    
    boot_params->firstModuleAddr = (u32)module_load_addr + 0x30; // skip elf?
    if(0x1FC10000 < ram_byte_size) {
        boot_params->pos = 0x1FC00000;
		boot_params->size = 0x10100;
	}
	else {
        boot_params->pos = 0;
        boot_params->size = 0;
	}

	__printf("executing LOADCORE entry at %p\n", loadcore_entry);
	loadcore_entry(boot_params);

	__printf("iopboot error\n");

    // error - loadcore shouldnt ever return
	while(1) *(u8*)0x80000000 = 2;
}