[rtems commit] arm/raspberrypi: VideoCore access corrections in cache operation and more error checking.

Pavel Pisa ppisa at rtems.org
Sun Jul 31 09:34:24 UTC 2016


Module:    rtems
Branch:    master
Commit:    3d3ad4dc1c54306aea643e66c377a7d06893f07b
Changeset: http://git.rtems.org/rtems/commit/?id=3d3ad4dc1c54306aea643e66c377a7d06893f07b

Author:    Pavel Pisa <pisa at cmp.felk.cvut.cz>
Date:      Sun Jul 31 11:33:06 2016 +0200

arm/raspberrypi: VideoCore access corrections in cache operation and more error checking.

The first, mistake in buffer size computation for cache flush
and invalidate has been corrected.

GCC __attribute__( ( aligned( 64 ) ) ) should work and works for local
variables. Code ensures right stack alignment. But attribute has
to be moved to type declaration to ensure that structure size is affected
by attribute. But even this seems to not work reliably for some reason.
May it be, the stack area between frame start and end of local variable buffer
accessed during context switch or some stack prefetch during resturn
such way that some cache lines belonging to buffer are filled to cache.
Extending buffer by one more cache line padding helps there.

In the longer term perspective, buffer should be moved to some static
area or cache aligned dynamic memory allocated. Concurrent calls
to the VideoCore operations and access serialization should be added
too but problem is that some calls are required during workspace and MMU
setup so variant without need of mutex would be required as well.

Framebuffer setup code and other VideoCore calls check more
precisely for errors and do not proceed forward with incorrect
data now.

Signed-off-by: Pavel Pisa <pisa at cmp.felk.cvut.cz>

---

 c/src/lib/libbsp/arm/raspberrypi/console/fb.c      |  27 ++++-
 c/src/lib/libbsp/arm/raspberrypi/include/rpi-fb.h  |   3 +-
 c/src/lib/libbsp/arm/raspberrypi/misc/vc.c         | 110 ++++++++++++++-------
 c/src/lib/libbsp/arm/raspberrypi/misc/vc_defines.h |   7 +-
 .../arm/raspberrypi/startup/bspgetworkarea.c       |   7 +-
 c/src/lib/libbsp/arm/raspberrypi/startup/cmdline.c |   6 +-
 6 files changed, 112 insertions(+), 48 deletions(-)

