1 /*
2  *  BootImageGenerator.cpp
3  *  elftosb
4  *
5  * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
6  * See included license file for license details.
7  */
8 
9 #include "BootImageGenerator.h"
10 #include "Logging.h"
11 
12 //! Name of product version option.
13 #define kProductVersionOption "productVersion"
14 
15 //! Name of component version option.
16 #define kComponentVersionOption "componentVersion"
17 
18 //! Name of option that specifies the drive tag for this .sb file.
19 #define kDriveTagOption "driveTag"
20 
21 using namespace elftosb;
22 
processVersionOptions(BootImage * image)23 void BootImageGenerator::processVersionOptions(BootImage * image)
24 {
25           // bail if no option context was set
26           if (!m_options)
27           {
28                     return;
29           }
30 
31           const StringValue * stringValue;
32           version_t version;
33 
34     // productVersion
35           if (m_options->hasOption(kProductVersionOption))
36           {
37                     stringValue = dynamic_cast<const StringValue *>(m_options->getOption(kProductVersionOption));
38                     if (stringValue)
39                     {
40                               version.set(*stringValue);
41                               image->setProductVersion(version);
42                     }
43         else
44         {
45             Log::log(Logger::WARNING, "warning: productVersion option is an unexpected type\n");
46         }
47           }
48 
49     // componentVersion
50           if (m_options->hasOption(kComponentVersionOption))
51           {
52                     stringValue = dynamic_cast<const StringValue *>(m_options->getOption(kComponentVersionOption));
53                     if (stringValue)
54                     {
55                               version.set(*stringValue);
56                               image->setComponentVersion(version);
57                     }
58         else
59         {
60             Log::log(Logger::WARNING, "warning: componentVersion option is an unexpected type\n");
61         }
62           }
63 }
64 
processDriveTagOption(BootImage * image)65 void BootImageGenerator::processDriveTagOption(BootImage * image)
66 {
67           if (m_options->hasOption(kDriveTagOption))
68           {
69                     const IntegerValue * intValue = dynamic_cast<const IntegerValue *>(m_options->getOption(kDriveTagOption));
70                     if (intValue)
71                     {
72                               image->setDriveTag(intValue->getValue());
73                     }
74         else
75         {
76             Log::log(Logger::WARNING, "warning: driveTag option is an unexpected type\n");
77         }
78           }
79 }
80 
81