rem @echo off
set
set BUILD=Premium
set OLDKERNEL=1

rem cd ..
set ROMHDR=TOOLS\romhdr.bin
set XIP_PATTERNS=BUILDS\%VERSION%\XIP\*;TOOLS\OEMXIPKernel

set SYS_PATTERNS=BUILDS\%VERSION%\COMMON\*;BUILDS\%VERSION%\DPI\*;BUILDS\%VERSION%\%LOCALE%\*

set OEM_PATTERNS=OEM\*;OEM\OEM_Lang_%LOCALE%

set EXT_PATTERNS=EXT\*\*

set DSM_TEMPLATE=723fb954-d931-4348-b672-82a188e587b5.dsm
set DSM_INCLUDES=*.*

echo Creating dump and relocating modules...
.\TOOLS\platformrebuilder.exe
if not "%errorlevel%"=="0" goto error

REM ===========================================================================================
cd temp

echo Copying OS.nb.payload...
copy ..\BUILDS\%VERSION%\nk.nb OS.nb.payload
copy ..\TOOLS\imgfs_%COMPRESS%.src imgfs.src
if not "%errorlevel%"=="0" goto error

echo.
..\TOOLS\IMGFS\ImgfsFromNb   OS.nb.payload imgfs.bin
if not "%errorlevel%"=="0" goto error

..\TOOLS\IMGFS\ImgfsFromDump imgfs.src imgfs-new.bin
if not "%errorlevel%"=="0" goto error

..\TOOLS\IMGFS\ImgfsToNb     imgfs-new.bin OS.nb.payload OS-new.nb -bigstoragemove
if not "%errorlevel%"=="0" goto error

REM ===========================================================================================

del imgfs-new.bin
del imgfs.bin
del OS.nb.payload
rem del OS-new.nb.payload

REM ===========================================================================================

call ..\Tools\FileSize "OS-new.nb" FWSIZE
@echo Firmware size is %FWSIZE% bytes

if %FWSIZE% LSS 74448897 GOTO OK

@echo Firmware size is too big, please select less packages!
exit 100

:OK
echo Size is OK
move OS-new.nb ..\RUU\OS-new.dip
echo Firmware is placed in RUU\OS.dip
..\RUU\SuperRUU.exe
goto :EOF

:error
echo.
echo ERROR! (errorlevel: %errorlevel%)