diff --git a/c/src/lib/libbsp/arm/raspberrypi/console/fb.c b/c/src/lib/libbsp/arm/raspberrypi/console/fb.c
index 8043c7d..1900a06 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/console/fb.c
+++ b/c/src/lib/libbsp/arm/raspberrypi/console/fb.c
@@ -162,11 +162,15 @@ static int parse_mode_from_string(
 
 static int find_mode_from_vc( void )
 {
+  int res;
+  unsigned int width;
+  unsigned int height;
   bcm2835_get_display_size_entries entries;
 
-  bcm2835_mailbox_get_display_size( &entries );
-  unsigned int width = entries.width;
-  unsigned int height = entries.height;
+  res = bcm2835_mailbox_get_display_size( &entries );
+
+  width = entries.width;
+  height = entries.height;
 
   if ( width == 0 || height == 0 ) {
     fb_var_info.xres = SCREEN_WIDTH;
@@ -175,8 +179,9 @@ static int find_mode_from_vc( void )
     fb_var_info.xres = width;
     fb_var_info.yres = height;
   }
+  printk("find_mode_from_vc %u x %u, res %d\n", width, height, res);
 
-  return 0;
+  return res;
 }
 
 bool rpi_fb_hdmi_is_present( void )
@@ -199,6 +204,7 @@ bool rpi_fb_hdmi_is_present( void )
 
 int rpi_fb_init( void )
 {
+  int res;
   int                               mode_from_cmdline;
   bcm2835_init_frame_buffer_entries init_frame_buffer_entries;
 
@@ -243,7 +249,16 @@ int rpi_fb_init( void )
   init_frame_buffer_entries.overscan_right = 0;
   init_frame_buffer_entries.overscan_top = 0;
   init_frame_buffer_entries.overscan_bottom = 0;
-  bcm2835_mailbox_init_frame_buffer( &init_frame_buffer_entries );
+  printk("bcm2835_mailbox_init_frame_buffer ...\n");
+  res = bcm2835_mailbox_init_frame_buffer( &init_frame_buffer_entries );
+  printk("bcm2835_mailbox_init_frame_buffer returned %d\n", res);
+  if (res != 0) {
+    printk("bcm2835_mailbox_init_frame_buffer retry ...\n");
+    res = bcm2835_mailbox_init_frame_buffer( &init_frame_buffer_entries );
+    printk("bcm2835_mailbox_init_frame_buffer returned %d\n", res);
+    if (res != 0)
+      return RPI_FB_INIT_SETUP_FAILED;
+  }
 
   bcm2835_get_pitch_entries get_pitch_entries;
   bcm2835_mailbox_get_pitch( &get_pitch_entries );
@@ -258,6 +273,8 @@ int rpi_fb_init( void )
   if ( fb_fix_info.smem_start == NULL )
     return RPI_FB_INIT_START_ADDR_UNKNOWN;
 
+  printk("fb_fix_info.smem_start %p\n", fb_fix_info.smem_start);
+
   arm_cp15_set_translation_table_entries( (void *) fb_fix_info.smem_start,
     (void *) fb_fix_info.smem_start +
     fb_fix_info.smem_len,
diff --git a/c/src/lib/libbsp/arm/raspberrypi/include/rpi-fb.h b/c/src/lib/libbsp/arm/raspberrypi/include/rpi-fb.h
index fa9a939..4f3c07f 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/include/rpi-fb.h
+++ b/c/src/lib/libbsp/arm/raspberrypi/include/rpi-fb.h
@@ -41,7 +41,8 @@ enum rpi_fb_init_result {
   RPI_FB_INIT_CMDLINE_DONT_INIT = -4,
   RPI_FB_INIT_CMDLINE_NO_MODE_REQ = -5,
   RPI_FB_INIT_MODE_PROBE_ERROR = -6,
-  RPI_FB_INIT_START_ADDR_UNKNOWN = -7,
+  RPI_FB_INIT_SETUP_FAILED = -7,
+  RPI_FB_INIT_START_ADDR_UNKNOWN = -8,
 };
 
 int rpi_fb_init( void );
diff --git a/c/src/lib/libbsp/arm/raspberrypi/misc/vc.c b/c/src/lib/libbsp/arm/raspberrypi/misc/vc.c
index a3753cc..2fff70b 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/misc/vc.c
+++ b/c/src/lib/libbsp/arm/raspberrypi/misc/vc.c
@@ -31,6 +31,8 @@
   #define BCM2835_VC_MEMORY_MAPPING 0xC0000000
 #endif
 
+#define BCM2835_VC_MEMORY_MAPPING_MASK 0x3fffffff
+
 static inline bool bcm2835_mailbox_buffer_suceeded(
   const bcm2835_mbox_buf_hdr *hdr )
 {
@@ -40,9 +42,11 @@ static inline bool bcm2835_mailbox_buffer_suceeded(
 
 static inline int bcm2835_mailbox_send_read_buffer( void *buf )
 {
+  RTEMS_COMPILER_MEMORY_BARRIER();
   raspberrypi_mailbox_write( BCM2835_MBOX_CHANNEL_PROP_AVC,
     (unsigned int) buf + BCM2835_VC_MEMORY_MAPPING );
   raspberrypi_mailbox_read( BCM2835_MBOX_CHANNEL_PROP_AVC );
+  RTEMS_COMPILER_MEMORY_BARRIER();
   return 0;
 }
 
@@ -66,15 +70,16 @@ static inline void bcm2835_mailbox_buffer_flush_and_invalidate(
 int bcm2835_mailbox_get_display_size(
   bcm2835_get_display_size_entries *_entries )
 {
-  struct {
+  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
     bcm2835_mbox_buf_hdr hdr;
     bcm2835_mbox_tag_display_size get_display_size;
     uint32_t end_tag;
-  } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
+    uint32_t padding_reserve[16];
+  } buffer;
   BCM2835_MBOX_INIT_BUF( &buffer );
   BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_display_size,
     BCM2835_MAILBOX_TAG_GET_DISPLAY_SIZE );
-  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
+  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( buffer ) );
 
   if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
     return -1;
@@ -85,13 +90,16 @@ int bcm2835_mailbox_get_display_size(
   if ( !bcm2835_mailbox_buffer_suceeded( &buffer.hdr ) )
     return -2;
 
+  if ( !BCM2835_MBOX_TAG_REPLY_IS_SET( &buffer.get_display_size ) )
+    return -3;
+
   return 0;
 }
 
 int bcm2835_mailbox_init_frame_buffer(
   bcm2835_init_frame_buffer_entries *_entries )
 {
-  struct {
+  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
     bcm2835_mbox_buf_hdr hdr;
     bcm2835_mbox_tag_display_size set_display_size;
     bcm2835_mbox_tag_virtual_size set_virtual_size;
@@ -103,7 +111,8 @@ int bcm2835_mailbox_init_frame_buffer(
     bcm2835_mbox_tag_allocate_buffer allocate_buffer;
     bcm2835_mbox_tag_get_pitch get_pitch;
     uint32_t end_tag;
-  } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
+    uint32_t padding_reserve[16];
+  } buffer;
   BCM2835_MBOX_INIT_BUF( &buffer );
   BCM2835_MBOX_INIT_TAG( &buffer.set_display_size,
     BCM2835_MAILBOX_TAG_SET_DISPLAY_SIZE );
@@ -137,7 +146,7 @@ int bcm2835_mailbox_init_frame_buffer(
   buffer.allocate_buffer.body.req.align = 0x100;
   BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_pitch,
     BCM2835_MAILBOX_TAG_GET_PITCH );
-  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
+  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( buffer ) );
 
   if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
     return -1;
@@ -147,12 +156,8 @@ int bcm2835_mailbox_init_frame_buffer(
   _entries->xvirt = buffer.set_virtual_size.body.resp.vwidth;
   _entries->yvirt = buffer.set_virtual_size.body.resp.vheight;
   _entries->depth = buffer.set_depth.body.resp.depth;
-#if ( BSP_IS_RPI2 == 1 )
   _entries->base = buffer.allocate_buffer.body.resp.base;
-#else
-  _entries->base = buffer.allocate_buffer.body.resp.base -
-                   BCM2835_VC_MEMORY_MAPPING;
-#endif
+  _entries->base &= BCM2835_VC_MEMORY_MAPPING_MASK;
   _entries->size = buffer.allocate_buffer.body.resp.size;
   _entries->pixel_order = buffer.set_pixel_order.body.resp.pixel_order;
   _entries->alpha_mode = buffer.set_alpha_mode.body.resp.alpha_mode;
@@ -166,20 +171,27 @@ int bcm2835_mailbox_init_frame_buffer(
   if ( !bcm2835_mailbox_buffer_suceeded( &buffer.hdr ) )
     return -2;
 
+  if ( !BCM2835_MBOX_TAG_REPLY_IS_SET( &buffer.allocate_buffer ) )
+    return -3;
+
+  if ( _entries->base < 0x100000 )
+    return -4;
+
   return 0;
 }
 
 int bcm2835_mailbox_get_pitch( bcm2835_get_pitch_entries *_entries )
 {
-  struct {
+  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
     bcm2835_mbox_buf_hdr hdr;
     bcm2835_mbox_tag_get_pitch get_pitch;
     uint32_t end_tag;
-  } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
+    uint32_t padding_reserve[16];
+  } buffer;
   BCM2835_MBOX_INIT_BUF( &buffer );
   BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_pitch,
     BCM2835_MAILBOX_TAG_GET_PITCH );
-  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
+  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( buffer ) );
 
   if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
     return -1;
@@ -189,6 +201,9 @@ int bcm2835_mailbox_get_pitch( bcm2835_get_pitch_entries *_entries )
   if ( !bcm2835_mailbox_buffer_suceeded( &buffer.hdr ) )
     return -2;
 
+  if ( !BCM2835_MBOX_TAG_REPLY_IS_SET( &buffer.get_pitch ) )
+    return -3;
+
   return 0;
 }
 
@@ -196,15 +211,16 @@ int bcm2835_mailbox_get_cmdline( bcm2835_get_cmdline_entries *_entries )
 {
   int i;
 
-  struct {
+  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
     bcm2835_mbox_buf_hdr hdr;
     bcm2835_mbox_tag_get_cmd_line get_cmd_line;
     uint32_t end_tag;
-  } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
+    uint32_t padding_reserve[16];
+  } buffer;
   BCM2835_MBOX_INIT_BUF( &buffer );
   BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_cmd_line,
     BCM2835_MAILBOX_TAG_GET_CMD_LINE );
-  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
+  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( buffer ) );
 
   if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
     return -1;
