Пример #1
0
n_int network_open(n_string ip, n_byte2 port, n_c_int * network_connection)
{
    struct sockaddr_in addr; /* Local address */
    /* Create socket for incoming connections */
    if ((*network_connection = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
    {
        return SHOW_ERROR("Failed to set up socket");
    }
    /* Construct local address structure */
    memory_erase((n_byte *)&addr, sizeof(addr));
    addr.sin_family = AF_INET;                /* Internet address family */
    if (ip)
    {
        addr.sin_addr.s_addr = inet_addr(ip);   /* Server IP address */
    }
    else
    {
        addr.sin_addr.s_addr = htonl(INADDR_ANY); /* Any incoming interface */
    }
    addr.sin_port = htons(port);      /* Local port */

    /* Bind to the local address */
    if (bind(*network_connection, (struct sockaddr *) &addr, sizeof(addr)) < 0)
    {
        return SHOW_ERROR("Failed to set up bind");
    }
    return 0;
}
Пример #2
0
static void * ar_pass_through(void * ptr)
{
    if (ptr == 0L)
    {
        ptr = memory_new(sizeof(n_array));
        if (ptr)
        {
            memory_erase((n_byte *)ptr, sizeof(n_array));
        }
    }
    return ptr;
}
Пример #3
0
// One-time setup on factory install
void memory_setup(void)
{
    if (memory_read_setup()) {
        memory_erase();
#ifndef TESTING
        // Lock Config Memory:        OP   MODE  PARAMETER1  PARAMETER2
        const uint8_t ataes_cmd[] = {0x0D, 0x02, 0x00, 0x00, 0x00, 0x00};
        // Return packet [Count(1) || Return Code (1) || CRC (2)]
        uint8_t ataes_ret[4] = {0};
        aes_process(ataes_cmd, sizeof(ataes_cmd), ataes_ret, 4);
#endif
        memory_write_setup(0x00);
    } else {
        memory_mempass();
    }
}
Пример #4
0
/**
 * Save regions info
 */
static void _app_save_regions_info(struct regions_info *info, bool for_boot)
{
	UNUSED(for_boot);
	uint32_t info_addr = INFO_ADDR(for_boot);
	dbg_print("bl: Save regions info to %x\r\n", (unsigned)info_addr);

	dbg_print("bl: Unlock regions info ...\r\n");
	memory_unlock((void *)info_addr, (void *)(info_addr + INFO_SIZE - 1));
	dbg_print("bl: Unlock regions info done\r\n");

	dbg_print("bl: Erase regions info ...\r\n");
	memory_erase((void *)info_addr, INFO_SIZE);
	dbg_print("bl: Erase regions info done\r\n");

	dbg_print("bl: Update regions info\r\n");
	region_info_write((void *)info_addr, info);  /* Save for boot */
	dbg_print("bl: Update regions info done\r\n");

	dbg_print("bl: Lock regions info ...\r\n");
	memory_lock((void *)info_addr, (void *)(info_addr + INFO_SIZE - 1));
	dbg_print("bl: Lock regions info done\r\n");
}
Пример #5
0
void land_init_high_def(n_byte double_spread)
{
    n_uint   lp = 0;
    n_byte4  value_setting = 0;

    math_bilinear_8_times((n_byte *)m_land.tiles[0].topography[0], m_topography_highdef, double_spread);
    memory_erase((n_byte *)m_highres_tide, sizeof(n_byte4) * HI_RES_MAP_AREA/32);

    while (lp < HI_RES_MAP_AREA)
    {
        n_byte val = m_topography_highdef[lp<<1];
        if ((val > 105) && (val < 151))
        {
            value_setting |= 1 << (lp & 31);
        }

        if ((lp & 31) == 31)
        {
            m_highres_tide[ lp >> 5 ] = value_setting;
            value_setting = 0;
        }
        lp++;

    }
Пример #6
0
static void object_erase(n_object * object)
{
    memory_erase((n_byte*)object, sizeof(n_object));
}
Пример #7
0
/**
 * Receive new firmware
 *
 * \param info Regions information struct
 * \param no_partition Use single partition, do not split memory to app + buff
 *
 * \return received firmware size
 */
static uint32_t _app_load(struct regions_info *info, bool no_partition)
{
	void *addr, *info_addr;
	uint32_t *p_sign, *p_len;
	uint32_t rx_size;
	uint32_t target_region;
	uint32_t i = 0, flags = 0xFF;
	if (info->boot_region != 0 && info->boot_region != 1) {
		dbg_print("bl: Boot region information (%d) invalid\r\n",
				(int)info->boot_region);
		return 0;
	}

	/* Wait media connection */
	i = 0;
	while (i < MEDIA_NUM_MAX) {
		media_select((enum media_types)i);
		if (media_connect()) {
			dbg_print("bl: Source media %s is ready\r\n",
					media_get_type_str((enum media_types)i));
			break;
		} else if (flags & (1 << i)) {
			flags &= ~(1 << i);
			dbg_print("bl: Source media %s not ready\r\n",
					media_get_type_str((enum media_types)i));
		}

		i++;
	}
	target_region = no_partition ? info->boot_region : (!info->boot_region);

	addr      = (void *)APP_START(target_region);
	info_addr = (void *)INFO_ADDR(false);
	dbg_print("bl: Load to %x, info @ %x\r\n", (unsigned)addr,
			(unsigned)info_addr);

	dbg_print("bl: Unlock download buffer & info area ...\r\n");
	memory_unlock(addr, (void *)((uint32_t)addr + APP_CODE_SIZE - 1));
	memory_unlock(info_addr, (void *)((uint32_t)info_addr + INFO_SIZE - 1));
	dbg_print("bl: Unlock download buffer & info area done\r\n");

	dbg_print("bl: Erase download buffer & info area ...\r\n");
	memory_erase(     addr, APP_CODE_SIZE);
	memory_erase(info_addr, INFO_SIZE);
	dbg_print("bl: Erase download buffer & info area done\r\n");

#ifdef DBG_USE_LED
	_app_led_blink(50, 4);
	_app_led_on(DBG_LED_PIN);
#endif

	/* Clear SW force boot trigger */
#ifdef TRIGGER_USE_FLAG
	info->trigger = TRIGGER_BOOT;
#endif
	p_sign = &info->signature[target_region];
	p_len  = &info->length[target_region];
	rx_size = media_load_file(addr, APP_SIZE,
			(uint8_t *)app_mem_block_buf, MEM_BLOCK_SIZE,
			_app_save_block);
	if (rx_size) {
		*p_sign = region_signature(addr, rx_size);
		*p_len  = rx_size;
	} else {
		*p_sign = 0;
		*p_len  = 0;
	}

	/* Save region information */
	region_info_write(info_addr, info);

	dbg_print("bl: Lock download buffer & info area ...\r\n");
	memory_lock(addr, (void *)((uint32_t)addr + APP_CODE_SIZE - 1));
	memory_lock(info_addr, (void *)((uint32_t)info_addr + INFO_SIZE - 1));
	dbg_print("bl: Lock download buffer & info area done\r\n");

#ifdef DBG_USE_LED
	_app_led_off(DBG_LED_PIN);
#endif

#if DUMP_ENABLE
	_dump_data("Downloaded APP:\r\n", addr, rx_size, true);
	_dump_data("INFO:\r\n", info_addr, INFO_SIZE, true);
#endif
	return rx_size;
}