Forum Topic - Passing custom data from startup-x86 to QNX environment: (7 Items)
   
Passing custom data from startup-x86 to QNX environment  
The scenario is: 
Platform :  x86 ,  UEFI boot

the start up BSP is updated such the EFI graphics capabilities (modes) are check.

The question is how to make that modes information (lets say list of modes) available to the run QNX environment.

I was thinking to add private structure to the system page block but i think that is going to break concept of system 
page.

I am looking for any suggestion from experts.

Regards,
Janusz 
Re: Passing custom data from startup-x86 to QNX environment  
Hi, 

simply reserve a small part of physical RAM.
I use that for example to pass the environment vars of a boot-monitor to the QNX environment:
...
kprintf("U-Boot env found at 0x%x\n", uboot_env );
alloc_ram(uboot_env, UBOOT_ENV_SIZE, 0);
as_add_containing(uboot_env, uboot_env - 1 + UBOOT_ENV_SIZE, AS_ATTR_RAM, "uboot-env", "memory");
...
The as_add_containing() is needed, to pass the physical base address and range to the system-page.
If you reserve RAM at a fixed physical address, the as_add_containing() is not really needed, but I would suggest it, 
because you can check the existence of your reserved RAM.

Regards
Michael
Re: Passing custom data from startup-x86 to QNX environment  
Hi Michale,
    Thank you for sharing. I started to discover that solution too with  -R option for startup-x86 -R 1024,8,GOP to let 
the system allocate small chunk of memory and exclude it from general system use. 

In the application i want to map that memory and read the content of it but i am experiencing mapping failure. 

.......
 #include <stdint.h>
#include <sys/mman.h>
#include <sys/mman.h>
#include <fcntl.h>

int main(void)
{
    struct posix_typed_mem_info info;
    int fd = posix_typed_mem_open("/memory/ram/GOP", O_RDWR, POSIX_TYPED_MEM_MAP_ALLOCATABLE);
    
    if (fd == -1) {
        printf("Error %s\n", strerror(errno));
    }
    else
    {
        int i = posix_typed_mem_get_info(fd, &info);
        if (i == 0)
        {
            printf("Max alloc %u  total %u fd %u\n", info.posix_tmi_length, info.__posix_tmi_total, fd);
            
            void * buff = mmap(NULL, 10,PROT_READ | PROT_WRITE , MAP_SHARED, fd, 0);
                        
            if (buff == MAP_FAILED) {
                printf("map failed %s\n", strerror(errno));
            }
            else
            {
                unsigned char *c = buff;
                printf("%c %c %c \n", c[0], c[1],c[2]);
            }
        }
        else
            printf("info error\n"); 
    }    
}
................................
mmap failes regardles of the posix_typed_mem_open  mapped parameter. 

I am testing it under QNX 8.0.0 64 bits on x86 hardware. 

Could you share your thoughts?

Regards,
Janusz

Re: Passing custom data from startup-x86 to QNX environment  
Hi Janusz, 

I do not see a real problem in your code. Perhaps next time, you additionally attach the output of your program to see 
for example the exact errno values.
As you only want to read the region, perhaps you do not need the PROT_WRITE.
Do you have a permission problem?
I assume your process needs the "PROCMGR_AID_MEM_PHYS" ability.

Regards
Michael
Re: Passing custom data from startup-x86 to QNX environment  
The problem is with the use of POSIX_TYPED_MEM_MAP_ALLOCATABLE. It's an unfortunate issue that I wanted to get to in a 
very long time but haven't had the chance. The semantics of this flag is that it does not allocate memory, but rather 
causes a mmap() to create a direct mapping of the physical range. 
There are two problems with that:
1. You need to pass the physical address in the last argument to mmap(), and it must be within the range of the typed 
memory object. Ideally this argument would have been a logical offset into the object, and 0 would suffice, but it isn't
.
2. Direct-physical mappings are really dangerous. Probably not an issue in your case, as I assume no other program will 
ever map that object.

I suggest using POSIX_TYPED_MEM_ALLOC_CONTIG instead.

--Elad
Re: Passing custom data from startup-x86 to QNX environment  
Thank you, Michael, and Elad for all comments.

The keys to make the simple reserved memory access program working are:
1.	startup-x86 -R 4096,4096,GOP   
        the alin – parameter must be in a size of system page size.

2.	open a reserved memory with POSIX_TYPED_MEM_ALLOCATE_CONTIG flag.
       ………………..
    	int fd = posix_typed_mem_open("GOP", O_RDWR, POSIX_TYPED_MEM_ALLOCATE_CONTIG );
    	if (fd == -1) {
        		printf("Error: %s\n", strerror(errno));
    	}
        void * buff = mmap(NULL, 10, PROT_READ | PROT_WRITE , MAP_PRIVATE, fd, 0);                        
        if (buff == MAP_FAILED) {
                printf("map failed: %s\n", strerror(errno));
        }
        else {
                unsigned char *c = buff;
                printf("%c %c %c \n", c[0], c[1],c[2]);
       }
      …………………

So, I am able to reserve a memory block and access it later on from QNX environment. It is OK to use a direct-physical 
mapping in my since it is going to be used in closed system.

I am having additional difficulty which is initialization (write into it a data which will be used later from qnx 
environment) of that reserved memory block. Any time I try to write into that block of memory the system reboots which 
implies that reboot callout is called.

What is proper mechanism to write into that reserved memory block from startup and in which step of startup 
initialization would be possible.
I have tried to use copy_memory function from startup library but that also cause system reboot.

Any advice is greatly appreciated.
Janusz
Re: Passing custom data from startup-x86 to QNX environment  
Hi Janusz, 

there is no special mechanism for accessing the reserved RAM during startup.
Well, you need a startup mapping for your area, created by startup_memory_map( ).

Regards
Michael