@@ -220,22 +236,26 @@ int bcm2835_mailbox_get_cmdline( bcm2835_get_cmdline_entries *_entries )
   if ( !bcm2835_mailbox_buffer_suceeded( &buffer.hdr ) )
     return -2;
 
+  if ( !BCM2835_MBOX_TAG_REPLY_IS_SET( &buffer.get_cmd_line ) )
+    return -3;
+
   return 0;
 }
 
 int bcm2835_mailbox_set_power_state( bcm2835_set_power_state_entries *_entries )
 {
-  struct {
+  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
     bcm2835_mbox_buf_hdr hdr;
     bcm2835_mbox_tag_power_state set_power_state;
     uint32_t end_tag;
-  } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
+    uint32_t padding_reserve[16];
+  } buffer;
   BCM2835_MBOX_INIT_BUF( &buffer );
   BCM2835_MBOX_INIT_TAG( &buffer.set_power_state,
     BCM2835_MAILBOX_TAG_SET_POWER_STATE );
   buffer.set_power_state.body.req.dev_id = _entries->dev_id;
   buffer.set_power_state.body.req.state = _entries->state;
-  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
+  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( buffer ) );
 
   if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
     return -1;
@@ -251,15 +271,16 @@ int bcm2835_mailbox_set_power_state( bcm2835_set_power_state_entries *_entries )
 
 int bcm2835_mailbox_get_arm_memory( bcm2835_get_arm_memory_entries *_entries )
 {
-  struct {
+  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
     bcm2835_mbox_buf_hdr hdr;
     bcm2835_mbox_tag_get_arm_memory get_arm_memory;
     uint32_t end_tag;
-  } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
+    uint32_t padding_reserve[16];
+  } buffer;
   BCM2835_MBOX_INIT_BUF( &buffer );
   BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_arm_memory,
     BCM2835_MAILBOX_TAG_GET_ARM_MEMORY );
