After giving the foundation for why I started this project in part one I will now show the steps and give the code for installing MongoDB v2.1.1 on the Raspberry Pi, but first listed are some perquisites.

  • SSH access to the Raspberry Pi, technically not needed but very helpful.
  • A text editor that can open and search through a directory of files. I used TextWrangler.
  • Some other computer to change and modify files prior to building MongoDB. I used a mac and I suggests using some other Unix like system.
  • And just as a note some of commands I included a the unix command prompt other commands are just listed the command without showing the command prompt.

1. Geting MongoDB. I used git hub for this. I would do this on the second Unix system.
git clone git://github.com/mongodb/mongo.git

2. Make sure version r2.1.1 is in the git hub repository.
cd mongo
git tag -l

3. Check out version r2.1.1.
git chekcout r2.1.1

4. Change TIME_UTC for newer gcc and boost capability:
Open the whole mongo folder in a text editor and do a find/replace in all files under the mongo folder for reference to TIME_UTC and replace it with TIME_UTC_ there will be just over 60 reference instances of this macro.

5. Update the inline assembly for atomic integers atomic_int.h I have included the whole file atomic_int.h so just copy this code and paste into original atomic_int.h file replacing the original code.
Before I list the code I would like to give thanks to soywiz for posting the majority of this code on this mongodb forum http://jira.mongodb.org/browse/SERVER-1811 The file is located:
[system@root~]# mongo/src/mongo/bson/util/atomic_int.h
The code is listed at the end of the steps.

6. Zip mongo directory and scp to Rasberry Pi.
[system@root~]# scp mongo.zip root@ipaddress:~/some_upload_dir

7. Compile and install mongodb: ADVISORY: it may take over 24 hours to compile and install. If you don't want to compile all option please visit the MongoDB website for further options.
scons all
scons --prefix=/opt/mongo install
Change the prefix options to install MongoDB in the location of your choice.

  1. // atomic_int.h
  2. // atomic wrapper for unsigned
  3.  
  4. /*    Copyright 2009 10gen Inc.
  5.  *
  6.  *    Licensed under the Apache License, Version 2.0 (the "License");
  7.  *    you may not use this file except in compliance with the License.
  8.  *    You may obtain a copy of the License at
  9.  *
  10.  *    http://www.apache.org/licenses/LICENSE-2.0
  11.  *
  12.  *    Unless required by applicable law or agreed to in writing, software
  13.  *    distributed under the License is distributed on an "AS IS" BASIS,
  14.  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15.  *    See the License for the specific language governing permissions and
  16.  *    limitations under the License.
  17.  */
  18.  
  19. #pragma once
  20.  
  21. namespace mongo {
  22.  
  23.     struct AtomicUInt {
  24.         AtomicUInt() : x(0) {}
  25.         AtomicUInt(unsigned z) : x(z) { }
  26.  
  27.         operator unsigned() const { return x; }
  28.         unsigned get() const { return x; }
  29.  
  30.         inline AtomicUInt operator++(); // ++prefix
  31.         inline AtomicUInt operator++(int);// postfix++
  32.         inline AtomicUInt operator--(); // --prefix
  33.         inline AtomicUInt operator--(int); // postfix--
  34.  
  35.       //  inline void zero();
  36.     inline void zero() { x = 0; } // TODO: this isn't thread safe
  37.         volatile unsigned x;
  38.     };
  39.  
  40. #if defined(__ARMEL__) || defined(__ARM_ARCH_5T__) || defined(__ARM_PCS) || defined(__ARM_EABI__)
  41.  
  42. #define arm_atomic_add_inline(ptr, val) \
  43.      ({ register unsigned int *__ptr asm("r2") = (ptr); \
  44.         register unsigned int __result asm("r1"); \
  45.         asm volatile ( \
  46.             "1: @ atomic_add\n\t" \
  47.             "ldr     r0, [r2]\n\t" \
  48.             "mov     r3, #0xffff0fff\n\t" \
  49.             "add     lr, pc, #4\n\t" \
  50.             "add     r1, r0, %2\n\t" \
  51.             "add     pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \
  52.             "bcc     1b" \
  53.             : "=&r" (__result) \
  54.             : "r" (__ptr), "rIL" (val) \
  55.             : "r0","r3","ip","lr","cc","memory" ); \
  56.         __result; })
  57.  
  58.   #define atomic_int_helper(ptr, val) \
  59.     (arm_atomic_add_inline(ptr, (val)) - (val))
  60.  
  61.    inline void AtomicUInt::set(unsigned newX) { asm volatile("" ::: "memory"); x = newX; }
  62.  
  63.   AtomicUInt AtomicUInt::operator++() {
  64.         return atomic_int_helper((unsigned *)&x, 1)+1;
  65.     }
  66.     AtomicUInt AtomicUInt::operator++(int) {
  67.         return atomic_int_helper((unsigned *)&x, 1);
  68.     }
  69.     AtomicUInt AtomicUInt::operator--() {
  70.         return atomic_int_helper((unsigned *)&x, -1)-1;
  71.     }
  72.     AtomicUInt AtomicUInt::operator--(int) {
  73.         return atomic_int_helper((unsigned *)&x, -1);
  74.     }
  75.  
  76. #else
  77. #error "unsupported compiler or platform"
  78. #endif
  79.  
  80. } // namespace mongo

Comments

Commenting is closed for this article.