-  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
+  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( buffer ) );
 
   if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
     return -1;
@@ -270,20 +291,24 @@ int bcm2835_mailbox_get_arm_memory( bcm2835_get_arm_memory_entries *_entries )
   if ( !bcm2835_mailbox_buffer_suceeded( &buffer.hdr ) )
     return -2;
 
+  if ( !BCM2835_MBOX_TAG_REPLY_IS_SET( &buffer.get_arm_memory ) )
+    return -3;
+
   return 0;
 }
 
 int bcm2835_mailbox_get_vc_memory( bcm2835_get_vc_memory_entries *_entries )
 {
-  struct {
+  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
     bcm2835_mbox_buf_hdr hdr;
     bcm2835_mbox_tag_get_vc_memory get_vc_memory;
     uint32_t end_tag;
-  } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
+    uint32_t padding_reserve[16];
+  } buffer;
   BCM2835_MBOX_INIT_BUF( &buffer );
   BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_vc_memory,
     BCM2835_MAILBOX_TAG_GET_VC_MEMORY );
-  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
+  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( buffer ) );
 
   if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
     return -1;
@@ -294,21 +319,25 @@ int bcm2835_mailbox_get_vc_memory( bcm2835_get_vc_memory_entries *_entries )
   if ( !bcm2835_mailbox_buffer_suceeded( &buffer.hdr ) )
     return -2;
 
+  if ( !BCM2835_MBOX_TAG_REPLY_IS_SET( &buffer.get_vc_memory ) )
+    return -3;
+
   return 0;
 }
 
 int bcm2835_mailbox_get_firmware_revision(
   bcm2835_mailbox_get_fw_rev_entries *_entries )
 {
-  struct {
+  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
     bcm2835_mbox_buf_hdr hdr;
     bcm2835_mbox_tag_get_fw_rev get_fw_rev;
     uint32_t end_tag;
-  } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
+    uint32_t padding_reserve[16];
+  } buffer;
   BCM2835_MBOX_INIT_BUF( &buffer );
   BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_fw_rev,
     BCM2835_MAILBOX_TAG_FIRMWARE_REVISION );
-  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
+  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( buffer ) );
 
   if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
     return -1;
@@ -318,20 +347,24 @@ int bcm2835_mailbox_get_firmware_revision(
   if ( !bcm2835_mailbox_buffer_suceeded( &buffer.hdr ) )
     return -2;
 
+  if ( !BCM2835_MBOX_TAG_REPLY_IS_SET( &buffer.get_fw_rev ) )
+    return -3;
+
   return 0;
 }
 
 int bcm2835_mailbox_get_board_model( bcm2835_get_board_spec_entries *_entries )
 {
-  struct {
+  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
     bcm2835_mbox_buf_hdr hdr;
     bcm2835_mbox_tag_get_board_spec get_board_model;
     uint32_t end_tag;
-  } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
+    uint32_t padding_reserve[16];
+  } buffer;
   BCM2835_MBOX_INIT_BUF( &buffer );
   BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_board_model,
     BCM2835_MAILBOX_TAG_GET_BOARD_MODEL );
-  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
+  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( buffer ) );
 
   if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
     return -1;
@@ -341,21 +374,25 @@ int bcm2835_mailbox_get_board_model( bcm2835_get_board_spec_entries *_entries )
   if ( !bcm2835_mailbox_buffer_suceeded( &buffer.hdr ) )
     return -2;
 
+  if ( !BCM2835_MBOX_TAG_REPLY_IS_SET( &buffer.get_board_model ) )
+    return -3;
+
   return 0;
 }
 
 int bcm2835_mailbox_get_board_revision(
   bcm2835_get_board_spec_entries *_entries )
 {
-  struct {
+  struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE {
     bcm2835_mbox_buf_hdr hdr;
     bcm2835_mbox_tag_get_board_spec get_board_revision;
     uint32_t end_tag;
-  } buffer BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE;
+    uint32_t padding_reserve[16];
+  } buffer;
   BCM2835_MBOX_INIT_BUF( &buffer );
   BCM2835_MBOX_INIT_TAG_NO_REQ( &buffer.get_board_revision,
     BCM2835_MAILBOX_TAG_GET_BOARD_VERSION );
-  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( &buffer ) );
+  bcm2835_mailbox_buffer_flush_and_invalidate( &buffer, sizeof( buffer ) );
 
   if ( bcm2835_mailbox_send_read_buffer( &buffer ) )
     return -1;
@@ -365,5 +402,8 @@ int bcm2835_mailbox_get_board_revision(
   if ( !bcm2835_mailbox_buffer_suceeded( &buffer.hdr ) )
     return -2;
 
+  if ( !BCM2835_MBOX_TAG_REPLY_IS_SET( &buffer.get_board_revision ) )
+    return -3;
+
   return 0;
 }
diff --git a/c/src/lib/libbsp/arm/raspberrypi/misc/vc_defines.h b/c/src/lib/libbsp/arm/raspberrypi/misc/vc_defines.h
index 8d1067b..bc901b4 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/misc/vc_defines.h
+++ b/c/src/lib/libbsp/arm/raspberrypi/misc/vc_defines.h
@@ -94,9 +94,12 @@ typedef struct {
   uint32_t val_len;
 } bcm2835_mbox_tag_hdr;
 
+#define BCM2835_MBOX_TAG_REPLY_IS_SET( _t_ ) \
+   ( ( _t_ )->tag_hdr.val_len & 0x80000000 )
+
 #define BCM2835_MBOX_INIT_BUF( _m_ ) { \
-    memset( ( _m_ ), 0, sizeof( *( _m_ ) ) ); \
-    ( _m_ )->hdr.buf_size = sizeof( *( _m_ ) ); \
+    memset( ( _m_ ), 0,  sizeof( *( _m_ ) ) ); \
+    ( _m_ )->hdr.buf_size = (void *)&(( _m_ )->end_tag) + 4 - (void *)( _m_ ); \
     ( _m_ )->hdr.buf_code = BCM2835_MBOX_BUF_CODE_PROCESS_REQUEST; \
     ( _m_ )->end_tag = 0; \
 }
diff --git a/c/src/lib/libbsp/arm/raspberrypi/startup/bspgetworkarea.c b/c/src/lib/libbsp/arm/raspberrypi/startup/bspgetworkarea.c
index 9dc7e02..6a43e3c 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/startup/bspgetworkarea.c
+++ b/c/src/lib/libbsp/arm/raspberrypi/startup/bspgetworkarea.c
@@ -70,8 +70,9 @@ void bsp_work_area_initialize(void)
   #endif
 
   memset( &vc_entry, 0, sizeof(vc_entry) );
-  bcm2835_mailbox_get_vc_memory( &vc_entry );
-  if (vc_entry.base != 0)
-    ram_end = ram_end > vc_entry.base? vc_entry.base: ram_end;
+  if (bcm2835_mailbox_get_vc_memory( &vc_entry ) >= 0) {
+    if (vc_entry.base > 10 * 1024 *1024)
+      ram_end = ram_end > vc_entry.base? vc_entry.base: ram_end;
+  }
   bsp_work_area_initialize_default( (void *) work_base, ram_end - work_base );
 }
diff --git a/c/src/lib/libbsp/arm/raspberrypi/startup/cmdline.c b/c/src/lib/libbsp/arm/raspberrypi/startup/cmdline.c
index d585e31..9e41813 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/startup/cmdline.c
+++ b/c/src/lib/libbsp/arm/raspberrypi/startup/cmdline.c
@@ -26,7 +26,8 @@ static bcm2835_get_cmdline_entries rpi_cmdline_entries;
 const char *rpi_cmdline_get_raw(void)
 {
   memset(&rpi_cmdline_entries, 0, sizeof(rpi_cmdline_entries));
-  bcm2835_mailbox_get_cmdline(&rpi_cmdline_entries);
+  if (bcm2835_mailbox_get_cmdline(&rpi_cmdline_entries) < 0)
+     return NULL;
   return rpi_cmdline_entries.cmdline;
 }
 
@@ -34,7 +35,8 @@ const char *rpi_cmdline_get_cached(void)
 {
   if (rpi_cmdline_ready <= 0) {
     const char *line = rpi_cmdline_get_raw();
-    strncpy(rpi_cmdline_cached, line, MAX_CMDLINE_LENGTH - 1);
+    if (line != NULL)
+      strncpy(rpi_cmdline_cached, line, MAX_CMDLINE_LENGTH - 1);
     rpi_cmdline_cached[MAX_CMDLINE_LENGTH - 1] = 0;
     rpi_cmdline_ready = 1;
   }



More information about the vc mailing list